added settings page
This commit is contained in:
@@ -2,6 +2,7 @@ import { API_BASE } from "../config/api.config";
|
||||
import Cookies from "js-cookie";
|
||||
import type { TFunction } from "i18next";
|
||||
import { toast } from "react-toastify";
|
||||
import { fetchSettings } from "./uxFncs";
|
||||
|
||||
export async function isAuthenticated() {
|
||||
if (Cookies.get("token")) {
|
||||
@@ -39,10 +40,14 @@ export async function signInUser(
|
||||
});
|
||||
|
||||
const response = await result.json();
|
||||
console.log(response);
|
||||
|
||||
if (result.status === 202) {
|
||||
Cookies.set("token", response.data.token);
|
||||
|
||||
const settings = await fetchSettings();
|
||||
Cookies.set("app-name", settings?.data[0].value);
|
||||
Cookies.set("currency", settings?.data[1].value);
|
||||
|
||||
return { ok: true as const };
|
||||
}
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ import Cookies from "js-cookie";
|
||||
import type {
|
||||
NewStorage,
|
||||
ProductFormValues,
|
||||
SettingsIntf,
|
||||
Storage,
|
||||
} from "../misc/interfaces";
|
||||
|
||||
@@ -229,3 +230,46 @@ export const deleteStorage = async (uuid: string) => {
|
||||
return { success: true, code: response.code };
|
||||
}
|
||||
};
|
||||
|
||||
export const mutateSettings = async (payload: SettingsIntf) => {
|
||||
const result = await fetch(`${API_BASE}/users/update-app-settings`, {
|
||||
method: "POST",
|
||||
body: JSON.stringify(payload),
|
||||
headers: {
|
||||
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
const response = await result.json();
|
||||
|
||||
if (response.code === "eu004") {
|
||||
return { success: false, code: response.code };
|
||||
}
|
||||
|
||||
if (response.code === "su003") {
|
||||
return { success: true, code: response.code };
|
||||
}
|
||||
};
|
||||
|
||||
export const fetchSettings = async () => {
|
||||
const result = await fetch(`${API_BASE}/users/settings`, {
|
||||
method: "GET",
|
||||
headers: {
|
||||
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
||||
"Content-Type": "application/json",
|
||||
Accept: "application/json",
|
||||
},
|
||||
});
|
||||
|
||||
const response = await result.json();
|
||||
|
||||
if (response.code === "eu005") {
|
||||
return { success: false, code: response.code };
|
||||
}
|
||||
|
||||
if (response.code === "su004") {
|
||||
return { success: true, data: response.data, code: response.code };
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user