From b91bbecb1be55b96f92eaca6f4bb8d33982b0834 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sat, 28 Nov 2020 00:28:02 +0300 Subject: feat: match new event interface --- src/components/EventCard/EventCard.tsx | 20 +++++++++++++------- src/containers/BsuFantomSection/EventForm.tsx | 24 +++++++++++++----------- src/types.ts | 20 ++++++++++++-------- 3 files changed, 38 insertions(+), 26 deletions(-) diff --git a/src/components/EventCard/EventCard.tsx b/src/components/EventCard/EventCard.tsx index 08b67bb..e131b8c 100644 --- a/src/components/EventCard/EventCard.tsx +++ b/src/components/EventCard/EventCard.tsx @@ -48,10 +48,12 @@ const EventCard: React.FC = ({ event, mutate }) => { const classes = useStyles(); const { user } = useAuth(); const { + name, + schedule, status, - data: { - name, - date, + nextRunAt, + lastRunAt, + context: { participants, conferenceId, attendanceId @@ -62,9 +64,11 @@ const EventCard: React.FC = ({ event, mutate }) => { const handleJoin = () => { if (user) { - const update = { data: { participants: [...participants, user.username] }}; + const { context } = event; + context.participants.push(user.username); + return requests - .patch(`/events/${event._id}`, update) + .patch(`/events/${event._id}`, { context }) .then(() => mutate()); } }; @@ -81,14 +85,16 @@ const EventCard: React.FC = ({ event, mutate }) => { {status === 'running' && } {status === 'complete' && } {status === 'failed' && } - {!status && } + {status === 'notStarted' && } ); return ( - + + {nextRunAt &&
Next run at: {new Date(nextRunAt).toLocaleTimeString()}
} + {lastRunAt &&
Last run at: {new Date(lastRunAt).toLocaleTimeString()}
} {conferenceId &&
ConferenceID: {conferenceId}
} {attendanceId &&
AttendanceID: {attendanceId}
}
diff --git a/src/containers/BsuFantomSection/EventForm.tsx b/src/containers/BsuFantomSection/EventForm.tsx index d92ad44..528636f 100644 --- a/src/containers/BsuFantomSection/EventForm.tsx +++ b/src/containers/BsuFantomSection/EventForm.tsx @@ -9,7 +9,7 @@ interface PropTypes { const EventForm: React.FC = ({ mutate }) => { const [name, setName] = useState(''); - const [date, setDate] = useState((new Date()).toLocaleDateString()); + const [schedule, setSchedule] = useState('* * * * * *'); const [attendanceId, setAttendanceId] = useState(''); const [conferenceId, setConferenceId] = useState(''); @@ -18,19 +18,21 @@ const EventForm: React.FC = ({ mutate }) => { }; const handleSubmit = () => { - if (date && conferenceId) { - const event: Event["data"] = { + if (schedule && conferenceId) { + const event: Partial = { name, - date: date + ' +03:00', - attendanceId, - conferenceId, - participants: [] - } + schedule, + context: { + attendanceId, + conferenceId, + participants: [] + } + }; setName(''); setAttendanceId(''); setConferenceId(''); - setDate(''); + setSchedule(''); return post('/events', event).then(() => mutate()); } @@ -50,8 +52,8 @@ const EventForm: React.FC = ({ mutate }) => {