From ffaaaa18793794506b3ba4d336c480dc6bf64ea0 Mon Sep 17 00:00:00 2001 From: Abh1noob Date: Thu, 14 Mar 2024 22:08:27 +0530 Subject: [PATCH] conditional hostel --- devsoc24-portal-fe/public/hostels.json | 28 --------- devsoc24-portal-fe/public/hostels.ts | 60 +++++++++++++++++++ .../src/app/profile/profile-form.tsx | 2 +- .../src/components/forms/vitian-form.tsx | 48 +++++++++++---- devsoc24-portal-fe/src/schemas/profile.ts | 7 +-- 5 files changed, 101 insertions(+), 44 deletions(-) delete mode 100644 devsoc24-portal-fe/public/hostels.json create mode 100644 devsoc24-portal-fe/public/hostels.ts diff --git a/devsoc24-portal-fe/public/hostels.json b/devsoc24-portal-fe/public/hostels.json deleted file mode 100644 index de31ed9..0000000 --- a/devsoc24-portal-fe/public/hostels.json +++ /dev/null @@ -1,28 +0,0 @@ -[ - "Ladies' Hostel - A Block", - "Ladies' Hostel - B Block", - "Ladies' Hostel - C Block", - "Ladies' Hostel - D Block", - "Ladies' Hostel - E Block", - "Ladies' Hostel - F Block", - "Ladies' Hostel - G Block", - "Ladies' Hostel - H Block", - "Men's Hostel - A Block", - "Men's Hostel - B Block", - "Men's Hostel - B Annex", - "Men's Hostel - C Block", - "Men's Hostel - D Block", - "Men's Hostel - D Annex", - "Men's Hostel - E Block", - "Men's Hostel - F Block", - "Men's Hostel - G Block", - "Men's Hostel - H Block", - "Men's Hostel - J Block", - "Men's Hostel - K Block", - "Men's Hostel - L Block", - "Men's Hostel - M Block", - "Men's Hostel - N Block", - "Men's Hostel - P Block", - "Men's Hostel - Q Block", - "Men's Hostel - R Block" -] diff --git a/devsoc24-portal-fe/public/hostels.ts b/devsoc24-portal-fe/public/hostels.ts new file mode 100644 index 0000000..69bacb0 --- /dev/null +++ b/devsoc24-portal-fe/public/hostels.ts @@ -0,0 +1,60 @@ +export const hostelDetails = { + all: [ + "Ladies' Hostel - A Block", + "Ladies' Hostel - B Block", + "Ladies' Hostel - C Block", + "Ladies' Hostel - D Block", + "Ladies' Hostel - E Block", + "Ladies' Hostel - F Block", + "Ladies' Hostel - G Block", + "Ladies' Hostel - H Block", + "Men's Hostel - A Block", + "Men's Hostel - B Block", + "Men's Hostel - B Annex", + "Men's Hostel - C Block", + "Men's Hostel - D Block", + "Men's Hostel - D Annex", + "Men's Hostel - E Block", + "Men's Hostel - F Block", + "Men's Hostel - G Block", + "Men's Hostel - H Block", + "Men's Hostel - J Block", + "Men's Hostel - K Block", + "Men's Hostel - L Block", + "Men's Hostel - M Block", + "Men's Hostel - N Block", + "Men's Hostel - P Block", + "Men's Hostel - Q Block", + "Men's Hostel - R Block", + ], + mens: [ + "Men's Hostel - A Block", + "Men's Hostel - B Block", + "Men's Hostel - B Annex", + "Men's Hostel - C Block", + "Men's Hostel - D Block", + "Men's Hostel - D Annex", + "Men's Hostel - E Block", + "Men's Hostel - F Block", + "Men's Hostel - G Block", + "Men's Hostel - H Block", + "Men's Hostel - J Block", + "Men's Hostel - K Block", + "Men's Hostel - L Block", + "Men's Hostel - M Block", + "Men's Hostel - N Block", + "Men's Hostel - P Block", + "Men's Hostel - Q Block", + "Men's Hostel - R Block", + ], + ladies: [ + "Ladies' Hostel - A Block", + "Ladies' Hostel - B Block", + "Ladies' Hostel - C Block", + "Ladies' Hostel - D Block", + "Ladies' Hostel - E Block", + "Ladies' Hostel - F Block", + "Ladies' Hostel - G Block", + "Ladies' Hostel - H Block", + ], +}; diff --git a/devsoc24-portal-fe/src/app/profile/profile-form.tsx b/devsoc24-portal-fe/src/app/profile/profile-form.tsx index 36a1e27..d1a1a50 100644 --- a/devsoc24-portal-fe/src/app/profile/profile-form.tsx +++ b/devsoc24-portal-fe/src/app/profile/profile-form.tsx @@ -13,7 +13,7 @@ import { Input } from "@/components/ui/input"; import { Button } from "@/components/ui/button"; import { profileSchema } from "@/schemas/profile"; import toast from "react-hot-toast"; -import blocks from "@/../public/hostels.json"; +import blocks from "public/hostels"; import axios, { type AxiosResponse } from "axios"; import { type userProps } from "@/interfaces"; import ToastContainer from "@/components/ToastContainer"; diff --git a/devsoc24-portal-fe/src/components/forms/vitian-form.tsx b/devsoc24-portal-fe/src/components/forms/vitian-form.tsx index 1b2931a..c3ab016 100644 --- a/devsoc24-portal-fe/src/components/forms/vitian-form.tsx +++ b/devsoc24-portal-fe/src/components/forms/vitian-form.tsx @@ -1,8 +1,8 @@ "use client"; -import blocks from "@/../public/hostels.json"; +import { hostelDetails } from "public/hostels"; import { vitianDetails } from "@/schemas/signup"; -import React from "react"; +import React, { useEffect, useState } from "react"; import { useForm } from "react-hook-form"; import { zodResolver } from "@hookform/resolvers/zod"; import { type z } from "zod"; @@ -48,6 +48,7 @@ export default function VitianForm({ }, mode: "onChange", }); + const [gender, setGender] = useState(""); async function onSubmit(data: VitianDetailsFormValues) { // const toastId = toast.loading("Saving...", { autoClose: false }); @@ -99,6 +100,11 @@ export default function VitianForm({ }, }); } + useEffect(() => { + const temp = localStorage.getItem("gender"); + setGender(temp!); + }, []); + return ( <> @@ -173,15 +179,35 @@ export default function VitianForm({ - {blocks.map((block, index) => ( - - {block} - - ))} + {gender === "Male" + ? hostelDetails.mens.map((block, index) => ( + + {block} + + )) + : gender === "Female" + ? hostelDetails.ladies.map((block, index) => ( + + {block} + + )) + : hostelDetails.all.map((block, index) => ( + + {block} + + ))} diff --git a/devsoc24-portal-fe/src/schemas/profile.ts b/devsoc24-portal-fe/src/schemas/profile.ts index 4dcca26..650e4cd 100644 --- a/devsoc24-portal-fe/src/schemas/profile.ts +++ b/devsoc24-portal-fe/src/schemas/profile.ts @@ -15,10 +15,9 @@ export const profileSchema = z.object({ invalid_type_error: "Last Name must be a string", }) .max(50, "Last Name cannot be longer than 50 characters"), - vit_email: z - .string({ - invalid_type_error: "VIT Email must be a string", - }), + vit_email: z.string({ + invalid_type_error: "VIT Email must be a string", + }), phone: z .string({ required_error: "Required",