remove province and city
Build and Deploy Docker Images / build_and_deploy (push) Has been cancelled
Build and Deploy Docker Images / build_and_deploy (push) Has been cancelled
This commit is contained in:
@@ -14,7 +14,7 @@ import useToggle from '@/hooks/helpers/useToggle';
|
||||
import { AddressSelectionModal } from './AddressSelectionModal';
|
||||
|
||||
const formatAddress = (address: Address) => {
|
||||
return `${address.address}، ${address.city}، ${address.province}`;
|
||||
return address.address;
|
||||
};
|
||||
|
||||
export const AddressSection = () => {
|
||||
|
||||
@@ -9,7 +9,7 @@ import { ef } from '@/lib/helpers/utfNumbers';
|
||||
import { Edit2 } from 'iconsax-react';
|
||||
|
||||
const formatAddress = (address: Address) => {
|
||||
return `${address.address}، ${address.city}، ${address.province}`;
|
||||
return address.address;
|
||||
};
|
||||
|
||||
interface AddressSelectionModalProps {
|
||||
|
||||
@@ -196,8 +196,6 @@ export interface OrderAddress {
|
||||
user: OrderUser;
|
||||
title: string;
|
||||
address: string;
|
||||
city: string;
|
||||
province: string;
|
||||
postalCode: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
@@ -439,12 +437,10 @@ export interface OrderDetailCarAddress {
|
||||
}
|
||||
|
||||
export interface OrderDetailUserAddress {
|
||||
city: string;
|
||||
phone: string;
|
||||
address: string;
|
||||
fullName: string;
|
||||
latitude: number;
|
||||
province: string;
|
||||
longitude: number;
|
||||
postalCode: string;
|
||||
}
|
||||
|
||||
@@ -79,12 +79,10 @@ export interface HistoryOrderDeliveryMethod {
|
||||
}
|
||||
|
||||
export interface HistoryOrderUserAddress {
|
||||
city: string;
|
||||
phone: string;
|
||||
address: string;
|
||||
fullName: string;
|
||||
latitude: number;
|
||||
province: string;
|
||||
longitude: number;
|
||||
postalCode: string;
|
||||
}
|
||||
@@ -97,8 +95,6 @@ export interface HistoryOrderAddress {
|
||||
user: string;
|
||||
title: string;
|
||||
address: string;
|
||||
city: string;
|
||||
province: string;
|
||||
postalCode: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
|
||||
@@ -1,90 +1,80 @@
|
||||
import InputField from '@/components/input/InputField';
|
||||
import { NominatimReverseGeocodingResponse } from '../../types/Types';
|
||||
import { useGetProfile } from '../../../hooks/userProfileData';
|
||||
import { useEffect } from 'react';
|
||||
import InputField from "@/components/input/InputField";
|
||||
import { useEffect } from "react";
|
||||
import { useGetProfile } from "../../../hooks/userProfileData";
|
||||
import { NominatimReverseGeocodingResponse } from "../../types/Types";
|
||||
|
||||
interface AddressFormProps {
|
||||
formData: {
|
||||
title: string;
|
||||
addressDetails: string;
|
||||
phone: string;
|
||||
postalCode: string;
|
||||
isDefault: boolean;
|
||||
};
|
||||
selectedAddress: NominatimReverseGeocodingResponse | null;
|
||||
onFormDataChange: (data: Partial<AddressFormProps['formData']>) => void;
|
||||
formData: {
|
||||
title: string;
|
||||
addressDetails: string;
|
||||
phone: string;
|
||||
postalCode: string;
|
||||
isDefault: boolean;
|
||||
};
|
||||
selectedAddress: NominatimReverseGeocodingResponse | null;
|
||||
onFormDataChange: (data: Partial<AddressFormProps["formData"]>) => void;
|
||||
}
|
||||
|
||||
export const AddressForm = ({
|
||||
formData,
|
||||
selectedAddress,
|
||||
onFormDataChange,
|
||||
}: AddressFormProps) => {
|
||||
export const AddressForm = ({ formData, selectedAddress, onFormDataChange }: AddressFormProps) => {
|
||||
const { data: profileData } = useGetProfile();
|
||||
|
||||
const { data: profileData } = useGetProfile()
|
||||
useEffect(() => {
|
||||
if (profileData?.data?.phone && !formData.phone) {
|
||||
onFormDataChange({ phone: "0" + profileData.data.phone });
|
||||
}
|
||||
}, [profileData?.data?.phone, formData.phone, onFormDataChange]);
|
||||
|
||||
useEffect(() => {
|
||||
if (profileData?.data?.phone && !formData.phone) {
|
||||
onFormDataChange({ phone: '0' + profileData.data.phone });
|
||||
}
|
||||
}, [profileData?.data?.phone, formData.phone, onFormDataChange]);
|
||||
|
||||
return (
|
||||
<div className='px-4'>
|
||||
<InputField
|
||||
htmlFor={'addressTitle'}
|
||||
labelText={'عنوان آدرس'}
|
||||
placeholder='مثال: منزل، محل کار ...'
|
||||
className='bg-inherit'
|
||||
inputClassName='text-xs!'
|
||||
value={formData.title}
|
||||
onChange={(e) => onFormDataChange({ title: e.target.value })}
|
||||
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={'addressDetails'}
|
||||
labelText={'جزئیات آدرس'}
|
||||
placeholder='میدان باغ ملی، مجتمع آسمان، واحد 12، پلاک 1234567890'
|
||||
className='bg-inherit mt-8'
|
||||
value={formData.addressDetails}
|
||||
onChange={(e) => onFormDataChange({ addressDetails: e.target.value })}
|
||||
inputClassName='text-xs!'
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={'phone'}
|
||||
labelText={'شماره تلفن'}
|
||||
placeholder='09123456789'
|
||||
className='bg-inherit mt-8'
|
||||
value={formData.phone}
|
||||
onChange={(e) => onFormDataChange({ phone: e.target.value })}
|
||||
inputClassName='text-xs!'
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={'postalCode'}
|
||||
labelText={'کد پستی'}
|
||||
placeholder={selectedAddress?.address?.postcode || '1234567890'}
|
||||
className='bg-inherit mt-8'
|
||||
value={formData.postalCode || selectedAddress?.address?.postcode || ''}
|
||||
onChange={(e) => onFormDataChange({ postalCode: e.target.value })}
|
||||
inputClassName='text-xs!'
|
||||
/>
|
||||
<div className='inline-flex justify-between items-center w-full mt-8'>
|
||||
<label
|
||||
htmlFor={'isDefault'}
|
||||
className='text-sm2 px-2 py-0.5 mt-0.5 cursor-pointer'
|
||||
>
|
||||
تنظیم به عنوان آدرس پیشفرض
|
||||
</label>
|
||||
<input
|
||||
name={'isDefault'}
|
||||
id={'isDefault'}
|
||||
className='h-4.5 w-4.5 checked:accent-primary cursor-pointer'
|
||||
onChange={(e) => onFormDataChange({ isDefault: e.target.checked })}
|
||||
type='checkbox'
|
||||
checked={formData.isDefault}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
return (
|
||||
<div className="px-4">
|
||||
<InputField
|
||||
htmlFor={"addressTitle"}
|
||||
labelText={"عنوان آدرس"}
|
||||
placeholder="مثال: منزل، محل کار ..."
|
||||
className="bg-inherit"
|
||||
inputClassName="text-xs!"
|
||||
value={formData.title}
|
||||
onChange={(e) => onFormDataChange({ title: e.target.value })}
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={"addressDetails"}
|
||||
labelText={"جزئیات آدرس"}
|
||||
placeholder="میدان باغ ملی، مجتمع آسمان، واحد 12، پلاک 1234567890"
|
||||
className="bg-inherit mt-8"
|
||||
value={formData.addressDetails}
|
||||
onChange={(e) => onFormDataChange({ addressDetails: e.target.value })}
|
||||
inputClassName="text-xs!"
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={"phone"}
|
||||
labelText={"شماره تلفن"}
|
||||
placeholder="09123456789"
|
||||
className="bg-inherit mt-8"
|
||||
value={formData.phone}
|
||||
onChange={(e) => onFormDataChange({ phone: e.target.value })}
|
||||
inputClassName="text-xs!"
|
||||
/>
|
||||
<InputField
|
||||
htmlFor={"postalCode"}
|
||||
labelText={"کد پستی"}
|
||||
placeholder={selectedAddress?.address?.postcode || "1234567890"}
|
||||
className="bg-inherit mt-8"
|
||||
value={formData.postalCode || selectedAddress?.address?.postcode || ""}
|
||||
onChange={(e) => onFormDataChange({ postalCode: e.target.value })}
|
||||
inputClassName="text-xs!"
|
||||
/>
|
||||
<div className="inline-flex justify-between items-center w-full mt-8">
|
||||
<label htmlFor={"isDefault"} className="text-sm2 px-2 py-0.5 mt-0.5 cursor-pointer">
|
||||
تنظیم به عنوان آدرس پیشفرض
|
||||
</label>
|
||||
<input
|
||||
name={"isDefault"}
|
||||
id={"isDefault"}
|
||||
className="h-4.5 w-4.5 checked:accent-primary cursor-pointer"
|
||||
onChange={(e) => onFormDataChange({ isDefault: e.target.checked })}
|
||||
type="checkbox"
|
||||
checked={formData.isDefault}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
|
||||
@@ -1,134 +1,124 @@
|
||||
import { useState, useEffect } from 'react';
|
||||
import { useRouter, useSearchParams } from 'next/navigation';
|
||||
import { useCreateAddress, useUpdateAddress } from '../../hooks/useAddressData';
|
||||
import { toast } from '@/components/Toast';
|
||||
import { CreateAddressType, UpdateAddressType, NominatimReverseGeocodingResponse, Address } from '../../types/Types';
|
||||
import { toast } from "@/components/Toast";
|
||||
import { useRouter, useSearchParams } from "next/navigation";
|
||||
import { useEffect, useState } from "react";
|
||||
import { useCreateAddress, useUpdateAddress } from "../../hooks/useAddressData";
|
||||
import { Address, CreateAddressType, NominatimReverseGeocodingResponse, UpdateAddressType } from "../../types/Types";
|
||||
|
||||
interface UseAddressFormProps {
|
||||
selectedPosition: [number, number] | null;
|
||||
selectedAddress: NominatimReverseGeocodingResponse | null;
|
||||
fallbackPosition?: [number, number] | null;
|
||||
initialPhone?: string;
|
||||
editMode?: boolean;
|
||||
addressData?: Address | null;
|
||||
selectedPosition: [number, number] | null;
|
||||
selectedAddress: NominatimReverseGeocodingResponse | null;
|
||||
fallbackPosition?: [number, number] | null;
|
||||
initialPhone?: string;
|
||||
editMode?: boolean;
|
||||
addressData?: Address | null;
|
||||
}
|
||||
|
||||
export const useAddressForm = ({
|
||||
selectedPosition,
|
||||
selectedAddress,
|
||||
fallbackPosition = [0, 0],
|
||||
initialPhone = '',
|
||||
editMode = false,
|
||||
addressData = null,
|
||||
}: UseAddressFormProps) => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get('redirect');
|
||||
const { mutate: createAddress, isPending: isCreating } = useCreateAddress();
|
||||
const { mutate: updateAddress, isPending: isUpdating } = useUpdateAddress();
|
||||
const isPending = isCreating || isUpdating;
|
||||
export const useAddressForm = ({ selectedPosition, selectedAddress, fallbackPosition = [0, 0], initialPhone = "", editMode = false, addressData = null }: UseAddressFormProps) => {
|
||||
const router = useRouter();
|
||||
const searchParams = useSearchParams();
|
||||
const redirect = searchParams.get("redirect");
|
||||
const { mutate: createAddress, isPending: isCreating } = useCreateAddress();
|
||||
const { mutate: updateAddress, isPending: isUpdating } = useUpdateAddress();
|
||||
const isPending = isCreating || isUpdating;
|
||||
|
||||
const [formData, setFormData] = useState({
|
||||
title: '',
|
||||
addressDetails: '',
|
||||
phone: initialPhone,
|
||||
postalCode: '',
|
||||
isDefault: false,
|
||||
});
|
||||
const [formData, setFormData] = useState({
|
||||
title: "",
|
||||
addressDetails: "",
|
||||
phone: initialPhone,
|
||||
postalCode: "",
|
||||
isDefault: false,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
if (editMode && addressData) {
|
||||
setFormData({
|
||||
title: addressData.title || '',
|
||||
addressDetails: addressData.address || '',
|
||||
phone: addressData.phone || initialPhone,
|
||||
postalCode: addressData.postalCode || '',
|
||||
isDefault: addressData.isDefault || false,
|
||||
});
|
||||
}
|
||||
}, [editMode, addressData, initialPhone]);
|
||||
useEffect(() => {
|
||||
if (editMode && addressData) {
|
||||
setFormData({
|
||||
title: addressData.title || "",
|
||||
addressDetails: addressData.address || "",
|
||||
phone: addressData.phone || initialPhone,
|
||||
postalCode: addressData.postalCode || "",
|
||||
isDefault: addressData.isDefault || false,
|
||||
});
|
||||
}
|
||||
}, [editMode, addressData, initialPhone]);
|
||||
|
||||
const handleFormDataChange = (data: Partial<typeof formData>) => {
|
||||
setFormData((prev) => ({ ...prev, ...data }));
|
||||
const handleFormDataChange = (data: Partial<typeof formData>) => {
|
||||
setFormData((prev) => ({ ...prev, ...data }));
|
||||
};
|
||||
|
||||
const submitAddress = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
|
||||
const positionToUse: [number, number] = selectedPosition || fallbackPosition || [0, 0];
|
||||
|
||||
if (!formData.title.trim()) {
|
||||
toast("لطفا عنوان آدرس را وارد کنید", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formData.addressDetails.trim()) {
|
||||
toast("لطفا جزئیات آدرس را وارد کنید", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formData.phone.trim()) {
|
||||
toast("لطفا شماره تلفن را وارد کنید", "error");
|
||||
return;
|
||||
}
|
||||
|
||||
const baseAddressData = {
|
||||
title: formData.title,
|
||||
address: formData.addressDetails,
|
||||
postalCode: formData.postalCode || selectedAddress?.address?.postcode || addressData?.postalCode || "",
|
||||
latitude: positionToUse[0],
|
||||
longitude: positionToUse[1],
|
||||
phone: formData.phone,
|
||||
isDefault: formData.isDefault,
|
||||
};
|
||||
|
||||
const submitAddress = (e: React.FormEvent<HTMLFormElement>) => {
|
||||
e.preventDefault();
|
||||
if (editMode && addressData) {
|
||||
const updateData: UpdateAddressType = {
|
||||
...baseAddressData,
|
||||
id: addressData.id,
|
||||
};
|
||||
|
||||
const positionToUse: [number, number] = selectedPosition || fallbackPosition || [0, 0];
|
||||
updateAddress(updateData, {
|
||||
onSuccess: () => {
|
||||
toast("آدرس با موفقیت بهروزرسانی شد", "success");
|
||||
if (redirect) {
|
||||
router.replace(redirect);
|
||||
} else {
|
||||
router.back();
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error instanceof Error ? error.message : "خطا در بهروزرسانی آدرس";
|
||||
toast(errorMessage, "error");
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const createData: CreateAddressType = baseAddressData;
|
||||
|
||||
if (!formData.title.trim()) {
|
||||
toast('لطفا عنوان آدرس را وارد کنید', 'error');
|
||||
return;
|
||||
}
|
||||
createAddress(createData, {
|
||||
onSuccess: () => {
|
||||
toast("آدرس با موفقیت ثبت شد", "success");
|
||||
if (redirect) {
|
||||
router.replace(redirect);
|
||||
} else {
|
||||
router.back();
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error instanceof Error ? error.message : "خطا در ثبت آدرس";
|
||||
toast(errorMessage, "error");
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
if (!formData.addressDetails.trim()) {
|
||||
toast('لطفا جزئیات آدرس را وارد کنید', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
if (!formData.phone.trim()) {
|
||||
toast('لطفا شماره تلفن را وارد کنید', 'error');
|
||||
return;
|
||||
}
|
||||
|
||||
const baseAddressData = {
|
||||
title: formData.title,
|
||||
address: formData.addressDetails,
|
||||
city: selectedAddress?.address?.city || selectedAddress?.address?.district || addressData?.city || '',
|
||||
province: selectedAddress?.address?.province || selectedAddress?.address?.state || addressData?.province || '',
|
||||
postalCode: formData.postalCode || selectedAddress?.address?.postcode || addressData?.postalCode || '',
|
||||
latitude: positionToUse[0],
|
||||
longitude: positionToUse[1],
|
||||
phone: formData.phone,
|
||||
isDefault: formData.isDefault,
|
||||
};
|
||||
|
||||
if (editMode && addressData) {
|
||||
const updateData: UpdateAddressType = {
|
||||
...baseAddressData,
|
||||
id: addressData.id,
|
||||
};
|
||||
|
||||
updateAddress(updateData, {
|
||||
onSuccess: () => {
|
||||
toast('آدرس با موفقیت بهروزرسانی شد', 'success');
|
||||
if (redirect) {
|
||||
router.replace(redirect);
|
||||
} else {
|
||||
router.back();
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error instanceof Error ? error.message : 'خطا در بهروزرسانی آدرس';
|
||||
toast(errorMessage, 'error');
|
||||
},
|
||||
});
|
||||
} else {
|
||||
const createData: CreateAddressType = baseAddressData;
|
||||
|
||||
createAddress(createData, {
|
||||
onSuccess: () => {
|
||||
toast('آدرس با موفقیت ثبت شد', 'success');
|
||||
if (redirect) {
|
||||
router.replace(redirect);
|
||||
} else {
|
||||
router.back();
|
||||
}
|
||||
},
|
||||
onError: (error) => {
|
||||
const errorMessage = error instanceof Error ? error.message : 'خطا در ثبت آدرس';
|
||||
toast(errorMessage, 'error');
|
||||
},
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
return {
|
||||
formData,
|
||||
isPending,
|
||||
handleFormDataChange,
|
||||
submitAddress,
|
||||
};
|
||||
return {
|
||||
formData,
|
||||
isPending,
|
||||
handleFormDataChange,
|
||||
submitAddress,
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { Address, NominatimReverseGeocodingResponse } from '../../types/Types';
|
||||
|
||||
export const formatAddress = (address: Address): string => {
|
||||
return `${address.address}، ${address.city}، ${address.province}`;
|
||||
return address.address;
|
||||
};
|
||||
|
||||
export const formatSelectedAddress = (selectedAddress: NominatimReverseGeocodingResponse | null): string => {
|
||||
@@ -11,8 +11,6 @@ export const formatSelectedAddress = (selectedAddress: NominatimReverseGeocoding
|
||||
|
||||
try {
|
||||
return [
|
||||
selectedAddress.address.state ?? selectedAddress.address.province,
|
||||
selectedAddress.address.city,
|
||||
selectedAddress.address.neighbourhood,
|
||||
!selectedAddress.address.road.startsWith('میدان') &&
|
||||
!selectedAddress.address.road.startsWith('بلوار') &&
|
||||
|
||||
@@ -70,7 +70,7 @@ function UserAddressesPage({ }: Props) {
|
||||
};
|
||||
|
||||
const formatAddress = (address: Address) => {
|
||||
return `${address.address}، ${address.city}، ${address.province}`;
|
||||
return address.address;
|
||||
};
|
||||
|
||||
const getEditHref = (addressId: string) => {
|
||||
|
||||
@@ -9,8 +9,6 @@ export interface Address {
|
||||
user: string;
|
||||
title: string;
|
||||
address: string;
|
||||
city: string;
|
||||
province: string;
|
||||
postalCode: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
@@ -25,8 +23,6 @@ export type AddressResponse = BaseResponse<Address>;
|
||||
export type CreateAddressType = {
|
||||
title: string;
|
||||
address: string;
|
||||
city: string;
|
||||
province: string;
|
||||
postalCode: string;
|
||||
latitude: number;
|
||||
longitude: number;
|
||||
|
||||
Reference in New Issue
Block a user