feat(checkout): unify manual address form with AddressModal, auto-save address and sync user profile on order
This commit is contained in:
1 parent
aa0dde6a35
commit
41f7e98d97
13 files changed
+9829
-9439
No files matched your search
@@ -8,6 +8,53 @@ import { IRAN_PROVINCES, PROVINCE_CITIES } from "../lib/data/provinces";
|
||||
import SearchableSelect from "./SearchableSelect";
|
||||
import { toast } from "sonner";
|
||||
|
||||
export interface AddressFormData {
|
||||
title: string;
|
||||
receptorName: string;
|
||||
phone: string;
|
||||
province: string;
|
||||
city: string;
|
||||
detail: string;
|
||||
zipCode: string;
|
||||
isDefault: boolean;
|
||||
}
|
||||
|
||||
export const normalizeDigits = (str: string) => {
|
||||
if (!str) return "";
|
||||
const persianDigits = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
|
||||
const arabicDigits = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
str = str.replace(persianDigits[i], i.toString()).replace(arabicDigits[i], i.toString());
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
export const validateAddressForm = (formData: AddressFormData): Record<string, string> => {
|
||||
const newErrors: Record<string, string> = {};
|
||||
if (!formData.title?.trim()) newErrors.title = "لطفاً عنوان آدرس را وارد کنید";
|
||||
if (!formData.receptorName?.trim()) newErrors.receptorName = "نام گیرنده را وارد کنید";
|
||||
|
||||
const normalizedPhone = normalizeDigits(formData.phone || "");
|
||||
if (!normalizedPhone) {
|
||||
newErrors.phone = "شماره تماس الزامی است";
|
||||
} else if (!/^09\d{9}$/.test(normalizedPhone)) {
|
||||
newErrors.phone = "شماره موبایل وارد شده معتبر نیست";
|
||||
}
|
||||
|
||||
if (!formData.province?.trim()) newErrors.province = "استان را مشخص کنید";
|
||||
if (!formData.city?.trim()) newErrors.city = "شهر را مشخص کنید";
|
||||
if (!formData.detail?.trim()) newErrors.detail = "آدرس دقیق پستی را وارد کنید";
|
||||
|
||||
const normalizedZip = normalizeDigits(formData.zipCode || "");
|
||||
if (!normalizedZip) {
|
||||
newErrors.zipCode = "کد پستی الزامی است";
|
||||
} else if (!/^\d{10}$/.test(normalizedZip)) {
|
||||
newErrors.zipCode = "کد پستی باید ۱۰ رقم باشد";
|
||||
}
|
||||
|
||||
return newErrors;
|
||||
};
|
||||
|
||||
interface AddressModalProps {
|
||||
isOpen: boolean;
|
||||
onClose: () => void;
|
||||
@@ -16,7 +63,7 @@ interface AddressModalProps {
|
||||
}
|
||||
|
||||
export default function AddressModal({ isOpen, onClose, onSave, editingAddress }: AddressModalProps) {
|
||||
const [formData, setFormData] = useState<Omit<Address, "id">>({
|
||||
const [formData, setFormData] = useState<AddressFormData>({
|
||||
title: "",
|
||||
receptorName: "",
|
||||
phone: "",
|
||||
@@ -60,45 +107,11 @@ export default function AddressModal({ isOpen, onClose, onSave, editingAddress }
|
||||
});
|
||||
}, [editingAddress, isOpen]);
|
||||
|
||||
const normalizeDigits = (str: string) => {
|
||||
const persianDigits = [/۰/g, /۱/g, /۲/g, /۳/g, /۴/g, /۵/g, /۶/g, /۷/g, /۸/g, /۹/g];
|
||||
const arabicDigits = [/٠/g, /١/g, /٢/g, /٣/g, /٤/g, /٥/g, /٦/g, /٧/g, /٨/g, /٩/g];
|
||||
for (let i = 0; i < 10; i++) {
|
||||
str = str.replace(persianDigits[i], i.toString()).replace(arabicDigits[i], i.toString());
|
||||
}
|
||||
return str;
|
||||
};
|
||||
|
||||
const validate = () => {
|
||||
const newErrors: Record<string, string> = {};
|
||||
if (!formData.title) newErrors.title = "لطفاً عنوان آدرس را وارد کنید";
|
||||
if (!formData.receptorName) newErrors.receptorName = "نام گیرنده را وارد کنید";
|
||||
|
||||
const normalizedPhone = normalizeDigits(formData.phone);
|
||||
if (!normalizedPhone) {
|
||||
newErrors.phone = "شماره تماس الزامی است";
|
||||
} else if (!/^09\d{9}$/.test(normalizedPhone)) {
|
||||
newErrors.phone = "شماره موبایل وارد شده معتبر نیست";
|
||||
}
|
||||
|
||||
if (!formData.province) newErrors.province = "استان را مشخص کنید";
|
||||
if (!formData.city) newErrors.city = "شهر را مشخص کنید";
|
||||
if (!formData.detail) newErrors.detail = "آدرس دقیق پستی را وارد کنید";
|
||||
|
||||
const normalizedZip = normalizeDigits(formData.zipCode);
|
||||
if (!normalizedZip) {
|
||||
newErrors.zipCode = "کد پستی الزامی است";
|
||||
} else if (!/^\d{10}$/.test(normalizedZip)) {
|
||||
newErrors.zipCode = "کد پستی باید ۱۰ رقم باشد";
|
||||
}
|
||||
|
||||
setErrors(newErrors);
|
||||
return Object.keys(newErrors).length === 0;
|
||||
};
|
||||
|
||||
const handleSubmit = (e: React.FormEvent) => {
|
||||
e.preventDefault();
|
||||
if (validate()) {
|
||||
const newErrors = validateAddressForm(formData);
|
||||
setErrors(newErrors);
|
||||
if (Object.keys(newErrors).length === 0) {
|
||||
setIsSubmitting(true);
|
||||
// Simulate small delay for UX
|
||||
setTimeout(() => {
|
||||
@@ -112,7 +125,7 @@ export default function AddressModal({ isOpen, onClose, onSave, editingAddress }
|
||||
toast.success(editingAddress ? "تغییرات آدرس با موفقیت ذخیره شد" : "آدرس جدید با موفقیت اضافه شد");
|
||||
setIsSubmitting(false);
|
||||
onClose();
|
||||
}, 600);
|
||||
}, 300);
|
||||
} else {
|
||||
toast.error("لطفاً موارد خطای فرم را اصلاح کنید");
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import { usePetStore } from "../lib/store/usePetStore";
|
||||
import { useUserStore } from "../lib/store/userStore";
|
||||
import { useSettingsStore } from "../lib/store/settingsStore";
|
||||
import TopUpModal from "./TopUpModal";
|
||||
import AddressModal from "./AddressModal";
|
||||
import AddressModal, { AddressFormData, validateAddressForm, normalizeDigits } from "./AddressModal";
|
||||
import SearchableSelect from "./SearchableSelect";
|
||||
import { IRAN_PROVINCES, PROVINCE_CITIES } from "../lib/data/provinces";
|
||||
import { toast } from "sonner";
|
||||
@@ -52,13 +52,18 @@ export default function CheckoutPage() {
|
||||
const [selectedPetId, setSelectedPetId] = useState<string | null>(activePetId || (pets[0]?.id ?? null));
|
||||
const [selectedAddressId, setSelectedAddressId] = useState<string>('');
|
||||
|
||||
// Custom manual address state if guest or not using stored addresses
|
||||
const [manualName, setManualName] = useState('');
|
||||
const [manualPhone, setManualPhone] = useState('');
|
||||
const [manualProvince, setManualProvince] = useState('');
|
||||
const [manualCity, setManualCity] = useState('');
|
||||
const [manualZipCode, setManualZipCode] = useState('');
|
||||
const [manualAddress, setManualAddress] = useState('');
|
||||
// Custom manual address state matching AddressModal if guest or not using stored addresses
|
||||
const [manualAddressData, setManualAddressData] = useState<AddressFormData>({
|
||||
title: 'منزل اصلی',
|
||||
receptorName: '',
|
||||
phone: '',
|
||||
province: '',
|
||||
city: '',
|
||||
detail: '',
|
||||
zipCode: '',
|
||||
isDefault: true
|
||||
});
|
||||
const [manualErrors, setManualErrors] = useState<Record<string, string>>({});
|
||||
|
||||
const handleCopy = (text: string, title: string) => {
|
||||
navigator.clipboard.writeText(text);
|
||||
@@ -71,10 +76,13 @@ export default function CheckoutPage() {
|
||||
if (isLoggedIn && profile.addresses && profile.addresses.length > 0) {
|
||||
const def = profile.addresses.find(a => a.isDefault) || profile.addresses[0];
|
||||
setSelectedAddressId(def.id);
|
||||
} else if (isLoggedIn && profile.firstName) {
|
||||
} else if (isLoggedIn && (profile.firstName || profile.mobile)) {
|
||||
// Pre-fill profile info for manual fields
|
||||
setManualName(`${profile.firstName} ${profile.lastName}`.trim());
|
||||
setManualPhone(profile.mobile || '');
|
||||
setManualAddressData(prev => ({
|
||||
...prev,
|
||||
receptorName: prev.receptorName || `${profile.firstName || ''} ${profile.lastName || ''}`.trim(),
|
||||
phone: prev.phone || profile.mobile || ''
|
||||
}));
|
||||
}
|
||||
});
|
||||
}, [isLoggedIn, profile]);
|
||||
@@ -109,19 +117,65 @@ export default function CheckoutPage() {
|
||||
const totalAmount = getTotal() + shippingFee;
|
||||
const activePet = getActivePet();
|
||||
|
||||
// 1. Validate shipping address
|
||||
const selectedAddr = profile.addresses?.find(a => a.id === selectedAddressId);
|
||||
let shippingAddressStr = '';
|
||||
if (selectedAddr) {
|
||||
shippingAddressStr = `${selectedAddr.province}، ${selectedAddr.city}، ${selectedAddr.detail}${selectedAddr.zipCode ? ` (کد پستی: ${selectedAddr.zipCode})` : ''} (گیرنده: ${selectedAddr.receptorName} - ${toPersian(selectedAddr.phone)})`;
|
||||
} else if (manualAddress) {
|
||||
const provCity = [manualProvince, manualCity].filter(Boolean).join('، ');
|
||||
shippingAddressStr = `${provCity ? provCity + '، ' : ''}${manualAddress}${manualZipCode ? ` (کد پستی: ${manualZipCode})` : ''}${manualName ? ` (گیرنده: ${manualName}${manualPhone ? ` - ${toPersian(manualPhone)}` : ''})` : ''}`;
|
||||
// 0. Ensure user is logged in before placing order
|
||||
if (!isLoggedIn) {
|
||||
toast.error("جهت تکمیل خرید و ثبت سفارش، لطفاً ابتدا وارد حساب کاربری خود شوید.");
|
||||
useUserStore.getState().setAuthModalOpen(true);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!selectedAddressId && !manualAddress) {
|
||||
toast.error("لطفاً یک آدرس برای ارسال سفارش انتخاب کرده یا آدرس جدید وارد کنید.");
|
||||
return;
|
||||
// 1. Validate and resolve shipping address
|
||||
const selectedAddr = profile.addresses?.find(a => a.id === selectedAddressId);
|
||||
let shippingAddressStr = '';
|
||||
|
||||
if (selectedAddr) {
|
||||
shippingAddressStr = `${selectedAddr.province}، ${selectedAddr.city}، ${selectedAddr.detail}${selectedAddr.zipCode ? ` (کد پستی: ${selectedAddr.zipCode})` : ''} (گیرنده: ${selectedAddr.receptorName} - ${toPersian(selectedAddr.phone)})`;
|
||||
} else {
|
||||
const addrErrors = validateAddressForm(manualAddressData);
|
||||
setManualErrors(addrErrors);
|
||||
if (Object.keys(addrErrors).length > 0) {
|
||||
toast.error("لطفاً اطلاعات آدرس و گیرنده را به صورت کامل و صحیح تکمیل کنید.");
|
||||
return;
|
||||
}
|
||||
|
||||
const cleanPhone = normalizeDigits(manualAddressData.phone);
|
||||
const cleanZip = normalizeDigits(manualAddressData.zipCode);
|
||||
|
||||
shippingAddressStr = `${manualAddressData.province}، ${manualAddressData.city}، ${manualAddressData.detail}${cleanZip ? ` (کد پستی: ${cleanZip})` : ''} (گیرنده: ${manualAddressData.receptorName} - ${toPersian(cleanPhone)})`;
|
||||
|
||||
// Auto-save the new manual address to user's permanent address list
|
||||
try {
|
||||
await useUserStore.getState().addAddress({
|
||||
id: Math.random().toString(36).substring(2, 9),
|
||||
title: manualAddressData.title || 'منزل اصلی',
|
||||
receptorName: manualAddressData.receptorName,
|
||||
phone: cleanPhone,
|
||||
province: manualAddressData.province,
|
||||
city: manualAddressData.city,
|
||||
detail: manualAddressData.detail,
|
||||
zipCode: cleanZip,
|
||||
isDefault: manualAddressData.isDefault
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to save manual address to user account:', e);
|
||||
}
|
||||
|
||||
// Auto-sync user's first and last name if not set or default
|
||||
const currentFirst = profile.firstName?.trim() || '';
|
||||
const currentLast = profile.lastName?.trim() || '';
|
||||
if (!currentFirst || currentFirst === 'کاربر' || !currentLast || currentLast === 'جدید') {
|
||||
const nameParts = manualAddressData.receptorName.trim().split(/\s+/);
|
||||
const newFirst = nameParts[0] || 'کاربر';
|
||||
const newLast = nameParts.slice(1).join(' ') || 'گرامی';
|
||||
try {
|
||||
await useUserStore.getState().updateProfile({
|
||||
firstName: newFirst,
|
||||
lastName: newLast
|
||||
});
|
||||
} catch (e) {
|
||||
console.error('Failed to update profile names:', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Validate wallet balance if payment method is wallet
|
||||
@@ -347,95 +401,138 @@ export default function CheckoutPage() {
|
||||
</div>
|
||||
</div>
|
||||
) : (
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 md:grid-cols-4 gap-3">
|
||||
<div>
|
||||
<label htmlFor="chk-fullname" className="text-[11px] font-bold text-medical-gray-700 block mb-1">نام و نام خانوادگی *</label>
|
||||
<input
|
||||
id="chk-fullname"
|
||||
name="name"
|
||||
type="text"
|
||||
autoComplete="name"
|
||||
value={manualName}
|
||||
onChange={(e) => setManualName(e.target.value)}
|
||||
className="w-full bg-medical-gray-50/70 border border-medical-gray-200 rounded-xl py-2 px-3 text-xs focus:ring-1 focus:ring-canina-blue outline-none"
|
||||
placeholder="مثلاً: پارسا آقایی"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="chk-tel" className="text-[11px] font-bold text-medical-gray-700 block mb-1">شماره همراه *</label>
|
||||
<input
|
||||
id="chk-tel"
|
||||
name="tel"
|
||||
type="tel"
|
||||
autoComplete="tel"
|
||||
value={manualPhone}
|
||||
onChange={(e) => setManualPhone(e.target.value.replace(/[^0-9]/g, ''))}
|
||||
className="w-full bg-medical-gray-50/70 border border-medical-gray-200 rounded-xl py-2 px-3 text-xs focus:ring-1 focus:ring-canina-blue outline-none dir-ltr text-right"
|
||||
placeholder="۰۹۱۲XXXXXXX"
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="chk-province" className="text-[11px] font-bold text-medical-gray-700 block mb-1">استان *</label>
|
||||
<SearchableSelect
|
||||
id="chk-province"
|
||||
options={IRAN_PROVINCES}
|
||||
value={manualProvince}
|
||||
placeholder="انتخاب استان..."
|
||||
searchPlaceholder="جستجوی استان..."
|
||||
onChange={(prov) => {
|
||||
const cities = PROVINCE_CITIES[prov] || [];
|
||||
setManualProvince(prov);
|
||||
setManualCity(cities[0] || '');
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="chk-city" className="text-[11px] font-bold text-medical-gray-700 block mb-1">شهر *</label>
|
||||
{manualProvince && PROVINCE_CITIES[manualProvince] ? (
|
||||
<SearchableSelect
|
||||
id="chk-city"
|
||||
options={PROVINCE_CITIES[manualProvince]}
|
||||
value={manualCity}
|
||||
placeholder="انتخاب شهر..."
|
||||
searchPlaceholder="جستجوی شهر..."
|
||||
onChange={(c) => setManualCity(c)}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
id="chk-city"
|
||||
type="text"
|
||||
value={manualCity}
|
||||
onChange={(e) => setManualCity(e.target.value)}
|
||||
className="w-full bg-medical-gray-50/70 border border-medical-gray-200 rounded-xl py-2 px-3 text-xs focus:ring-1 focus:ring-canina-blue outline-none"
|
||||
placeholder="نام شهر..."
|
||||
/>
|
||||
)}
|
||||
</div>
|
||||
<div className="sm:col-span-2 md:col-span-3">
|
||||
<label htmlFor="chk-street" className="text-[11px] font-bold text-medical-gray-700 block mb-1">آدرس دقیق پستی *</label>
|
||||
<input
|
||||
id="chk-street"
|
||||
name="street-address"
|
||||
autoComplete="street-address"
|
||||
value={manualAddress}
|
||||
onChange={(e) => setManualAddress(e.target.value)}
|
||||
className="w-full bg-medical-gray-50/70 border border-medical-gray-200 rounded-xl py-2 px-3 text-xs focus:ring-1 focus:ring-canina-blue outline-none"
|
||||
placeholder="خیابان، کوچه، پلاک، واحد..."
|
||||
/>
|
||||
</div>
|
||||
<div>
|
||||
<label htmlFor="chk-zipcode" className="text-[11px] font-bold text-medical-gray-700 block mb-1">کد پستی (۱۰ رقمی)</label>
|
||||
<input
|
||||
id="chk-zipcode"
|
||||
type="text"
|
||||
maxLength={10}
|
||||
value={manualZipCode}
|
||||
onChange={(e) => setManualZipCode(e.target.value.replace(/[^0-9]/g, ''))}
|
||||
className="w-full bg-medical-gray-50/70 border border-medical-gray-200 rounded-xl py-2 px-3 text-xs focus:ring-1 focus:ring-canina-blue outline-none dir-ltr text-right"
|
||||
placeholder="۱۲۳۴۵۶۷۸۹۰"
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="space-y-4">
|
||||
{/* Row 1: Title */}
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-title" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">عنوان آدرس (مثلاً: خانه، محل کار)</label>
|
||||
<input
|
||||
id="chk-title"
|
||||
name="address-line1"
|
||||
autoComplete="address-line1"
|
||||
type="text"
|
||||
value={manualAddressData.title}
|
||||
onChange={e => setManualAddressData({...manualAddressData, title: e.target.value})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 text-xs", manualErrors.title ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="مثال: منزل اصلی"
|
||||
/>
|
||||
{manualErrors.title && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.title}</p>}
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{/* Row 2: Name & Phone */}
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-name" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">نام و نام خانوادگی گیرنده *</label>
|
||||
<input
|
||||
id="chk-name"
|
||||
name="name"
|
||||
autoComplete="name"
|
||||
type="text"
|
||||
value={manualAddressData.receptorName}
|
||||
onChange={e => setManualAddressData({...manualAddressData, receptorName: e.target.value})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 text-xs", manualErrors.receptorName ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="نام و نام خانوادگی..."
|
||||
/>
|
||||
{manualErrors.receptorName && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.receptorName}</p>}
|
||||
</div>
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-tel" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">شماره همراه گیرنده *</label>
|
||||
<input
|
||||
id="chk-tel"
|
||||
name="tel"
|
||||
autoComplete="tel"
|
||||
type="text"
|
||||
value={manualAddressData.phone}
|
||||
onChange={e => setManualAddressData({...manualAddressData, phone: e.target.value})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 text-left text-xs", manualErrors.phone ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="09120000000"
|
||||
dir="ltr"
|
||||
/>
|
||||
{manualErrors.phone && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.phone}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-4">
|
||||
{/* Row 3: Province & City */}
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-province" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">استان *</label>
|
||||
<SearchableSelect
|
||||
id="chk-province"
|
||||
options={IRAN_PROVINCES}
|
||||
value={manualAddressData.province}
|
||||
placeholder="انتخاب استان..."
|
||||
searchPlaceholder="جستجوی استان..."
|
||||
onChange={(newProv) => {
|
||||
const cities = PROVINCE_CITIES[newProv] || [];
|
||||
setManualAddressData({
|
||||
...manualAddressData,
|
||||
province: newProv,
|
||||
city: cities[0] || ""
|
||||
});
|
||||
}}
|
||||
/>
|
||||
{manualErrors.province && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.province}</p>}
|
||||
</div>
|
||||
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-city" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">شهر *</label>
|
||||
{manualAddressData.province && PROVINCE_CITIES[manualAddressData.province] ? (
|
||||
<SearchableSelect
|
||||
id="chk-city"
|
||||
options={PROVINCE_CITIES[manualAddressData.province]}
|
||||
value={manualAddressData.city}
|
||||
placeholder="انتخاب شهر..."
|
||||
searchPlaceholder="جستجوی شهر..."
|
||||
onChange={(c) => setManualAddressData({...manualAddressData, city: c})}
|
||||
/>
|
||||
) : (
|
||||
<input
|
||||
id="chk-city"
|
||||
name="address-level2"
|
||||
type="text"
|
||||
value={manualAddressData.city}
|
||||
onChange={e => setManualAddressData({...manualAddressData, city: e.target.value})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 text-xs", manualErrors.city ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="نام شهر..."
|
||||
/>
|
||||
)}
|
||||
{manualErrors.city && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.city}</p>}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Row 4: Detail Address */}
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-street" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">آدرس دقیق پستی *</label>
|
||||
<textarea
|
||||
id="chk-street"
|
||||
name="street-address"
|
||||
autoComplete="street-address"
|
||||
rows={2}
|
||||
value={manualAddressData.detail}
|
||||
onChange={e => setManualAddressData({...manualAddressData, detail: e.target.value})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 resize-none text-xs", manualErrors.detail ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="خیابان، کوچه، پلاک، واحد..."
|
||||
/>
|
||||
{manualErrors.detail && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.detail}</p>}
|
||||
</div>
|
||||
|
||||
{/* Row 5: Zip Code */}
|
||||
<div className="space-y-1">
|
||||
<label htmlFor="chk-zip" className="text-[10px] font-black text-medical-gray-400 uppercase tracking-widest block pr-2">کد پستی (۱۰ رقمی) *</label>
|
||||
<input
|
||||
id="chk-zip"
|
||||
name="postal-code"
|
||||
autoComplete="postal-code"
|
||||
type="text"
|
||||
maxLength={10}
|
||||
value={manualAddressData.zipCode}
|
||||
onChange={e => setManualAddressData({...manualAddressData, zipCode: e.target.value.replace(/[^0-9]/g, '')})}
|
||||
className={cn("w-full bg-medical-gray-50 border rounded-2xl py-3 px-5 outline-none font-bold transition-all focus:ring-2 focus:ring-canina-blue/20 text-left text-xs", manualErrors.zipCode ? "border-red-300" : "border-medical-gray-100")}
|
||||
placeholder="1234567890"
|
||||
dir="ltr"
|
||||
/>
|
||||
{manualErrors.zipCode && <p className="text-[10px] text-red-500 font-bold pr-2">{manualErrors.zipCode}</p>}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</section>
|
||||
|
||||
@@ -752,6 +849,7 @@ export default function CheckoutPage() {
|
||||
}}
|
||||
/>
|
||||
|
||||
|
||||
<AddressModal
|
||||
isOpen={showAddressModal}
|
||||
onClose={() => setShowAddressModal(false)}
|
||||
|
||||
Reference in new issue
Block a user