fix: frontend error codes and translations
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
import { API_BASE } from "../../config/api.config";
|
import {API_BASE} from "../../config/api.config";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import type { TFunction } from "i18next";
|
import type {TFunction} from "i18next";
|
||||||
import { fetchSettings } from "./settings";
|
import {fetchSettings} from "./settings";
|
||||||
import type { ChangePasswordIntf } from "../../misc/interfaces";
|
import type {ChangePasswordIntf} from "../../misc/interfaces";
|
||||||
import { createApiError } from "./apiError";
|
import {createApiError} from "./apiError";
|
||||||
|
|
||||||
export async function isAuthenticated() {
|
export async function isAuthenticated() {
|
||||||
if (Cookies.get("token")) {
|
if (Cookies.get("token")) {
|
||||||
@@ -37,7 +37,7 @@ export async function signInUser(
|
|||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
Accept: "application/json",
|
Accept: "application/json",
|
||||||
},
|
},
|
||||||
body: JSON.stringify({ username, password }),
|
body: JSON.stringify({username, password}),
|
||||||
});
|
});
|
||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
@@ -49,7 +49,7 @@ export async function signInUser(
|
|||||||
Cookies.set("app-name", settings?.data[0].value);
|
Cookies.set("app-name", settings?.data[0].value);
|
||||||
Cookies.set("currency", settings?.data[1].value);
|
Cookies.set("currency", settings?.data[1].value);
|
||||||
|
|
||||||
return { ok: true as const };
|
return {ok: true as const};
|
||||||
}
|
}
|
||||||
|
|
||||||
Cookies.remove("token");
|
Cookies.remove("token");
|
||||||
@@ -58,7 +58,7 @@ export async function signInUser(
|
|||||||
|
|
||||||
export function signOutUser() {
|
export function signOutUser() {
|
||||||
Cookies.remove("token");
|
Cookies.remove("token");
|
||||||
return { ok: true as const };
|
return {ok: true as const};
|
||||||
}
|
}
|
||||||
|
|
||||||
export const mutatePassword = async (payload: ChangePasswordIntf) => {
|
export const mutatePassword = async (payload: ChangePasswordIntf) => {
|
||||||
@@ -77,8 +77,8 @@ export const mutatePassword = async (payload: ChangePasswordIntf) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "su005") {
|
if (response.code === "SU005") {
|
||||||
return { code: response.code };
|
return {code: response.code};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw createApiError(response.code, "Change password failed");
|
throw createApiError(response.code, "Change password failed");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { API_BASE } from "../../config/api.config";
|
import {API_BASE} from "../../config/api.config";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import type { ProductFormValues } from "../../misc/interfaces";
|
import type {ProductFormValues} from "../../misc/interfaces";
|
||||||
import { createApiError } from "./apiError";
|
import {createApiError} from "./apiError";
|
||||||
|
|
||||||
export const getProducts = async () => {
|
export const getProducts = async () => {
|
||||||
const result = await fetch(`${API_BASE}/products/all-products`, {
|
const result = await fetch(`${API_BASE}/products/all-products`, {
|
||||||
@@ -13,7 +13,7 @@ export const getProducts = async () => {
|
|||||||
});
|
});
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "sp002") {
|
if (response.code === "SP002") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,7 +31,7 @@ export const getProductDetails = async (uuid: string) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "sp003") {
|
if (response.code === "SP003") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,7 +63,7 @@ export const mutateProduct = async (
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "sp005") {
|
if (response.code === "SP005") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,8 +83,8 @@ export const deleteSelectedProducts = async (uuids: string[]) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "sp006") {
|
if (response.code === "SP006") {
|
||||||
return { success: true };
|
return {success: true};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw createApiError(response.code, "Delete products failed");
|
throw createApiError(response.code, "Delete products failed");
|
||||||
@@ -113,7 +113,7 @@ export const createProduct = async (values: ProductFormValues) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "sp001") {
|
if (response.code === "SP001") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { API_BASE } from "../../config/api.config";
|
import {API_BASE} from "../../config/api.config";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import type { SettingsIntf } from "../../misc/interfaces";
|
import type {SettingsIntf} from "../../misc/interfaces";
|
||||||
import { createApiError } from "./apiError";
|
import {createApiError} from "./apiError";
|
||||||
|
|
||||||
export const fetchSettings = async () => {
|
export const fetchSettings = async () => {
|
||||||
const result = await fetch(`${API_BASE}/users/settings`, {
|
const result = await fetch(`${API_BASE}/users/settings`, {
|
||||||
@@ -15,8 +15,8 @@ export const fetchSettings = async () => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "su004") {
|
if (response.code === "SU004") {
|
||||||
return { success: true, data: response.data, code: response.code };
|
return {success: true, data: response.data, code: response.code};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw createApiError(response.code, "Fetch settings failed");
|
throw createApiError(response.code, "Fetch settings failed");
|
||||||
@@ -35,8 +35,8 @@ export const mutateSettings = async (payload: SettingsIntf) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "su003") {
|
if (response.code === "SU003") {
|
||||||
return { success: true, code: response.code };
|
return {success: true, code: response.code};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw createApiError(response.code, "Update settings failed");
|
throw createApiError(response.code, "Update settings failed");
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { API_BASE } from "../../config/api.config";
|
import {API_BASE} from "../../config/api.config";
|
||||||
import Cookies from "js-cookie";
|
import Cookies from "js-cookie";
|
||||||
import type { NewStorage, Storage } from "../../misc/interfaces";
|
import type {NewStorage, Storage} from "../../misc/interfaces";
|
||||||
import { createApiError } from "./apiError";
|
import {createApiError} from "./apiError";
|
||||||
|
|
||||||
export const getStorages = async () => {
|
export const getStorages = async () => {
|
||||||
const result = await fetch(`${API_BASE}/storage/all-storages`, {
|
const result = await fetch(`${API_BASE}/storage/all-storages`, {
|
||||||
@@ -14,7 +14,7 @@ export const getStorages = async () => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "ss001") {
|
if (response.code === "SS001") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,7 +34,7 @@ export const mutateNewStorage = async (values: NewStorage) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "ss002") {
|
if (response.code === "SS002") {
|
||||||
return response.data;
|
return response.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,8 +79,8 @@ export const deleteStorage = async (uuid: string) => {
|
|||||||
|
|
||||||
const response = await result.json();
|
const response = await result.json();
|
||||||
|
|
||||||
if (response.code === "ss004") {
|
if (response.code === "SS004") {
|
||||||
return { success: true, code: response.code };
|
return {success: true, code: response.code};
|
||||||
}
|
}
|
||||||
|
|
||||||
throw createApiError(response.code, "Delete storage failed");
|
throw createApiError(response.code, "Delete storage failed");
|
||||||
|
|||||||
@@ -6,7 +6,6 @@
|
|||||||
"details": "Details",
|
"details": "Details",
|
||||||
"username": "Benutzername",
|
"username": "Benutzername",
|
||||||
"password": "Passwort",
|
"password": "Passwort",
|
||||||
"eu001": "Falscher Benutzername oder Passwort!",
|
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"product-name": "Produktname",
|
"product-name": "Produktname",
|
||||||
"price": "Preis",
|
"price": "Preis",
|
||||||
@@ -57,5 +56,29 @@
|
|||||||
"change": "Ändern",
|
"change": "Ändern",
|
||||||
"error": "Fehler",
|
"error": "Fehler",
|
||||||
"success": "Erfolg",
|
"success": "Erfolg",
|
||||||
"submit": "Absenden"
|
"submit": "Absenden",
|
||||||
|
"EG001": "Ein unerwarteter Fehler ist aufgetreten. Bitte versuchen Sie es später erneut.",
|
||||||
|
"EU001": "Falscher Benutzername oder Passwort!",
|
||||||
|
"EU002": "Ihr Konto wurde deaktiviert. Bitte wenden Sie sich an einen Administrator.",
|
||||||
|
"EU003": "Bitte geben Sie Benutzername und Passwort ein.",
|
||||||
|
"EU004": "Einige erforderliche Angaben fehlen. Bitte überprüfen Sie Ihre Eingabe.",
|
||||||
|
"EU005": "Anmeldung aufgrund eines technischen Problems fehlgeschlagen. Bitte versuchen Sie es erneut.",
|
||||||
|
"EU006": "Anmeldung fehlgeschlagen. Bitte versuchen Sie es erneut.",
|
||||||
|
"EU007": "Passwort konnte nicht geändert werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EU008": "Ihre Einstellungen konnten nicht gespeichert werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EU009": "Ihre Einstellungen konnten nicht geladen werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"ES001": "Bitte füllen Sie alle erforderlichen Felder für den Lagerort aus.",
|
||||||
|
"ES002": "Einige erforderliche Lagerinformationen fehlen. Bitte überprüfen Sie Ihre Eingabe.",
|
||||||
|
"ES003": "Der Lagerort konnte nicht aktualisiert werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"ES004": "Der Lagerort konnte nicht gelöscht werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"ES005": "Keine Lagerorte gefunden.",
|
||||||
|
"ES006": "Der Lagerort konnte nicht erstellt werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EP001": "Das Produkt konnte nicht erstellt werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EP002": "Keine Produkte gefunden.",
|
||||||
|
"EP003": "Produkt nicht gefunden.",
|
||||||
|
"EP004": "Die Produktmenge konnte nicht aktualisiert werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EP005": "Das Produkt konnte nicht aktualisiert werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EP006": "Das Produkt konnte nicht gelöscht werden. Bitte versuchen Sie es erneut.",
|
||||||
|
"EP007": "Bitte geben Sie mindestens einen Produktnamen ein.",
|
||||||
|
"EP008": "Einige erforderliche Produktinformationen fehlen. Bitte überprüfen Sie Ihre Eingabe."
|
||||||
}
|
}
|
||||||
@@ -6,7 +6,6 @@
|
|||||||
"details": "Details",
|
"details": "Details",
|
||||||
"username": "Username",
|
"username": "Username",
|
||||||
"password": "Password",
|
"password": "Password",
|
||||||
"eu001": "Wrong username or password!",
|
|
||||||
"login": "Login",
|
"login": "Login",
|
||||||
"product-name": "Product name",
|
"product-name": "Product name",
|
||||||
"price": "Price",
|
"price": "Price",
|
||||||
@@ -57,5 +56,29 @@
|
|||||||
"change": "Change",
|
"change": "Change",
|
||||||
"error": "Error",
|
"error": "Error",
|
||||||
"success": "Success",
|
"success": "Success",
|
||||||
"submit": "Submit"
|
"submit": "Submit",
|
||||||
|
"EG001": "An unexpected error occurred. Please try again later.",
|
||||||
|
"EU001": "Wrong username or password!",
|
||||||
|
"EU002": "Your account has been deactivated. Please contact an administrator.",
|
||||||
|
"EU003": "Please enter both username and password.",
|
||||||
|
"EU004": "Some required information is missing. Please check your input.",
|
||||||
|
"EU005": "Login failed due to a technical issue. Please try again.",
|
||||||
|
"EU006": "Login failed. Please try again.",
|
||||||
|
"EU007": "Failed to change your password. Please try again.",
|
||||||
|
"EU008": "Your settings could not be saved. Please try again.",
|
||||||
|
"EU009": "Your settings could not be loaded. Please try again.",
|
||||||
|
"ES001": "Please fill in all required fields for the storage location.",
|
||||||
|
"ES002": "Some required storage information is missing. Please check your input.",
|
||||||
|
"ES003": "The storage location could not be updated. Please try again.",
|
||||||
|
"ES004": "The storage location could not be deleted. Please try again.",
|
||||||
|
"ES005": "No storage locations found.",
|
||||||
|
"ES006": "The storage location could not be created. Please try again.",
|
||||||
|
"EP001": "The product could not be created. Please try again.",
|
||||||
|
"EP002": "No products found.",
|
||||||
|
"EP003": "Product not found.",
|
||||||
|
"EP004": "The product amount could not be updated. Please try again.",
|
||||||
|
"EP005": "The product could not be updated. Please try again.",
|
||||||
|
"EP006": "The product could not be deleted. Please try again.",
|
||||||
|
"EP007": "Please enter at least a product name.",
|
||||||
|
"EP008": "Some required product information is missing. Please check your input."
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user