diff --git a/devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx b/devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx index e375128..8760936 100644 --- a/devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx +++ b/devsoc24-portal-fe/src/app/forgot/forgot-pass-form.tsx @@ -31,22 +31,7 @@ export default function ForgotForm() { async function onSubmit(data: ForgotFormValues) { console.log(data); - // const toastId = toast.loading("Logging in...", { autoClose: false }); - // const res = await loginUser(data); - - // toast.update(toastId, { - // render: - // res === 200 ? "Login successful!" : res !== 500 ? res : , - // type: res === 200 ? "success" : "error", - // isLoading: false, - // autoClose: 2000, - // }); - - // if (res === 200) { - // setTimeout(() => { - // void router.push("/overview"); - // }, 2000); - // } + } return ( diff --git a/devsoc24-portal-fe/src/app/login/login-form.tsx b/devsoc24-portal-fe/src/app/login/login-form.tsx index 69ab1b0..686e0a1 100644 --- a/devsoc24-portal-fe/src/app/login/login-form.tsx +++ b/devsoc24-portal-fe/src/app/login/login-form.tsx @@ -17,7 +17,7 @@ import "react-toastify/dist/ReactToastify.css"; import { useRouter } from "next/navigation"; import { EyeIcon, EyeOffIcon, LockKeyholeIcon, MailIcon } from "lucide-react"; import Link from "next/link"; -import { type LoginResponse } from "@/schemas/api"; +import { type APIResponse, type LoginResponse } from "@/schemas/api"; import axios, { type AxiosError } from "axios"; import { BadRequest, ServerError } from "@/components/toast"; @@ -39,7 +39,7 @@ export default function LoginForm() { async function onSubmit(formVal: LoginFormValues) { const toastId = toast.loading("Logging in...", { autoClose: false }); try { - const { data } = await axios.post( + const { data } = await axios.post( `${process.env.NEXT_PUBLIC_API_URL}/login`, { email: formVal.email, password: formVal.password }, ); @@ -54,8 +54,10 @@ export default function LoginForm() { isLoading: false, autoClose: 2000, }); + const res = data.data as LoginResponse; + setTimeout(() => { - if (data.profile_complete) { + if (res.profile_complete) { void router.push("/"); } else { void router.push("/signup/details?email=" + formVal.email); @@ -101,6 +103,9 @@ export default function LoginForm() { isLoading: false, autoClose: 2000, }); + setTimeout(() => { + void router.push("/signup/verify?email=" + formVal.email); + }, 1500); } else if (error.response?.status === 400) { toast.update(toastId, { render: , diff --git a/devsoc24-portal-fe/src/app/reset/page.tsx b/devsoc24-portal-fe/src/app/reset/page.tsx index 7dcd6a5..acc88e1 100644 --- a/devsoc24-portal-fe/src/app/reset/page.tsx +++ b/devsoc24-portal-fe/src/app/reset/page.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useState } from "react"; import Logo from "@/components/logo"; -import { ModeToggle } from "@/components/theme-toggle"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import Image from "next/image"; import title from "@/assets/images/title.svg"; @@ -31,7 +30,6 @@ export default function Page() {
- {/* */}
diff --git a/devsoc24-portal-fe/src/app/signup/details/page.tsx b/devsoc24-portal-fe/src/app/signup/details/page.tsx index 447bb2e..cd8ae15 100644 --- a/devsoc24-portal-fe/src/app/signup/details/page.tsx +++ b/devsoc24-portal-fe/src/app/signup/details/page.tsx @@ -13,7 +13,7 @@ import { DiscordIcon } from "@/assets/images/discord"; import TeamDetailsForm from "./team-form"; export default function Page() { - const [form, setForm] = useState(0); + const [form, setForm] = useState(2); const [isBannerVisible, setIsBannerVisible] = useState(true); return ( @@ -64,7 +64,7 @@ export default function Page() {

{form === 0 && } {form === 1 && } - {form === 2 && } + {form === 2 && }
); diff --git a/devsoc24-portal-fe/src/app/signup/details/personal-details-form.tsx b/devsoc24-portal-fe/src/app/signup/details/personal-details-form.tsx index 23025a9..4abb8f4 100644 --- a/devsoc24-portal-fe/src/app/signup/details/personal-details-form.tsx +++ b/devsoc24-portal-fe/src/app/signup/details/personal-details-form.tsx @@ -52,30 +52,18 @@ export default function PersonalDetails({ useEffect(() => { form.setValue("firstName", localStorage.getItem("first_name") ?? ""); form.setValue("lastName", localStorage.getItem("last_name") ?? ""); + form.setValue("email", email ?? ""); form.setValue("phoneNumber", localStorage.getItem("phone_number") ?? ""); form.setValue("country", localStorage.getItem("country") ?? "+91"); - const gender = localStorage.getItem("gender"); - console.log(gender); - - switch (gender) { - case "Male": { - form.setValue("gender", "Male"); - break; - } - case "Female": { - form.setValue("gender", "Female"); - break; - } - case "Others": { - form.setValue("gender", "Others"); - break; - } - case "Prefer Not to Say": { - form.setValue("gender", "Prefer Not to Say"); - break; - } - } - }); + form.setValue( + "gender", + (localStorage.getItem("gender") as + | "Male" + | "Female" + | "Others" + | "Prefer Not to Say") ?? undefined, + ); + }, []); async function onSubmit(data: PersonalDetailsFormValues) { localStorage.setItem("first_name", data.firstName); @@ -104,6 +92,7 @@ export default function PersonalDetails({ type="text" placeholder="First Name" autoComplete="First Name" + required {...field} className={` ${ form.getFieldState("firstName").invalid @@ -155,6 +144,7 @@ export default function PersonalDetails({ type="email" placeholder="Email Address" autoComplete="email" + required disabled {...field} className={` ${ @@ -206,6 +196,7 @@ export default function PersonalDetails({ type="text" placeholder="Phone Number" autoComplete="phone" + required {...field} className={`pl-[80px] ${ form.getFieldState("phoneNumber").invalid diff --git a/devsoc24-portal-fe/src/app/signup/details/team-form.tsx b/devsoc24-portal-fe/src/app/signup/details/team-form.tsx index 0649aab..3df8ad9 100644 --- a/devsoc24-portal-fe/src/app/signup/details/team-form.tsx +++ b/devsoc24-portal-fe/src/app/signup/details/team-form.tsx @@ -6,12 +6,10 @@ import React, { useState } from "react"; import CreateTeamForm from "@/components/forms/create-team-form"; import JoinTeamForm from "@/components/forms/join-team-form"; import { Button } from "@/components/ui/button"; +import { useRouter } from "next/navigation"; -export default function TeamDetailsForm({ - setForm, -}: { - setForm: React.Dispatch>; -}) { +export default function TeamDetailsForm() { + const router = useRouter(); const [isNewTeam, setisNewTeam] = useState(false); return ( @@ -35,7 +33,12 @@ export default function TeamDetailsForm({

{isNewTeam ? : } - +

You can join / create a team later!

diff --git a/devsoc24-portal-fe/src/app/signup/page.tsx b/devsoc24-portal-fe/src/app/signup/page.tsx index e305726..1f42d21 100644 --- a/devsoc24-portal-fe/src/app/signup/page.tsx +++ b/devsoc24-portal-fe/src/app/signup/page.tsx @@ -2,7 +2,6 @@ import React, { useEffect, useState } from "react"; import Logo from "@/components/logo"; -import { ModeToggle } from "@/components/theme-toggle"; import { Card, CardContent, CardHeader } from "@/components/ui/card"; import Image from "next/image"; import title from "@/assets/images/title.svg"; @@ -31,7 +30,6 @@ export default function Page() {
- {/* */}
diff --git a/devsoc24-portal-fe/src/components/forms/create-team-form.tsx b/devsoc24-portal-fe/src/components/forms/create-team-form.tsx index 94b3e13..01c0a4a 100644 --- a/devsoc24-portal-fe/src/components/forms/create-team-form.tsx +++ b/devsoc24-portal-fe/src/components/forms/create-team-form.tsx @@ -5,13 +5,6 @@ import React from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { type z } from "zod"; -import { - Select, - SelectContent, - SelectItem, - SelectTrigger, - SelectValue, -} from "@/components/ui/select"; import { Form, FormControl, @@ -22,10 +15,17 @@ import { } from "@/components/ui/form"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; +import { toast, ToastContainer } from "react-toastify"; +import "react-toastify/dist/ReactToastify.css"; +import axios, { type AxiosError } from "axios"; +import { type APIResponse } from "@/schemas/api"; +import { useRouter } from "next/navigation"; +import { BadRequest, ServerError } from "../toast"; type CreateTeamFormValues = z.infer; export default function CreateTeamForm() { + const router = useRouter(); const createTeamForm = useForm({ resolver: zodResolver(createTeamSchema), defaultValues: { @@ -35,57 +35,113 @@ export default function CreateTeamForm() { }); async function onSubmit(data: CreateTeamFormValues) { + const toastId = toast.loading("Creating...", { autoClose: false }); console.log(data); - // const toastId = toast.loading("Logging in...", { autoClose: false }); - // const res = await loginUser(data); - - // toast.update(toastId, { - // render: - // res === 200 ? "Login successful!" : res !== 500 ? res : , - // type: res === 200 ? "success" : "error", - // isLoading: false, - // autoClose: 2000, - // }); - - // if (res === 200) { - // setTimeout(() => { - // void router.push("/overview"); - // }, 2000); - // } + try { + await axios.post( + `${process.env.NEXT_PUBLIC_API_URL}/team/create`, + { name: data.teamName }, + { + withCredentials: true, + }, + ); + toast.update(toastId, { + render: ( +
+

Success!

+

Team created successfully.

+
+ ), + type: "success", + isLoading: false, + autoClose: 2000, + }); + setTimeout(() => { + void router.push("/"); + }, 1500); + return; + } catch (err) { + console.log(err); + if (axios.isAxiosError(err)) { + const error = err as AxiosError; + if (error.response?.status === 400) { + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } else if (error.response?.status === 417) { + toast.update(toastId, { + render: ( +
+

User is already in a team!

+

Leave the team to create a new one.

+
+ ), + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } else if (error.response?.status === 409) { + toast.update(toastId, { + render: ( +
+

Team name already exists!

+

Please choose a different name for your team.

+
+ ), + }); + return; + } + } + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } } return ( -
- - ( - - Team Name - -
- -
-
- -
- )} - /> - - - + <> + +
+ + ( + + Team Name + +
+ +
+
+ +
+ )} + /> + + + + ); } diff --git a/devsoc24-portal-fe/src/components/forms/external-form.tsx b/devsoc24-portal-fe/src/components/forms/external-form.tsx index 1b782a9..c5b4296 100644 --- a/devsoc24-portal-fe/src/components/forms/external-form.tsx +++ b/devsoc24-portal-fe/src/components/forms/external-form.tsx @@ -23,6 +23,12 @@ import { } from "@/components/ui/form"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; +import { ToastContainer, toast } from "react-toastify"; +import "react-toastify/dist/ReactToastify.css"; +import axios, { type AxiosError } from "axios"; +import { type APIResponse } from "@/schemas/api"; +import { BadRequest, ServerError } from "../toast"; +import { useSearchParams } from "next/navigation"; type ExternalDetailsFormValues = z.infer; @@ -31,6 +37,8 @@ export default function ExternalForm({ }: { setForm: React.Dispatch>; }) { + const searchParams = useSearchParams(); + const email = searchParams.get("email"); const externalForm = useForm({ resolver: zodResolver(externalDetails), defaultValues: { @@ -43,155 +51,222 @@ export default function ExternalForm({ }); async function onSubmit(data: ExternalDetailsFormValues) { - console.log(data); - // const toastId = toast.loading("Logging in...", { autoClose: false }); - // const res = await loginUser(data); + const toastId = toast.loading("Saving...", { autoClose: false }); + const updatedData = { + first_name: localStorage.getItem("first_name"), + last_name: localStorage.getItem("last_name"), + phone: localStorage.getItem("phone_number"), + gender: localStorage.getItem("gender"), + is_vitian: false, + email: email, + college: data.collegeName, + city: data.collegeCity, + state: data.collegeState, + reg_no: data.collegeRollNumber, + }; + console.log(updatedData); - // toast.update(toastId, { - // render: - // res === 200 ? "Login successful!" : res !== 500 ? res : , - // type: res === 200 ? "success" : "error", - // isLoading: false, - // autoClose: 2000, - // }); - - // if (res === 200) { - // setTimeout(() => { - // void router.push("/overview"); - // }, 2000); - // } + try { + await axios.post( + `${process.env.NEXT_PUBLIC_API_URL}/user/complete-profile`, + updatedData, + { + withCredentials: true, + }, + ); + toast.update(toastId, { + render: ( +
+

Success!

+

Account details saved successfully.

+
+ ), + type: "success", + isLoading: false, + autoClose: 2000, + }); + setForm(2); + return; + } catch (err) { + console.log(err); + if (axios.isAxiosError(err)) { + const error = err as AxiosError; + if (error.response?.status === 400) { + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + } else if (error.response?.status === 403) { + toast.update(toastId, { + render: ( +
+

Email not verified!

+

Please verify your email.

+
+ ), + type: "error", + isLoading: false, + autoClose: 2000, + }); + } else if (error.response?.status === 404) { + toast.update(toastId, { + render: ( +
+

User not found!

+

Please sign up.

+
+ ), + }); + } + return; + } + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } } return ( -
- - ( - - College Name - -
- -
-
- -
- )} - /> + <> + + + + ( + + College Name + +
+ +
+
+ +
+ )} + /> - ( - - College Location - -
- -
-
- -
- )} - /> - ( - - {/* VIT Email Address */} - -
- -
-
- -
- )} - /> + ( + + College Location + +
+ +
+
+ +
+ )} + /> + ( + + +
+ +
+
+ +
+ )} + /> - ( - - College Identification Number - -
- -
-
- -
- )} - /> -
- - -
- - + ( + + College Identification Number + +
+ +
+
+ +
+ )} + /> +
+ + +
+ + + ); } diff --git a/devsoc24-portal-fe/src/components/forms/join-team-form.tsx b/devsoc24-portal-fe/src/components/forms/join-team-form.tsx index 909e138..cf640ad 100644 --- a/devsoc24-portal-fe/src/components/forms/join-team-form.tsx +++ b/devsoc24-portal-fe/src/components/forms/join-team-form.tsx @@ -4,7 +4,7 @@ import { joinTeamSchema } from "@/schemas/signup"; import React from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; -import { z } from "zod"; // Change this line from { type z } to { z } +import { type z } from "zod"; import { Form, FormControl, @@ -15,11 +15,17 @@ import { } from "@/components/ui/form"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; -import axios from "axios"; // Removed AxiosResponse import +import axios, { type AxiosError } from "axios"; +import { ToastContainer, toast } from "react-toastify"; +import "react-toastify/dist/ReactToastify.css"; +import { type APIResponse } from "@/schemas/api"; +import { useRouter } from "next/navigation"; +import { BadRequest, ServerError } from "../toast"; type CreateTeamFormValues = z.infer; export default function JoinTeamForm() { + const router = useRouter(); const createTeamForm = useForm({ resolver: zodResolver(joinTeamSchema), defaultValues: { @@ -29,90 +35,128 @@ export default function JoinTeamForm() { }); async function onSubmit(data: CreateTeamFormValues) { + const toastId = toast.loading("Joining...", { autoClose: false }); console.log(data); - console.log("submittt") - // const toastId = toast.loading("Logging in...", { autoClose: false }); - // const res = await loginUser(data); - - // toast.update(toastId, { - // render: - // res === 200 ? "Login successful!" : res !== 500 ? res : , - // type: res === 200 ? "success" : "error", - // isLoading: false, - // autoClose: 2000, - // }); - - // if (res === 200) { - // setTimeout(() => { - // void router.push("/overview"); - // }, 2000); - // } - } - - const handleJoinTeam = async (e: string) => { - console.log("clicked"); try { - const response = await axios.post( + await axios.post( `${process.env.NEXT_PUBLIC_API_URL}/team/join`, - { - code: e, - }, + { code: data.teamCode }, { withCredentials: true, }, ); - console.log("FETCH IDEA: ", response); - } catch (e) { - if (axios.isAxiosError(e)) { - switch (e.response?.status) { - // case 404: - // console.log("no team"); - // case 417: - // console.log("team no idea"); - default: - console.log(e); + toast.update(toastId, { + render: ( +
+

Success!

+

Team joined successfully.

+
+ ), + type: "success", + isLoading: false, + autoClose: 2000, + }); + setTimeout(() => { + void router.push("/"); + }, 1500); + return; + } catch (err) { + console.log(err); + if (axios.isAxiosError(err)) { + const error = err as AxiosError; + if (error.response?.status === 400) { + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } else if (error.response?.status === 417) { + toast.update(toastId, { + render: ( +
+

User is already in a team!

+

Leave the team to create a new one.

+
+ ), + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } else if (error.response?.status === 409) { + toast.update(toastId, { + render: ( +
+

Invalid team code!

+

Please check the team code and try again.

+
+ ), + }); + return; + } else if (error.response?.status === 424) { + toast.update(toastId, { + render: ( +
+

Team is full!

+

Try joining another team.

+
+ ), + }); + return; } } + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; } - }; + } return ( -
- - ( - - Team Code - -
- -
-
- {/* Display error message */} - {createTeamForm.formState.errors.teamCode && ( - - {createTeamForm.formState.errors.teamCode.message} - - )} -
- )} - /> - - - + <> + +
+ + ( + + Team Code + +
+ +
+
+ {/* Display error message */} + {createTeamForm.formState.errors.teamCode && ( + + {createTeamForm.formState.errors.teamCode.message} + + )} +
+ )} + /> + + + + ); } diff --git a/devsoc24-portal-fe/src/components/forms/vitian-form.tsx b/devsoc24-portal-fe/src/components/forms/vitian-form.tsx index 6f7a2d9..f184c63 100644 --- a/devsoc24-portal-fe/src/components/forms/vitian-form.tsx +++ b/devsoc24-portal-fe/src/components/forms/vitian-form.tsx @@ -23,6 +23,12 @@ import { } from "@/components/ui/form"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; +import { ToastContainer, toast } from "react-toastify"; +import "react-toastify/dist/ReactToastify.css"; +import { useSearchParams } from "next/navigation"; +import { BadRequest, ServerError } from "../toast"; +import axios, { type AxiosError } from "axios"; +import { type APIResponse } from "@/schemas/api"; type VitianDetailsFormValues = z.infer; @@ -31,6 +37,8 @@ export default function VitianForm({ }: { setForm: React.Dispatch>; }) { + const searchParams = useSearchParams(); + const email = searchParams.get("email"); const vitianForm = useForm({ resolver: zodResolver(vitianDetails), defaultValues: { @@ -43,9 +51,91 @@ export default function VitianForm({ }); async function onSubmit(data: VitianDetailsFormValues) { - console.log(data); - // const toastId = toast.loading("Logging in...", { autoClose: false }); - // const res = await loginUser(data); + const toastId = toast.loading("Saving...", { autoClose: false }); + const updatedData = { + first_name: localStorage.getItem("first_name"), + last_name: localStorage.getItem("last_name"), + phone: localStorage.getItem("phone_number"), + gender: localStorage.getItem("gender"), + is_vitian: true, + email: email, + college: "VIT Vellore", + city: "Vellore", + state: "Tamil Nadu", + reg_no: data.regNumber, + block: data.block, + room: data.roomNumber, + vit_email: data.vitEmail, + }; + console.log(updatedData); + + try { + await axios.post( + `${process.env.NEXT_PUBLIC_API_URL}/user/complete-profile`, + updatedData, + { + withCredentials: true, + }, + ); + toast.update(toastId, { + render: ( +
+

Success!

+

Account details saved successfully.

+
+ ), + type: "success", + isLoading: false, + autoClose: 2000, + }); + setTimeout(() => setForm(2), 1500); + return; + } catch (err) { + console.log(err); + if (axios.isAxiosError(err)) { + const error = err as AxiosError; + if (error.response?.status === 400) { + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + } else if (error.response?.status === 403) { + toast.update(toastId, { + render: ( +
+

Email not verified!

+

Please verify your email.

+
+ ), + type: "error", + isLoading: false, + autoClose: 2000, + }); + } else if (error.response?.status === 404) { + toast.update(toastId, { + render: ( +
+

User not found!

+

Please sign up.

+
+ ), + type: "error", + isLoading: false, + autoClose: 2000, + }); + } + return; + } + toast.update(toastId, { + render: , + type: "error", + isLoading: false, + autoClose: 2000, + }); + return; + } // toast.update(toastId, { // render: @@ -62,134 +152,137 @@ export default function VitianForm({ // } } return ( -
- - ( - - Registration Number - -
- -
-
- -
- )} - /> - ( - - VIT Email Address - -
- -
-
- -
- )} - /> - ( - - Block - -
- -
-
- -
- )} - /> - ( - - Room Number - -
- -
-
- -
- )} - /> -
- - -
- - + <> + +
+ + ( + + Registration Number + +
+ +
+
+ +
+ )} + /> + ( + + VIT Email Address + +
+ +
+
+ +
+ )} + /> + ( + + Block + +
+ +
+
+ +
+ )} + /> + ( + + Room Number + +
+ +
+
+ +
+ )} + /> +
+ + +
+ + + ); } diff --git a/devsoc24-portal-fe/src/schemas/signup.ts b/devsoc24-portal-fe/src/schemas/signup.ts index 0d9ffce..7a989f6 100644 --- a/devsoc24-portal-fe/src/schemas/signup.ts +++ b/devsoc24-portal-fe/src/schemas/signup.ts @@ -47,10 +47,10 @@ export const personalDetailsSchema = z.object({ .max(50, "First Name cannot be longer than 50 characters"), lastName: z .string({ - required_error: "First Name is required", - invalid_type_error: "First Name must be a string", + required_error: "Last Name is required", + invalid_type_error: "Last Name must be a string", }) - .max(50, "First Name cannot be longer than 50 characters"), + .max(50, "Last Name cannot be longer than 50 characters"), email: z .string({ required_error: "Email is required", @@ -95,39 +95,39 @@ export const vitianDetails = z.object({ invalid_type_error: "VIT Email must be a string", }) .regex(/^[a-zA-Z0-9._-]+@vitstudent.ac.in$/, "Enter a valid VIT email"), - block: z.union([ - z.literal("Ladies' Hostel - A Block"), - z.literal("Ladies' Hostel - B Block"), - z.literal("Ladies' Hostel - C Block"), - z.literal("Ladies' Hostel - D Block"), - z.literal("Ladies' Hostel - E Block"), - z.literal("Ladies' Hostel - F Block"), - z.literal("Ladies' Hostel - G Block"), - z.literal("Ladies' Hostel - H Block"), - z.literal("Men's Hostel - A Block"), - z.literal("Men's Hostel - B Block"), - z.literal("Men's Hostel - B Annex"), - z.literal("Men's Hostel - C Block"), - z.literal("Men's Hostel - D Block"), - z.literal("Men's Hostel - D Annex"), - z.literal("Men's Hostel - E Block"), - z.literal("Men's Hostel - F Block"), - z.literal("Men's Hostel - G Block"), - z.literal("Men's Hostel - H Block"), - z.literal("Men's Hostel - J Block"), - z.literal("Men's Hostel - K Block"), - z.literal("Men's Hostel - L Block"), - z.literal("Men's Hostel - M Block"), - z.literal("Men's Hostel - N Block"), - z.literal("Men's Hostel - P Block"), - z.literal("Men's Hostel - Q Block"), - z.literal("Men's Hostel - R Block"), - ]), + block: z + .literal("Ladies' Hostel - A Block") + .or(z.literal("Ladies' Hostel - B Block")) + .or(z.literal("Ladies' Hostel - C Block")) + .or(z.literal("Ladies' Hostel - D Block")) + .or(z.literal("Ladies' Hostel - E Block")) + .or(z.literal("Ladies' Hostel - F Block")) + .or(z.literal("Ladies' Hostel - G Block")) + .or(z.literal("Ladies' Hostel - H Block")) + .or(z.literal("Men's Hostel - A Block")) + .or(z.literal("Men's Hostel - B Block")) + .or(z.literal("Men's Hostel - B Annex")) + .or(z.literal("Men's Hostel - C Block")) + .or(z.literal("Men's Hostel - D Block")) + .or(z.literal("Men's Hostel - D Annex")) + .or(z.literal("Men's Hostel - E Block")) + .or(z.literal("Men's Hostel - F Block")) + .or(z.literal("Men's Hostel - G Block")) + .or(z.literal("Men's Hostel - H Block")) + .or(z.literal("Men's Hostel - J Block")) + .or(z.literal("Men's Hostel - K Block")) + .or(z.literal("Men's Hostel - L Block")) + .or(z.literal("Men's Hostel - M Block")) + .or(z.literal("Men's Hostel - N Block")) + .or(z.literal("Men's Hostel - P Block")) + .or(z.literal("Men's Hostel - Q Block")) + .or(z.literal("Men's Hostel - R Block")), roomNumber: z .string({ required_error: "Required", invalid_type_error: "Room number must be a string", }) + .min(1, "Enter a valid room number") .max(10, "Enter a valid room number"), }); @@ -137,56 +137,58 @@ export const externalDetails = z.object({ required_error: "Required", invalid_type_error: "College name must be a string", }) + .min(1, "Enter a valid college name") .max(50, "Enter a valid college name"), collegeCity: z .string({ required_error: "Required", invalid_type_error: "College city must be a string", }) + .min(1, "Enter a valid college city") .max(50, "Enter a valid college city"), - collegeState: z.union([ - z.literal("Andaman and Nicobar Islands"), - z.literal("Andhra Pradesh"), - z.literal("Arunachal Pradesh"), - z.literal("Assam"), - z.literal("Bihar"), - z.literal("Chandigarh"), - z.literal("Chhattisgarh"), - z.literal("Dadra and Nagar Haveli"), - z.literal("Daman and Diu"), - z.literal("Delhi"), - z.literal("Goa"), - z.literal("Gujarat"), - z.literal("Haryana"), - z.literal("Himachal Pradesh"), - z.literal("Jammu and Kashmir"), - z.literal("Jharkhand"), - z.literal("Karnataka"), - z.literal("Kerala"), - z.literal("Lakshadweep"), - z.literal("Madhya Pradesh"), - z.literal("Maharashtra"), - z.literal("Manipur"), - z.literal("Meghalaya"), - z.literal("Mizoram"), - z.literal("Nagaland"), - z.literal("Odisha"), - z.literal("Puducherry"), - z.literal("Punjab"), - z.literal("Rajasthan"), - z.literal("Sikkim"), - z.literal("Tamil Nadu"), - z.literal("Telangana"), - z.literal("Tripura"), - z.literal("Uttar Pradesh"), - z.literal("Uttarakhand"), - z.literal("West Bengal"), - ]), + collegeState: z + .literal("Andaman and Nicobar Islands") + .or(z.literal("Andhra Pradesh")) + .or(z.literal("Arunachal Pradesh")) + .or(z.literal("Assam")) + .or(z.literal("Bihar")) + .or(z.literal("Chandigarh")) + .or(z.literal("Chhattisgarh")) + .or(z.literal("Dadra and Nagar Haveli")) + .or(z.literal("Daman and Diu")) + .or(z.literal("Delhi")) + .or(z.literal("Goa")) + .or(z.literal("Gujarat")) + .or(z.literal("Haryana")) + .or(z.literal("Himachal Pradesh")) + .or(z.literal("Jammu and Kashmir")) + .or(z.literal("Jharkhand")) + .or(z.literal("Karnataka")) + .or(z.literal("Kerala")) + .or(z.literal("Lakshadweep")) + .or(z.literal("Madhya Pradesh")) + .or(z.literal("Maharashtra")) + .or(z.literal("Manipur")) + .or(z.literal("Meghalaya")) + .or(z.literal("Mizoram")) + .or(z.literal("Nagaland")) + .or(z.literal("Odisha")) + .or(z.literal("Puducherry")) + .or(z.literal("Punjab")) + .or(z.literal("Rajasthan")) + .or(z.literal("Sikkim")) + .or(z.literal("Tamil Nadu")) + .or(z.literal("Telangana")) + .or(z.literal("Tripura")) + .or(z.literal("Uttar Pradesh")) + .or(z.literal("Uttarakhand")) + .or(z.literal("West Bengal")), collegeRollNumber: z .string({ required_error: "Required", invalid_type_error: "College roll number must be a string", }) + .min(1, "Enter a valid college roll number") .max(50, "Enter a valid college roll number"), });