From e0637f6739de194d8214a4f345fc6e86e088b6a4 Mon Sep 17 00:00:00 2001 From: Carlos Valente Date: Fri, 25 Oct 2024 08:36:54 +0200 Subject: [PATCH] refactor: clear state on sheet flows --- .../panel/sources-panel/SourcesPanel.tsx | 27 ++++++++++--------- .../import-map/ImportMapForm.tsx | 2 +- 2 files changed, 15 insertions(+), 14 deletions(-) diff --git a/apps/client/src/features/app-settings/panel/sources-panel/SourcesPanel.tsx b/apps/client/src/features/app-settings/panel/sources-panel/SourcesPanel.tsx index ed6f5fdcab..f68420c4a5 100644 --- a/apps/client/src/features/app-settings/panel/sources-panel/SourcesPanel.tsx +++ b/apps/client/src/features/app-settings/panel/sources-panel/SourcesPanel.tsx @@ -70,6 +70,17 @@ export default function SourcesPanel() { fileInputRef.current?.click(); }; + const resetFlow = () => { + // we purposely omit clearing the authentication status + setImportFlow('none'); + setRundown(null); + setHasFile('none'); + setWorksheets(null); + setCustomFields(null); + setError(''); + setSheetId(null); + }; + const openGSheetFlow = async () => { const result = await verifyAuth(); if (result) { @@ -89,7 +100,7 @@ export default function SourcesPanel() { }; const cancelGSheetFlow = () => { - setImportFlow('none'); + resetFlow(); }; const handleSubmitImportPreview = async (importMap: ImportMap) => { @@ -110,9 +121,7 @@ export default function SourcesPanel() { }; const cancelImportMap = async () => { - setImportFlow('none'); - setHasFile('none'); - setWorksheets(null); + resetFlow(); if (authenticationStatus === 'authenticated') { const result = await verifyAuth(); if (result) { @@ -127,6 +136,7 @@ export default function SourcesPanel() { setHasFile('none'); setWorksheets(null); setCustomFields(null); + setError(''); }; const handleSubmitExport = async (importMap: ImportMap) => { @@ -134,15 +144,6 @@ export default function SourcesPanel() { await exportRundown(sheetId, importMap); }; - const resetFlow = () => { - setImportFlow('none'); - setRundown(null); - setHasFile('none'); - setWorksheets(null); - setCustomFields(null); - setError(''); - }; - const isExcelFlow = importFlow === 'excel'; const isGSheetFlow = importFlow === 'gsheet'; const isAuthenticated = authenticationStatus === 'authenticated'; diff --git a/apps/client/src/features/app-settings/panel/sources-panel/import-map/ImportMapForm.tsx b/apps/client/src/features/app-settings/panel/sources-panel/import-map/ImportMapForm.tsx index 87467ee597..2c009342a4 100644 --- a/apps/client/src/features/app-settings/panel/sources-panel/import-map/ImportMapForm.tsx +++ b/apps/client/src/features/app-settings/panel/sources-panel/import-map/ImportMapForm.tsx @@ -121,7 +121,7 @@ export default function ImportMapForm(props: ImportMapFormProps) { Ontime field - From spreadsheet name + Column name in spreadsheet