Add variable pricing and purchase options to product forms.
Support fixed vs variable pricing, payment type, purchase units, and decimal quantity inputs in create/update flows. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -14,6 +14,7 @@ import { useMultipleUpload } from '../uploader/hooks/useUploaderData'
|
||||
import { Pages } from '@/config/Pages'
|
||||
import type { ErrorType } from '@/helpers/types'
|
||||
import { extractErrorMessage } from '@/config/func'
|
||||
import { PaymentType, PricingType, PurchaseUnit } from './enum/Enum'
|
||||
|
||||
const UpdateProduct: FC = () => {
|
||||
const { id } = useParams<{ id: string }>()
|
||||
@@ -45,7 +46,13 @@ const UpdateProduct: FC = () => {
|
||||
isSpecialOffer: false,
|
||||
order: 0,
|
||||
stock: undefined,
|
||||
maxPurchaseQuantity: undefined
|
||||
maxPurchaseQuantity: undefined,
|
||||
minPurchaseQuantity: undefined,
|
||||
purchasePitch: undefined,
|
||||
pricingType: PricingType.FIXED,
|
||||
paymentType: PaymentType.INSTANT,
|
||||
purchaseUnit: PurchaseUnit.NUMBER,
|
||||
needAdminAcceptance: false,
|
||||
},
|
||||
validationSchema: Yup.object().shape({
|
||||
title: Yup.string().required('نام کالا الزامی است'),
|
||||
@@ -53,6 +60,17 @@ const UpdateProduct: FC = () => {
|
||||
price: Yup.number().required('قیمت الزامی است').min(0, 'قیمت باید مثبت باشد'),
|
||||
discount: Yup.number().min(0, 'تخفیف باید مثبت باشد'),
|
||||
attribute: Yup.string(),
|
||||
pricingType: Yup.string().required(),
|
||||
paymentType: Yup.string().required(),
|
||||
minPurchaseQuantity: Yup.number().when('pricingType', {
|
||||
is: PricingType.VARIABLE,
|
||||
then: (schema) => schema.min(0, 'حداقل مقدار باید مثبت باشد'),
|
||||
}),
|
||||
maxPurchaseQuantity: Yup.number().min(0, 'حداکثر مقدار باید مثبت باشد'),
|
||||
purchasePitch: Yup.number().when('pricingType', {
|
||||
is: PricingType.VARIABLE,
|
||||
then: (schema) => schema.min(0, 'گام تغییر باید مثبت باشد'),
|
||||
}),
|
||||
variants: Yup.array().of(
|
||||
Yup.object().shape({
|
||||
id: Yup.string(),
|
||||
@@ -83,7 +101,13 @@ const UpdateProduct: FC = () => {
|
||||
variants,
|
||||
isActive,
|
||||
isSpecialOffer: isSpecial,
|
||||
images: allImages
|
||||
images: allImages,
|
||||
needAdminAcceptance: values.paymentType === PaymentType.AFTER_PREPARATION,
|
||||
...(values.pricingType === PricingType.FIXED && {
|
||||
purchaseUnit: values.purchaseUnit ?? PurchaseUnit.NUMBER,
|
||||
minPurchaseQuantity: values.minPurchaseQuantity ?? 1,
|
||||
purchasePitch: undefined,
|
||||
}),
|
||||
}
|
||||
|
||||
updateProduct({ id, params: productData }, {
|
||||
@@ -132,7 +156,13 @@ const UpdateProduct: FC = () => {
|
||||
isSpecialOffer: product.isSpecialOffer || false,
|
||||
order: product.order ?? 0,
|
||||
stock: product.variants?.[0]?.stock,
|
||||
maxPurchaseQuantity: product.maxPurchaseQuantity
|
||||
maxPurchaseQuantity: product.maxPurchaseQuantity,
|
||||
minPurchaseQuantity: product.minPurchaseQuantity,
|
||||
purchasePitch: product.purchasePitch,
|
||||
pricingType: product.pricingType ?? PricingType.FIXED,
|
||||
paymentType: product.paymentType ?? (product.needAdminAcceptance ? PaymentType.AFTER_PREPARATION : PaymentType.INSTANT),
|
||||
purchaseUnit: product.purchaseUnit ?? PurchaseUnit.NUMBER,
|
||||
needAdminAcceptance: product.needAdminAcceptance ?? false,
|
||||
})
|
||||
setIsActive(product.isActive || false)
|
||||
setIsSpecial(product.isSpecialOffer || false)
|
||||
|
||||
Reference in New Issue
Block a user