fix crud product
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
# VITE_API_BASE_URL = 'https://negareh-api.dev.danakcorp.com'
|
||||
VITE_API_BASE_URL = 'http://10.39.173.88:4000'
|
||||
VITE_API_BASE_URL = 'https://negareh-api.dev.danakcorp.com'
|
||||
# VITE_API_BASE_URL = 'http://10.39.173.88:4000'
|
||||
VITE_TOKEN_NAME = 'negareh_at'
|
||||
VITE_REFRESH_TOKEN_NAME = 'negareh_art'
|
||||
|
||||
@@ -25,7 +25,6 @@ const CreateProduct: FC = () => {
|
||||
const { mutate: createProduct, isPending } = useCreateProduct()
|
||||
|
||||
const handleSave = (values: CreateProductType) => {
|
||||
values.categoryId = Number(values.categoryId)
|
||||
createProduct(values, {
|
||||
onSuccess: () => {
|
||||
toast.success('عملیات با موفقیت انجام شد')
|
||||
@@ -40,7 +39,7 @@ const CreateProduct: FC = () => {
|
||||
|
||||
const formik = useFormik<CreateProductType>({
|
||||
initialValues: {
|
||||
categoryId: undefined,
|
||||
categoryId: '',
|
||||
desc: '',
|
||||
images: [],
|
||||
isActive: true,
|
||||
|
||||
@@ -22,13 +22,12 @@ const UpdateProduct: FC = () => {
|
||||
const navigate = useNavigate()
|
||||
const { id } = useParams()
|
||||
const [files, setFiles] = useState<File[]>([])
|
||||
const { data: product, refetch } = useGetProductDetail(Number(id))
|
||||
const { data: product, refetch } = useGetProductDetail(id!)
|
||||
const { mutate: upload, isPending: isUploading } = useMultiUpload()
|
||||
const { mutate: updateProduct, isPending } = useUpdateProduct()
|
||||
|
||||
const handleSave = (values: CreateProductType) => {
|
||||
values.categoryId = Number(values.categoryId)
|
||||
updateProduct({ id: Number(id), params: values }, {
|
||||
updateProduct({ id: id!, params: values }, {
|
||||
onSuccess: () => {
|
||||
toast.success('عملیات با موفقیت انجام شد')
|
||||
refetch()
|
||||
|
||||
@@ -65,7 +65,7 @@ export const useCreateProduct = () => {
|
||||
});
|
||||
};
|
||||
|
||||
export const useGetProductDetail = (id: number) => {
|
||||
export const useGetProductDetail = (id: string) => {
|
||||
return useQuery({
|
||||
queryKey: ["product", id],
|
||||
queryFn: () => api.getProductDetail(id),
|
||||
@@ -76,7 +76,7 @@ export const useGetProductDetail = (id: number) => {
|
||||
export const useUpdateProduct = () => {
|
||||
const queryClient = new QueryClient();
|
||||
return useMutation({
|
||||
mutationFn: ({ id, params }: { id: number; params: CreateProductType }) =>
|
||||
mutationFn: ({ id, params }: { id: string; params: CreateProductType }) =>
|
||||
api.updateProduct(id, params),
|
||||
onSuccess: () => {
|
||||
queryClient.refetchQueries({
|
||||
|
||||
@@ -31,7 +31,7 @@ export const getProducts = async () => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const getProductDetail = async (id:number) => {
|
||||
export const getProductDetail = async (id:string) => {
|
||||
const { data } = await axios.get<ProductDetailResponeType>(`/admin/products/${id}`);
|
||||
return data;
|
||||
};
|
||||
@@ -41,7 +41,7 @@ export const createProduct = async (params:CreateProductType) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const updateProduct = async (id: number, params:CreateProductType) => {
|
||||
export const updateProduct = async (id: string, params:CreateProductType) => {
|
||||
const { data } = await axios.patch(`/admin/products/${id}`, params);
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -8,7 +8,7 @@ export interface CategoryType extends RowDataType {
|
||||
children: CategoryType[];
|
||||
createdAt: string;
|
||||
deletedAt: string | null;
|
||||
id: number;
|
||||
id: string;
|
||||
isActive: boolean;
|
||||
order: number | null;
|
||||
parent: CategoryType | null;
|
||||
@@ -27,7 +27,7 @@ export type CreateCategoryType = {
|
||||
}
|
||||
|
||||
export type CreateProductType = {
|
||||
categoryId?: number,
|
||||
categoryId?: string,
|
||||
title: string,
|
||||
desc: string,
|
||||
linkUrl: string,
|
||||
@@ -41,7 +41,7 @@ export type ProductType = {
|
||||
category: CategoryType,
|
||||
createdAt: string,
|
||||
desc: string,
|
||||
id: number,
|
||||
id: string,
|
||||
images: string[],
|
||||
isActive: boolean,
|
||||
linkUrl: string,
|
||||
|
||||
Reference in New Issue
Block a user