select category and subcategory

This commit is contained in:
hamid zarghami
2026-02-15 09:43:19 +03:30
parent caa40699f9
commit 8732374c9a
8 changed files with 106 additions and 44 deletions
+9 -12
View File
@@ -27,10 +27,7 @@ const UpdateProduct: FC = () => {
const { mutate: updateProduct, isPending } = useUpdateProduct()
const { mutate: multipleUpload, isPending: isUploading } = useMultipleUpload()
const navigate = useNavigate()
const categories = categoriesData?.data?.map(category => ({
label: category.title,
value: category.id
})) || []
const categories = categoriesData?.data ?? []
const product = productData?.data
@@ -75,11 +72,11 @@ const UpdateProduct: FC = () => {
const variants =
values.variants.length > 0
? values.variants.map((v) => ({
...(v.id && { id: v.id }),
value: v.value ?? '',
price: v.price ?? 0,
...(v.stock !== undefined && v.stock !== null && { stock: v.stock })
}))
...(v.id && { id: v.id }),
value: v.value ?? '',
price: v.price ?? 0,
...(v.stock !== undefined && v.stock !== null && { stock: v.stock })
}))
: [{ value: '', price: values.price, ...(values.stock !== undefined && values.stock !== null && { stock: values.stock }) }]
const productData: CreateProductType = {
...values,
@@ -192,9 +189,9 @@ const UpdateProduct: FC = () => {
formik={formik}
categories={categories}
initialHasVariants={
(product?.variants?.length ?? 0) > 1 ||
((product?.variants?.length === 1) && (product.variants[0].value ?? '') !== '')
}
(product?.variants?.length ?? 0) > 1 ||
((product?.variants?.length === 1) && (product.variants[0].value ?? '') !== '')
}
/>
</div>
</div>