Skip to content

Commit

Permalink
AddEventToPublishSchedule + Edit/Delete Days + Edit/Delete PS Events (#…
Browse files Browse the repository at this point in the history
…61)

* added two modals and started search and filter

* progress on add day modal and day planner modal.

* added create event form inside day planner

Co-authored-by: chloecheng8 <[email protected]>
Co-authored-by: kristenyee <[email protected]>
Co-authored-by: Subin Kim <[email protected]>

* Put the catalog component in PlannerEvents component + fixed useState management for button visibility

* updated branch from dev

* added Add Day Modal back to Publish Schedule and connected to backend

* AddDayContext file so no need for multiple prop passes for addDayForm and CreateEventForm

* Post request to /published-schedule inside CreateEventForm

* AddEventToPublishedSchedule form used in PS modal to create new ps and catalog

* fixed addEventOverlay rendering the datePart and location on event form

* AddEventToPublishScheduleForm creates new events in the PS and catalog, PaginationFooter data param fix

* Planner Timeline changes

* light styling

* semi styled published schedule form

* matched ps form styling

* updated styling, events display on timeline

* can add existing catalog event to ps

* sorting events on schedule by startTime

* fixing bugs + re-implementing catalog add

* (rest of changes)

* replace location with description for individual ps events

* fixed bugs and added styling to timeline

* change to use planner context

* merge conflict fixes

* live events on timeline

* fixed ps table styling + removed date/location from ps form

* migrated day context to planner context

* missed a file

* edit existing day

* delete day if no events + more styling

* handled 2 overlapping events

* close ps form after submission + prevent multiple fetches of catalog

* delete day + (bad) data revalidation

* edit day from day planner implemented

* edit day, edit events (mostly), plus bug fixes

* updated navbar, dropdown, catalog, 'finish day' + fixed ps student view

* editing event reflects correctly on timeline, edit/delete appear on hover, delete event mostly implemented

* edit buttons updated, styling of delete event modal still has darkness bug

* fixed delete event + styled edit/delete buttons

* fixed host bug

* minor visual touch-ups, fixed timeline height issue

* alt timeline size fix

* fixed season cutoff

* removed unnessary addDayModal

* made catalog scroll bar nicer

* fixed small catalog bug

* fixed bugs, removed second variable tracking edit state, added some toasts

* update catalog on timeline event edit

* removed unnessary console logs

* fixed season select issue

* fixed bug of currently edited event disappearing when editing different event

* toast clean up

* fixed day toast error message

---------

Co-authored-by: Philip Jian <[email protected]>
Co-authored-by: chloecheng8 <[email protected]>
Co-authored-by: kristenyee <[email protected]>
Co-authored-by: Subin Kim <[email protected]>
Co-authored-by: subinqkim <[email protected]>
Co-authored-by: michellelin1 <[email protected]>
Co-authored-by: ThatMegamind <[email protected]>
Co-authored-by: ThatMegamind <[email protected]>
  • Loading branch information
9 people authored Mar 29, 2024
1 parent c80db93 commit fe6b403
Show file tree
Hide file tree
Showing 33 changed files with 1,626 additions and 634 deletions.
1 change: 1 addition & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"plugin:react/recommended",
"plugin:prettier/recommended"
],
"parser": "@babel/eslint-parser",
"parserOptions": {
"ecmaFeatures": {
"jsx": true
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
10 changes: 1 addition & 9 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -56,13 +55,6 @@ const App = () => {
<Route exact path="/signUp" element={<SignUp />} />
<Route exact path="/emailAction" element={<EmailAction redirectPath="/" />} />
<Route exact path="/awaitConfirmation" element={<AwaitConfirmation redirectPath="/" />} />
<Route
exact
path="/notification-sandbox"
element={
<NotificationSandbox />
}
/>
<Route
exact
path="/catalog"
Expand Down Expand Up @@ -99,7 +91,7 @@ const App = () => {
redirectPath="/login"
roles={[ADMIN_ROLE]}
/>
} />
} />
</Route>
</Routes>
</Router>
Expand Down
153 changes: 153 additions & 0 deletions src/components/AddDayForm/AddDayForm.jsx
Original file line number Diff line number Diff line change
@@ -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 (
<Box p="20px">
<Heading size="lg" textAlign="center" mb="8px" color="#2D3748">{!dayData ? 'Add New Day' : 'Edit Day Details'}</Heading>
<form onSubmit={handleSubmit(data => submitData(data))}>
<Box mb="4vh">
{/* DATE */}
<Box mb="15px">
<FormControl isInvalid={errors && errors.date} >
<FormLabel fontWeight="bold" color="gray.600">Date *</FormLabel>
<Input
size="md"
type="date"
{...register('date')}
defaultValue={dayData && dayData.eventDate}
/>
<FormErrorMessage>{errors.date && errors.date.message}</FormErrorMessage>
</FormControl>
</Box>

{/* LOCATION */}
<Box mb="15px">
<FormControl isInvalid={errors && errors.location} >
<FormLabel fontWeight="bold" color="gray.600">Location *</FormLabel>
<Input placeholder='Location' {...register('location')} defaultValue={dayData && dayData.location}/>
<FormErrorMessage>{errors.location && errors.location.message}</FormErrorMessage>
</FormControl>
</Box>


{/* DETAILS */}
<Box mb="15px">
<FormControl isInvalid={errors && errors.details}>
<FormLabel fontWeight="bold" color="gray.600">Details</FormLabel>
<Textarea placeholder='Details' {...register('details')} defaultValue={dayData && dayData.details}/>
<FormErrorMessage>
{errors.details && errors.details.message}
</FormErrorMessage>
</FormControl>
</Box>
</Box>

<Flex justifyContent="space-between">
<Button width="48%" size='lg' onClick={onClose}>
Cancel
</Button>
<Button
width="48%"
type='submit'
size='lg'
bgColor="#2c93d1"
color="white"
_hover={{ bgColor: '#1b6896' }}
>
{!dayData ? '+ Add To Schedule' : 'Save Changes'}
</Button>
</Flex>
</form>
</Box>
);
};

AddDayForm.propTypes = {
onClose: PropTypes.func,
onOpen: PropTypes.func,
setDayId: PropTypes.func,
dayData: PropTypes.object,
setShouldDataRevalidate: PropTypes.func
};
AddDayForm.defaultProps = {
onClose: () => {},
onOpen: () => {},
dayData: null
};
export default AddDayForm;
Loading

0 comments on commit fe6b403

Please sign in to comment.