Skip to content

Commit fe6b403

Browse files
ctc-devopsPhilip-Jianchloecheng8kristenyeeSubinQKim
authored
AddEventToPublishSchedule + Edit/Delete Days + Edit/Delete PS Events (#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]>
1 parent c80db93 commit fe6b403

33 files changed

+1626
-634
lines changed

.eslintrc.json

+1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"plugin:react/recommended",
99
"plugin:prettier/recommended"
1010
],
11+
"parser": "@babel/eslint-parser",
1112
"parserOptions": {
1213
"ecmaFeatures": {
1314
"jsx": true

package.json

-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
"react-dom": "^18.2.0",
2828
"react-hook-form": "^7.45.4",
2929
"react-html-email": "^3.0.0",
30-
"react-icons": "^5.0.1",
3130
"react-router-dom": "^6.20.0",
3231
"react-script": "^2.0.5",
3332
"react-icons": "^5.0.1",

src/App.jsx

+1-9
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import PublishedSchedule from './pages/PublishedSchedule/PublishedSchedule';
1515
import Playground from './pages/Playground/Playground';
1616
import Planner from './pages/Planner/Planner';
1717
import Navbar from './components/Navbar/Navbar';
18-
import NotificationSandbox from './pages/NotificationSandbox/NotificationSandbox';
1918
import Accounts from './pages/Accounts/Accounts';
2019
import { AuthContextProvider, useAuthContext } from './common/AuthContext';
2120

@@ -56,13 +55,6 @@ const App = () => {
5655
<Route exact path="/signUp" element={<SignUp />} />
5756
<Route exact path="/emailAction" element={<EmailAction redirectPath="/" />} />
5857
<Route exact path="/awaitConfirmation" element={<AwaitConfirmation redirectPath="/" />} />
59-
<Route
60-
exact
61-
path="/notification-sandbox"
62-
element={
63-
<NotificationSandbox />
64-
}
65-
/>
6658
<Route
6759
exact
6860
path="/catalog"
@@ -99,7 +91,7 @@ const App = () => {
9991
redirectPath="/login"
10092
roles={[ADMIN_ROLE]}
10193
/>
102-
} />
94+
} />
10395
</Route>
10496
</Routes>
10597
</Router>
+153
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
/* eslint-disable react/jsx-props-no-spreading */
2+
import {
3+
Box,
4+
FormLabel,
5+
Input,
6+
FormControl,
7+
FormErrorMessage,
8+
Button,
9+
Textarea,
10+
useToast,
11+
Heading,
12+
Flex
13+
} from '@chakra-ui/react';
14+
import { PropTypes } from 'prop-types';
15+
import { yupResolver } from '@hookform/resolvers/yup';
16+
import { useForm } from 'react-hook-form';
17+
import * as yup from 'yup';
18+
import { NPOBackend } from '../../utils/auth_utils';
19+
20+
const schema = yup.object({
21+
date: yup.date().nullable().transform((curr, orig) => orig === '' ? null : curr).required('Date required'),
22+
location: yup.string().required('Location required').max(50, 'Location exceeds 50 character limit'),
23+
details: yup
24+
.string()
25+
.max(50, 'Details exceeds 50 character limit'),
26+
});
27+
28+
const AddDayForm = ({ onClose, onOpen, setDayId, dayData, setShouldDataRevalidate }) => {
29+
const toast = useToast();
30+
const {
31+
handleSubmit,
32+
register,
33+
formState: { errors },
34+
} = useForm({
35+
resolver: yupResolver(schema),
36+
});
37+
38+
const submitData = async data => {
39+
const { date, details, location } = data;
40+
toast.closeAll();
41+
try {
42+
const payload = {
43+
eventDate: date,
44+
location: location,
45+
notes: details,
46+
};
47+
48+
let response;
49+
if (dayData) {
50+
response = await NPOBackend.put(`/day/${dayData.id}`, payload);
51+
setShouldDataRevalidate(true);
52+
} else {
53+
response = await NPOBackend.post('/day/', payload);
54+
}
55+
56+
if (response.status === 200 || (response.status == 201 && response.data.status === 'Success')) {
57+
const id = dayData ? dayData.id : response.data['id'];
58+
setDayId(id);
59+
onOpen(id);
60+
} else if (response.status == 201 && response.data.status === 'Failed') {
61+
toast({
62+
title: 'This date already exists in the schedule.',
63+
description: `${date.toLocaleDateString()}`,
64+
status: 'error',
65+
variant: 'subtle',
66+
position: 'top-right',
67+
containerStyle: {
68+
mt: '6rem',
69+
},
70+
duration: 3000,
71+
isClosable: true,
72+
});
73+
}
74+
75+
} catch (error) {
76+
console.log(error);
77+
}
78+
}
79+
80+
return (
81+
<Box p="20px">
82+
<Heading size="lg" textAlign="center" mb="8px" color="#2D3748">{!dayData ? 'Add New Day' : 'Edit Day Details'}</Heading>
83+
<form onSubmit={handleSubmit(data => submitData(data))}>
84+
<Box mb="4vh">
85+
{/* DATE */}
86+
<Box mb="15px">
87+
<FormControl isInvalid={errors && errors.date} >
88+
<FormLabel fontWeight="bold" color="gray.600">Date *</FormLabel>
89+
<Input
90+
size="md"
91+
type="date"
92+
{...register('date')}
93+
defaultValue={dayData && dayData.eventDate}
94+
/>
95+
<FormErrorMessage>{errors.date && errors.date.message}</FormErrorMessage>
96+
</FormControl>
97+
</Box>
98+
99+
{/* LOCATION */}
100+
<Box mb="15px">
101+
<FormControl isInvalid={errors && errors.location} >
102+
<FormLabel fontWeight="bold" color="gray.600">Location *</FormLabel>
103+
<Input placeholder='Location' {...register('location')} defaultValue={dayData && dayData.location}/>
104+
<FormErrorMessage>{errors.location && errors.location.message}</FormErrorMessage>
105+
</FormControl>
106+
</Box>
107+
108+
109+
{/* DETAILS */}
110+
<Box mb="15px">
111+
<FormControl isInvalid={errors && errors.details}>
112+
<FormLabel fontWeight="bold" color="gray.600">Details</FormLabel>
113+
<Textarea placeholder='Details' {...register('details')} defaultValue={dayData && dayData.details}/>
114+
<FormErrorMessage>
115+
{errors.details && errors.details.message}
116+
</FormErrorMessage>
117+
</FormControl>
118+
</Box>
119+
</Box>
120+
121+
<Flex justifyContent="space-between">
122+
<Button width="48%" size='lg' onClick={onClose}>
123+
Cancel
124+
</Button>
125+
<Button
126+
width="48%"
127+
type='submit'
128+
size='lg'
129+
bgColor="#2c93d1"
130+
color="white"
131+
_hover={{ bgColor: '#1b6896' }}
132+
>
133+
{!dayData ? '+ Add To Schedule' : 'Save Changes'}
134+
</Button>
135+
</Flex>
136+
</form>
137+
</Box>
138+
);
139+
};
140+
141+
AddDayForm.propTypes = {
142+
onClose: PropTypes.func,
143+
onOpen: PropTypes.func,
144+
setDayId: PropTypes.func,
145+
dayData: PropTypes.object,
146+
setShouldDataRevalidate: PropTypes.func
147+
};
148+
AddDayForm.defaultProps = {
149+
onClose: () => {},
150+
onOpen: () => {},
151+
dayData: null
152+
};
153+
export default AddDayForm;

0 commit comments

Comments
 (0)