added HPG VEhicles Mission, Audio settings; mission Context menu
This commit is contained in:
@@ -6,7 +6,7 @@ import { Audio } from "../../../_components/Audio";
|
||||
/* import { useState } from "react"; */
|
||||
import { ExitIcon, ExternalLinkIcon } from "@radix-ui/react-icons";
|
||||
import Link from "next/link";
|
||||
import { SettingsBtn } from "./_components/Settings";
|
||||
import { Settings } from "_components/Settings";
|
||||
|
||||
export default function Navbar() {
|
||||
/* const [isDark, setIsDark] = useState(false);
|
||||
@@ -35,7 +35,7 @@ export default function Navbar() {
|
||||
</div>
|
||||
{/* <ThemeSwap isDark={isDark} toggleTheme={toggleTheme} /> */}
|
||||
<div className="flex items-center">
|
||||
<SettingsBtn />
|
||||
<Settings />
|
||||
<Link
|
||||
href={process.env.NEXT_PUBLIC_HUB_URL || "#!"}
|
||||
target="_blank"
|
||||
|
||||
@@ -1,103 +0,0 @@
|
||||
"use client";
|
||||
import { useRef } from "react";
|
||||
import { GearIcon } from "@radix-ui/react-icons";
|
||||
import { SettingsIcon, Volume2 } from "lucide-react";
|
||||
|
||||
export const SettingsBtn = () => {
|
||||
const modalRef = useRef<HTMLDialogElement>(null);
|
||||
|
||||
return (
|
||||
<div>
|
||||
<button
|
||||
className="btn btn-ghost"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
modalRef.current?.showModal();
|
||||
}}
|
||||
>
|
||||
<GearIcon className="w-5 h-5" />
|
||||
</button>
|
||||
|
||||
<dialog ref={modalRef} className="modal">
|
||||
<div className="modal-box">
|
||||
<h3 className="flex items-center gap-2 text-lg font-bold mb-5">
|
||||
<SettingsIcon size={20} /> Einstellungen
|
||||
</h3>
|
||||
<div className="flex flex-col items-center justify-center">
|
||||
<fieldset className="fieldset w-full">
|
||||
<label className="floating-label w-full text-base">
|
||||
<span>Eingabegerät</span>
|
||||
<select className="input w-full" defaultValue={0}>
|
||||
<option key={0} value={0} disabled>
|
||||
Bitte wähle ein Eingabegerät...
|
||||
</option>
|
||||
<option key={1} value={1}>
|
||||
Audiogerät 1
|
||||
</option>
|
||||
<option key={2} value={2}>
|
||||
Audiogerät 2
|
||||
</option>
|
||||
<option key={3} value={3}>
|
||||
Audiogerät 3
|
||||
</option>
|
||||
</select>
|
||||
</label>
|
||||
</fieldset>
|
||||
{/* FÜGE HIER BITTE DEN MIKROFONAUSSCHLAG EIN WIE IN DER V1 */}
|
||||
<div className="divider w-full" />
|
||||
</div>
|
||||
<p className="flex items-center gap-2 text-base mb-2">
|
||||
<Volume2 size={20} /> Ausgabelautstärke
|
||||
</p>
|
||||
<div className="w-full">
|
||||
<input
|
||||
type="range"
|
||||
min={0}
|
||||
max={100}
|
||||
defaultValue={40}
|
||||
className="range range-xs range-accent w-full"
|
||||
/>
|
||||
<div className="flex justify-between px-2.5 mt-2 text-xs">
|
||||
<span>0</span>
|
||||
<span>25</span>
|
||||
<span>50</span>
|
||||
<span>75</span>
|
||||
<span>100</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="flex justify-between modal-action">
|
||||
<button
|
||||
className="btn btn-soft"
|
||||
type="submit"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
modalRef.current?.close();
|
||||
}}
|
||||
>
|
||||
Schließen
|
||||
</button>
|
||||
<button
|
||||
className="btn btn-soft btn-success"
|
||||
type="submit"
|
||||
onSubmit={() => false}
|
||||
onClick={() => {
|
||||
modalRef.current?.close();
|
||||
}}
|
||||
>
|
||||
Speichern
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</dialog>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export const Settings = () => {
|
||||
return (
|
||||
<div>
|
||||
<SettingsBtn />
|
||||
</div>
|
||||
);
|
||||
};
|
||||
@@ -4,7 +4,7 @@ import { useForm } from "react-hook-form";
|
||||
import { zodResolver } from "@hookform/resolvers/zod";
|
||||
import { BellRing, BookmarkPlus } from "lucide-react";
|
||||
import { Select } from "_components/Select";
|
||||
import { KEYWORD_CATEGORY, missionType, Prisma } from "@repo/db";
|
||||
import { KEYWORD_CATEGORY, Mission, missionType, Prisma } from "@repo/db";
|
||||
import { MissionOptionalDefaults, MissionOptionalDefaultsSchema } from "@repo/db/zod";
|
||||
import { usePannelStore } from "_store/pannelStore";
|
||||
import { useSession } from "next-auth/react";
|
||||
@@ -21,6 +21,8 @@ import { getStationsAPI } from "querys/stations";
|
||||
import { useMapStore } from "_store/mapStore";
|
||||
import { getConnectedAircraftsAPI } from "querys/aircrafts";
|
||||
import { HPGValidationRequired } from "helpers/hpgValidationRequired";
|
||||
import { selectRandomHPGMissionSzenery } from "helpers/selectRandomHPGMission";
|
||||
import { AxiosError } from "axios";
|
||||
|
||||
export const MissionForm = () => {
|
||||
const { isEditingMission, editingMissionId, setEditingMission } = usePannelStore();
|
||||
@@ -93,7 +95,8 @@ export const MissionForm = () => {
|
||||
hpgAmbulanceState: null,
|
||||
hpgPoliceState: null,
|
||||
hpgMissionString: null,
|
||||
|
||||
hpgSelectedMissionString: null,
|
||||
hpg: null,
|
||||
missionLog: [],
|
||||
}) as Partial<MissionOptionalDefaults>,
|
||||
[session.data?.user.id],
|
||||
@@ -132,6 +135,47 @@ export const MissionForm = () => {
|
||||
}
|
||||
}, [missionFormValues, form, defaultFormValues]);
|
||||
|
||||
const saveMission = async (
|
||||
mission: MissionOptionalDefaults,
|
||||
{ alertWhenValid = false, createNewMission = false } = {},
|
||||
) => {
|
||||
const [hpgSzenario, hpgSzenarioCode] = mission.hpgMissionString?.split(":") || [];
|
||||
const szenarioCode = selectRandomHPGMissionSzenery(hpgSzenarioCode || "");
|
||||
let newMission: Mission;
|
||||
if (createNewMission) {
|
||||
newMission = await createMissionMutation.mutateAsync({
|
||||
...(mission as unknown as Prisma.MissionCreateInput),
|
||||
missionAdditionalInfo:
|
||||
!mission.missionAdditionalInfo.length && hpgSzenario
|
||||
? `HPG-Szenario: ${hpgSzenario}`
|
||||
: mission.missionAdditionalInfo,
|
||||
hpgSelectedMissionString: szenarioCode,
|
||||
});
|
||||
if (validationRequired) {
|
||||
await startHpgValidation(newMission.id, {
|
||||
alertWhenValid,
|
||||
});
|
||||
}
|
||||
return newMission;
|
||||
} else {
|
||||
newMission = await editMissionMutation.mutateAsync({
|
||||
id: Number(editingMissionId),
|
||||
mission: {
|
||||
...(mission as unknown as Prisma.MissionCreateInput),
|
||||
missionAdditionalInfo:
|
||||
!mission.missionAdditionalInfo.length && hpgSzenario
|
||||
? `HPG-Szenario: ${hpgSzenario}`
|
||||
: mission.missionAdditionalInfo,
|
||||
hpgSelectedMissionString: szenarioCode,
|
||||
},
|
||||
});
|
||||
}
|
||||
if (validationRequired) {
|
||||
await startHpgValidation(newMission.id, {});
|
||||
}
|
||||
return newMission;
|
||||
};
|
||||
|
||||
return (
|
||||
<form className="space-y-4">
|
||||
{/* Koorinaten Section */}
|
||||
@@ -266,7 +310,7 @@ export const MissionForm = () => {
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
{/* TODO: Nur anzeigen wenn eine Station mit HPG ausgewählt ist */}
|
||||
|
||||
<div className="mb-4">
|
||||
<select
|
||||
{...form.register("hpgMissionString")}
|
||||
@@ -330,29 +374,20 @@ export const MissionForm = () => {
|
||||
className="btn btn-primary flex-1"
|
||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
||||
try {
|
||||
const hpgSzenario = mission.hpgMissionString?.split(":")[0];
|
||||
const newMission = await editMissionMutation.mutateAsync({
|
||||
id: Number(editingMissionId),
|
||||
mission: {
|
||||
...(mission as unknown as Prisma.MissionCreateInput),
|
||||
missionAdditionalInfo:
|
||||
!mission.missionAdditionalInfo.length && hpgSzenario
|
||||
? `HPG-Szenario: ${hpgSzenario}`
|
||||
: mission.missionAdditionalInfo,
|
||||
},
|
||||
});
|
||||
if (validationRequired) {
|
||||
await startHpgValidation(newMission.id);
|
||||
}
|
||||
const newMission = await saveMission(mission);
|
||||
toast.success(`Einsatz ${newMission.id} erfolgreich aktualisiert`);
|
||||
setSeachOSMElements([]); // Reset search elements
|
||||
setEditingMission(false, null); // Reset editing state
|
||||
form.reset(); // Reset the form
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
toast.error(
|
||||
`Fehler beim Aktualisieren des Einsatzes: ${(error as Error).message}`,
|
||||
);
|
||||
if (error instanceof AxiosError) {
|
||||
toast.error(
|
||||
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
|
||||
);
|
||||
} else {
|
||||
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`);
|
||||
}
|
||||
}
|
||||
})}
|
||||
>
|
||||
@@ -365,25 +400,24 @@ export const MissionForm = () => {
|
||||
className="btn btn-warning"
|
||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
||||
try {
|
||||
const hpgSzenario = mission.hpgMissionString?.split(":")[0];
|
||||
const newMission = await createMissionMutation.mutateAsync({
|
||||
...(mission as unknown as Prisma.MissionCreateInput),
|
||||
missionAdditionalInfo:
|
||||
!mission.missionAdditionalInfo.length && hpgSzenario
|
||||
? `HPG-Szenario: ${hpgSzenario}`
|
||||
: mission.missionAdditionalInfo,
|
||||
const newMission = await saveMission(mission, {
|
||||
alertWhenValid: true,
|
||||
});
|
||||
if (validationRequired) {
|
||||
await startHpgValidation(newMission.id, {
|
||||
alertWhenValid: true,
|
||||
});
|
||||
} else {
|
||||
if (!validationRequired) {
|
||||
await sendAlertMutation.mutateAsync(newMission.id);
|
||||
}
|
||||
setSeachOSMElements([]); // Reset search elements
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`);
|
||||
if (error instanceof AxiosError) {
|
||||
toast.error(
|
||||
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
|
||||
);
|
||||
} else {
|
||||
toast.error(
|
||||
`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
})}
|
||||
>
|
||||
@@ -394,21 +428,24 @@ export const MissionForm = () => {
|
||||
className="btn btn-primary flex-1"
|
||||
onClick={form.handleSubmit(async (mission: MissionOptionalDefaults) => {
|
||||
try {
|
||||
const hpgSzenario = mission.hpgMissionString?.split(":")[0];
|
||||
const newMission = await createMissionMutation.mutateAsync({
|
||||
...(mission as unknown as Prisma.MissionCreateInput),
|
||||
missionAdditionalInfo:
|
||||
!mission.missionAdditionalInfo.length && hpgSzenario
|
||||
? `HPG-Szenario: ${hpgSzenario}`
|
||||
: mission.missionAdditionalInfo,
|
||||
const newMission = await saveMission(mission, {
|
||||
createNewMission: true,
|
||||
});
|
||||
|
||||
setSeachOSMElements([]); // Reset search elements
|
||||
await startHpgValidation(newMission.id);
|
||||
toast.success(`Einsatz ${newMission.publicId} erstellt`);
|
||||
form.reset();
|
||||
setOpen(false);
|
||||
} catch (error) {
|
||||
toast.error(`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`);
|
||||
if (error instanceof AxiosError) {
|
||||
toast.error(
|
||||
`Fehler beim Erstellen des Einsatzes: ${error.response?.data.error}`,
|
||||
);
|
||||
} else {
|
||||
toast.error(
|
||||
`Fehler beim Erstellen des Einsatzes: ${(error as Error).message}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
})}
|
||||
>
|
||||
|
||||
Reference in New Issue
Block a user