fix crud product

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