Skip to content

Commit

Permalink
feat: add loading states to inclusion and exclusion modals
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuhanming committed Jun 2, 2024
1 parent 764442a commit d83d608
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
11 changes: 11 additions & 0 deletions src/routes/admin/windows/ViewWindow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ interface State {
partnerViewed: StudentBase | null;
isAutoExclusionModalShown: boolean;
isPairStudentsModalShown: boolean;
isExcluding: boolean;
isIncluding: boolean;
isAutoExcluding: boolean;
isPairingStudents: boolean;
}
Expand All @@ -62,6 +64,13 @@ export const ViewWindow = (): ReactElement<typeof ViewWindowPage> => {
studentBeingIncluded: null,
submissionsViewed: null,
interviewsViewed: null,
partnerViewed: null,
isAutoExclusionModalShown: false,
isPairStudentsModalShown: false,
isExcluding: false,
isIncluding: false,
isAutoExcluding: false,
isPairingStudents: false,
} as State,
);
const toast = useToast();
Expand Down Expand Up @@ -301,12 +310,14 @@ export const ViewWindow = (): ReactElement<typeof ViewWindowPage> => {
window={window}
/>
<ConfirmExclusion
isLoading={state.isExcluding}
isOpen={studentBeingExcluded != null}
name={studentBeingExcluded?.name ?? ''}
onClose={(): void => setState({ studentBeingExcluded: null })}
onConfirmExclude={onConfirmExclude}
/>
<ConfirmInclusion
isLoading={state.isIncluding}
isOpen={studentBeingIncluded != null}
name={studentBeingIncluded?.name ?? ''}
onClose={(): void => setState({ studentBeingIncluded: null })}
Expand Down
8 changes: 6 additions & 2 deletions src/routes/admin/windows/modals/ConfirmExclusion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ import { Button, FormControl, FormLabel, Stack, Text } from '@chakra-ui/react';

import { Modal } from '@/components/modal';
import { Select } from '@/components/select';
import { emptyFunction } from '@/utils/functionUtils';

interface Props {
isOpen: boolean;
isLoading: boolean;
onClose: () => void;
name: string;
onConfirmExclude: (reason: string) => void | Promise<void>;
Expand All @@ -27,6 +29,7 @@ interface ReasonOption {

export const ConfirmExclusion = ({
isOpen,
isLoading,
onClose,
name,
onConfirmExclude,
Expand All @@ -50,11 +53,12 @@ export const ConfirmExclusion = ({
<Modal
actions={
<Stack direction="row" spacing={2}>
<Button onClick={onClose} variant="secondary">
<Button isDisabled={isLoading} onClick={onClose} variant="secondary">
Cancel
</Button>
<Button
isDisabled={reason == null || reason === ''}
isLoading={isLoading}
onClick={handleExclude}
variant="primary"
>
Expand All @@ -63,7 +67,7 @@ export const ConfirmExclusion = ({
</Stack>
}
isOpen={isOpen}
onClose={onClose}
onClose={isLoading ? emptyFunction : onClose}
size="md"
title={`Exclude ${name}?`}
>
Expand Down
13 changes: 10 additions & 3 deletions src/routes/admin/windows/modals/ConfirmInclusion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ import { ReactElement } from 'react';
import { Button, Stack, Text } from '@chakra-ui/react';

import { Modal } from '@/components/modal';
import { emptyFunction } from '@/utils/functionUtils';

interface Props {
isOpen: boolean;
isLoading: boolean;
onClose: () => void;
name: string;
onConfirmInclude: () => void | Promise<void>;
}

export const ConfirmInclusion = ({
isOpen,
isLoading,
onClose,
name,
onConfirmInclude,
Expand All @@ -20,16 +23,20 @@ export const ConfirmInclusion = ({
<Modal
actions={
<Stack direction="row" spacing={2}>
<Button onClick={onClose} variant="secondary">
<Button isDisabled={isLoading} onClick={onClose} variant="secondary">
Cancel
</Button>
<Button onClick={onConfirmInclude} variant="primary">
<Button
isLoading={isLoading}
onClick={onConfirmInclude}
variant="primary"
>
Include
</Button>
</Stack>
}
isOpen={isOpen}
onClose={onClose}
onClose={isLoading ? emptyFunction : onClose}
title={`Include ${name}?`}
>
<Text>Are you sure you wish to include {name}?</Text>
Expand Down

0 comments on commit d83d608

Please sign in to comment.