-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathOWeek.tsx
More file actions
256 lines (239 loc) · 8.48 KB
/
OWeek.tsx
File metadata and controls
256 lines (239 loc) · 8.48 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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
import React, { useState } from "react";
import { Button, TextField, FormControl, Checkbox, FormControlLabel, Alert } from "@mui/material";
import TitleHero from "../../features/TitleHero/TitleHero";
import { motion, useScroll, useTransform } from "framer-motion";
import { useRef } from "react";
import { createTheme, ThemeProvider, styled } from "@mui/material/styles";
import { useNavigate } from "react-router-dom";
import { RiserUserInput } from "./RiserGame.model";
import Filter from "bad-words";
import RiserLeaderboard from "../../features/Leaderboard/RiserLeaderboard";
import { Info, Leaderboard, MoreHoriz, Refresh, SportsScore } from "@mui/icons-material";
import { isUniqueEmail } from "../../services/firestoreServices";
import cleanEmail from "../../services/cleanEmails";
import { FaTrophy } from "react-icons/fa";
const theme = createTheme({
palette: {
primary: {
main: "#F3B52A",
},
secondary: {
main: "#5899F5",
},
},
});
// I dont think this is optimal but we are in a slight rush
const SubmitButton = styled(Button)({
boxShadow: "none",
color: "white",
fontWeight: "bold",
textTransform: "none",
padding: "6px 12px",
border: "2px solid",
lineHeight: 1.5,
borderColor: "#5899F5",
backgroundColor: "rgba(9, 31, 62, 0.5)",
"&:hover": {
padding: "6px 12px",
border: "2px solid",
lineHeight: 1.5,
borderColor: "#5899F5",
backgroundColor: "rgba(9, 31, 62, 0.5)",
},
"&:active": {
padding: "6px 12px",
border: "2px solid",
lineHeight: 1.5,
borderColor: "#5899F5",
backgroundColor: "rgba(9, 31, 62, 0.5)",
},
"&:focus": {
padding: "6px 12px",
border: "2px solid",
lineHeight: 1.5,
borderColor: "#5899F5",
backgroundColor: "rgba(9, 31, 62, 0.5)",
},
});
export default function RiserGame() {
const navigate = useNavigate();
const pageInfo = {
title: "O-Week Riser",
description: `Test your skill and luck at our riser game where you just need to hit the button at the right time. Win big prizes`,
};
const leaderboard = [
{
rank: 1,
name: "First Last",
score: 7999,
},
{
rank: 2,
name: "First Last",
score: 7999,
},
];
// Animations
const scrollRef = useRef(null);
const { scrollYProgress } = useScroll({
target: scrollRef,
offset: ["start start", "end start"],
});
const y = useTransform(scrollYProgress, [0, 1], ["0%", "80%"]);
const opacityValue = useTransform(scrollYProgress, [0, 0.6], ["100%", "0%"]);
const scaleValue = useTransform(scrollYProgress, [0, 0.9], ["1", "0.9"]);
// Form Field Values
const [firstName, setFirstName] = useState("");
const [lastName, setLastName] = useState("");
const [email, setEmail] = useState("");
const [studentId, setStudentId] = useState("");
const [isMember, setIsMember] = useState(false);
// Handle form submission
const handleSubmit = (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();
const inputs = {
firstName,
lastName,
email,
};
const fullName = firstName + " " + lastName;
const filter = new Filter();
// Inputs length check
if (Object.values(inputs).filter((input) => input.length > 0).length < 3) {
alert("Please fill in all required details");
}
// Profanity check
else if (filter.isProfane(fullName) || filter.isProfane(email)) {
alert("Profanity detected, please delete any inappropriate text.");
}
// Email Check
else if (!email.match(/\S+@\S+\.\S+/)) {
alert("Invalid email, please enter a valid email.");
}
// Student ID Check
else if (!studentId.match(/^\d{7}$/) && studentId.length > 0) {
alert(
"Invalid student ID, please recheck you have entered it correctly. If you don't have a studentID leave it blank",
);
} else {
const sanitisedEmail = cleanEmail(email);
// Pass
const validInput: RiserUserInput = {
name: fullName,
email: sanitisedEmail,
studentID: studentId === "" ? "0000000" : studentId,
HMMember: isMember,
};
isUniqueEmail(validInput.email)
.then(() => {
navigate("/O-Week/playGame", { state: { ...validInput } });
})
.catch((e) => {
console.log(e);
navigate("/O-Week");
alert("Error: Student ID is already been used. If this is a mistake please contact our staff");
});
}
};
return (
<div className="flex flex-col items-center justify-center gap-20 w-screen max-w-full">
<motion.section ref={scrollRef} style={{ y, opacity: opacityValue, scale: scaleValue }} className="">
<TitleHero pageTitle={pageInfo.title} pageDescription={pageInfo.description}></TitleHero>
</motion.section>
<section className="flex flex-col items-center px-16 gap-6">
<h2 className="font-bold text-2xl text-yellow-500">How to play</h2>
<SportsScore fontSize="large" />
<p>The goal of the game is to get as close to 2024 without going over</p>
<MoreHoriz fontSize="large" />
<p>You will get 3 tries and your best score out of those three is submitted</p>
<Refresh fontSize="large" />
<p>Press the button to start and press it again to stop</p>
<Info fontSize="large" />
<p>Note: The event prizes are over, but feel free to play our minigame :)</p>
</section>
<section className="flex flex-col items-center px-16 gap-6">
<FaTrophy size="3em" />
<h2 className="font-bold text-2xl text-yellow-500">Rewards</h2>
<s>First place : $20</s>
<s>Second place : $15</s>
<s>Third place : $15</s>
<s>Additional placements : Mystery Merch </s>
</section>
<form onSubmit={handleSubmit}>
<h1 className="font-bold text-3xl flex justify-center mb-8">Enter your details</h1>
<FormControl>
<div className="border border-[#5899F5] bg-[#5899F5] bg-opacity-5 p-12 flex flex-col justify-center gap-10 rounded-md">
<ThemeProvider theme={theme}>
<TextField
type="text"
value={firstName}
onChange={(e) => setFirstName(e.target.value)}
variant="standard"
color="primary"
label="First Name*"
InputLabelProps={{
sx: { color: "white", "&.Mui-focused": { color: "white" } },
}}
sx={{ input: { color: "white" } }}
focused
/>
<TextField
type="text"
value={lastName}
onChange={(e) => setLastName(e.target.value)}
variant="standard"
color="primary"
label="Last Name*"
InputLabelProps={{
sx: { color: "white", "&.Mui-focused": { color: "white" } },
}}
sx={{ input: { color: "white" } }}
focused
/>
<TextField
type="email"
value={email}
onChange={(e) => setEmail(e.target.value)}
variant="standard"
color="primary"
label="Email*"
InputLabelProps={{
sx: { color: "white", "&.Mui-focused": { color: "white" } },
}}
sx={{ input: { color: "white" } }}
focused
/>
<TextField
type="text"
value={studentId}
onChange={(e) => setStudentId(e.target.value)}
variant="standard"
color="primary"
label="Student ID"
InputLabelProps={{
sx: { color: "white", "&.Mui-focused": { color: "white" } },
}}
sx={{ input: { color: "white" } }}
focused
/>
<FormControlLabel
control={
<Checkbox
checked={isMember}
onChange={(e) => setIsMember(e.target.checked)}
sx={{ color: "white" }}
/>
}
label="HackMelbourne Member"
/>
<SubmitButton type="submit" variant="outlined" color="secondary" sx={{ marginTop: "2em" }}>
Submit
</SubmitButton>
</ThemeProvider>
</div>
</FormControl>
</form>
<RiserLeaderboard></RiserLeaderboard>
</div>
);
}