This repository has been archived by the owner on Sep 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 135
/
DeleteSiteButton.js
78 lines (73 loc) · 1.84 KB
/
DeleteSiteButton.js
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
import React, { useState, useRef } from 'react';
import { mutate } from 'swr';
import {
AlertDialog,
AlertDialogBody,
AlertDialogFooter,
AlertDialogHeader,
AlertDialogContent,
AlertDialogOverlay,
IconButton,
Button
} from '@chakra-ui/core';
import { deleteSite } from '@/lib/db';
import { useAuth } from '@/lib/auth';
const DeleteSitebutton = ({ siteId }) => {
const [isOpen, setIsOpen] = useState();
const cancelRef = useRef();
const auth = useAuth();
const onClose = () => setIsOpen(false);
const onDelete = () => {
deleteSite(siteId);
mutate(
['/api/sites', auth.user.token],
async (data) => {
return {
sites: data.sites.filter((site) => site.id !== siteId)
};
},
false
);
onClose();
};
return (
<>
<IconButton
aria-label="Delete site"
icon="delete"
variant="ghost"
onClick={() => setIsOpen(true)}
/>
<AlertDialog
isOpen={isOpen}
leastDestructiveRef={cancelRef}
onClose={onClose}
>
<AlertDialogOverlay />
<AlertDialogContent>
<AlertDialogHeader fontSize="lg" fontWeight="bold">
Delete Site
</AlertDialogHeader>
<AlertDialogBody>
Are you sure? This will also delete all feedback left on the site.
You can't undo this action afterwards.
</AlertDialogBody>
<AlertDialogFooter>
<Button ref={cancelRef} onClick={onClose}>
Cancel
</Button>
<Button
fontWeight="bold"
variantColor="red"
onClick={onDelete}
ml={3}
>
Delete
</Button>
</AlertDialogFooter>
</AlertDialogContent>
</AlertDialog>
</>
);
};
export default DeleteSitebutton;