discount ccustomer
This commit is contained in:
@@ -40,7 +40,8 @@ const CreateDiscount: FC = () => {
|
||||
targetServices: [],
|
||||
direct: true,
|
||||
value: 0,
|
||||
isActive: true
|
||||
isActive: true,
|
||||
userPhone: ''
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
value: Yup.number().required(t('errors.required')),
|
||||
@@ -52,6 +53,9 @@ const CreateDiscount: FC = () => {
|
||||
onSubmit(values) {
|
||||
values.targetServices = serviceId
|
||||
values.type = +values.type
|
||||
if (values.userPhone === '') {
|
||||
values.userPhone = undefined
|
||||
}
|
||||
const params: CreateDiscountType = {
|
||||
...values,
|
||||
startDate: moment(values.startDate, 'jYYYY-jMM-jDD').format('YYYY-MM-DD'),
|
||||
@@ -167,19 +171,27 @@ const CreateDiscount: FC = () => {
|
||||
error_text={formik.touched.endDate && formik.errors.endDate ? formik.errors.endDate : ''}
|
||||
/>
|
||||
</div>
|
||||
|
||||
{
|
||||
!formik.values.direct &&
|
||||
<div className='mt-6 rowTwoInput'>
|
||||
<Input
|
||||
label='شماره مشتری (اختیاری)'
|
||||
placeholder='شماره مشتری را وارد کنید'
|
||||
{...formik.getFieldProps('userPhone')}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div className='min-h-[calc(100vh-201px)] bg-white w-sidebar xl:block hidden py-10 px-5 h-fit rounded-3xl'>
|
||||
<div className='text-sm flex items-center justify-between'>
|
||||
<p>
|
||||
{t('discount.service_status')}
|
||||
{'وضعیت تخفیف'}
|
||||
</p>
|
||||
<div className='flex gap-1 text-xs items-center text-description'>
|
||||
<div>
|
||||
{t('ads.deactive')}
|
||||
</div>
|
||||
<SwitchComponent
|
||||
active={false}
|
||||
onChange={() => { }}
|
||||
active={formik.values.isActive}
|
||||
onChange={(value) => formik.setFieldValue('isActive', value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -85,6 +85,7 @@ const DiscountList: FC = () => {
|
||||
<tr>
|
||||
<Td text={t('discount.title')} />
|
||||
<Td text={t('discount.type')} />
|
||||
<Td text={t('discount.customer')} />
|
||||
<Td text={t('discount.code')} />
|
||||
<Td text={t('discount.startDate')} />
|
||||
<Td text={t('discount.endDate')} />
|
||||
@@ -100,6 +101,7 @@ const DiscountList: FC = () => {
|
||||
<tr key={item.id} className='tr'>
|
||||
<Td text={item.title} />
|
||||
<Td text={t(`discount.${item.type}`)} />
|
||||
<Td text={item.user ? item.user.firstName + ' ' + item.user.lastName : '-'} />
|
||||
<Td text={item.code} />
|
||||
<Td text={moment(item.startDate, 'jYYYY-jMM-jDD').format('jYYYY-jMM-jDD')} />
|
||||
<Td text={moment(item.endDate, 'jYYYY-jMM-jDD').format('jYYYY-jMM-jDD')} />
|
||||
|
||||
@@ -42,7 +42,8 @@ const UpdateDiscount: FC = () => {
|
||||
targetServices: [],
|
||||
direct: true,
|
||||
value: 0,
|
||||
isActive: true
|
||||
isActive: true,
|
||||
userPhone: ''
|
||||
},
|
||||
validationSchema: Yup.object({
|
||||
value: Yup.number().required(t('errors.required')),
|
||||
@@ -52,6 +53,9 @@ const UpdateDiscount: FC = () => {
|
||||
type: Yup.string().required(t('errors.required')),
|
||||
}),
|
||||
onSubmit(values) {
|
||||
if (values.userPhone === '') {
|
||||
values.userPhone = undefined
|
||||
}
|
||||
values.targetServices = serviceId
|
||||
const params: CreateDiscountType = {
|
||||
...values,
|
||||
@@ -81,6 +85,10 @@ const UpdateDiscount: FC = () => {
|
||||
direct: getDiscountDetail.data?.data?.discount.applicationType === 'DIRECT',
|
||||
})
|
||||
|
||||
if (getDiscountDetail.data?.data?.discount.user) {
|
||||
formik.setFieldValue('userPhone', getDiscountDetail.data?.data?.discount.user?.phone)
|
||||
}
|
||||
|
||||
// delete getDiscountDetail.data?.data?.discount.subscriptionPlans
|
||||
|
||||
const ids = getDiscountDetail.data?.data?.discount.subscriptionPlans.map((item: SubscriptionPlanType) => item?.service?.id)
|
||||
@@ -192,19 +200,26 @@ const UpdateDiscount: FC = () => {
|
||||
defaulValue={formik.values.endDate}
|
||||
/>
|
||||
</div>
|
||||
{
|
||||
!formik.values.direct &&
|
||||
<div className='mt-6 rowTwoInput'>
|
||||
<Input
|
||||
label='شماره مشتری (اختیاری)'
|
||||
placeholder='شماره مشتری را وارد کنید'
|
||||
{...formik.getFieldProps('userPhone')}
|
||||
/>
|
||||
</div>
|
||||
}
|
||||
</div>
|
||||
<div className='min-h-[calc(100vh-201px)] bg-white w-sidebar xl:block hidden py-10 px-5 h-fit rounded-3xl'>
|
||||
<div className='text-sm flex items-center justify-between'>
|
||||
<p>
|
||||
{t('discount.service_status')}
|
||||
{'وضعیت تخفیف'}
|
||||
</p>
|
||||
<div className='flex gap-1 text-xs items-center text-description'>
|
||||
<div>
|
||||
{t('ads.deactive')}
|
||||
</div>
|
||||
<SwitchComponent
|
||||
active={false}
|
||||
onChange={() => { }}
|
||||
active={formik.values.isActive}
|
||||
onChange={(value) => formik.setFieldValue('isActive', value)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -7,6 +7,7 @@ export type CreateDiscountType = {
|
||||
endDate: string;
|
||||
isActive: boolean;
|
||||
targetServices: string[];
|
||||
userPhone?: string;
|
||||
};
|
||||
|
||||
export enum DiscountType {
|
||||
@@ -34,6 +35,7 @@ export type DiscountItemType = {
|
||||
updatedAt: string;
|
||||
isActive: boolean;
|
||||
users: { firstName: string; lastName: string }[];
|
||||
user: { firstName: string; lastName: string; phone: string };
|
||||
};
|
||||
|
||||
export type SubscriptionPlanType = {
|
||||
|
||||
Reference in New Issue
Block a user