Skip to content

Commit

Permalink
refactor: clear state on sheet flows
Browse files Browse the repository at this point in the history
  • Loading branch information
cpvalente committed Oct 25, 2024
1 parent 46e9fcb commit e0637f6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -89,7 +100,7 @@ export default function SourcesPanel() {
};

const cancelGSheetFlow = () => {
setImportFlow('none');
resetFlow();
};

const handleSubmitImportPreview = async (importMap: ImportMap) => {
Expand All @@ -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) {
Expand All @@ -127,22 +136,14 @@ export default function SourcesPanel() {
setHasFile('none');
setWorksheets(null);
setCustomFields(null);
setError('');
};

const handleSubmitExport = async (importMap: ImportMap) => {
if (!sheetId) return;
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';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ export default function ImportMapForm(props: ImportMapFormProps) {
<thead>
<tr>
<th>Ontime field</th>
<th>From spreadsheet name</th>
<th>Column name in spreadsheet</th>
<th className={style.singleActionCell} />
</tr>
</thead>
Expand Down

0 comments on commit e0637f6

Please sign in to comment.