Add (new post)

This commit is contained in:
2023-07-29 02:20:51 +08:00
parent cb371fae26
commit 58b939f72e
26 changed files with 3754 additions and 62 deletions

View File

@@ -0,0 +1,53 @@
import { defineStore } from "pinia";
import route from "ziggy-js/src/js/index";
import axios from "axios";
export const usePostStore = defineStore("postStore", {
state: () => ({
data: {
defaultLocaleSlug: "my",
countryLocales: [],
localeCategories: [],
},
}),
getters: {
defaultLocaleSlug(state) {
return state.data.defaultLocaleSlug;
},
countryLocales(state) {
return state.data.countryLocales;
},
localeCategories(state) {
return state.data.localeCategories;
},
},
actions: {
async fetchCountryLocales() {
try {
const response = await axios.get(route("api.admin.country-locales"));
console.log(response);
this.data.countryLocales = response.data.country_locales;
this.data.defaultLocaleSlug = response.data.default_locale_slug;
} catch (error) {
// alert(error);
console.log(error);
}
},
async fetchLocaleCategories(countryLocaleSlug) {
try {
const response = await axios.get(
route("api.admin.categories", {
country_locale_slug: countryLocaleSlug,
})
);
console.log(response);
this.data.localeCategories = response.data.categories;
} catch (error) {
// alert(error);
console.log(error);
}
},
},
});

View File

@@ -0,0 +1,44 @@
import { defineStore } from "pinia";
import axios from "axios";
export const useAuthStore = defineStore("auth", {
state: () => ({
loggedIn: localStorage.getItem("token") ? true : false,
user: null,
}),
getters: {},
actions: {
async login(credentials) {
await axios.get("sanctum/csrf-cookie");
const response = (await axios.post("api/login", credentials)).data;
if (response) {
const token = `Bearer ${response.token}`;
localStorage.setItem("token", token);
axios.defaults.headers.common["Authorization"] = token;
await this.ftechUser();
}
},
async logout() {
const response = (await axios.post("api/logout")).data;
if (response) {
localStorage.removeItem("token");
this.$reset();
}
},
async ftechUser() {
this.user = (await axios.get("api/me")).data;
this.loggedIn = true;
},
},
});

View File

@@ -0,0 +1,8 @@
import { defineStore } from "pinia";
export const useErrorStore = defineStore("error", {
state: () => ({
message: null,
errors: {},
}),
});