From 4497d90f23de6abf011a676d0bba745f0e70e7d7 Mon Sep 17 00:00:00 2001 From: eug-vs Date: Sun, 15 Nov 2020 01:38:57 +0300 Subject: feat: join the event by button --- src/components/EventCard/EventCard.tsx | 19 ++++++++++++++++--- src/containers/BsuFantomSection/BsuFantomSection.tsx | 7 ++++--- 2 files changed, 20 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/components/EventCard/EventCard.tsx b/src/components/EventCard/EventCard.tsx index 192d0b3..bd09c45 100644 --- a/src/components/EventCard/EventCard.tsx +++ b/src/components/EventCard/EventCard.tsx @@ -7,12 +7,14 @@ import { Button } from '@material-ui/core'; import { Event } from '../../types'; +import { patch } from '../../requests'; interface PropTypes { event: Event; + mutate: () => void; } -const EventCard: React.FC = ({ event }) => { +const EventCard: React.FC = ({ event, mutate }) => { const { data: { name, @@ -23,9 +25,15 @@ const EventCard: React.FC = ({ event }) => { } } = event; + const handleJoin = () => { + // TODO: add your username to participants list + const update = { data: { participants: [...participants, Math.random()] }} + return patch(`/events/${event._id}`, update).then(() => mutate()); + }; + return ( - + {conferenceId &&
ConferenceID: {conferenceId}
} {attendanceId &&
AttendanceID: {attendanceId}
} @@ -40,7 +48,12 @@ const EventCard: React.FC = ({ event }) => {
{(participants?.length || 0) < 3 && ( - diff --git a/src/containers/BsuFantomSection/BsuFantomSection.tsx b/src/containers/BsuFantomSection/BsuFantomSection.tsx index 527c41b..a05d180 100644 --- a/src/containers/BsuFantomSection/BsuFantomSection.tsx +++ b/src/containers/BsuFantomSection/BsuFantomSection.tsx @@ -4,8 +4,9 @@ import { Grid, Link } from '@material-ui/core'; import EventCard from '../../components/EventCard/EventCard'; import { useEvents } from '../../hooks/APIClient'; + const BsuFantomSection: React.FC = () => { - const { data: events } = useEvents(); + const { data: events, mutate } = useEvents(); return ( @@ -14,9 +15,9 @@ const BsuFantomSection: React.FC = () => {

- {events?.map(event => ( + {events?.map((event, index) => ( - + ))} -- cgit v1.2.3