Skip to content

Commit

Permalink
Merge pull request #89 from ctc-uci/69-administrators-page-flow
Browse files Browse the repository at this point in the history
69 administrators page flow
  • Loading branch information
Aokijiop authored Feb 23, 2024
2 parents c01be0d + 1fe44ee commit 3f279ca
Show file tree
Hide file tree
Showing 9 changed files with 626 additions and 338 deletions.
6 changes: 6 additions & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Gabarito:wght@400;500;600;700;800;900&family=Poppins:ital,wght@0,100;0,200;0,300;0,400;0,500;0,600;0,700;0,800;0,900;1,100;1,200;1,300;1,400;1,500;1,600;1,700;1,800;1,900&family=Rubik:wght@300;400;500;600;700;800;900&display=swap"
rel="stylesheet"
/>
<title>Vite + React</title>
</head>
<body>
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
"react-dropzone": "^14.2.3",
"react-hook-form": "7.37.0",
"react-icons": "^5.0.1",
"react-pdf": "^7.7.0",
"react-router-dom": "^6.21.1",
"vite-plugin-top-level-await": "^1.4.1",
"yup": "^1.3.3"
Expand Down
14 changes: 4 additions & 10 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import SelectEvent from './pages/SelectEvent';
import DummyVolunteerQR from './pages/DummyVolunteerQR';
import DummyAdminQR from './pages/DummyAdminQR';
import Navbar from './components/Navbar/Navbar';
import AdminPage from './pages/AdminPage';

const Layout = () => {
return (
Expand Down Expand Up @@ -64,26 +65,19 @@ const App = () => {
<Route path="/event-creation" element={<DummyEventCreation />} />
<Route path="/select-event" element={<SelectEvent />} />

{/* SPRINT 4 */}

{/* Jessie and Brendan */}

<Route path="/data-entry-modal-test" element={<DataEntryModalTestPage />} />
{/* Rayan and Emmy */}
<Route path="/checkin/:eventId" element={<DummyCheckin />} />
{/* Phillip and Katy */}
<Route path="/stats" element={<DummyStatsPage />} />
{/* Nate and Farhnaz */}
<Route path="/event-card-page" element={<EventCardTest />} />
<Route path="/filtered-event-page" element={<FilteredEvents />} />
{/* Matthew and Bobby */}
<Route path="/register/:eventId" element={<Register />} />
{/* If your Sprint 3 task requires you to create a new component, you can use this route to test the look of your component */}
<Route path="/playground" element={<Playground />} />

{/* SPRINT 5 */}
{/* Kevin and Jasmine */}
<Route path="/volunteer-qr/:eventId/:volunteerId" element={<DummyVolunteerQR />} />
<Route path="/admin-qr/" element={<DummyAdminQR />} />

<Route path="/admin" element={<AdminPage />} />
</Routes>
</Router>
</ChakraProvider>
Expand Down
180 changes: 180 additions & 0 deletions src/components/AdminModals/AddUserModal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,180 @@
import {
Flex,
Modal,
ModalOverlay,
ModalContent,
ModalHeader,
ModalFooter,
ModalBody,
Spinner,
FormControl,
FormLabel,
Input,
Button,
Select,
useToast,
ModalCloseButton,
} from '@chakra-ui/react';
import Dropzone from '../Dropzone.tsx';
import { useState} from 'react';
import { postProfile } from '../../utils/profileUtils.js';
import PropTypes from 'prop-types';


export default function AddUserModal({ isOpen, onClose, setAdminData }) {
const [isLoading, setIsLoading] = useState(false);
const [userData, setUserData] = useState({
first_name: '',
last_name: '',
role: 'admin',
email: '',
});
const toast = useToast();

const handleSubmit = async () => {
try {
await postProfile(userData);

toast({
title: 'New administrator added.',
description: 'New administrator added.',
position: 'bottom-right',
status: 'success',
duration: 9000,
isClosable: true,
});

setAdminData(prev => [...prev, userData]);
setUserData({
first_name: '',
last_name: '',
role: 'admin',
email: '',
});

onClose();
} catch (err) {
console.log('Error:', err);
toast({
title: 'Error creating new administrator.',
description: 'There was an error creating new administator. Please try again.',
status: 'error',
position: 'bottom-right',
duration: 9000,
isClosable: true,
});
}
};

const emailRegex = /\S+@\S+\.\S+/;
const isSubmittable =
userData.first_name === '' || userData.last_name === '' || !emailRegex.test(userData.email);

console.log('userData:', userData);

return (
<Flex>
<Modal isOpen={isOpen} onClose={onClose}>
<ModalOverlay />
<ModalContent
minW={'40%'}
borderRadius={'30px'}
boxShadow={'0px 6.9760003089904785px 6.9760003089904785px 0px #00000080'}
>
<ModalHeader>
<ModalHeader
fontSize={'24px'}
justify={'center'}
align={'center'}
fontWeight={'700'}
lineHeight={'29.05px'}
marginBottom={'-25px'}
>
Add New User
</ModalHeader>
<ModalCloseButton />
</ModalHeader>

<ModalBody>
<FormControl>
<Flex flexDir={'column'} align={'center'} justify={'center'}>
{isLoading ? (
<Spinner />
) : (
<Dropzone
height={'141px'}
setIsLoading={setIsLoading}
setData={setUserData}
data={userData}
/>
)}
</Flex>

<Flex flexDirection={'row'}>
<Flex flexDirection={'column'} width={'100%'} paddingRight={'10px'}>
<FormLabel paddingTop={'10px'} fontWeight={'700'} fontSize={'12px'}>
First Name
</FormLabel>
<Input
type="text"
placeholder="Johnny"
onChange={e => setUserData({ ...userData, first_name: e.target.value })}
/>
</Flex>
<Flex flexDirection={'column'} width={'100%'} paddingLeft={'10px'}>
<FormLabel paddingTop={'10px'} fontWeight={'700'} fontSize={'12px'}>
Last Name
</FormLabel>
<Input
type="text"
placeholder="Appleseed"
onChange={e => setUserData({ ...userData, last_name: e.target.value })}
/>
</Flex>
</Flex>
<FormLabel paddingTop={'10px'} fontWeight={'700'} fontSize={'12px'}>
Email
</FormLabel>
<Input
type="email"
placeholder="[email protected]"
onChange={e => setUserData({ ...userData, email: e.target.value })}
/>
<FormLabel paddingTop={'10px'} fontWeight={'700'} fontSize={'12px'}>
Add Role
</FormLabel>
<Input type="text" placeholder="Admin" isDisabled />
<FormLabel paddingTop={'10px'} fontWeight={'700'} fontSize={'12px'}>
Set Account Type
</FormLabel>
<Select
value={userData.role}
onChange={e => setUserData({ ...userData, role: e.target.value })}
>
<option value="admin">Admin</option>
</Select>
</FormControl>
</ModalBody>

<ModalFooter justifyContent={'center'}>
<Button
backgroundColor={'#95D497'}
borderRadius={'30px'}
isDisabled={isSubmittable}
w={'100%'}
onClick={handleSubmit}
>
Send Email
</Button>
</ModalFooter>
</ModalContent>
</Modal>
</Flex>
);
}

AddUserModal.propTypes = {
isOpen: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
setAdminData: PropTypes.func.isRequired,
};
Loading

0 comments on commit 3f279ca

Please sign in to comment.