submit order
This commit is contained in:
Generated
+428
-330
File diff suppressed because it is too large
Load Diff
@@ -7,6 +7,7 @@ import { useTranslation } from 'react-i18next';
|
|||||||
import { useCheckoutStore } from '../../store/Store';
|
import { useCheckoutStore } from '../../store/Store';
|
||||||
import { toast } from '@/components/Toast';
|
import { toast } from '@/components/Toast';
|
||||||
import { useCreateOrder } from '../../hooks/useOrderData';
|
import { useCreateOrder } from '../../hooks/useOrderData';
|
||||||
|
import { extractErrorMessage } from '@/lib/func';
|
||||||
|
|
||||||
type SummarySectionProps = {
|
type SummarySectionProps = {
|
||||||
cartModal: boolean;
|
cartModal: boolean;
|
||||||
@@ -34,12 +35,16 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
|||||||
}
|
}
|
||||||
|
|
||||||
createOrder(undefined, {
|
createOrder(undefined, {
|
||||||
onSuccess: () => {
|
onSuccess: (data) => {
|
||||||
|
if (data?.data?.paymentUrl) {
|
||||||
|
window.location.href = data?.data?.paymentUrl;
|
||||||
|
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
|
||||||
|
} else {
|
||||||
toast('سفارش با موفقیت ثبت شد', 'success');
|
toast('سفارش با موفقیت ثبت شد', 'success');
|
||||||
onToggleCartModal();
|
}
|
||||||
},
|
},
|
||||||
onError: () => {
|
onError: (error) => {
|
||||||
toast('خطا در ثبت سفارش', 'error');
|
toast(extractErrorMessage(error), 'error');
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ import { api } from "@/config/axios";
|
|||||||
import {
|
import {
|
||||||
ShipmentMethodsResponse,
|
ShipmentMethodsResponse,
|
||||||
PaymentMethodsResponse,
|
PaymentMethodsResponse,
|
||||||
|
CreateOrderResponse,
|
||||||
} from "../types/Types";
|
} from "../types/Types";
|
||||||
|
|
||||||
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
||||||
@@ -37,7 +38,7 @@ export const setPaymentMethod = async (id: string) => {
|
|||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|
||||||
export const createOrder = async () => {
|
export const createOrder = async (): Promise<CreateOrderResponse> => {
|
||||||
const { data } = await api.post("/public/checkout");
|
const { data } = await api.post<CreateOrderResponse>("/public/checkout");
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -128,3 +128,125 @@ export type CheckoutStoreType = {
|
|||||||
isSelectedShipment: boolean;
|
isSelectedShipment: boolean;
|
||||||
setIsSelectedShipment: (value: boolean) => void;
|
setIsSelectedShipment: (value: boolean) => void;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export interface OrderUser {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
phone: string;
|
||||||
|
birthDate: string;
|
||||||
|
marriageDate: string;
|
||||||
|
referrer: string | null;
|
||||||
|
isActive: boolean;
|
||||||
|
gender: boolean;
|
||||||
|
wallet: number;
|
||||||
|
points: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderDeliveryMethod {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
title: string;
|
||||||
|
method: "dineIn" | "pickup" | "deliveryCar" | "deliveryCourier";
|
||||||
|
restaurant: Restaurant;
|
||||||
|
deliveryFee: number;
|
||||||
|
minOrderPrice: number;
|
||||||
|
description: string;
|
||||||
|
enabled: boolean;
|
||||||
|
order: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderAddress {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
user: OrderUser;
|
||||||
|
title: string;
|
||||||
|
address: string;
|
||||||
|
city: string;
|
||||||
|
province: string;
|
||||||
|
postalCode: string;
|
||||||
|
latitude: number;
|
||||||
|
longitude: number;
|
||||||
|
phone: string;
|
||||||
|
isDefault: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderFood {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
restaurant: Restaurant;
|
||||||
|
category: string;
|
||||||
|
title: string;
|
||||||
|
desc: string | null;
|
||||||
|
content: string | null;
|
||||||
|
price: number;
|
||||||
|
points: number | null;
|
||||||
|
order: number | null;
|
||||||
|
prepareTime: number | null;
|
||||||
|
sat: boolean;
|
||||||
|
sun: boolean;
|
||||||
|
mon: boolean;
|
||||||
|
breakfast: boolean;
|
||||||
|
noon: boolean;
|
||||||
|
dinner: boolean;
|
||||||
|
stock: number;
|
||||||
|
stockDefault: number;
|
||||||
|
isActive: boolean;
|
||||||
|
images: string | null;
|
||||||
|
inPlaceServe: boolean;
|
||||||
|
pickupServe: boolean;
|
||||||
|
rate: number;
|
||||||
|
discount: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface OrderItem {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
order: Order;
|
||||||
|
food: OrderFood;
|
||||||
|
quantity: number;
|
||||||
|
unitPrice: number;
|
||||||
|
discount: number;
|
||||||
|
totalPrice: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Order {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
user: OrderUser;
|
||||||
|
restaurant: Restaurant;
|
||||||
|
deliveryMethod: OrderDeliveryMethod;
|
||||||
|
address: OrderAddress;
|
||||||
|
paymentMethod: PaymentMethodResponse;
|
||||||
|
orderNumber: number;
|
||||||
|
couponDiscount: number;
|
||||||
|
itemsDiscount: number;
|
||||||
|
totalDiscount: number;
|
||||||
|
subTotal: number;
|
||||||
|
tax: number;
|
||||||
|
shipmentFee: number;
|
||||||
|
total: number;
|
||||||
|
totalItems: number;
|
||||||
|
status: string;
|
||||||
|
paymentStatus: string;
|
||||||
|
items?: OrderItem[];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CreateOrderData {
|
||||||
|
order: Order;
|
||||||
|
paymentUrl: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type CreateOrderResponse = BaseResponse<CreateOrderData>;
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
import Button from '@/components/button/PrimaryButton';
|
import Button from '@/components/button/PrimaryButton';
|
||||||
import { ef } from '@/lib/helpers/utfNumbers';
|
import { ef } from '@/lib/helpers/utfNumbers';
|
||||||
import { CardTick } from 'iconsax-react';
|
import { CardTick } from 'iconsax-react';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useParams, useRouter } from 'next/navigation';
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
|
||||||
type Props = object
|
type Props = object
|
||||||
@@ -11,6 +11,8 @@ type Props = object
|
|||||||
export default function VerifyIndex({ }: Props) {
|
export default function VerifyIndex({ }: Props) {
|
||||||
// const { t } = useTranslation('notifications')
|
// const { t } = useTranslation('notifications')
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const params = useParams();
|
||||||
|
const name = params.name as string;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className='h-full bg-inherit relative flex flex-col lg:gap-4'>
|
<div className='h-full bg-inherit relative flex flex-col lg:gap-4'>
|
||||||
@@ -57,7 +59,7 @@ export default function VerifyIndex({ }: Props) {
|
|||||||
|
|
||||||
<Button
|
<Button
|
||||||
className='mt-12'
|
className='mt-12'
|
||||||
onClick={() => router.back()} // TODO: redirect to order
|
onClick={() => router.push(`/${name}`)} // TODO: redirect to order
|
||||||
>
|
>
|
||||||
بازگشت
|
بازگشت
|
||||||
</Button>
|
</Button>
|
||||||
|
|||||||
Reference in New Issue
Block a user