added mission fields

This commit is contained in:
PxlLoewe
2025-04-23 19:01:26 -07:00
parent 3761943cc2
commit f6e4449f68
12 changed files with 198 additions and 113 deletions

View File

@@ -1,4 +1,4 @@
import { Prisma } from "@repo/db";
import { Mission, Prisma } from "@repo/db";
import { MissionOptionalDefaults } from "@repo/db/zod";
import { create } from "zustand";
@@ -6,29 +6,29 @@ interface MissionStore {
missions: MissionOptionalDefaults[];
setMissions: (missions: MissionOptionalDefaults[]) => void;
getMissions: () => Promise<undefined>;
createMission: (mission: MissionOptionalDefaults) => Promise<Mission>;
setMission: (mission: MissionOptionalDefaults) => void;
}
export const useMissionsStore = create<MissionStore>((set) => ({
missions: [
{
state: "draft",
id: "01250325",
addressLat: 52.520008,
addressLng: 13.404954,
addressStreet: "Alexanderplatz",
addressCity: "Berlin",
addressZip: "10178",
missionAdditionalInfo: "Additional info",
missionCategory: "AB_Atmung",
missionKeyword: "Zunehmende Beschwerden",
missionSummary: "AB1_0",
missionPatientInfo: "M/10",
},
],
missions: [],
setMissions: (missions) => set({ missions }),
createMission: async (mission) => {
const res = await fetch("/api/mission", {
method: "PUT",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify(mission),
});
if (!res.ok) return undefined;
const data = await res.json();
set((state) => ({ missions: [...state.missions, data] }));
return data;
},
getMissions: async () => {
const res = await fetch("/api/mission", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
@@ -62,3 +62,10 @@ export const useMissionsStore = create<MissionStore>((set) => ({
}
}),
}));
useMissionsStore
.getState()
.getMissions()
.then(() => {
console.log("Missions loaded");
});