aboutsummaryrefslogtreecommitdiff
path: root/modern/src/common/components/RemoveDialog.js
diff options
context:
space:
mode:
authorAnton Tananaev <anton@traccar.org>2022-05-08 11:48:09 -0700
committerAnton Tananaev <anton@traccar.org>2022-05-08 11:48:09 -0700
commit2352071211b61c10fa5bf5736baaff7809d18bf0 (patch)
tree743e4adc1cc35fb3585b912daaa8719ae5757f60 /modern/src/common/components/RemoveDialog.js
parent044733ff543156d76437daae8edb66850d785ac9 (diff)
downloadtrackermap-web-2352071211b61c10fa5bf5736baaff7809d18bf0.tar.gz
trackermap-web-2352071211b61c10fa5bf5736baaff7809d18bf0.tar.bz2
trackermap-web-2352071211b61c10fa5bf5736baaff7809d18bf0.zip
Organize common code
Diffstat (limited to 'modern/src/common/components/RemoveDialog.js')
-rw-r--r--modern/src/common/components/RemoveDialog.js37
1 files changed, 37 insertions, 0 deletions
diff --git a/modern/src/common/components/RemoveDialog.js b/modern/src/common/components/RemoveDialog.js
new file mode 100644
index 00000000..1b75e926
--- /dev/null
+++ b/modern/src/common/components/RemoveDialog.js
@@ -0,0 +1,37 @@
+import React from 'react';
+import Button from '@material-ui/core/Button';
+import Dialog from '@material-ui/core/Dialog';
+import DialogActions from '@material-ui/core/DialogActions';
+import DialogContent from '@material-ui/core/DialogContent';
+import DialogContentText from '@material-ui/core/DialogContentText';
+import { useTranslation } from '../../LocalizationProvider';
+
+const RemoveDialog = ({
+ open, endpoint, itemId, onResult,
+}) => {
+ const t = useTranslation();
+
+ const handleRemove = async () => {
+ const response = await fetch(`/api/${endpoint}/${itemId}`, { method: 'DELETE' });
+ if (response.ok) {
+ onResult(true);
+ }
+ };
+
+ return (
+ <Dialog
+ open={open}
+ onClose={() => { onResult(false); }}
+ >
+ <DialogContent>
+ <DialogContentText>{t('sharedRemoveConfirm')}</DialogContentText>
+ </DialogContent>
+ <DialogActions>
+ <Button color="primary" onClick={handleRemove}>{t('sharedRemove')}</Button>
+ <Button autoFocus onClick={() => onResult(false)}>{t('sharedCancel')}</Button>
+ </DialogActions>
+ </Dialog>
+ );
+};
+
+export default RemoveDialog;