Skip to content

Commit 64f892c

Browse files
committed
Add a loading state to the dialog as well as an alert if there was an error
1 parent a27e8fb commit 64f892c

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

frontends/main/src/app-pages/DashboardPage/CoursewareDisplay/DashboardDialogs.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
Stack,
88
Alert,
99
Checkbox,
10+
CircularProgress,
1011
} from "ol-components"
1112
import { Button } from "@mitodl/smoot-design"
1213

@@ -18,6 +19,10 @@ const BoldText = styled.span(({ theme }) => ({
1819
...theme.typography.subtitle1,
1920
}))
2021

22+
const ButtonCircularProgress = styled(CircularProgress)({
23+
marginLeft: "8px",
24+
})
25+
2126
type DashboardDialogProps = {
2227
title: string
2328
enrollmentId: number
@@ -94,7 +99,9 @@ const UnenrollDialogInner: React.FC<DashboardDialogProps> = ({
9499
initialValues: {},
95100
onSubmit: async () => {
96101
await destroyEnrollment.mutateAsync()
97-
modal.hide()
102+
if (!destroyEnrollment.isError) {
103+
modal.hide()
104+
}
98105
},
99106
})
100107
return (
@@ -114,15 +121,28 @@ const UnenrollDialogInner: React.FC<DashboardDialogProps> = ({
114121
>
115122
Cancel
116123
</Button>
117-
<Button variant="primary" type="submit">
124+
<Button
125+
variant="primary"
126+
type="submit"
127+
disabled={destroyEnrollment.isPending}
128+
>
118129
Unenroll
130+
{destroyEnrollment.isPending ? (
131+
<ButtonCircularProgress size={16} />
132+
) : null}
119133
</Button>
120134
</DialogActions>
121135
}
122136
>
123137
<Typography variant="body1">
124138
Are you sure you want to unenroll from {title}?
125139
</Typography>
140+
{destroyEnrollment.isError && (
141+
<Alert severity="error">
142+
There was a problem unenrolling you from this course. Please try again
143+
later.
144+
</Alert>
145+
)}
126146
</FormDialog>
127147
)
128148
}

0 commit comments

Comments
 (0)