Create file constant

This commit is contained in:
hamid zarghami
2025-12-03 09:08:48 +03:30
parent 20e6f2e6f6
commit 975e29bbc9
9 changed files with 76 additions and 42 deletions
@@ -1,32 +1,67 @@
'use client';
import { useGetAddresses } from '@/app/[name]/(Profile)/profile/address/hooks/useAddressData';
import { Address } from '@/app/[name]/(Profile)/profile/address/types/Types';
import PrimaryButton from '@/components/button/PrimaryButton';
import { ChevronLeft } from 'lucide-react';
import Link from 'next/link';
import { useParams } from 'next/navigation';
import { useTranslation } from 'react-i18next';
type AddressSectionProps = {
address: string;
const formatAddress = (address: Address) => {
return `${address.address}، ${address.city}، ${address.province}`;
};
export const AddressSection = ({ address }: AddressSectionProps) => {
export const AddressSection = () => {
const params = useParams<{ name: string; id: string }>();
const { t } = useTranslation('parallels', { keyPrefix: 'OrderDetail' });
const { data: addresses } = useGetAddresses();
const { data: addressesResponse, isLoading } = useGetAddresses();
const addresses = addressesResponse?.data || [];
const redirectUrl = `/${params.name}/order/checkout/${params.id}`;
console.log(addresses);
// اگر در حال بارگذاری است، چیزی نمایش نده
if (isLoading) {
return null;
}
// اگر آدرس ندارد
if (addresses.length === 0) {
return (
<section className="bg-container rounded-container box-shadow-normal p-4">
<div className="py-3">
<h3 className="text-sm2 font-medium leading-5 mb-4">{t("SectionAddress.Title")}</h3>
<p className='text-sm2 text-disabled-text mb-4'>
آدرسی ثبت نشده است
</p>
<Link href={`/${params.name}/profile/address/new?redirect=${encodeURIComponent(redirectUrl)}`}>
<PrimaryButton>
افزودن آدرس جدید
</PrimaryButton>
</Link>
</div>
</section>
);
}
// فیلتر کردن آدرس‌های غیر پیش‌فرض
const nonDefaultAddresses = addresses.filter(addr => !addr.isDefault);
// اگر فقط آدرس پیش‌فرض دارد، نمایش نده
if (nonDefaultAddresses.length === 0) {
return null;
}
// آدرس اول غیر پیش‌فرض را نمایش بده
const firstNonDefaultAddress = nonDefaultAddresses[0];
return (
<section className="bg-container rounded-container box-shadow-normal p-4">
<div className="py-3">
<div className='w-full flex justify-between items-center gap-2'>
<h3 className="text-sm2 font-medium leading-5 inline-block">{t("SectionAddress.Title")}</h3>
<Link href={`/${params.name}/profile/address?redirect=/${params.name}/order/checkout/${params.id}`}>
<Link href={`/${params.name}/profile/address?redirect=${encodeURIComponent(redirectUrl)}`}>
<button
className='text-sm2 text-primary dark:text-foreground cursor-pointer'
onClick={() => { /* Handle address change */ }}
>
{t("SectionAddress.ButtonChangeAddress")}
<ChevronLeft className='inline-block mr-1 mb-0.5 stroke-primary dark:stroke-foreground' size='16' />
@@ -34,7 +69,7 @@ export const AddressSection = ({ address }: AddressSectionProps) => {
</Link>
</div>
<p className='mt-6 text-sm2'>
{address}
{formatAddress(firstNonDefaultAddress)}
</p>
</div>
</section>
@@ -17,7 +17,6 @@ function OrderDetailInex() {
const [couponCode, setCouponCode] = React.useState<string>('');
const [couponCodeError, setCouponCodeError] = React.useState<string>('');
const [tableNumber, setTableNumber] = useState(0);
const address = "اراک، مصطفی خمینی، خیابان سینا کوچه چمران ساختمان شهرزاد";
const { state: cartModal, toggle: toggleCartModal } = useToggle();
const incrementTableNumber = () => setTableNumber((prev) => prev + 1);
@@ -51,7 +50,7 @@ function OrderDetailInex() {
/>
{deliveryType === '0' && (
<AddressSection address={address} />
<AddressSection />
)}
{deliveryType === '1' && (