-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathEventIsEnrolled.tsx
More file actions
97 lines (89 loc) · 3.39 KB
/
Copy pathEventIsEnrolled.tsx
File metadata and controls
97 lines (89 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { useParams } from 'react-router-dom';
import * as Sentry from '@sentry/browser';
import { useQuery } from '@apollo/client';
import styles from './event.module.scss';
import occurrenceQuery from './queries/occurrenceQuery';
import { OccurrenceQuery } from '../api/generatedTypes/graphql';
import LoadingSpinner from '../../common/components/spinner/LoadingSpinner';
import OccurrenceInfo from './partial/OccurrenceInfo';
import UnenrolModal from './modal/UnenrolModal';
import VenueFeatures from './VenueFeatures';
import Paragraph from '../../common/components/paragraph/Paragraph';
import EventPage from './EventPage';
import ErrorMessage from '../../common/components/error/Error';
import Button from '../../common/components/button/Button';
import useChildRouteGoBackTo from '../profile/children/child/useChildRouteGoBackTo';
import { shouldAllowUnenrolment } from './EventUtils';
import AppConfig from '../app/AppConfig';
const EventIsEnrolled = () => {
const { t } = useTranslation();
const goBackTo = useChildRouteGoBackTo();
const [isOpen, setIsOpen] = useState(false);
const params = useParams<{ childId: string; occurrenceId: string }>();
const { loading, error, data } = useQuery<OccurrenceQuery>(occurrenceQuery, {
variables: {
id: params.occurrenceId,
childId: params.childId,
},
});
const errorMessage = <ErrorMessage message={t('api.errorMessage')} />;
if (loading) return <LoadingSpinner isLoading={true} />;
if (error) {
Sentry.captureException(error);
return errorMessage;
}
if (!data?.occurrence) return errorMessage;
const disableUnenrolling = !shouldAllowUnenrolment(data.occurrence.time);
const unerolHoursBeforeOccurrence =
AppConfig.enrolmentCancellationTimeLimitHours;
return (
<EventPage event={data.occurrence.event} backTo={goBackTo}>
<OccurrenceInfo
className={styles.occurrenceInfo}
occurrence={data.occurrence}
/>
<div className={styles.description}>
<Paragraph text={data.occurrence.event.description || ''} />
</div>
<div className={styles.participantsPerInvite}>
{t(
`event.participantsPerInviteEnumLong.${data.occurrence.event.participantsPerInvite}`
)}
</div>
<h2>{t('event.cancellation.heading')}</h2>
<p id="eventCancellationDescription">
{disableUnenrolling
? t('enrollment.cancellation.disabledDescription', {
unerolHoursBeforeOccurrence,
})
: t('enrollment.cancellation.enabledDescription', {
unerolHoursBeforeOccurrence,
})}
</p>
<div className={styles.cancelButtonWrapper}>
<Button
id="unenrolButton"
variant="secondary"
aria-describedby="eventCancellationDescription"
onClick={() => setIsOpen(true)}
disabled={disableUnenrolling}
>
{t('event.cancellation.buttonText')}
</Button>
</div>
<VenueFeatures venue={data.occurrence.venue} />
{isOpen && !disableUnenrolling && (
<UnenrolModal
isOpen={isOpen}
setIsOpen={setIsOpen}
childId={params.childId ?? ''}
occurrenceId={data.occurrence.id}
eventGroupId={data?.occurrence?.event?.eventGroup?.id}
/>
)}
</EventPage>
);
};
export default EventIsEnrolled;