improved product details page

This commit is contained in:
2026-05-27 18:07:56 +02:00
parent 8ac83520a9
commit 11b490b2e5
5 changed files with 348 additions and 30 deletions
+70 -6
View File
@@ -1,5 +1,6 @@
import { API_BASE } from "../config/api.config";
import Cookies from "js-cookie";
import type { ProductFormValues } from "../misc/interfaces";
export const getProducts = async () => {
const result = await fetch(`${API_BASE}/products/all-products`, {
@@ -40,10 +41,73 @@ export const getProductDetails = async (uuid: string) => {
}
};
export const formatDate = (isoString: string) => {
const date = new Date(isoString);
const day = String(date.getDate()).padStart(2, "0");
const month = String(date.getMonth() + 1).padStart(2, "0");
const year = date.getFullYear();
return `${day}.${month}.${year}`;
export const toInputDate = (value?: string) => {
if (!value) {
return "";
}
if (/^\d{4}-\d{2}-\d{2}$/.test(value)) {
return value;
}
const date = new Date(value);
if (Number.isNaN(date.getTime())) {
return "";
}
return date.toISOString().slice(0, 10);
};
export const mutateProduct = async (
values: ProductFormValues,
itemUUID: string,
) => {
const payload = {
...values,
expiry_date: values.expiry_date || null,
bottling_date: values.bottling_date || null,
};
const result = await fetch(
`${API_BASE}/products/mutate/update-item?item=${itemUUID}`,
{
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 === "ep004") {
return { success: false, code: response.code };
}
if (response.code === "sp004") {
return response.data;
}
};
export const getStorages = async () => {
const result = await fetch(`${API_BASE}/storage/all-storages`, {
headers: {
Authorization: `Bearer ${Cookies.get("token") || ""}`,
"Content-Type": "application/json",
Accept: "application/json",
},
});
const response = await result.json();
if (response.code === "es001") {
return { success: false, code: response.code };
}
if (response.code === "ss001") {
return response.data;
}
};