feat(settings): added in setting store
This commit is contained in:
29
frontend/src/lib/store/useSettings.ts
Normal file
29
frontend/src/lib/store/useSettings.ts
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import axios from "axios";
|
||||||
|
import {create} from "zustand";
|
||||||
|
|
||||||
|
interface SettingState {
|
||||||
|
settings: any[];
|
||||||
|
|
||||||
|
fetchSettings: () => Promise<void>;
|
||||||
|
setSettings: (settings: any[]) => void;
|
||||||
|
}
|
||||||
|
interface FetchModulesResponse {
|
||||||
|
data: any[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export const useSettingStore = create<SettingState>()((set) => ({
|
||||||
|
settings: [],
|
||||||
|
setSettings: (settings) => set({settings}),
|
||||||
|
fetchSettings: async () => {
|
||||||
|
try {
|
||||||
|
//const response = await axios.get<{data: Setting[]}>(`${process.env.NEXT_PUBLIC_URL}/api/settings/client`);
|
||||||
|
const response = await axios.get(`/api/server/settings`, {});
|
||||||
|
const data: FetchModulesResponse = response.data; //await response.json();
|
||||||
|
//console.log(data);
|
||||||
|
set({settings: data.data});
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Failed to fetch settings:", error);
|
||||||
|
set({settings: []});
|
||||||
|
}
|
||||||
|
},
|
||||||
|
}));
|
||||||
Reference in New Issue
Block a user