616058b603
- Added a new profile route under the hidden layout. - Introduced a Sidebar component for navigation between inventory, add product, and profile pages. - Created InventoryPage to display a list of products with sorting and pagination. - Implemented ViewProduct page to show details of a selected product. - Integrated API calls for fetching products and product details. - Updated route tree to include new routes and components.
42 lines
1.0 KiB
TypeScript
42 lines
1.0 KiB
TypeScript
import { API_BASE } from "../config/api.config";
|
|
import Cookies from "js-cookie";
|
|
|
|
export const getProducts = async () => {
|
|
const result = await fetch(`${API_BASE}/products/all-products`, {
|
|
headers: {
|
|
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
|
"Content-Type": "application/json",
|
|
Accept: "application/json",
|
|
},
|
|
});
|
|
const response = await result.json();
|
|
|
|
if (response.code === "ep002") {
|
|
return { success: false, code: response.code };
|
|
}
|
|
|
|
if (response.code === "sp002") {
|
|
return response.data;
|
|
}
|
|
};
|
|
|
|
export const getProductDetails = async (uuid: string) => {
|
|
const result = await fetch(`${API_BASE}/products/view?uuid=${uuid}`, {
|
|
headers: {
|
|
Authorization: `Bearer ${Cookies.get("token") || ""}`,
|
|
"Content-Type": "application/json",
|
|
Accept: "application/json",
|
|
},
|
|
});
|
|
|
|
const response = await result.json();
|
|
|
|
if (response.code === "ep003") {
|
|
return { success: false, code: response.code };
|
|
}
|
|
|
|
if (response.code === "sp003") {
|
|
return response.data;
|
|
}
|
|
};
|