51 lines
1.2 KiB
TypeScript
51 lines
1.2 KiB
TypeScript
import { Prisma } from "@repo/db";
|
|
import { MissionOptionalDefaults } from "@repo/db/zod";
|
|
import { create } from "zustand";
|
|
|
|
interface MissionStore {
|
|
missions: MissionOptionalDefaults[];
|
|
setMissions: (missions: MissionOptionalDefaults[]) => void;
|
|
getMissions: () => Promise<undefined>;
|
|
}
|
|
|
|
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",
|
|
},
|
|
],
|
|
setMissions: (missions) => set({ missions }),
|
|
getMissions: async () => {
|
|
const res = await fetch("/api/mission", {
|
|
headers: {
|
|
"Content-Type": "application/json",
|
|
},
|
|
body: JSON.stringify({
|
|
OR: [
|
|
{
|
|
state: "draft",
|
|
},
|
|
{
|
|
state: "running",
|
|
},
|
|
],
|
|
} as Prisma.MissionWhereInput),
|
|
});
|
|
if (!res.ok) return undefined;
|
|
const data = await res.json();
|
|
set({ missions: data });
|
|
return undefined;
|
|
},
|
|
}));
|