File size: 3,240 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import {
   Image,
   Modal,
   ModalBody,
   ModalCloseButton,
   ModalContent,
   ModalHeader,
   ModalOverlay,
   Text,
   useColorModeValue,
   useDisclosure,
   VStack,
} from '@chakra-ui/react';
import React, { useEffect } from 'react';
import { PrimaryBtn, SecondaryBtn } from '../utils/Buttons';
import Logo from '../assets/images/logo.png';
import { useLocation, useNavigate } from 'react-router-dom';
import { useDispatch, useSelector } from 'react-redux';
import { setLoginAlert } from '../store/loginAlert';

const LoginAlert = () => {
   const { onClose } = useDisclosure();
   const dispatch = useDispatch();
   const loginAlert = useSelector((state) => state.loginAlert.showLoginAlert);

   const navigate = useNavigate();
   const location = useLocation();

   const handleClose = () => {
      dispatch(setLoginAlert(false));
   };

   const handleClick = (pathname) => {
      handleClose();
      navigate(`/${pathname}`);
   };

   useEffect(() => {
      dispatch(setLoginAlert(false));
   }, [location, dispatch]); // close modal when route change

   return (
      <>
         <Modal
            isCentered
            onClose={onClose}
            isOpen={loginAlert}
            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'
               >
                  Log in to continue
               </ModalHeader>
               <ModalCloseButton onClick={handleClose} />
               <ModalBody px='1rem'>
                  <Image
                     src={Logo}
                     transform='rotate(-10deg)'
                     mt={2}
                     w={{ base: '60px', md: '90px' }}
                     alt='logo'
                  />
                  <Text
                     mt={5}
                     color={useColorModeValue(
                        'light.cardSecondaryColor',
                        'dark.cardSecondaryColor'
                     )}
                  >
                     We're a place where coders share, stay up-to-date and grow
                     their careers.
                  </Text>
                  <VStack mt={5} mb={7}>
                     <PrimaryBtn
                        w='90%'
                        bg='light.primary'
                        onClick={() => handleClick('login')}
                     >
                        Log in
                     </PrimaryBtn>
                     <SecondaryBtn
                        w='90%'
                        onClick={() => handleClick('create-account')}
                     >
                        Create account
                     </SecondaryBtn>
                  </VStack>
               </ModalBody>
            </ModalContent>
         </Modal>
      </>
   );
};

export default LoginAlert;