From 6cd2a41a531c815b813e13d3ce8deeac000f8ef1 Mon Sep 17 00:00:00 2001 From: mdshamoon Date: Mon, 15 Jan 2024 16:14:37 +0530 Subject: [PATCH 1/2] added fix for translation --- src/components/floweditor/FlowEditor.tsx | 26 ++++++++++++++---------- src/graphql/queries/Organization.ts | 1 + src/services/AuthService.tsx | 11 +++++++++- 3 files changed, 26 insertions(+), 12 deletions(-) diff --git a/src/components/floweditor/FlowEditor.tsx b/src/components/floweditor/FlowEditor.tsx index 476bc32be..6584e9e00 100644 --- a/src/components/floweditor/FlowEditor.tsx +++ b/src/components/floweditor/FlowEditor.tsx @@ -15,7 +15,7 @@ import { DialogBox } from 'components/UI/DialogBox/DialogBox'; import { setNotification } from 'common/notification'; import { PUBLISH_FLOW, RESET_FLOW_COUNT } from 'graphql/mutations/Flow'; import { EXPORT_FLOW, GET_FLOW_DETAILS, GET_FREE_FLOW } from 'graphql/queries/Flow'; -import { setAuthHeaders } from 'services/AuthService'; +import { getOrganizationServices, setAuthHeaders } from 'services/AuthService'; import { SideDrawerContext } from 'context/session'; import { Loading } from 'components/UI/Layout/Loading/Loading'; import Track from 'services/TrackService'; @@ -48,6 +48,7 @@ export const FlowEditor = () => { const [currentEditDialogBox, setCurrentEditDialogBox] = useState(false); const [dialogMessage, setDialogMessage] = useState(''); const { drawerOpen } = useContext(SideDrawerContext); + const isTranslationEnabled = getOrganizationServices('autoTranslationEnabled'); let modal = null; let dialog = null; @@ -420,16 +421,19 @@ export const FlowEditor = () => { > Reset flow counts - + + {isTranslationEnabled && ( + + )}
{loading && } diff --git a/src/graphql/queries/Organization.ts b/src/graphql/queries/Organization.ts index 8235b0592..cc4f3a05f 100644 --- a/src/graphql/queries/Organization.ts +++ b/src/graphql/queries/Organization.ts @@ -115,6 +115,7 @@ export const GET_ORGANIZATION_SERVICES = gql` query organizationServices { organizationServices { dialogflow + autoTranslationEnabled googleCloudStorage flowUuidDisplay rolesAndPermission diff --git a/src/services/AuthService.tsx b/src/services/AuthService.tsx index cc9e6ad86..ab849aa01 100644 --- a/src/services/AuthService.tsx +++ b/src/services/AuthService.tsx @@ -9,6 +9,15 @@ interface RegisterRequest { token?: string; } +type ServiceType = + | 'dialogflow' + | 'autoTranslationEnabled' + | 'googleCloudStorage' + | 'flowUuidDisplay' + | 'rolesAndPermission' + | 'contactProfileEnabled' + | 'ticketingEnabled'; + // get the current authentication session export const getAuthSession = (element?: string) => { const session = localStorage.getItem('glific_session'); @@ -172,7 +181,7 @@ export const setOrganizationServices = (services: string) => { localStorage.setItem('organizationServices', services); }; -export const getOrganizationServices = (service: string) => { +export const getOrganizationServices = (service: ServiceType) => { let services: any = localStorage.getItem('organizationServices'); if (!services) return null; services = JSON.parse(services); From 9030e71e5e114674911184a035a4ca422fd020a6 Mon Sep 17 00:00:00 2001 From: mdshamoon Date: Mon, 15 Jan 2024 16:18:12 +0530 Subject: [PATCH 2/2] added error handling --- src/containers/Flow/FlowTranslation.tsx | 4 ++++ src/i18n/en/en.json | 3 ++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/containers/Flow/FlowTranslation.tsx b/src/containers/Flow/FlowTranslation.tsx index 7ec02fa77..4a83e6f54 100644 --- a/src/containers/Flow/FlowTranslation.tsx +++ b/src/containers/Flow/FlowTranslation.tsx @@ -47,6 +47,10 @@ export const FlowTranslation = ({ flowId, setDialog, loadFlowEditor }: FlowTrans setNotification(inlineFlowLocalization.errors[0].message, 'warning'); } }, + onError: () => { + setDialog(false); + setNotification(t('An error occured while translating flows.')); + }, }); const [exportFlowTranslations, { loading: exportLoad }] = useLazyQuery( diff --git a/src/i18n/en/en.json b/src/i18n/en/en.json index 6e7f5b54f..8a91f6e65 100644 --- a/src/i18n/en/en.json +++ b/src/i18n/en/en.json @@ -441,5 +441,6 @@ "Request JSON": "Request JSON", "Response JSON": "Response JSON", "Webhook Logs": "Webhook Logs", - "Translate": "Translate" + "Translate": "Translate", + "An error occured while translating flows.": "An error occured while translating flows." }