Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor: clear state on sheet flows #1296

Merged
merged 1 commit into from
Oct 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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