select shipment method in payment
This commit is contained in:
@@ -1,8 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import Combobox, { ComboboxOption } from '@/components/combobox/Combobox';
|
import Combobox from '@/components/combobox/Combobox';
|
||||||
import { Box, Icon, Shop, TruckTick } from 'iconsax-react';
|
import { Box } from 'iconsax-react';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { useGetShipmentMethod } from '../../hooks/useOrderData';
|
||||||
|
|
||||||
type ShippingSectionProps = {
|
type ShippingSectionProps = {
|
||||||
deliveryType: string;
|
deliveryType: string;
|
||||||
@@ -10,13 +11,15 @@ type ShippingSectionProps = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => {
|
export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: ShippingSectionProps) => {
|
||||||
|
|
||||||
|
const { data: shipmentMethod } = useGetShipmentMethod();
|
||||||
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
|
||||||
|
|
||||||
const deliveryOptions: Array<ComboboxOption> = [
|
const options = shipmentMethod?.data.map((item) => ({
|
||||||
{ id: '0', title: t("SectionShipping.InputDeliveryType.Options.Delivery"), icon: TruckTick },
|
id: item.id,
|
||||||
{ id: '1', title: t("SectionShipping.InputDeliveryType.Options.Serve"), icon: Shop },
|
title: item.shipmentMethod.title,
|
||||||
{ id: '2', title: t("SectionShipping.InputDeliveryType.Options.Pickup"), icon: Box },
|
// icon: Box
|
||||||
];
|
})) || [];
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="bg-container rounded-container box-shadow-normal p-4">
|
<section className="bg-container rounded-container box-shadow-normal p-4">
|
||||||
@@ -26,10 +29,16 @@ export const ShippingSection = ({ deliveryType, onDeliveryTypeChange }: Shipping
|
|||||||
className='relative mt-6'
|
className='relative mt-6'
|
||||||
icon={Box}
|
icon={Box}
|
||||||
title=''
|
title=''
|
||||||
|
placeholder={'انتخاب روش ارسال'}
|
||||||
searchable={false}
|
searchable={false}
|
||||||
options={deliveryOptions}
|
options={options}
|
||||||
selectedId={deliveryType}
|
selectedId={deliveryType}
|
||||||
onSelectionChange={(e, i) => onDeliveryTypeChange(String(i))}
|
onSelectionChange={(e, i) => {
|
||||||
|
const selectedOption = options[i];
|
||||||
|
if (selectedOption) {
|
||||||
|
onDeliveryTypeChange(selectedOption.id);
|
||||||
|
}
|
||||||
|
}}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
</section>
|
</section>
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { useQuery } from "@tanstack/react-query";
|
import { useQuery } from "@tanstack/react-query";
|
||||||
import { getShipmentMethod } from "../service/OrderService";
|
import { getPaymentMethod, getShipmentMethod } from "../service/OrderService";
|
||||||
|
|
||||||
export const useGetShipmentMethod = () => {
|
export const useGetShipmentMethod = () => {
|
||||||
return useQuery({
|
return useQuery({
|
||||||
@@ -7,3 +7,10 @@ export const useGetShipmentMethod = () => {
|
|||||||
queryFn: getShipmentMethod,
|
queryFn: getShipmentMethod,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const useGetPaymentMethod = () => {
|
||||||
|
return useQuery({
|
||||||
|
queryKey: ["payment-method"],
|
||||||
|
queryFn: getPaymentMethod,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|||||||
@@ -1,6 +1,19 @@
|
|||||||
import { api } from "@/config/axios";
|
import { api } from "@/config/axios";
|
||||||
|
import {
|
||||||
|
ShipmentMethodsResponse,
|
||||||
|
PaymentMethodsResponse,
|
||||||
|
} from "../types/Types";
|
||||||
|
|
||||||
export const getShipmentMethod = async () => {
|
export const getShipmentMethod = async (): Promise<ShipmentMethodsResponse> => {
|
||||||
const { data } = await api.get("/public/shipment-methods/restaurant");
|
const { data } = await api.get<ShipmentMethodsResponse>(
|
||||||
|
"/public/shipment-methods/restaurant"
|
||||||
|
);
|
||||||
|
return data;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const getPaymentMethod = async (): Promise<PaymentMethodsResponse> => {
|
||||||
|
const { data } = await api.get<PaymentMethodsResponse>(
|
||||||
|
"/public/payments/methods/restaurant"
|
||||||
|
);
|
||||||
return data;
|
return data;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,89 @@
|
|||||||
|
import { BaseResponse } from "@/app/[name]/(Main)/types/Types";
|
||||||
|
|
||||||
|
export interface ShipmentMethod {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
title: string;
|
||||||
|
description: string;
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RestaurantShipmentMethod {
|
||||||
|
id: string;
|
||||||
|
restaurant: string;
|
||||||
|
shipmentMethod: ShipmentMethod;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
price: number;
|
||||||
|
minOrderPrice: number;
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ShipmentMethodsResponse = BaseResponse<RestaurantShipmentMethod[]>;
|
||||||
|
|
||||||
|
export interface ServiceArea {
|
||||||
|
type: "Polygon";
|
||||||
|
coordinates: number[][][];
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface Restaurant {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
slug: string;
|
||||||
|
logo: string | null;
|
||||||
|
address: string | null;
|
||||||
|
menuColor: string | null;
|
||||||
|
latitude: number | null;
|
||||||
|
longitude: number | null;
|
||||||
|
serviceArea: ServiceArea;
|
||||||
|
isActive: boolean;
|
||||||
|
establishedYear: number | null;
|
||||||
|
phoneNumber: string | null;
|
||||||
|
phone: string;
|
||||||
|
instagram: string | null;
|
||||||
|
telegram: string | null;
|
||||||
|
whatsapp: string | null;
|
||||||
|
description: string | null;
|
||||||
|
seoTitle: string | null;
|
||||||
|
seoDescription: string | null;
|
||||||
|
tagNames: string | null;
|
||||||
|
images: string | null;
|
||||||
|
vat: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface PaymentMethod {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
name: string;
|
||||||
|
keyName: string;
|
||||||
|
description: string;
|
||||||
|
icon: string | null;
|
||||||
|
isActive: boolean;
|
||||||
|
isOnline: boolean;
|
||||||
|
order: number;
|
||||||
|
paymentUrl: string | null;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface RestaurantPaymentMethod {
|
||||||
|
id: string;
|
||||||
|
createdAt: string;
|
||||||
|
updatedAt: string;
|
||||||
|
deletedAt: string | null;
|
||||||
|
restaurant: Restaurant;
|
||||||
|
paymentMethod: PaymentMethod;
|
||||||
|
merchantId: string | null;
|
||||||
|
callbackUrl: string | null;
|
||||||
|
isActive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type PaymentMethodsResponse = BaseResponse<RestaurantPaymentMethod[]>;
|
||||||
|
|
||||||
Reference in New Issue
Block a user