File size: 1,935 Bytes
f5071ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import {
   Box,
   Modal,
   ModalBody,
   ModalCloseButton,
   ModalContent,
   ModalHeader,
   ModalOverlay,
   useColorModeValue,
   useDisclosure,
} from '@chakra-ui/react';
import { VscClose } from 'react-icons/vsc';
import { useNavigate } from 'react-router-dom';
import { BtnDefault, BtnRed, SecondaryBtn } from '../utils/Buttons';

const LeavePageAlert = () => {
   const { isOpen, onOpen, onClose } = useDisclosure();

   const navigate = useNavigate();

   return (
      <>
         <SecondaryBtn onClick={onOpen}>
            <VscClose size={23} />
         </SecondaryBtn>
         <Modal
            isCentered
            onClose={onClose}
            isOpen={isOpen}
            motionPreset='none'
            closeOnOverlayClick={false}
            size={{ base: 'full', md: '2xl' }}
         >
            <ModalOverlay />
            <ModalContent
               bg={useColorModeValue('light.cardBg', 'dark.cardBg')}
               className='shadow'
            >
               <ModalHeader
                  borderBottom='1px solid'
                  borderBottomColor={useColorModeValue(
                     'light.cardBorder',
                     'dark.cardBorder'
                  )}
                  p='1rem'
               >
                  You have unsaved changes
               </ModalHeader>
               <ModalCloseButton />
               <ModalBody mt='1rem' p='.5rem 1rem'>
                  You've made changes to your post. Do you want to navigate to
                  leave this page?
                  <Box mt={5} mb={3}>
                     <BtnRed mr={2} onClick={() => navigate(-1)}>
                        Leave the page
                     </BtnRed>

                     <BtnDefault onClick={onClose}>Keep editing</BtnDefault>
                  </Box>
               </ModalBody>
            </ModalContent>
         </Modal>
      </>
   );
};

export default LeavePageAlert;