Skip to content

Commit

Permalink
conditional hostel
Browse files Browse the repository at this point in the history
  • Loading branch information
Abh1noob committed Mar 14, 2024
1 parent c505df5 commit ffaaaa1
Show file tree
Hide file tree
Showing 5 changed files with 101 additions and 44 deletions.
28 changes: 0 additions & 28 deletions devsoc24-portal-fe/public/hostels.json

This file was deleted.

60 changes: 60 additions & 0 deletions devsoc24-portal-fe/public/hostels.ts
Original file line number Diff line number Diff line change
@@ -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",
],
};
2 changes: 1 addition & 1 deletion devsoc24-portal-fe/src/app/profile/profile-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
48 changes: 37 additions & 11 deletions devsoc24-portal-fe/src/components/forms/vitian-form.tsx
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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 });
Expand Down Expand Up @@ -99,6 +100,11 @@ export default function VitianForm({
},
});
}
useEffect(() => {
const temp = localStorage.getItem("gender");
setGender(temp!);
}, []);

return (
<>
<ToastContainer />
Expand Down Expand Up @@ -173,15 +179,35 @@ export default function VitianForm({
</SelectTrigger>
</FormControl>
<SelectContent>
{blocks.map((block, index) => (
<SelectItem
key={index}
value={block}
className="rounded-none border-b border-border/30"
>
<span>{block}</span>
</SelectItem>
))}
{gender === "Male"
? hostelDetails.mens.map((block, index) => (
<SelectItem
key={index}
value={block}
className="rounded-none border-b border-border/30"
>
<span>{block}</span>
</SelectItem>
))
: gender === "Female"
? hostelDetails.ladies.map((block, index) => (
<SelectItem
key={index}
value={block}
className="rounded-none border-b border-border/30"
>
<span>{block}</span>
</SelectItem>
))
: hostelDetails.all.map((block, index) => (
<SelectItem
key={index}
value={block}
className="rounded-none border-b border-border/30"
>
<span>{block}</span>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
Expand Down
7 changes: 3 additions & 4 deletions devsoc24-portal-fe/src/schemas/profile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down

0 comments on commit ffaaaa1

Please sign in to comment.