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 { toast } from '@/components/Toast';
|
||||
import { useCreateOrder } from '../../hooks/useOrderData';
|
||||
import { extractErrorMessage } from '@/lib/func';
|
||||
|
||||
type SummarySectionProps = {
|
||||
cartModal: boolean;
|
||||
@@ -34,12 +35,16 @@ export const SummarySection = ({ cartModal, onToggleCartModal }: SummarySectionP
|
||||
}
|
||||
|
||||
createOrder(undefined, {
|
||||
onSuccess: () => {
|
||||
toast('سفارش با موفقیت ثبت شد', 'success');
|
||||
onToggleCartModal();
|
||||
onSuccess: (data) => {
|
||||
if (data?.data?.paymentUrl) {
|
||||
window.location.href = data?.data?.paymentUrl;
|
||||
toast('در حال ریدایرکت به صفحه پرداخت...', 'success');
|
||||
} else {
|
||||
toast('سفارش با موفقیت ثبت شد', 'success');
|
||||
}
|
||||
},
|
||||
onError: () => {
|
||||
toast('خطا در ثبت سفارش', 'error');
|
||||
onError: (error) => {
|
||||
toast(extractErrorMessage(error), 'error');
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@ import { api } from "@/config/axios";
|
||||
import {
|
||||
ShipmentMethodsResponse,
|
||||
PaymentMethodsResponse,
|
||||
CreateOrderResponse,
|
||||
} from "../types/Types";
|
||||
|
||||
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
||||
@@ -37,7 +38,7 @@ export const setPaymentMethod = async (id: string) => {
|
||||
return data;
|
||||
};
|
||||
|
||||
export const createOrder = async () => {
|
||||
const { data } = await api.post("/public/checkout");
|
||||
export const createOrder = async (): Promise<CreateOrderResponse> => {
|
||||
const { data } = await api.post<CreateOrderResponse>("/public/checkout");
|
||||
return data;
|
||||
};
|
||||
|
||||
@@ -128,3 +128,125 @@ export type CheckoutStoreType = {
|
||||
isSelectedShipment: boolean;
|
||||
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 { ef } from '@/lib/helpers/utfNumbers';
|
||||
import { CardTick } from 'iconsax-react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { useParams, useRouter } from 'next/navigation';
|
||||
import React from 'react'
|
||||
|
||||
type Props = object
|
||||
@@ -11,6 +11,8 @@ type Props = object
|
||||
export default function VerifyIndex({ }: Props) {
|
||||
// const { t } = useTranslation('notifications')
|
||||
const router = useRouter();
|
||||
const params = useParams();
|
||||
const name = params.name as string;
|
||||
|
||||
return (
|
||||
<div className='h-full bg-inherit relative flex flex-col lg:gap-4'>
|
||||
@@ -56,8 +58,8 @@ export default function VerifyIndex({ }: Props) {
|
||||
<hr className='border border-border my-3' />
|
||||
|
||||
<Button
|
||||
className='mt-12'
|
||||
onClick={() => router.back()} // TODO: redirect to order
|
||||
className='mt-12'
|
||||
onClick={() => router.push(`/${name}`)} // TODO: redirect to order
|
||||
>
|
||||
بازگشت
|
||||
</Button>
|
||||
|
||||
Reference in New Issue
Block a user