aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoreug-vs <eug-vs@keemail.me>2020-11-28 00:28:02 +0300
committereug-vs <eug-vs@keemail.me>2020-11-28 00:28:02 +0300
commitb91bbecb1be55b96f92eaca6f4bb8d33982b0834 (patch)
treedb236dcdb2393ae58bd62cadf57658ebaa49d66e
parent270a348496ee4d001e3dc3776a67e8376ff40674 (diff)
downloadfamcs-kit-b91bbecb1be55b96f92eaca6f4bb8d33982b0834.tar.gz
feat: match new event interface
-rw-r--r--src/components/EventCard/EventCard.tsx20
-rw-r--r--src/containers/BsuFantomSection/EventForm.tsx24
-rw-r--r--src/types.ts20
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<PropTypes> = ({ 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<PropTypes> = ({ 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<PropTypes> = ({ event, mutate }) => {
{status === 'running' && <RunningIcon className={classes.running}/>}
{status === 'complete' && <CompleteIcon className={classes.complete} />}
{status === 'failed' && <FailedIcon color="error" />}
- {!status && <NotStartedIcon color="disabled" />}
+ {status === 'notStarted' && <NotStartedIcon color="disabled" />}
</div>
);
return (
<Card variant="outlined">
- <CardHeader title={title} subheader={date} />
+ <CardHeader title={title} subheader={schedule} />
<CardContent>
+ {nextRunAt && <div> Next run at: {new Date(nextRunAt).toLocaleTimeString()} </div>}
+ {lastRunAt && <div> Last run at: {new Date(lastRunAt).toLocaleTimeString()} </div>}
{conferenceId && <div> ConferenceID: {conferenceId} </div>}
{attendanceId && <div> AttendanceID: {attendanceId} </div>}
<div>
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<PropTypes> = ({ mutate }) => {
const [name, setName] = useState<string>('');
- const [date, setDate] = useState<string>((new Date()).toLocaleDateString());
+ const [schedule, setSchedule] = useState<string>('* * * * * *');
const [attendanceId, setAttendanceId] = useState<string>('');
const [conferenceId, setConferenceId] = useState<string>('');
@@ -18,19 +18,21 @@ const EventForm: React.FC<PropTypes> = ({ mutate }) => {
};
const handleSubmit = () => {
- if (date && conferenceId) {
- const event: Event["data"] = {
+ if (schedule && conferenceId) {
+ const event: Partial<Event> = {
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<PropTypes> = ({ mutate }) => {
</Grid>
<Grid item sm={6} xs={12}>
<TextField
- value={date}
- onChange={createHandler(setDate)}
+ value={schedule}
+ onChange={createHandler(setSchedule)}
variant="outlined"
label="Date"
fullWidth
diff --git a/src/types.ts b/src/types.ts
index 7243934..a239702 100644
--- a/src/types.ts
+++ b/src/types.ts
@@ -8,15 +8,19 @@ export interface User extends Base {
username: string;
}
+export interface EventContext {
+ participants: string[];
+ conferenceId: string;
+ attendanceId: string;
+}
+
export interface Event extends Base {
- status?: 'running' | 'complete' | 'failed';
+ name: string;
+ schedule: string;
+ status?: 'running' | 'complete' | 'failed' | 'notStarted';
failReason?: string;
- data: {
- name: string;
- participants: string[];
- date: string;
- conferenceId: string;
- attendanceId: string;
- }
+ context: EventContext;
+ nextRunAt: string;
+ lastRunAt: string;
}