user optional
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
VITE_TOKEN_NAME = 'dmnu_a_t'
|
||||
VITE_REFRESH_TOKEN_NAME = 'dmnu-a-rt'
|
||||
|
||||
VITE_BASE_URL = 'https://dmenu-api.danakcorp.com'
|
||||
# VITE_BASE_URL = 'http://192.168.99.131:2000'
|
||||
# VITE_BASE_URL = 'https://dmenu-api.danakcorp.com'
|
||||
VITE_BASE_URL = 'http://192.168.99.131:2000'
|
||||
|
||||
VITE_SOCKET_URL = 'https://dmenu-api.danakcorp.com'
|
||||
@@ -108,9 +108,9 @@ export const useCreateOrderForm = () => {
|
||||
paymentDesc: '',
|
||||
},
|
||||
validationSchema: Yup.object().shape({
|
||||
userPhone: Yup.string().required('شماره تلفن الزامی است'),
|
||||
firstName: Yup.string().required('نام الزامی است'),
|
||||
lastName: Yup.string().required('نام خانوادگی الزامی است'),
|
||||
userPhone: Yup.string(),
|
||||
firstName: Yup.string(),
|
||||
lastName: Yup.string(),
|
||||
deliveryMethodId: Yup.string().required('روش تحویل الزامی است'),
|
||||
paymentMethodId: Yup.string().required('روش پرداخت الزامی است'),
|
||||
items: Yup.array()
|
||||
@@ -160,9 +160,8 @@ export const useCreateOrderForm = () => {
|
||||
return
|
||||
}
|
||||
|
||||
const submitOrder = (userId: string, addressId?: string) => {
|
||||
const submitOrder = (userId?: string, addressId?: string) => {
|
||||
const payload: CreateOrderType = {
|
||||
userId,
|
||||
items: values.items,
|
||||
deliveryMethodId: values.deliveryMethodId,
|
||||
paymentMethodId: values.paymentMethodId,
|
||||
@@ -170,6 +169,10 @@ export const useCreateOrderForm = () => {
|
||||
packingFee: values.packingFee || 0,
|
||||
}
|
||||
|
||||
if (userId) {
|
||||
payload.userId = userId
|
||||
}
|
||||
|
||||
if (values.description.trim()) {
|
||||
payload.description = values.description.trim()
|
||||
}
|
||||
@@ -242,19 +245,24 @@ export const useCreateOrderForm = () => {
|
||||
|
||||
const submitFlow = async () => {
|
||||
try {
|
||||
const isCustomerRequiredForDelivery =
|
||||
selectedDelivery?.method === DeliveryMethodEnum.DeliveryCourier
|
||||
|
||||
const userId = await registerNewCustomer()
|
||||
if (!userId) {
|
||||
toast.error('کاربر انتخاب نشده است')
|
||||
if (isCustomerRequiredForDelivery && !userId) {
|
||||
toast.error('برای ثبت آدرس، انتخاب مشتری الزامی است')
|
||||
return
|
||||
}
|
||||
|
||||
let addressId: string | undefined
|
||||
if (userId) {
|
||||
try {
|
||||
addressId = await resolveAddressId(userId)
|
||||
} catch (error) {
|
||||
toast.error(extractErrorMessage(error as ErrorType, 'خطا در ثبت آدرس'))
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if (
|
||||
selectedDelivery?.method === DeliveryMethodEnum.DeliveryCourier &&
|
||||
|
||||
@@ -265,7 +265,7 @@ export interface CreateOrderCarAddress {
|
||||
}
|
||||
|
||||
export interface CreateOrderType {
|
||||
userId: string;
|
||||
userId?: string;
|
||||
items: CreateOrderItem[];
|
||||
deliveryMethodId: string;
|
||||
paymentMethodId: string;
|
||||
|
||||
Reference in New Issue
Block a user