import { useState } from "react"; import AppInput from "../../components/AppInput"; import { Button } from "../../components/ui/button"; import { FileText, User, Loader2 } from "lucide-react"; import { formatPrice } from "../../utils/helpers"; import { formatDateRange } from "./ShippingInformation"; import { useParams } from "@remix-run/react"; import { Address, CartItem, CartItem as CartItemType, SellerCourierList, } from "src/api/types"; import { useVerifyDiscountCode } from "../../requestHandler/use-discount-hooks"; interface ReceiverInformationProps { selectedAddressInfo: Address | null; selectedCourierInfo: SellerCourierList | null; total: string; cartItems: CartItemType[]; discountValue: number | null; } export const ReceiverInformation = ({ selectedAddressInfo, selectedCourierInfo, total, cartItems, discountValue, }: ReceiverInformationProps) => { const [discountCode, setDiscountCode] = useState(""); const { cartId } = useParams(); const isFaceToFace = selectedCourierInfo?.courierIsFaceToFace; // Use the verify discount code hook const { mutate: verifyDiscountCode, isPending: isLoading } = useVerifyDiscountCode(); const sendDiscountCode = async () => { if (!cartId || !discountCode) return; verifyDiscountCode( { code: parseInt(discountCode), cartId: cartId, }, { onSuccess: () => { setDiscountCode(""); }, } ); }; return (
{!isFaceToFace && (

تحویل گیرنده

{}} disabled={true} /> {}} />
) => { const value = e.target.value; setDiscountCode(value); }} />
)}
); }; interface InvoiceContentProps { selectedCourierInfo: SellerCourierList | null; selectedAddressInfo: Address | null; cartItems: CartItem[]; total: string; discountValue: number | null; } export const InvoiceContent = ({ selectedCourierInfo, selectedAddressInfo, cartItems, total, discountValue, }: InvoiceContentProps) => { const isFaceToFace = selectedCourierInfo?.courierIsFaceToFace; return (

فاکتور خرید

{!selectedCourierInfo ? (

در حال بارگذاری...

) : ( <> {!isFaceToFace && (

کد پستی

{!selectedAddressInfo ? ( ) : (

{selectedAddressInfo?.postalCode}

)}

زمان تحویل

{formatDateRange(selectedCourierInfo?.estimatedDays)}

{!selectedAddressInfo ? ( ) : (

آدرس:{selectedAddressInfo?.mainAddress}

)}
)}
{cartItems?.map((item, index) => (

{item.productVariant?.productTitle}

{formatPrice(item.productVariant?.discountPrice || "0")}x {item.quantity} تومان

))}

مقدار تخفیف

{!selectedCourierInfo ? ( ) : (

{formatPrice(discountValue?.toString() || "0")} تومان

)}

هزینه ارسال

{!selectedCourierInfo ? ( ) : (

{selectedCourierInfo?.courierIsFreightCollect ? "پس پرداخت" : `${formatPrice( selectedCourierInfo?.deliveryPrice?.toString() || "0" )} تومان`}

)}

مبلغ کل فاکتور

{!selectedCourierInfo ? ( ) : (

{formatPrice(parseFloat(total).toString())} تومان

)}
)}
); };