diff --git a/layout/Attendee/Profile/Profile.tsx b/layout/Attendee/Profile/Profile.tsx index 02654b43..b4b54fdd 100644 --- a/layout/Attendee/Profile/Profile.tsx +++ b/layout/Attendee/Profile/Profile.tsx @@ -11,17 +11,17 @@ import Button from "@components/Button"; import Heading from "@components/Heading"; import ResetPassword from "@components/ResetPassword"; -import { CheckpointTracker, CodeInput } from "./components"; +import { CheckpointTracker } from "./components"; import CVInput from "./components/CVInput"; -import { resetPassword } from "@lib/api"; import { getFirstName } from "@lib/naming"; +import { getCourses } from "@lib/api"; interface Course { id: any; name: string; } -function Profile({ courses }) { +function Profile() { const { user, editUser } = useAuth() as { user: IAttendee; editUser: (username: FormData) => void; @@ -31,6 +31,16 @@ function Profile({ courses }) { const [username, setUsername] = useState(user.nickname || ""); const [course, setCourse] = useState(user.course.toString() || ""); + const [courses, setCourses] = useState([ + { id: "", name: "None" }, + ]); + + useEffect(() => { + getCourses().then((response) => { + setCourses(response.data.concat(courses)); + }); + }, []); + const [photoFileUrl, setPhotoFileUrl] = useState(user.avatar); const companyBadges = user.badges.filter((entry) => entry.type == 4).length; diff --git a/layout/SignUp/SignUp.tsx b/layout/SignUp/SignUp.tsx index 3f6638cf..6c1a6c46 100644 --- a/layout/SignUp/SignUp.tsx +++ b/layout/SignUp/SignUp.tsx @@ -1,13 +1,31 @@ +import { useEffect, useState } from "react"; + import { motion as Motion } from "framer-motion"; import Card from "@components/Card"; import Return from "@components/Return"; import { SignUpForm } from "./components"; - import Title from "@layout/moonstone/authentication/Title"; import Text from "@layout/moonstone/authentication/Text"; -function Signup({ courses }) { +import { getCourses } from "@lib/api"; + +interface Course { + id: any; + name: string; +} + +function Signup() { + const [courses, setCourses] = useState([ + { id: "", name: "None" }, + ]); + + useEffect(() => { + getCourses().then((response) => { + setCourses(response.data.concat(courses)); + }); + }, []); + return (
diff --git a/pages/attendee/profile.tsx b/pages/attendee/profile.tsx index f3d7931b..bfd600d6 100644 --- a/pages/attendee/profile.tsx +++ b/pages/attendee/profile.tsx @@ -1,18 +1,3 @@ import Profile from "@layout/Attendee/Profile"; -import { getCourses } from "@lib/api"; - -export async function getServerSideProps(context) { - context.res.setHeader( - "Cache-Control", - "public, s-maxage=3600, stale-while-revalidate=3600" - ); - - const courses = await getCourses().then((response) => - response.data.concat({ id: "", name: "None" }) - ); - - return { props: { courses: courses } }; -} - export default Profile; diff --git a/pages/register/[uuid].js b/pages/register/[uuid].js index 443b6217..d6dd32a2 100644 --- a/pages/register/[uuid].js +++ b/pages/register/[uuid].js @@ -17,20 +17,7 @@ import PasswordInput from "@components/PasswordInput"; import Title from "@layout/moonstone/authentication/Title"; import Text from "@layout/moonstone/authentication/Text"; -export async function getServerSideProps(context) { - context.res.setHeader( - "Cache-Control", - "public, s-maxage=3600, stale-while-revalidate=3600" - ); - - const courses = await getCourses().then((response) => - response.data.concat({ id: "", name: "None" }) - ); - - return { props: { courses: courses } }; -} - -function Register({ courses }) { +function Register() { const { sign_up, errors, isLoading } = useAuth(); const router = useRouter(); const { uuid } = router.query; @@ -42,6 +29,16 @@ function Register({ courses }) { const [password, updatePassword] = useState(""); const [password_confirmation, updatePasswordConfirmation] = useState(""); + const [courses, setCourses] = useState([ + { id: "", name: "None" } + ]); + + useEffect(() => { + getCourses().then((response) => { + setCourses(response.data.concat(courses)); + }); + }, []); + const onFinish = (e) => { e.preventDefault(); sign_up({ diff --git a/pages/signup.tsx b/pages/signup.tsx index 69c40005..74b66d31 100644 --- a/pages/signup.tsx +++ b/pages/signup.tsx @@ -1,18 +1,3 @@ -import { getCourses } from "@lib/api"; - import SignUp from "@layout/SignUp"; -export async function getServerSideProps(context) { - context.res.setHeader( - "Cache-Control", - "public, s-maxage=3600, stale-while-revalidate=3600" - ); - - const courses = await getCourses().then((response) => - response.data.concat({ id: "", name: "None" }) - ); - - return { props: { courses: courses } }; -} - export default SignUp;