Skip to content

Commit d0d1c5b

Browse files
authored
Show waitlist label (#2160)
2 parents 94d4ad5 + bb44ad7 commit d0d1c5b

File tree

6 files changed

+1131
-9352
lines changed

6 files changed

+1131
-9352
lines changed

frontend/src/components/pages/events/EventDetail/SignUp/Actions.tsx

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,21 @@ import { useMutation } from "@apollo/client";
22
import { Alert, Unstable_Grid2 as Grid, Snackbar, TextField, Tooltip, Typography } from "@mui/material";
33
import { useState } from "react";
44

5-
import { LoginRequired, PermissionRequired } from "@/components/Auth";
6-
import { EventDetailFieldsFragment, EventSignOffDocument, EventSignUpDocument } from "@/generated/graphql";
7-
import dayjs from "@/lib/date";
8-
95
import { CountdownStatusText } from "./Countdown";
106
import { useCountdown } from "./hooks/useCountdown";
117
import { SignUpButton } from "./SignUpButton";
128

9+
import { LoginRequired, PermissionRequired } from "@/components/Auth";
10+
import { EventDetailFieldsFragment, EventSignOffDocument, EventSignUpDocument } from "@/generated/graphql";
11+
import dayjs from "@/lib/date";
12+
1313
type Event = {
1414
id: string;
1515
hasExtraInformation?: boolean | null;
1616
signupOpenDate: string;
1717
deadline: string;
1818
bindingSignup?: boolean | null;
19+
isAttendable: boolean;
1920
} & Pick<EventDetailFieldsFragment, "userAttendance">;
2021

2122
type Props = {
@@ -115,6 +116,7 @@ export const Actions: React.FC<Props> = ({ event }) => {
115116
onSignUp={handleSignUp}
116117
onSignOff={handleSignOff}
117118
isSignedUp={isSignedUp}
119+
event={event}
118120
/>
119121
</span>
120122
</Tooltip>

frontend/src/components/pages/events/EventDetail/SignUp/SignUpButton.tsx

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,45 @@
11
import { LoadingButton } from "@mui/lab";
22
import { Button, Dialog, DialogActions, DialogContent, Typography } from "@mui/material";
3-
import { useState } from "react";
3+
import { useContext, useState } from "react";
4+
5+
import dayjs from "@/lib/date";
6+
import { UserContext } from "@/pages/events/[id]";
7+
8+
type Event = {
9+
signupOpenDate: string;
10+
isFull?: boolean | null;
11+
allowedGradeYears?: Array<number> | null;
12+
isAttendable: boolean;
13+
};
14+
15+
type User = {
16+
gradeYear?: number | null;
17+
};
418

519
type Props = {
620
isSignedUp?: boolean | null;
721
disabled?: boolean;
822
onSignUp: () => void;
923
onSignOff: () => void;
24+
event: Event;
1025
};
1126

12-
export const SignUpButton: React.FC<Props> = ({ isSignedUp, onSignUp, onSignOff, disabled }) => {
27+
function isWaitList(event: Event, user: User) {
28+
const signUpOpenDate = event.signupOpenDate ? dayjs(event.signupOpenDate) : undefined;
29+
const isSignUpOpen = signUpOpenDate && dayjs().isSameOrAfter(signUpOpenDate);
30+
31+
let canAttend = event.isAttendable && isSignUpOpen;
32+
if (user.gradeYear && event.allowedGradeYears) {
33+
canAttend = canAttend && event.allowedGradeYears.includes(user.gradeYear);
34+
}
35+
36+
return event.isFull && canAttend;
37+
}
38+
39+
export const SignUpButton: React.FC<Props> = ({ isSignedUp, onSignUp, onSignOff, disabled, event }) => {
1340
const [confirmSignOff, setConfirmSignOff] = useState(false);
1441
const [loading, setLoading] = useState(false);
42+
const user = useContext(UserContext);
1543

1644
function handleSignUp() {
1745
setLoading(true);
@@ -25,7 +53,6 @@ export const SignUpButton: React.FC<Props> = ({ isSignedUp, onSignUp, onSignOff,
2553
setTimeout(() => setLoading(false), 1000);
2654
onSignOff();
2755
}
28-
2956
return (
3057
<>
3158
<Dialog open={confirmSignOff}>
@@ -54,7 +81,7 @@ export const SignUpButton: React.FC<Props> = ({ isSignedUp, onSignUp, onSignOff,
5481
)}
5582
{!isSignedUp && (
5683
<LoadingButton fullWidth loading={loading} variant="contained" onClick={handleSignUp} disabled={disabled}>
57-
Meld på
84+
{user != null && isWaitList(event, user) ? "Meld på venteliste" : "Meld på"}
5885
</LoadingButton>
5986
)}
6087
</>

0 commit comments

Comments
 (0)