35 lines
977 B
TypeScript
35 lines
977 B
TypeScript
|
import { defineStore } from "pinia";
|
||
|
import type { InviteViewModel } from "@/viewmodels/admin/invite.models";
|
||
|
import { http } from "@/serverCom";
|
||
|
import type { PermissionObject } from "@/types/permissionTypes";
|
||
|
import type { AxiosResponse } from "axios";
|
||
|
|
||
|
export const useInviteStore = defineStore("invite", {
|
||
|
state: () => {
|
||
|
return {
|
||
|
invites: [] as Array<InviteViewModel>,
|
||
|
loading: "loading" as "loading" | "fetched" | "failed",
|
||
|
};
|
||
|
},
|
||
|
actions: {
|
||
|
fetchInvites() {
|
||
|
this.loading = "loading";
|
||
|
http
|
||
|
.get("/admin/invite")
|
||
|
.then((result) => {
|
||
|
this.invites = result.data;
|
||
|
this.loading = "fetched";
|
||
|
})
|
||
|
.catch((err) => {
|
||
|
this.loading = "failed";
|
||
|
});
|
||
|
},
|
||
|
deleteInvite(invite: number): Promise<AxiosResponse<any, any>> {
|
||
|
return http.delete(`/admin/invite/${invite}`).then((result) => {
|
||
|
this.fetchInvites();
|
||
|
return result;
|
||
|
});
|
||
|
},
|
||
|
},
|
||
|
});
|