Added api for add property
All checks were successful
Build frontend / build (push) Successful in 1m39s
All checks were successful
Build frontend / build (push) Successful in 1m39s
This commit is contained in:
@ -52,7 +52,7 @@ import {
|
|||||||
Trees
|
Trees
|
||||||
} from 'lucide-react';
|
} from 'lucide-react';
|
||||||
import toast, { Toaster } from 'react-hot-toast';
|
import toast, { Toaster } from 'react-hot-toast';
|
||||||
import { addRentProperty, addSaleProperty, getCurrencies, uploadPicture } from '../../../utils/api';
|
import { addRentProperty, addSaleProperty, buildRentPropertyPayload, getCurrencies, uploadPicture } from '../../../utils/api';
|
||||||
import {
|
import {
|
||||||
BuildingType,
|
BuildingType,
|
||||||
RentPropertyCondition,
|
RentPropertyCondition,
|
||||||
@ -683,6 +683,7 @@ const handleMarkerDragEnd = async (lat, lng) => {
|
|||||||
propertyType: formData.furnished ? RentPropertyCondition.WITH_FURNITURE : RentPropertyCondition.WITHOUT_FURNITURE,
|
propertyType: formData.furnished ? RentPropertyCondition.WITH_FURNITURE : RentPropertyCondition.WITHOUT_FURNITURE,
|
||||||
documentType: formData.documentType,
|
documentType: formData.documentType,
|
||||||
governorate: formData.city,
|
governorate: formData.city,
|
||||||
|
city: formData.city,
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@ -696,8 +697,11 @@ const handleMarkerDragEnd = async (lat, lng) => {
|
|||||||
toast.success(t('toast.salePropertySuccess'));
|
toast.success(t('toast.salePropertySuccess'));
|
||||||
} else {
|
} else {
|
||||||
const rentTypeMap = { daily: RentType.DAILY, monthly: RentType.MONTHLY, both: RentType.MONTHLY };
|
const rentTypeMap = { daily: RentType.DAILY, monthly: RentType.MONTHLY, both: RentType.MONTHLY };
|
||||||
const payload = {
|
const payload = buildRentPropertyPayload({
|
||||||
propertyInformation: propInfo,
|
propertyInformation: propInfo,
|
||||||
|
city: formData.city,
|
||||||
|
governorate: formData.city,
|
||||||
|
documentType: formData.documentType,
|
||||||
deposit: parseFloat(formData.deposit) || 0,
|
deposit: parseFloat(formData.deposit) || 0,
|
||||||
monthlyRent: parseFloat(formData.monthlyPrice) || 0,
|
monthlyRent: parseFloat(formData.monthlyPrice) || 0,
|
||||||
dailyRent: parseFloat(formData.dailyPrice) || 0,
|
dailyRent: parseFloat(formData.dailyPrice) || 0,
|
||||||
@ -706,7 +710,7 @@ const handleMarkerDragEnd = async (lat, lng) => {
|
|||||||
rentType: rentTypeMap[formData.offerType] ?? RentType.MONTHLY,
|
rentType: rentTypeMap[formData.offerType] ?? RentType.MONTHLY,
|
||||||
type: formData.furnished ? RentPropertyType.FURNISHED : RentPropertyType.UNFURNISHED,
|
type: formData.furnished ? RentPropertyType.FURNISHED : RentPropertyType.UNFURNISHED,
|
||||||
allowedPaymentPeriod: formData.allowedPaymentPeriod || '',
|
allowedPaymentPeriod: formData.allowedPaymentPeriod || '',
|
||||||
};
|
});
|
||||||
const res = await addRentProperty(payload);
|
const res = await addRentProperty(payload);
|
||||||
toast.success(t('toast.rentPropertySuccess'));
|
toast.success(t('toast.rentPropertySuccess'));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -56,6 +56,7 @@ import {
|
|||||||
import toast, { Toaster } from "react-hot-toast";
|
import toast, { Toaster } from "react-hot-toast";
|
||||||
import AuthService from "../../services/AuthService";
|
import AuthService from "../../services/AuthService";
|
||||||
import {
|
import {
|
||||||
|
buildRentPropertyPayload,
|
||||||
getMyRentListings,
|
getMyRentListings,
|
||||||
getMySaleListings,
|
getMySaleListings,
|
||||||
editRentProperty,
|
editRentProperty,
|
||||||
@ -1588,8 +1589,11 @@ export default function OwnerPropertiesPage() {
|
|||||||
|
|
||||||
if (formData.purpose === 'rent') {
|
if (formData.purpose === 'rent') {
|
||||||
const rentTypeMap = { daily: 1, monthly: 0, both: 0 };
|
const rentTypeMap = { daily: 1, monthly: 0, both: 0 };
|
||||||
const payload = {
|
const payload = buildRentPropertyPayload({
|
||||||
propertyInformation: propInfo,
|
propertyInformation: propInfo,
|
||||||
|
city: formData.city || property?.city || property?.governorate || "",
|
||||||
|
governorate: formData.city || property?.city || property?.governorate || "",
|
||||||
|
documentType: formData.documentType || property?.documentType || "",
|
||||||
deposit: parseFloat(formData.deposit) || 0,
|
deposit: parseFloat(formData.deposit) || 0,
|
||||||
monthlyRent: parseFloat(formData.monthlyPrice) || 0,
|
monthlyRent: parseFloat(formData.monthlyPrice) || 0,
|
||||||
dailyRent: parseFloat(formData.dailyPrice) || 0,
|
dailyRent: parseFloat(formData.dailyPrice) || 0,
|
||||||
@ -1599,7 +1603,7 @@ export default function OwnerPropertiesPage() {
|
|||||||
rentType: rentTypeMap[formData.rentType] ?? 0,
|
rentType: rentTypeMap[formData.rentType] ?? 0,
|
||||||
type: formData.furnished ? 0 : 1,
|
type: formData.furnished ? 0 : 1,
|
||||||
allowedPaymentPeriod: formData.allowedPaymentPeriod || '',
|
allowedPaymentPeriod: formData.allowedPaymentPeriod || '',
|
||||||
};
|
});
|
||||||
await editRentProperty(property.id, payload);
|
await editRentProperty(property.id, payload);
|
||||||
} else {
|
} else {
|
||||||
const payload = {
|
const payload = {
|
||||||
|
|||||||
@ -299,10 +299,35 @@ export async function getMyRentListings() {
|
|||||||
return apiFetch("/RentProperties/GetMyRentListings");
|
return apiFetch("/RentProperties/GetMyRentListings");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function buildRentPropertyPayload(data = {}) {
|
||||||
|
const propertyInformation = data?.propertyInformation || {};
|
||||||
|
const cityValue =
|
||||||
|
data?.city ??
|
||||||
|
data?.governorate ??
|
||||||
|
propertyInformation?.city ??
|
||||||
|
propertyInformation?.governorate ??
|
||||||
|
"";
|
||||||
|
const documentTypeValue =
|
||||||
|
data?.documentType ?? propertyInformation?.documentType ?? "";
|
||||||
|
|
||||||
|
return {
|
||||||
|
...data,
|
||||||
|
city: cityValue,
|
||||||
|
governorate: cityValue,
|
||||||
|
documentType: documentTypeValue,
|
||||||
|
propertyInformation: {
|
||||||
|
...propertyInformation,
|
||||||
|
city: cityValue,
|
||||||
|
governorate: propertyInformation?.governorate ?? cityValue,
|
||||||
|
documentType: documentTypeValue,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
export async function addRentProperty(data) {
|
export async function addRentProperty(data) {
|
||||||
return apiFetch("/RentProperties/AddRentProperty", {
|
return apiFetch("/RentProperties/AddRentProperty", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
body: data,
|
body: buildRentPropertyPayload(data),
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user