Add MissionForm WIP
This commit is contained in:
178
apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx
Normal file
178
apps/dispatch/app/dispatch/_components/pannel/MissionForm.tsx
Normal file
@@ -0,0 +1,178 @@
|
||||
"use client";
|
||||
import React, { useState } from "react";
|
||||
import { useForm, Controller } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { z } from "zod";
|
||||
import { MissionSchema } from "@repo/db/zod";
|
||||
import { Mission } from "@repo/db/zod";
|
||||
import { Trash2 } from "lucide-react";
|
||||
import { Select } from "_components/Select";
|
||||
|
||||
const clearBtn = () => {
|
||||
return (
|
||||
<button className="btn btn-sm btn-circle btn-info">
|
||||
<Trash2 className="w-4 h-4" />
|
||||
</button>
|
||||
);
|
||||
};
|
||||
|
||||
const missionFormSchema = MissionSchema.pick({
|
||||
addressLat: true,
|
||||
addressLng: true,
|
||||
addressStreet: true,
|
||||
addressCity: true,
|
||||
addressZip: true,
|
||||
missionCategory: true,
|
||||
missionKeyword: true,
|
||||
missionAdditionalInfo: true,
|
||||
missionPatientInfo: true,
|
||||
});
|
||||
|
||||
type MissionFormValues = z.infer<typeof missionFormSchema>;
|
||||
|
||||
const dummyRettungsmittel = [
|
||||
"Christoph 31",
|
||||
"Christoph 100",
|
||||
"Christoph Berlin",
|
||||
"Christophorus 1",
|
||||
];
|
||||
|
||||
export const MissionForm: React.FC = () => {
|
||||
const [missionCategory, setMissionCategory] = useState<"PRIMÄR" | "SEKUNDÄR">(
|
||||
"PRIMÄR",
|
||||
);
|
||||
const form = useForm<MissionFormValues>({
|
||||
resolver: zodResolver(missionFormSchema),
|
||||
defaultValues: {
|
||||
addressLat: 0,
|
||||
addressLng: 0,
|
||||
missionCategory: "PRIMÄR",
|
||||
},
|
||||
});
|
||||
const { control, register, handleSubmit, watch } = form;
|
||||
|
||||
const onSubmit = (data: MissionFormValues) => {
|
||||
console.log(data);
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-4">
|
||||
{/* Koorinaten Section */}
|
||||
<div className="form-control">
|
||||
<h2 className="text-lg font-bold mb-2">Koordinaten</h2>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("addressLat")}
|
||||
className="input input-sm input-neutral input-bordered w-full"
|
||||
readOnly
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("addressLng")}
|
||||
className="input input-sm input-neutral input-bordered w-full"
|
||||
readOnly
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Adresse Section */}
|
||||
<div className="form-control">
|
||||
<h2 className="text-lg font-bold mb-2">Adresse</h2>
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("addressStreet")}
|
||||
placeholder="Straße"
|
||||
className="input input-primary input-bordered w-full mb-4"
|
||||
/>
|
||||
<div className="grid grid-cols-2 gap-4">
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("addressCity")}
|
||||
placeholder="Stadt"
|
||||
className="input input-primary input-bordered w-full"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("addressZip")}
|
||||
placeholder="PLZ"
|
||||
className="input input-primary input-bordered w-full"
|
||||
/>
|
||||
</div>
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("missionAdditionalInfo")}
|
||||
placeholder="Zusätzliche Adressinformationen"
|
||||
className="input input-primary input-bordered w-full mt-4"
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Rettungsmittel Section */}
|
||||
<div className="form-control">
|
||||
<h2 className="text-lg font-bold mb-2">Rettungsmittel</h2>
|
||||
<Controller
|
||||
name="rettungsmittel"
|
||||
control={form.control}
|
||||
render={({ field }) => (
|
||||
<Select
|
||||
isMulti
|
||||
form={form}
|
||||
name="rettungsmittel"
|
||||
label={""}
|
||||
options={dummyRettungsmittel.map((item) => ({
|
||||
label: item,
|
||||
}))}
|
||||
/>
|
||||
)}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* Einsatzdaten Section */}
|
||||
<div className="form-control">
|
||||
<h2 className="text-lg font-bold mb-2">Einsatzdaten</h2>
|
||||
<select
|
||||
{...form.register("missionCategory")}
|
||||
className="select select-primary select-bordered w-full mb-4"
|
||||
onChange={(e) =>
|
||||
setMissionCategory(e.target.value as "PRIMÄR" | "SEKUNDÄR")
|
||||
}
|
||||
>
|
||||
<option value="PRIMÄR">PRIMÄR</option>
|
||||
<option value="SEKUNDÄR">SEKUNDÄR</option>
|
||||
</select>
|
||||
<input
|
||||
type="text"
|
||||
{...form.register("missionKeyword")}
|
||||
placeholder="Stichwort"
|
||||
className="input input-primary input-bordered w-full mb-4"
|
||||
/>
|
||||
<textarea
|
||||
{...form.register("missionAdditionalInfo")}
|
||||
placeholder="Einsatzinformationen"
|
||||
className="textarea textarea-primary textarea-bordered w-full mb-4"
|
||||
/>
|
||||
{missionCategory === "SEKUNDÄR" && (
|
||||
<input
|
||||
type="text"
|
||||
placeholder="Zielkrankenhaus"
|
||||
className="input input-primary input-bordered w-full"
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* Patienteninformationen Section */}
|
||||
<div className="form-control">
|
||||
<h2 className="text-lg font-bold mb-2">Patienteninformationen</h2>
|
||||
<textarea
|
||||
{...form.register("missionPatientInfo")}
|
||||
placeholder="Patienteninformationen"
|
||||
className="textarea textarea-primary textarea-bordered w-full"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<button type="submit" className="btn btn-primary mt-4">
|
||||
Alarmieren
|
||||
</button>
|
||||
</form>
|
||||
);
|
||||
};
|
||||
@@ -1,19 +1,23 @@
|
||||
import { Missions } from "dispatch/_components/pannel/Missions";
|
||||
import { usePannelStore } from "_store/pannelStore";
|
||||
import { cn } from "helpers/cn";
|
||||
import { MissionForm } from "./MissionForm";
|
||||
import { Trash2 } from "lucide-react";
|
||||
|
||||
export const Pannel = () => {
|
||||
const { isOpen, setOpen } = usePannelStore();
|
||||
return (
|
||||
<div className={cn("flex-1 max-w-[400px] z-9999999")}>
|
||||
<div className={cn("flex-1 max-w-[600px] z-9999999")}>
|
||||
<div className="bg-base-100 h-full w-full">
|
||||
<div className="flex justify-between items-center p-4">
|
||||
<h1 className="text-xl font-bold">Pannel</h1>
|
||||
<div className="flex flex-row justify-between items-center p-4">
|
||||
<h1 className="text-xl font-bold">Neuer Einsatz</h1>
|
||||
<button className="btn" onClick={() => setOpen(false)}>
|
||||
Close
|
||||
Schließen
|
||||
</button>
|
||||
</div>
|
||||
<Missions />
|
||||
<div className="divider" />
|
||||
<div className="p-4">
|
||||
<MissionForm />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user