From ac61f257c078c7a297f54421474ae7717e7a1d0b Mon Sep 17 00:00:00 2001 From: Shobhit-Nagpal Date: Mon, 12 May 2025 14:31:27 +0530 Subject: [PATCH] fix: import preview enable after error --- .../app-settings/panel/sources-panel/SourcesPanel.tsx | 1 + .../panel/sources-panel/import-map/ImportMapForm.tsx | 11 ++++++++++- 2 files changed, 11 insertions(+), 1 deletion(-) 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 7e7a1bf12..850c80669 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 @@ -103,6 +103,7 @@ export default function SourcesPanel() { }; const handleSubmitImportPreview = async (importMap: ImportMap) => { + setError(''); // to clear previous error if (importFlow === 'excel') { try { const previewData = await importRundownPreviewExcel(importMap); 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 34252e1b8..a678debdf 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 @@ -1,4 +1,4 @@ -import { useState } from 'react'; +import { useEffect, useState } from 'react'; import { useFieldArray, useForm } from 'react-hook-form'; import { IoAdd, IoTrash } from 'react-icons/io5'; import { Button, IconButton, Input, Select, Tooltip } from '@chakra-ui/react'; @@ -28,6 +28,7 @@ export default function ImportMapForm(props: ImportMapFormProps) { control, handleSubmit, register, + setValue, formState: { errors, isValid }, } = useForm({ mode: 'onChange', @@ -45,6 +46,14 @@ export default function ImportMapForm(props: ImportMapFormProps) { const [loading, setLoading] = useState<'' | 'export' | 'import'>(''); + // Set first sheet as default worksheet when 'event schedule' sheet is not there + useEffect(() => { + if (!worksheetNames || worksheetNames.length === 0) return; + if (!worksheetNames.includes(namedImportMap.Worksheet)) { + setValue('Worksheet', worksheetNames[0], { shouldValidate: true, shouldDirty: true }); + } + }, [worksheetNames, setValue, namedImportMap.Worksheet]); + const handleExport = async (values: NamedImportMap) => { setLoading('export'); const importMap = convertToImportMap(values);