diff --git a/.eslintrc.json b/.eslintrc.json index fd40dae..5bd272e 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -8,6 +8,7 @@ "plugin:react/recommended", "plugin:prettier/recommended" ], + "parser": "@babel/eslint-parser", "parserOptions": { "ecmaFeatures": { "jsx": true diff --git a/package.json b/package.json index 5cac9b3..7aa722c 100644 --- a/package.json +++ b/package.json @@ -27,7 +27,6 @@ "react-dom": "^18.2.0", "react-hook-form": "^7.45.4", "react-html-email": "^3.0.0", - "react-icons": "^5.0.1", "react-router-dom": "^6.20.0", "react-script": "^2.0.5", "react-icons": "^5.0.1", diff --git a/src/App.jsx b/src/App.jsx index 5ec7bfe..fdb9d98 100644 --- a/src/App.jsx +++ b/src/App.jsx @@ -15,7 +15,6 @@ import PublishedSchedule from './pages/PublishedSchedule/PublishedSchedule'; import Playground from './pages/Playground/Playground'; import Planner from './pages/Planner/Planner'; import Navbar from './components/Navbar/Navbar'; -import NotificationSandbox from './pages/NotificationSandbox/NotificationSandbox'; import Accounts from './pages/Accounts/Accounts'; import { AuthContextProvider, useAuthContext } from './common/AuthContext'; @@ -56,13 +55,6 @@ const App = () => { } /> } /> } /> - - } - /> { redirectPath="/login" roles={[ADMIN_ROLE]} /> - } /> + } /> diff --git a/src/components/AddDayForm/AddDayForm.jsx b/src/components/AddDayForm/AddDayForm.jsx new file mode 100644 index 0000000..1313b4a --- /dev/null +++ b/src/components/AddDayForm/AddDayForm.jsx @@ -0,0 +1,153 @@ +/* eslint-disable react/jsx-props-no-spreading */ +import { + Box, + FormLabel, + Input, + FormControl, + FormErrorMessage, + Button, + Textarea, + useToast, + Heading, + Flex +} from '@chakra-ui/react'; +import { PropTypes } from 'prop-types'; +import { yupResolver } from '@hookform/resolvers/yup'; +import { useForm } from 'react-hook-form'; +import * as yup from 'yup'; +import { NPOBackend } from '../../utils/auth_utils'; + +const schema = yup.object({ + date: yup.date().nullable().transform((curr, orig) => orig === '' ? null : curr).required('Date required'), + location: yup.string().required('Location required').max(50, 'Location exceeds 50 character limit'), + details: yup + .string() + .max(50, 'Details exceeds 50 character limit'), +}); + +const AddDayForm = ({ onClose, onOpen, setDayId, dayData, setShouldDataRevalidate }) => { + const toast = useToast(); + const { + handleSubmit, + register, + formState: { errors }, + } = useForm({ + resolver: yupResolver(schema), + }); + + const submitData = async data => { + const { date, details, location } = data; + toast.closeAll(); + try { + const payload = { + eventDate: date, + location: location, + notes: details, + }; + + let response; + if (dayData) { + response = await NPOBackend.put(`/day/${dayData.id}`, payload); + setShouldDataRevalidate(true); + } else { + response = await NPOBackend.post('/day/', payload); + } + + if (response.status === 200 || (response.status == 201 && response.data.status === 'Success')) { + const id = dayData ? dayData.id : response.data['id']; + setDayId(id); + onOpen(id); + } else if (response.status == 201 && response.data.status === 'Failed') { + toast({ + title: 'This date already exists in the schedule.', + description: `${date.toLocaleDateString()}`, + status: 'error', + variant: 'subtle', + position: 'top-right', + containerStyle: { + mt: '6rem', + }, + duration: 3000, + isClosable: true, + }); + } + + } catch (error) { + console.log(error); + } + } + + return ( + + {!dayData ? 'Add New Day' : 'Edit Day Details'} +
submitData(data))}> + + {/* DATE */} + + + Date * + + {errors.date && errors.date.message} + + + + {/* LOCATION */} + + + Location * + + {errors.location && errors.location.message} + + + + + {/* DETAILS */} + + + Details +