select category and subcategory
This commit is contained in:
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user