printout page

This commit is contained in:
Julian Krauser 2024-10-19 16:24:33 +02:00
parent 225b686de6
commit f3ffdb1ffd
7 changed files with 137 additions and 8 deletions

View file

@ -0,0 +1,60 @@
import { defineStore } from "pinia";
import { http } from "@/serverCom";
import type { ProtocolPrintoutViewModel } from "../../viewmodels/admin/protocolPrintout.models";
import { useProtocolStore } from "./protocol";
export const useProtocolPrintoutStore = defineStore("protocolPrintout", {
state: () => {
return {
printout: [] as Array<ProtocolPrintoutViewModel>,
loading: "loading" as "loading" | "fetched" | "failed",
printing: undefined as undefined | "loading" | "success" | "failed",
};
},
actions: {
fetchProtocolPrintout() {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/printouts`)
.then((result) => {
this.printout = result.data;
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
fetchProtocolPrintoutById(printoutId: string) {
const protocolId = useProtocolStore().activeProtocol;
this.loading = "loading";
http
.get(`/admin/protocol/${protocolId}/printout/${printoutId}`)
.then((result) => {
this.loading = "fetched";
})
.catch((err) => {
this.loading = "failed";
});
},
createProtocolPrintout() {
this.printing = "loading";
const protocolId = useProtocolStore().activeProtocol;
if (protocolId == null) return;
return http
.post(`/admin/protocol/${protocolId}/printout`)
.then((res) => {
this.fetchProtocolPrintout();
this.printing = "success";
})
.catch((err) => {
this.printing = "failed";
})
.finally(() => {
setTimeout(() => {
this.printing = undefined;
}, 1500);
});
},
},
});