forked from tl-its-umich-edu/canvas-course-manager-next
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConfirmDialog.tsx
91 lines (79 loc) · 2.2 KB
/
ConfirmDialog.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
import React from 'react'
import { styled } from '@mui/material/styles'
import { Button, Paper, Typography } from '@mui/material'
import { CloudDone as CloudDoneIcon } from '@mui/icons-material'
import { DownloadData } from '../models/models.js'
const PREFIX = 'ConfirmDialog'
const classes = {
padding: `${PREFIX}-padding`,
dialog: `${PREFIX}-dialog`,
dialogIcon: `${PREFIX}-dialogIcon`,
dialogButton: `${PREFIX}-dialogButton`
}
const Root = styled('div')((
{
theme
}
) => ({
[`& .${classes.padding}`]: {
padding: theme.spacing(1)
},
[`&.${classes.dialog}`]: {
textAlign: 'center',
margin: 'auto',
marginTop: 30,
marginBottom: 15
},
[`& .${classes.dialogIcon}`]: {
color: theme.palette.info.main
},
[`& .${classes.dialogButton}`]: {
margin: 5
}
}))
interface ConfirmDialogProps {
title?: string
message?: string
icon?: JSX.Element
cancel: () => void
submit: (() => void) | (() => Promise<void>)
download?: DownloadData
disabled?: boolean
}
export default function ConfirmDialog (props: ConfirmDialogProps): JSX.Element {
const defaultTitle = 'Review your CSV file'
const defaultMessage = 'Your file is valid! If this looks correct, click "Submit" to proceed.'
let downloadProps
if (props.download !== undefined) {
downloadProps = {
component: 'a',
href: props.download.data,
download: props.download.fileName
}
}
const submitButton = (
<Button
className={classes.dialogButton}
variant='contained'
color='primary'
onClick={props.submit}
disabled={props.disabled}
{...downloadProps}
>
Submit
</Button>
)
return (
<Root className={classes.dialog}>
<Paper className={classes.padding} role='status'>
<Typography>{props.title ?? defaultTitle}</Typography>
{props.icon !== undefined ? props.icon : <CloudDoneIcon className={classes.dialogIcon} fontSize='large' />}
<Typography gutterBottom>{props.message ?? defaultMessage}</Typography>
<Button className={classes.dialogButton} variant='outlined' onClick={props.cancel} disabled={props.disabled}>
Cancel
</Button>
{submitButton}
</Paper>
</Root>
)
}