From 0c0fc094c83272db75531f0ab8755b66345c4c85 Mon Sep 17 00:00:00 2001 From: Jacob Boyles Date: Thu, 27 Mar 2025 16:10:29 -0400 Subject: [PATCH] staffing requests done --- app/staffing/page.tsx | 52 ++++++++++++++++++++++++++++++++++----- models/staffingRequest.ts | 2 +- 2 files changed, 47 insertions(+), 7 deletions(-) diff --git a/app/staffing/page.tsx b/app/staffing/page.tsx index 6ca6307..203e297 100644 --- a/app/staffing/page.tsx +++ b/app/staffing/page.tsx @@ -12,20 +12,26 @@ import { import { Input } from "@/components/ui/input"; import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select"; import { Response } from "@/models/response"; +import { StaffingRequest as StaffingRequestType } from "@/models/staffingRequest"; import { zodResolver } from "@hookform/resolvers/zod"; import { useRouter } from "next/navigation"; -import { useEffect, useState } from "react"; +import { useContext, useEffect, useState } from "react"; import { Row, Col, Button, Spinner } from "react-bootstrap"; import DatePicker from "react-datepicker"; import { useForm } from "react-hook-form"; import { toast } from "react-toastify"; import { z } from "zod"; +import { AuthContext } from "../Providers"; + const formSchema = z.object({ + email: z.string().email(), organization: z.string().nonempty(), estimatedPilots: z.number().positive(), - start: z.date(), + start: z.date().refine((date) => date > new Date(), { + message: "Start date must be in the future", + }), duration: z.string().nonempty(), }); @@ -43,6 +49,7 @@ const generateDurationOptions = () => { export default function StaffingRequest() { + const authContext = useContext(AuthContext); const router = useRouter(); const [loading, setLoading] = useState(true); @@ -50,6 +57,7 @@ export default function StaffingRequest() { const form = useForm>({ resolver: zodResolver(formSchema), defaultValues: { + email: "", organization: "", estimatedPilots: 0, start: new Date(), @@ -64,13 +72,22 @@ export default function StaffingRequest() { async function onSubmit(values: z.infer) { setLoading(true); + const requestBody: StaffingRequestType = { + cid: authContext?.user?.cid as number, + fullName: authContext?.user?.fullName as string, + email: values.email, + organization: values.organization, + estimatedPilots: values.estimatedPilots, + start: values.start, + duration: values.duration, + }; await fetch(`${process.env.NEXT_PUBLIC_API_URL}/staffingrequests`, { method: "POST", headers: { "Content-Type": "application/json", "Authorization": `Bearer ${localStorage.getItem("accessToken")}`, }, - body: JSON.stringify(values), + body: JSON.stringify(requestBody), }).then(async (response) => { if (!response.ok) { const error = await response.json() as Response; @@ -102,6 +119,21 @@ export default function StaffingRequest() {
+ + ( + + Email + + + + + + )} + /> + Organization - + )} /> + + Estimated Pilots - + field.onChange(e.target.value === "" ? undefined : Number(e.target.value))} + /> @@ -139,6 +178,7 @@ export default function StaffingRequest() { render={({ field }) => ( Start +
Duration