From f442cb8d74ee82f7150d63dc63161c9aaed51003 Mon Sep 17 00:00:00 2001 From: Igor Santos Date: Wed, 30 Oct 2024 11:44:24 -0300 Subject: [PATCH] fix(webpage): remove OpenAPI config and phone pressure --- clients/deploy/docker-compose.yml | 3 - .../src/components/PressurePhoneConnected.tsx | 159 +----------------- .../src/pages/api/campaigns/[widget_id].ts | 30 ---- 3 files changed, 2 insertions(+), 190 deletions(-) delete mode 100644 clients/packages/webpage-client/src/pages/api/campaigns/[widget_id].ts diff --git a/clients/deploy/docker-compose.yml b/clients/deploy/docker-compose.yml index 51e9ba5b18..3cf665bb32 100644 --- a/clients/deploy/docker-compose.yml +++ b/clients/deploy/docker-compose.yml @@ -84,9 +84,6 @@ services: - REACT_APP_DOMAIN_API_REST=${PUBLIC_REST_API:-http://api-rest.bonde.devel} - REACT_APP_DOMAIN_PUBLIC=${DEFAULT_DOMAIN_RULE:-bonde.devel} - REACT_APP_ACTIVE_API_CACHE=${ACTIVE_API_CACHE:-false} - - REACT_APP_OPENAPI_URL=${PUBLIC_OPENAPI_URL:-https://openapi.staging.bonde.org} - - REACT_APP_OPENAPI_TOKEN=${PUBLIC_OPENAPI_TOKEN} - - REACT_APP_OPENAPI_CAMPAIGN_ID=${PUBLIC_OPENAPI_CAMPAIGN_ID} healthcheck: test: "${DOCKER_WEB_HEALTHCHECK_TEST:-wget -qO- localhost:3000/api/ping}" interval: "60s" diff --git a/clients/packages/webpage-client/src/components/PressurePhoneConnected.tsx b/clients/packages/webpage-client/src/components/PressurePhoneConnected.tsx index 8c823943bd..4fa7583eef 100644 --- a/clients/packages/webpage-client/src/components/PressurePhoneConnected.tsx +++ b/clients/packages/webpage-client/src/components/PressurePhoneConnected.tsx @@ -1,161 +1,6 @@ -import { useEffect, useState } from 'react'; -import { gql } from '@apollo/client'; -import { - PressureAnalytics, - FinishMessageCustom, - PressureTellAFriend, -} from '../bonde-webpage'; -import Utils from '../Utils'; - -import { - PhonePressurePlugin, - // asyncFillWidget, - // selectors as MobSelectors, -} from '../bonde-webpage'; -import { client } from '../apis/graphql'; - -export const addTwilioCall = gql` - mutation addTwilioCall( - $widgetId: Int! - $communityId: Int! - $from: String! - $to: String! - ) { - addTwilioCall( - input: { - call: { - widgetId: $widgetId - communityId: $communityId - from: $from - to: $to - } - } - ) { - twilioCall { - id - widgetId - activistId - twilioAccountSid - twilioCallSid - from - to - data - createdAt - updatedAt - communityId - } - } - } -`; - -export const watchTwilioCallTransitions = gql` - query watchTwilioCallTransitions($widgetId: Int!, $from: String!) { - watchTwilioCallTransitions(call: { widgetId: $widgetId, from: $from }) { - widgetId - activistId - twilioCallId - twilioCallAccountSid - twilioCallCallSid - twilioCallFrom - twilioCallTo - twilioCallTransitionId - twilioCallTransitionSequenceNumber - twilioCallTransitionStatus - twilioCallTransitionCallDuration - twilioCallTransitionCreatedAt - twilioCallTransitionUpdatedAt - } - } -`; - -export const countTwilioCallsByWidget = gql` - query CountTwilioCallsByWidget($widgetId: Int!) { - allTwilioCalls(condition: { widgetId: $widgetId }) { - totalCount - } - } -`; - -const TwilioCall = ({ children, totalCount }) => { - const [phonePressureCount, setPhonePressureCount] = useState(0); - const [callTransition, setCallTransition] = useState(null); - const [observableQuery, setObservableQuery] = useState(null); - - useEffect(() => { - if (totalCount > phonePressureCount) { - setPhonePressureCount(totalCount); - } - }, [totalCount]); - - const call = (variables: any, watchQuery = false) => { - setPhonePressureCount(phonePressureCount + 1); - return client.mutate({ mutation: addTwilioCall, variables }).then(() => { - if (watchQuery && !observableQuery) { - const observable = client.watchQuery({ - pollInterval: 2000, - query: watchTwilioCallTransitions, - variables: { widgetId: variables.widgetId, from: variables.from }, - }); - observable.subscribe({ - next: ({ - data: { watchTwilioCallTransitions: transitions }, - }: any) => { - setCallTransition(transitions); - }, - }); - setObservableQuery(observable); - } - }); - }; - - return children({ - call, - callTransition, - observableQuery, - phonePressureCount, - }); -}; - -// const mapDispatchToProps = { asyncFillWidget }; - -// const mapStateToProps = (state: any) => -// MobSelectors(state).getMobilizationLink(); - -const PressurePhoneConnected = (props: any) => { - const [totalCount, setTotalCount] = useState(0); - - useEffect(() => { - client - .query({ - query: countTwilioCallsByWidget, - variables: { widgetId: props.widget.id }, - }) - .then(({ data }) => { - setTotalCount(data.allTwilioCalls.totalCount); - }); - }, []); - +const PressurePhoneConnected = () => { return ( - - {(twilio: any) => - console.log("should be implement asyncFillWidget >>> ", { values })} - twilio={twilio} - analyticsEvents={PressureAnalytics} - overrides={{ - FinishCustomMessage: { component: FinishMessageCustom }, - FinishDefaultMessage: { - component: PressureTellAFriend, - props: { - imageUrl: Utils.imageUrl, - href: Utils.getSharedPath(props.mobilization), - }, - }, - }} - /> - } - +
); }; diff --git a/clients/packages/webpage-client/src/pages/api/campaigns/[widget_id].ts b/clients/packages/webpage-client/src/pages/api/campaigns/[widget_id].ts deleted file mode 100644 index 0001d01da7..0000000000 --- a/clients/packages/webpage-client/src/pages/api/campaigns/[widget_id].ts +++ /dev/null @@ -1,30 +0,0 @@ -import getConfig from 'next/config' - -interface Request { - method: 'GET', - query: { - widget_id: number - } -} - -const { - publicRuntimeConfig: { openApiUrl, openApiCampaignId }, - serverRuntimeConfig: { openApiToken } -} = getConfig(); - -const campaign_id = openApiCampaignId; - -export default async (req: Request, res: any) => { - if (req.method === 'GET') { - // const { widget_id } = req.query - const endpoint = `${openApiUrl}/api/campaigns/${campaign_id}/`; - const response = await fetch(endpoint, { - method: 'GET', - headers: { 'Content-Type': 'application/json', 'OpenAPI-Token': openApiToken } - }) - - return res.status(200).json(await response.json()) - } - - return res.status(400) -} \ No newline at end of file