Fixed mission form

This commit is contained in:
PxlLoewe
2025-06-01 15:02:38 -07:00
parent 9826f970d8
commit fdb62aa4d2
5 changed files with 29 additions and 27 deletions

View File

@@ -121,7 +121,7 @@ export const ContextMenu = () => {
const nodeWay: [number, number][] = [];
closestToContext.nodes.map((node: { lat: number; lon: number }) =>
closestToContext.nodes?.foreach((node: { lat: number; lon: number }) =>
nodeWay.push([node.lat, node.lon]),
);

View File

@@ -88,9 +88,9 @@ export const MissionForm = () => {
createdUserId: session.data?.user.id,
type: "primär",
addressOSMways: [],
missionKeywordAbbreviation: "",
missionKeywordCategory: "",
missionKeywordName: "",
missionKeywordAbbreviation: null as any,
missionKeywordCategory: null as any,
missionKeywordName: null as any,
hpgFireEngineState: null,
hpgAmbulanceState: null,
hpgPoliceState: null,
@@ -108,6 +108,8 @@ export const MissionForm = () => {
});
const { missionFormValues, setOpen } = usePannelStore((state) => state);
console.log("MissionForm rendered", form.formState.errors);
const validationRequired = HPGValidationRequired(
form.watch("missionStationIds"),
aircrafts,
@@ -164,6 +166,7 @@ export const MissionForm = () => {
id: Number(editingMissionId),
mission: {
...(mission as unknown as Prisma.MissionCreateInput),
state: undefined, // state should not be updated
missionAdditionalInfo:
!mission.missionAdditionalInfo.length && hpgSzenario
? `HPG-Szenario: ${hpgSzenario}`
@@ -261,8 +264,8 @@ export const MissionForm = () => {
className="select select-primary select-bordered w-full mb-4"
onChange={(e) => {
form.setValue("type", e.target.value as missionType);
form.setValue("missionKeywordName", null);
form.setValue("missionKeywordAbbreviation", null);
form.setValue("missionKeywordName", KEYWORD_CATEGORY.AB_ATMUNG);
form.setValue("missionKeywordAbbreviation", "");
form.setValue("hpgMissionString", null);
}}
>
@@ -275,9 +278,15 @@ export const MissionForm = () => {
{...form.register("missionKeywordCategory")}
className="select select-primary select-bordered w-full mb-4"
onChange={(e) => {
const firstKeyword = keywords?.find(
(k) => k.category === form.watch("missionKeywordCategory"),
);
form.setValue("missionKeywordCategory", e.target.value as string);
form.setValue("missionKeywordName", null);
form.setValue("missionKeywordAbbreviation", "");
form.setValue("missionKeywordName", firstKeyword?.name || (null as any));
form.setValue(
"missionKeywordAbbreviation",
firstKeyword?.abreviation || (null as any),
);
form.setValue("hpgMissionString", "");
}}
defaultValue=""
@@ -296,8 +305,8 @@ export const MissionForm = () => {
className="select select-primary select-bordered w-full mb-4"
onChange={(e) => {
const keyword = keywords?.find((k) => k.abreviation === e.target.value);
form.setValue("missionKeywordName", keyword?.name || null);
form.setValue("missionKeywordAbbreviation", keyword?.abreviation || null);
form.setValue("missionKeywordName", keyword?.name || (null as any));
form.setValue("missionKeywordAbbreviation", keyword?.abreviation || (null as any));
form.setValue("hpgMissionString", "default");
}}
defaultValue="default"