131 lines
3.6 KiB
TypeScript
131 lines
3.6 KiB
TypeScript
|
import { defineStore } from "pinia";
|
||
|
import { http } from "../serverCom";
|
||
|
import type { AxiosResponse } from "axios";
|
||
|
import { useConfigurationStore } from "./configuration";
|
||
|
|
||
|
export const useSetupStore = defineStore("setup", {
|
||
|
state: () => {
|
||
|
return {
|
||
|
dictionary: ["club", "clubImages", "app", "mail", "account", "finished"],
|
||
|
step: 0 as number,
|
||
|
successfull: 0 as number,
|
||
|
};
|
||
|
},
|
||
|
getters: {
|
||
|
stepIndex: (state) => (dict: string) => state.dictionary.findIndex((d) => d == dict),
|
||
|
},
|
||
|
actions: {
|
||
|
skip(dict: string) {
|
||
|
let myIndex = this.stepIndex(dict);
|
||
|
this.step += 1;
|
||
|
if (this.successfull <= myIndex) {
|
||
|
this.successfull = myIndex + 1;
|
||
|
}
|
||
|
},
|
||
|
async setClub(data: {
|
||
|
name?: string;
|
||
|
imprint?: string;
|
||
|
privacy?: string;
|
||
|
website?: string;
|
||
|
}): Promise<AxiosResponse<any, any>> {
|
||
|
let configStore = useConfigurationStore();
|
||
|
|
||
|
let myIndex = this.stepIndex("club");
|
||
|
const res = await http.post(`/setup/club`, {
|
||
|
name: data.name,
|
||
|
imprint: data.imprint,
|
||
|
privacy: data.privacy,
|
||
|
website: data.website,
|
||
|
});
|
||
|
configStore.configure();
|
||
|
|
||
|
this.step += 1;
|
||
|
if (this.successfull <= myIndex) {
|
||
|
this.successfull = myIndex;
|
||
|
}
|
||
|
return res;
|
||
|
},
|
||
|
async setClubImages(data: { icon?: File; logo?: File }): Promise<AxiosResponse<any, any>> {
|
||
|
let configStore = useConfigurationStore();
|
||
|
|
||
|
let myIndex = this.stepIndex("clubImages");
|
||
|
const formData = new FormData();
|
||
|
|
||
|
if (data.icon) {
|
||
|
formData.append("icon", data.icon);
|
||
|
}
|
||
|
|
||
|
if (data.logo) {
|
||
|
formData.append("logo", data.logo);
|
||
|
}
|
||
|
|
||
|
const res = await http.post(`/setup/club/images`, formData, {
|
||
|
headers: {
|
||
|
"Content-Type": "multipart/form-data",
|
||
|
},
|
||
|
});
|
||
|
configStore.configure();
|
||
|
|
||
|
this.step += 1;
|
||
|
if (this.successfull <= myIndex) {
|
||
|
this.successfull = myIndex;
|
||
|
}
|
||
|
return res;
|
||
|
},
|
||
|
async setApp(data: { login_message: string; show_cal_link: boolean }): Promise<AxiosResponse<any, any>> {
|
||
|
let myIndex = this.stepIndex("app");
|
||
|
const res = await http.post(`/setup/app`, {
|
||
|
custom_login_message: data.login_message,
|
||
|
show_link_to_calendar: data.show_cal_link,
|
||
|
});
|
||
|
this.step += 1;
|
||
|
if (this.successfull <= myIndex) {
|
||
|
this.successfull = myIndex;
|
||
|
}
|
||
|
return res;
|
||
|
},
|
||
|
async setMailConfig(data: {
|
||
|
host: string;
|
||
|
port: number;
|
||
|
secure: boolean;
|
||
|
mail: string;
|
||
|
username: string;
|
||
|
password: string;
|
||
|
}): Promise<AxiosResponse<any, any>> {
|
||
|
let myIndex = this.stepIndex("mail");
|
||
|
const res = await http.post(`/setup/mail`, {
|
||
|
host: data.host,
|
||
|
port: data.port,
|
||
|
secure: data.secure,
|
||
|
mail: data.mail,
|
||
|
username: data.username,
|
||
|
password: data.password,
|
||
|
});
|
||
|
this.step += 1;
|
||
|
if (this.successfull <= myIndex) {
|
||
|
this.successfull = myIndex;
|
||
|
}
|
||
|
return res;
|
||
|
},
|
||
|
async createAdmin(credentials: {
|
||
|
username: string;
|
||
|
mail: string;
|
||
|
firstname: string;
|
||
|
lastname: string;
|
||
|
}): Promise<AxiosResponse<any, any>> {
|
||
|
let myIndex = this.stepIndex("account");
|
||
|
const res = await http.post(`/setup/me`, {
|
||
|
username: credentials.username,
|
||
|
mail: credentials.mail,
|
||
|
firstname: credentials.firstname,
|
||
|
lastname: credentials.lastname,
|
||
|
});
|
||
|
this.step += 1;
|
||
|
if (this.successfull < myIndex) {
|
||
|
this.successfull = myIndex;
|
||
|
}
|
||
|
return res;
|
||
|
},
|
||
|
},
|
||
|
});
|