Skip to content

Commit

Permalink
Handle assign errors better in the frontend
Browse files Browse the repository at this point in the history
  • Loading branch information
kristoferlund committed Sep 9, 2022
1 parent f9d93ac commit 7c29c35
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
6 changes: 5 additions & 1 deletion packages/frontend/src/model/periods.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ import {
periodReceiverPraiseListKey,
} from '@/utils/periods';
import { useApiAuthClient } from '@/utils/api';
import { ApiAuthGet, isResponseOk } from './api';
import { ApiAuthGet, isApiResponseAxiosError, isResponseOk } from './api';
import { ActiveUserId } from './auth';
import { AllPraiseList, PraiseIdList, SinglePraise } from './praise';
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Expand Down Expand Up @@ -353,6 +353,10 @@ export const useAssignQuantifiers = (
status: 'QUANTIFY' as PeriodStatusType,
};
setPeriod(updatedPeriod);
return response as AxiosResponse<PeriodDetailsDto>;
}
if (isApiResponseAxiosError(response)) {
throw response;
}
return response as AxiosResponse | AxiosError;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,29 @@ export const PeriodDetails = (): JSX.Element | null => {
};

const handleAssign = (): void => {
const toastId = 'assignToast';
const promise = assignQuantifiers();
void toast.promise(
promise,
{
loading: 'Assigning quantifiers …',
success: 'Quantifiers assigned',
error: 'Assign failed',
success: () => {
setTimeout(() => history.go(0), 2000);
return 'Quantifiers assigned';
},
error: () => {
setTimeout(() => toast.remove(toastId), 2000);
return 'Assign failed';
},
},
{
id: toastId,
position: 'top-center',
loading: {
duration: Infinity,
},
}
);
promise.finally(() => setTimeout(() => history.go(0), 1000));
};

const handleExport = (): void => {
Expand Down

0 comments on commit 7c29c35

Please sign in to comment.