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