From f0ae26721e74af42be0f8d6b6eed19c053305b92 Mon Sep 17 00:00:00 2001 From: Kurund Jalmi Date: Thu, 28 Dec 2023 00:18:36 +0000 Subject: [PATCH] add import functionality --- src/containers/Flow/FlowTranslation.tsx | 28 ++++++++++++++++++++++++- src/graphql/mutations/Flow.ts | 8 ++----- 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/src/containers/Flow/FlowTranslation.tsx b/src/containers/Flow/FlowTranslation.tsx index f2c70875b..f11d4edb6 100644 --- a/src/containers/Flow/FlowTranslation.tsx +++ b/src/containers/Flow/FlowTranslation.tsx @@ -4,11 +4,13 @@ import { DialogBox } from 'components/UI/DialogBox/DialogBox'; import { FormControl, RadioGroup, FormControlLabel, Radio } from '@mui/material'; import { useTranslation } from 'react-i18next'; -import { AUTO_TRANSLATE_FLOW } from 'graphql/mutations/Flow'; +import { AUTO_TRANSLATE_FLOW, IMPORT_FLOW_LOCALIZATIONS } from 'graphql/mutations/Flow'; import { EXPORT_FLOW_LOCALIZATIONS } from 'graphql/queries/Flow'; import { setNotification } from 'common/notification'; import { exportCsvFile } from 'common/utils'; +import { ImportButton } from 'components/UI/ImportButton/ImportButton'; +import { Loading } from 'components/UI/Layout/Loading/Loading'; import styles from './FlowTranslation.module.css'; export interface FlowTranslationProps { @@ -18,6 +20,7 @@ export interface FlowTranslationProps { export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => { const [action, setAction] = useState('auto'); + const [importing, setImporting] = useState(false); const { t } = useTranslation(); @@ -46,6 +49,13 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => }, }); + const [importFlow] = useMutation(IMPORT_FLOW_LOCALIZATIONS, { + onCompleted: (result: any) => { + const { status } = result.importFlow; + setImporting(false); + }, + }); + const handleAuto = () => { autoTranslateFlow({ variables: { id: flowId } }); }; @@ -72,6 +82,20 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => setAction((event.target as HTMLInputElement).value); }; + const importButton = ( + setImporting(true)} + afterImport={(result: string) => + importFlow({ variables: { localization: result, id: flowId } }) + } + /> + ); + + if (importing) { + return ; + } + const dialogContent = (
@@ -85,6 +109,7 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => } label={t('Export translations')} /> } label={t('Import translations')} /> + {action === 'import' ? importButton : ''}
); @@ -100,6 +125,7 @@ export const FlowTranslation = ({ flowId, setDialog }: FlowTranslationProps) => handleCancel={() => { setDialog(false); }} + skipOk={action === 'import'} > {dialogContent} diff --git a/src/graphql/mutations/Flow.ts b/src/graphql/mutations/Flow.ts index fdaeb37be..0c6ad8eb3 100644 --- a/src/graphql/mutations/Flow.ts +++ b/src/graphql/mutations/Flow.ts @@ -139,13 +139,9 @@ export const AUTO_TRANSLATE_FLOW = gql` `; export const IMPORT_FLOW_LOCALIZATIONS = gql` - mutation importFlowLocalization($id: ID!) { - importFlowLocalization(id: $id) { + mutation importFlowLocalization($localization: String!, $id: ID!) { + importFlowLocalization(localization: $localization, id: $id) { success - errors { - key - message - } } } `;