- {key.startsWith("No") || key.startsWith("Only") ? (
-
);
})}
@@ -528,56 +426,50 @@ const PropertyViewModal = ({ isOpen, onClose, property }) => {
)}
-
{t('priceInfo')}
+
{t("priceInfo")}
{property.purpose === "rent" ? (
{property.dailyPrice > 0 && (
- {t('dailyPriceLabel')}
+ {t("dailyPriceLabel")}
- {Number(property.dailyPrice).toLocaleString()} {t('syp')}
+ {Number(property.dailyPrice).toLocaleString()} {t("syp")}
)}
{property.monthlyPrice > 0 && (
- {t('monthlyPriceLabel')}
+ {t("monthlyPriceLabel")}
- {Number(property.monthlyPrice).toLocaleString()} {t('syp')}
+ {Number(property.monthlyPrice).toLocaleString()} {t("syp")}
)}
{property.deposit > 0 && (
- {t('depositLabel')}
+ {t("depositLabel")}
- {Number(property.deposit).toLocaleString()} {t('syp')}
+ {Number(property.deposit).toLocaleString()} {t("syp")}
)}
- {t('rentTypeLabel')}{" "}
- {property.rentType === "daily"
- ? t('daily')
- : property.rentType === "monthly"
- ? t('monthly')
- : t('dailyAndMonthly')}
+ {t("rentTypeLabel")} {property.rentType === "daily" ? t("daily") : property.rentType === "monthly" ? t("monthly") : t("dailyAndMonthly")}
{property.rating > 0 && (
- {t('ratingLabel')}
+ {t("ratingLabel")}
- {Number(property.rating).toFixed(1)}{" "}
-
+ {Number(property.rating).toFixed(1)}
)}
) : (
- {t('salePriceLabel')}
+ {t("salePriceLabel")}
- {Number(property.salePrice).toLocaleString()} {t('syp')}
+ {Number(property.salePrice).toLocaleString()} {t("syp")}
)}
@@ -591,9 +483,9 @@ const PropertyViewModal = ({ isOpen, onClose, property }) => {
const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const { t } = useTranslation();
const [formData, setFormData] = useState({
- propertyType: 'apartment',
+ propertyType: "apartment",
furnished: false,
- description: '',
+ description: "",
bedrooms: 0,
bathrooms: 0,
floor: 0,
@@ -605,31 +497,30 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
serviceDetails: {},
terms: {},
customTerms: [],
- nearbySchool: '',
- nearbyHospital: '',
- nearbyRestaurant: '',
- nearbyUniversity: '',
- nearbyPark: '',
- nearbyMall: '',
- purpose: 'rent',
+ nearbySchool: "",
+ nearbyHospital: "",
+ nearbyRestaurant: "",
+ nearbyUniversity: "",
+ nearbyPark: "",
+ nearbyMall: "",
+ purpose: "rent",
currencyId: 1,
dailyPrice: 0,
monthlyPrice: 0,
deposit: 0,
- rentType: 'monthly',
- allowedPaymentPeriod: '',
+ rentType: "monthly",
+ allowedPaymentPeriod: "",
salePrice: 0,
});
- const [newCustomTerm, setNewCustomTerm] = useState('');
+ const [newCustomTerm, setNewCustomTerm] = useState("");
const [isSaving, setIsSaving] = useState(false);
const [existingImages, setExistingImages] = useState([]);
const [newImages, setNewImages] = useState([]);
- const editApiBase =
- process.env.NEXT_PUBLIC_API_URL || 'https://45.93.137.91.nip.io/api';
+ const editApiBase = process.env.NEXT_PUBLIC_API_URL || "https://45.93.137.91.nip.io/api";
const editImgUrl = (path) => {
if (!path) return null;
- if (path.startsWith('http://') || path.startsWith('https://')) return path;
+ if (path.startsWith("http://") || path.startsWith("https://")) return path;
return `${editApiBase}${path}`;
};
@@ -639,10 +530,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const info = raw.propertyInformation || {};
let details = {};
try {
- details =
- typeof info.detailsJSON === 'object' && info.detailsJSON
- ? info.detailsJSON
- : JSON.parse(info.detailsJSON || '{}');
+ details = typeof info.detailsJSON === "object" && info.detailsJSON ? info.detailsJSON : JSON.parse(info.detailsJSON || "{}");
} catch {
details = {};
}
@@ -653,15 +541,15 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
Object.keys(serviceI18nKeys).forEach((key) => {
const val = propServices[key];
- if (val && typeof val === 'string') {
+ if (val && typeof val === "string") {
services[key] = true;
serviceDetails[key] = val;
- } else if (val && typeof val === 'object' && val.detail) {
+ } else if (val && typeof val === "object" && val.detail) {
services[key] = true;
serviceDetails[key] = val.detail;
} else {
services[key] = !!val;
- serviceDetails[key] = details.serviceDetails?.[key] || '';
+ serviceDetails[key] = details.serviceDetails?.[key] || "";
}
});
@@ -669,7 +557,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
rawSvcArray.forEach((key) => {
if (!(key in services)) {
services[key] = true;
- serviceDetails[key] = details.serviceDetails?.[key] || '';
+ serviceDetails[key] = details.serviceDetails?.[key] || "";
}
});
@@ -678,7 +566,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
Object.keys(termI18nKeys).forEach((key) => {
terms[key] = !!propTerms[key];
});
- if (details.terms && typeof details.terms === 'object') {
+ if (details.terms && typeof details.terms === "object") {
Object.entries(details.terms).forEach(([key, val]) => {
if (val && !(key in terms)) {
terms[key] = true;
@@ -689,52 +577,41 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const prox = property.proximity || details.nearbyDistances || {};
setFormData({
- propertyType: property.propertyType || 'apartment',
+ propertyType: property.propertyType || "apartment",
furnished: property.furnished ?? false,
- description: property.description || details.description || '',
+ description: property.description || details.description || "",
bedrooms: property.bedrooms || 0,
bathrooms: property.bathrooms || 0,
floor: property.floor ?? details.floorNumber ?? details.floor ?? 0,
salons: property.salons ?? details.numberOfSalons ?? details.salons ?? 0,
- balconies:
- property.balconies ??
- details.numberOfBalconies ??
- details.balconies ??
- 0,
+ balconies: property.balconies ?? details.numberOfBalconies ?? details.balconies ?? 0,
livingRooms: property.livingRooms ?? details.numberOfLivingRooms ?? details.livingRooms ?? 0,
area: property.area || 0,
services,
serviceDetails,
terms,
customTerms: details.customTerms || [],
- nearbySchool: prox.School ?? prox.school ?? prox.nearbySchool ?? '',
- nearbyHospital: prox.Hospital ?? prox.hospital ?? prox.nearbyHospital ?? '',
- nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? prox.nearbyRestaurant ?? '',
- nearbyUniversity: prox.University ?? prox.university ?? prox.nearbyUniversity ?? '',
- nearbyPark: prox.Park ?? prox.park ?? prox.nearbyPark ?? '',
- nearbyMall: prox.Mall ?? prox.mall ?? prox.nearbyMall ?? '',
- purpose: property.purpose || 'rent',
+ nearbySchool: prox.School ?? prox.school ?? prox.nearbySchool ?? "",
+ nearbyHospital: prox.Hospital ?? prox.hospital ?? prox.nearbyHospital ?? "",
+ nearbyRestaurant: prox.Restaurant ?? prox.restaurant ?? prox.nearbyRestaurant ?? "",
+ nearbyUniversity: prox.University ?? prox.university ?? prox.nearbyUniversity ?? "",
+ nearbyPark: prox.Park ?? prox.park ?? prox.nearbyPark ?? "",
+ nearbyMall: prox.Mall ?? prox.mall ?? prox.nearbyMall ?? "",
+ purpose: property.purpose || "rent",
currencyId: property.currencyId || 1,
- ...(property.purpose === 'rent'
+ ...(property.purpose === "rent"
? {
dailyPrice: property.dailyPrice || 0,
monthlyPrice: property.monthlyPrice || 0,
deposit: property.deposit || 0,
- rentType: property.rentType || 'monthly',
- allowedPaymentPeriod:
- property.allowedPaymentPeriod ||
- details.allowedPaymentPeriod ||
- '',
+ rentType: property.rentType || "monthly",
+ allowedPaymentPeriod: property.allowedPaymentPeriod || details.allowedPaymentPeriod || "",
}
: { salePrice: property.salePrice || 0 }),
});
- setNewCustomTerm('');
+ setNewCustomTerm("");
setNewImages([]);
- const rawImages = Array.isArray(property.images)
- ? property.images
- : Array.isArray(info.images)
- ? info.images
- : [];
+ const rawImages = Array.isArray(property.images) ? property.images : Array.isArray(info.images) ? info.images : [];
setExistingImages(rawImages.filter((p) => p && p.trim()));
}, [property, isOpen]);
@@ -770,7 +647,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
...prev,
customTerms: [...(prev.customTerms || []), term],
}));
- setNewCustomTerm('');
+ setNewCustomTerm("");
};
const removeCustomTerm = (index) => {
@@ -796,9 +673,9 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const handleAddImages = async (files) => {
const validFiles = Array.from(files).filter((f) => {
- if (!f.type.startsWith('image/')) return false;
+ if (!f.type.startsWith("image/")) return false;
if (f.size > 5 * 1024 * 1024) {
- toast.error(t('fileTooLarge') || 'الصورة كبيرة جداً');
+ toast.error(t("fileTooLarge") || "الصورة كبيرة جداً");
return false;
}
return true;
@@ -808,7 +685,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const currentCount = existingImages.length + newImages.length;
const slots = maxTotal - currentCount;
if (slots <= 0) {
- toast.error(t('maxImagesReached') || 'الحد الأقصى 10 صور');
+ toast.error(t("maxImagesReached") || "الحد الأقصى 10 صور");
return;
}
const toAdd = validFiles.slice(0, slots);
@@ -826,7 +703,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const path = result?.value || result?.path || result?.url || result;
entry.path = path;
} catch {
- toast.error(t('uploadFailed') || 'فشل رفع الصورة');
+ toast.error(t("uploadFailed") || "فشل رفع الصورة");
} finally {
entry.uploading = false;
setNewImages((prev) => [...prev]);
@@ -852,16 +729,16 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
const handleSave = async () => {
const errors = [];
- if (!formData.description?.trim()) errors.push(t('descriptionRequired') || 'الوصف مطلوب');
- if (formData.bedrooms < 1) errors.push(t('bedroomsRequired') || 'يجب أن يكون عدد الغرف على الأقل 1');
- if (formData.bathrooms < 1) errors.push(t('bathroomsRequired') || 'يجب أن يكون عدد الحمامات على الأقل 1');
- if (!formData.area || formData.area <= 0) errors.push(t('areaRequired') || 'المساحة مطلوبة');
- if (formData.purpose === 'rent') {
+ if (!formData.description?.trim()) errors.push(t("descriptionRequired") || "الوصف مطلوب");
+ if (formData.bedrooms < 1) errors.push(t("bedroomsRequired") || "يجب أن يكون عدد الغرف على الأقل 1");
+ if (formData.bathrooms < 1) errors.push(t("bathroomsRequired") || "يجب أن يكون عدد الحمامات على الأقل 1");
+ if (!formData.area || formData.area <= 0) errors.push(t("areaRequired") || "المساحة مطلوبة");
+ if (formData.purpose === "rent") {
if ((!formData.dailyPrice || formData.dailyPrice <= 0) && (!formData.monthlyPrice || formData.monthlyPrice <= 0)) {
- errors.push(t('priceRequired') || 'يجب إدخال سعر الأجر الشهري أو اليومي');
+ errors.push(t("priceRequired") || "يجب إدخال سعر الأجر الشهري أو اليومي");
}
- } else if (formData.purpose === 'sale') {
- if (!formData.salePrice || formData.salePrice <= 0) errors.push(t('priceRequired') || 'السعر مطلوب');
+ } else if (formData.purpose === "sale") {
+ if (!formData.salePrice || formData.salePrice <= 0) errors.push(t("priceRequired") || "السعر مطلوب");
}
if (errors.length > 0) {
toast.error(errors[0]);
@@ -869,9 +746,7 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
}
setIsSaving(true);
try {
- const uploadedPaths = newImages
- .filter((e) => e.path && !e.uploading)
- .map((e) => e.path);
+ const uploadedPaths = newImages.filter((e) => e.path && !e.uploading).map((e) => e.path);
const allImages = [...existingImages, ...uploadedPaths];
await onSave({ ...formData, _images: allImages });
} catch {
@@ -898,15 +773,10 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
>
-
{t('editProperty')}
-
- {t('editSubtitle')}
-
+
{t("editProperty")}
+
{t("editSubtitle")}
-
@@ -914,66 +784,45 @@ const PropertyEditModal = ({ isOpen, onClose, property, onSave }) => {
{/* Basic Info */}
-
- {t('basicInfo')}
-
+
{t("basicInfo")}
-
+
-
+
{[
- { value: true, label: t('furnished') },
- { value: false, label: t('unfurnished') },
+ { value: true, label: t("furnished") },
+ { value: false, label: t("unfurnished") },
].map((opt) => (
-
-
- {t('descriptionLabel')}
-
+
{t("descriptionLabel")}