25 lines
655 B
TypeScript
25 lines
655 B
TypeScript
import { defineStore } from "pinia";
|
|||
|
|
|
||
|
|
export type ContactStatus = "idle" | "loading" | "success";
|
||
|
|
|
||
|
|
const emptyForm = () => ({ name: "", org: "", phone: "", message: "" });
|
||
|
|
|
||
|
|
export const useContactStore = defineStore("contact", {
|
||
|
|
state: () => ({
|
||
|
|
form: emptyForm(),
|
||
|
|
status: "idle" as ContactStatus,
|
||
|
|
}),
|
||
|
|
actions: {
|
||
|
|
// TODO: connect to the real API endpoint; currently simulates the request like the original
|
||
|
|
async submit() {
|
||
|
|
this.status = "loading";
|
||
|
|
await new Promise((r) => setTimeout(r, 1100));
|
||
|
|
this.status = "success";
|
||
|
|
},
|
||
|
|
reset() {
|
||
|
|
this.form = emptyForm();
|
||
|
|
this.status = "idle";
|
||
|
|
},
|
||
|
|
},
|
||
|
|
});
|