add stock
This commit is contained in:
@@ -41,7 +41,7 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories, initi
|
||||
formik.setFieldValue('variants', [...formik.values.variants, newVariant()])
|
||||
}
|
||||
|
||||
const updateVariant = (index: number, field: keyof ProductVariant, value: string | number) => {
|
||||
const updateVariant = (index: number, field: keyof ProductVariant, value: string | number | undefined) => {
|
||||
const next = [...formik.values.variants]
|
||||
next[index] = { ...next[index], [field]: value }
|
||||
formik.setFieldValue('variants', next)
|
||||
@@ -80,6 +80,22 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories, initi
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className='mt-5'>
|
||||
<Input
|
||||
name='maxPurchaseQuantity'
|
||||
label='حداکثر تعداد خرید'
|
||||
placeholder='خالی = بینهایت'
|
||||
type='number'
|
||||
min={0}
|
||||
value={formik.values.maxPurchaseQuantity === undefined || formik.values.maxPurchaseQuantity === null ? '' : formik.values.maxPurchaseQuantity}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value
|
||||
formik.setFieldValue('maxPurchaseQuantity', v === '' ? undefined : Number(v))
|
||||
}}
|
||||
error_text={formik.touched.maxPurchaseQuantity && formik.errors.maxPurchaseQuantity ? formik.errors.maxPurchaseQuantity : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{/* بخش قیمتگذاری و تنوع */}
|
||||
<div className='mt-6 p-5 sm:p-6 rounded-2xl border border-gray-200/80 bg-gray-50/50'>
|
||||
<div className='text-sm font-medium text-gray-800 mb-1'>قیمتگذاری و تنوع</div>
|
||||
@@ -109,6 +125,19 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories, initi
|
||||
onChange={(e) => formik.setFieldValue('price', Number(e.target.value))}
|
||||
error_text={formik.touched.price && formik.errors.price ? formik.errors.price : ''}
|
||||
/>
|
||||
<Input
|
||||
name='stock'
|
||||
label='موجودی'
|
||||
placeholder='خالی = بینهایت'
|
||||
type='number'
|
||||
min={0}
|
||||
value={formik.values.stock === undefined || formik.values.stock === null ? '' : formik.values.stock}
|
||||
onChange={(e) => {
|
||||
const v = e.target.value
|
||||
formik.setFieldValue('stock', v === '' ? undefined : Number(v))
|
||||
}}
|
||||
error_text={formik.touched.stock && formik.errors.stock ? formik.errors.stock : ''}
|
||||
/>
|
||||
<Input
|
||||
name='discount'
|
||||
label='تخفیف (تومان)'
|
||||
@@ -163,7 +192,7 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories, initi
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<label className='block text-sm font-medium text-gray-700 mb-2'>تنوعها و قیمت هر کدام</label>
|
||||
<label className='block text-sm font-medium text-gray-700 mb-2'>تنوعها، قیمت و موجودی هر کدام</label>
|
||||
<div className='space-y-3'>
|
||||
{formik.values.variants.map((v, index) => (
|
||||
<div
|
||||
@@ -184,6 +213,17 @@ const BasicInfoSection: FC<BasicInfoSectionProps> = ({ formik, categories, initi
|
||||
onChange={(e) => updateVariant(index, 'price', Number(e.target.value))}
|
||||
className='flex-1 min-w-0 shrink-0'
|
||||
/>
|
||||
<Input
|
||||
placeholder='موجودی (خالی=بینهایت)'
|
||||
type='number'
|
||||
min={0}
|
||||
value={v.stock === undefined || v.stock === null ? '' : v.stock}
|
||||
onChange={(e) => {
|
||||
const val = e.target.value
|
||||
updateVariant(index, 'stock', val === '' ? undefined : Number(val))
|
||||
}}
|
||||
className='flex-1 min-w-0 shrink-0'
|
||||
/>
|
||||
<div className='min-w-5'>
|
||||
<Trash
|
||||
onClick={() => removeVariant(index)}
|
||||
|
||||
Reference in New Issue
Block a user