feat: implement product save functionality with frontend-backend integration
This commit is contained in:
@@ -4,7 +4,7 @@ import type { IProductItem } from 'src/types/product';
|
||||
import useSWR from 'swr';
|
||||
import { useMemo } from 'react';
|
||||
|
||||
import { fetcher, endpoints } from 'src/lib/axios';
|
||||
import axiosInstance, { fetcher, endpoints } from 'src/lib/axios';
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
@@ -90,3 +90,74 @@ export function useSearchProducts(query: string) {
|
||||
|
||||
return memoizedValue;
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
type SaveProductData = {
|
||||
id: string;
|
||||
sku: string;
|
||||
name: string;
|
||||
code: string;
|
||||
price: number;
|
||||
taxes: number;
|
||||
tags: string[];
|
||||
sizes: string[];
|
||||
publish: string;
|
||||
gender: string[];
|
||||
coverUrl: string;
|
||||
images: string[];
|
||||
colors: string[];
|
||||
quantity: number;
|
||||
category: string;
|
||||
available: number;
|
||||
totalSold: number;
|
||||
description: string;
|
||||
totalRatings: number;
|
||||
totalReviews: number;
|
||||
inventoryType: string;
|
||||
subDescription: string;
|
||||
priceSale: number | null;
|
||||
newLabel: {
|
||||
content: string;
|
||||
enabled: boolean;
|
||||
};
|
||||
saleLabel: {
|
||||
content: string;
|
||||
enabled: boolean;
|
||||
};
|
||||
ratings: {
|
||||
name: string;
|
||||
starCount: number;
|
||||
reviewCount: number;
|
||||
}[];
|
||||
};
|
||||
export async function saveProduct(productId: string, saveProductData: SaveProductData) {
|
||||
console.log('save product ?');
|
||||
// const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
|
||||
|
||||
const res = await axiosInstance.post('http://localhost:7272/api/product/saveProduct', {
|
||||
data: saveProductData,
|
||||
});
|
||||
|
||||
return res;
|
||||
|
||||
// const url = productId ? [endpoints.product.details, { params: { productId } }] : '';
|
||||
|
||||
// const { data, isLoading, error, isValidating } = useSWR<SaveProductData>(
|
||||
// url,
|
||||
// fetcher,
|
||||
// swrOptions
|
||||
// );
|
||||
|
||||
// const memoizedValue = useMemo(
|
||||
// () => ({
|
||||
// product: data?.product,
|
||||
// productLoading: isLoading,
|
||||
// productError: error,
|
||||
// productValidating: isValidating,
|
||||
// }),
|
||||
// [data?.product, error, isLoading, isValidating]
|
||||
// );
|
||||
|
||||
// return memoizedValue;
|
||||
}
|
||||
|
Reference in New Issue
Block a user