fixd larg lines in HomePage , add cookies rather than localStorage,make canvas background Login page
This commit is contained in:
167
app/utils/api.js
167
app/utils/api.js
@ -1,3 +1,4 @@
|
||||
import { Toast } from "flowbite-react";
|
||||
import AuthService from "../services/AuthService";
|
||||
|
||||
const API_BASE = process.env.NEXT_PUBLIC_API_URL || "https://45.93.137.91.nip.io/api";
|
||||
@ -20,10 +21,7 @@ export function isApiBlockedError(error) {
|
||||
}
|
||||
|
||||
function redirectToBlockedPage() {
|
||||
if (
|
||||
typeof window !== "undefined" &&
|
||||
window.location.pathname !== "/blocked"
|
||||
) {
|
||||
if (typeof window !== "undefined" && window.location.pathname !== "/blocked") {
|
||||
window.location.replace("/blocked");
|
||||
}
|
||||
}
|
||||
@ -50,12 +48,7 @@ async function apiFetch(endpoint, options = {}) {
|
||||
const hasBody = options.body != null;
|
||||
const bodyIsFormData = isFormData(options.body);
|
||||
|
||||
if (
|
||||
hasBody &&
|
||||
!bodyIsFormData &&
|
||||
!headers["Content-Type"] &&
|
||||
!headers["content-type"]
|
||||
) {
|
||||
if (hasBody && !bodyIsFormData && !headers["Content-Type"] && !headers["content-type"]) {
|
||||
headers["Content-Type"] = "application/json";
|
||||
}
|
||||
|
||||
@ -65,10 +58,7 @@ async function apiFetch(endpoint, options = {}) {
|
||||
const res = await fetch(url, {
|
||||
...options,
|
||||
headers,
|
||||
body:
|
||||
hasBody && !bodyIsFormData && typeof options.body !== "string"
|
||||
? JSON.stringify(options.body)
|
||||
: options.body,
|
||||
body: hasBody && !bodyIsFormData && typeof options.body !== "string" ? JSON.stringify(options.body) : options.body,
|
||||
});
|
||||
|
||||
assertNotBlocked(res);
|
||||
@ -91,10 +81,9 @@ async function apiFetch(endpoint, options = {}) {
|
||||
return text;
|
||||
}
|
||||
} catch (error) {
|
||||
if (error instanceof TypeError && error.message === 'Failed to fetch') {
|
||||
throw new Error(
|
||||
`تعذر الاتصال بالخادم. تحقق من اتصالك بالإنترنت أو حاول مرة أخرى لاحقاً. (${API_BASE}${endpoint})`,
|
||||
);
|
||||
if (error instanceof TypeError && error.message === "Failed to fetch") {
|
||||
|
||||
throw new Error(`تعذر الاتصال بالخادم. تحقق من اتصالك بالإنترنت أو حاول مرة أخرى لاحقاً. (${API_BASE}${endpoint})`);
|
||||
}
|
||||
throw error;
|
||||
}
|
||||
@ -137,8 +126,7 @@ async function authFetch(endpoint, body, token = null) {
|
||||
data = text;
|
||||
}
|
||||
|
||||
const message =
|
||||
typeof data === "object" && data?.message ? data.message : null;
|
||||
const message = typeof data === "object" && data?.message ? data.message : null;
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
@ -176,8 +164,7 @@ async function reportFetch(endpoint, body) {
|
||||
data = text;
|
||||
}
|
||||
|
||||
const message =
|
||||
typeof data === "object" && data?.message ? data.message : null;
|
||||
const message = typeof data === "object" && data?.message ? data.message : null;
|
||||
|
||||
return {
|
||||
status: res.status,
|
||||
@ -200,9 +187,7 @@ export async function getRentPropertyLocations(params = {}) {
|
||||
if (params.maxOffset != null) qs.set("maxOffset", params.maxOffset);
|
||||
if (params.minOffset != null) qs.set("minOffset", params.minOffset);
|
||||
const query = qs.toString();
|
||||
return apiFetch(
|
||||
`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ""}`,
|
||||
);
|
||||
return apiFetch(`/RentProperties/GetRentPropertiesLocations${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
export async function getSaleProperties() {
|
||||
@ -227,19 +212,13 @@ export async function getTopRecommendations(count = 10) {
|
||||
return apiFetch(`/Recommendations/GetTopRecommendations?count=${count}`);
|
||||
}
|
||||
|
||||
export async function getAvailableDateRanges(
|
||||
propertyId,
|
||||
fromDate = null,
|
||||
toDate = null,
|
||||
) {
|
||||
export async function getAvailableDateRanges(propertyId, fromDate = null, toDate = null) {
|
||||
const qs = new URLSearchParams();
|
||||
if (fromDate) qs.set("fromDate", fromDate);
|
||||
if (toDate) qs.set("toDate", toDate);
|
||||
const query = qs.toString();
|
||||
|
||||
return apiFetch(
|
||||
`/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ""}`,
|
||||
);
|
||||
return apiFetch(`/Reservations/GetAvailableDates/available/${propertyId}${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
export async function getReservations() {
|
||||
@ -250,18 +229,12 @@ export async function getReservation(id) {
|
||||
return apiFetch(`/Reservations/GetReservation?id=${id}`);
|
||||
}
|
||||
|
||||
export async function checkAvailability(
|
||||
propertyId,
|
||||
fromDate = null,
|
||||
toDate = null,
|
||||
) {
|
||||
export async function checkAvailability(propertyId, fromDate = null, toDate = null) {
|
||||
const qs = new URLSearchParams();
|
||||
if (fromDate) qs.set("fromDate", fromDate);
|
||||
if (toDate) qs.set("toDate", toDate);
|
||||
const query = qs.toString();
|
||||
return apiFetch(
|
||||
`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ""}`,
|
||||
);
|
||||
return apiFetch(`/Reservations/GetAvailable/${propertyId}${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
export async function bookReservation(propertyInfoId, startDate, endDate) {
|
||||
@ -297,18 +270,12 @@ export async function getMyRentListings() {
|
||||
|
||||
export function buildRentPropertyPayload(data = {}) {
|
||||
const propertyInformation = data?.propertyInformation || {};
|
||||
|
||||
const rawCityValue =
|
||||
data?.city ??
|
||||
data?.governorate ??
|
||||
propertyInformation?.city ??
|
||||
propertyInformation?.governorate ??
|
||||
1;
|
||||
|
||||
|
||||
const rawCityValue = data?.city ?? data?.governorate ?? propertyInformation?.city ?? propertyInformation?.governorate ?? 1;
|
||||
|
||||
const cityInt = parseInt(rawCityValue, 10) || 1;
|
||||
|
||||
const documentTypeValue =
|
||||
data?.documentType ?? propertyInformation?.documentType ?? 1;
|
||||
const documentTypeValue = data?.documentType ?? propertyInformation?.documentType ?? 1;
|
||||
|
||||
return {
|
||||
...data,
|
||||
@ -483,40 +450,23 @@ async function multipartAuthFetch(endpoint, formData) {
|
||||
};
|
||||
}
|
||||
|
||||
export async function addOwner(
|
||||
data,
|
||||
frontImage = null,
|
||||
backImage = null,
|
||||
licenseImage = null,
|
||||
) {
|
||||
export async function addOwner(data, frontImage = null, backImage = null, licenseImage = null) {
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append("FirstName", data.firstName || data.FirstName || "");
|
||||
formData.append("LastName", data.lastName || data.LastName || "");
|
||||
formData.append("Email", data.email || data.Email || "");
|
||||
|
||||
const phoneValue =
|
||||
data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || "";
|
||||
const whatsappValue =
|
||||
data.whatsAppNumber ||
|
||||
data.whatsapp ||
|
||||
data.WhatsAppNumber ||
|
||||
data.WhatsApp ||
|
||||
"";
|
||||
const phoneValue = data.phone || data.phoneNumber || data.Phone || data.PhoneNumber || "";
|
||||
const whatsappValue = data.whatsAppNumber || data.whatsapp || data.WhatsAppNumber || data.WhatsApp || "";
|
||||
|
||||
formData.append("PhoneNumber", phoneValue);
|
||||
formData.append("Phone", phoneValue);
|
||||
formData.append("WhatsAppNumber", whatsappValue);
|
||||
|
||||
formData.append(
|
||||
"NationalNumber",
|
||||
data.nationalNumber || data.NationalNumber || "",
|
||||
);
|
||||
formData.append("NationalNumber", data.nationalNumber || data.NationalNumber || "");
|
||||
formData.append("Password", data.password || data.Password || "");
|
||||
formData.append(
|
||||
"Type",
|
||||
String(data.type ?? data.ownerType ?? data.Type ?? 0),
|
||||
);
|
||||
formData.append("Type", String(data.type ?? data.ownerType ?? data.Type ?? 0));
|
||||
formData.append("Language", String(data.language ?? data.Language ?? 1));
|
||||
|
||||
if (frontImage) formData.append("FrontIdCarImagePath", frontImage);
|
||||
@ -573,20 +523,12 @@ export async function sendPhoneOTP() {
|
||||
|
||||
export async function verifyEmail(code) {
|
||||
const token = AuthService.getToken();
|
||||
return authFetch(
|
||||
`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`,
|
||||
{},
|
||||
token,
|
||||
);
|
||||
return authFetch(`/Auth/VerifyEmail?code=${encodeURIComponent(code)}`, {}, token);
|
||||
}
|
||||
|
||||
export async function verifyPhone(code) {
|
||||
const token = AuthService.getToken();
|
||||
return authFetch(
|
||||
`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`,
|
||||
{},
|
||||
token,
|
||||
);
|
||||
return authFetch(`/Auth/VerifyPhoneNumber?code=${encodeURIComponent(code)}`, {}, token);
|
||||
}
|
||||
|
||||
export function isEmail(value) {
|
||||
@ -622,14 +564,9 @@ export async function confirmDepositPayment(bookingId) {
|
||||
});
|
||||
}
|
||||
|
||||
export async function adminConfirmDeposit(
|
||||
reservationId,
|
||||
adminId,
|
||||
comment = null,
|
||||
) {
|
||||
export async function adminConfirmDeposit(reservationId, adminId, comment = null) {
|
||||
const token = AuthService.getToken();
|
||||
const normalizedComment =
|
||||
typeof comment === "string" && comment.trim() ? comment.trim() : null;
|
||||
const normalizedComment = typeof comment === "string" && comment.trim() ? comment.trim() : null;
|
||||
const payload = {
|
||||
reservationId,
|
||||
adminId,
|
||||
@ -657,8 +594,7 @@ export async function adminConfirmDeposit(
|
||||
data = text;
|
||||
}
|
||||
|
||||
const message =
|
||||
typeof data === "object" && data?.message ? data.message : null;
|
||||
const message = typeof data === "object" && data?.message ? data.message : null;
|
||||
|
||||
return { status: res.status, data, ok: res.ok, message };
|
||||
}
|
||||
@ -698,15 +634,9 @@ export async function getMyTransaction() {
|
||||
export async function payDeposit(data) {
|
||||
const formData = new FormData();
|
||||
|
||||
formData.append(
|
||||
"ReservationId",
|
||||
String(data.reservationId ?? data.ReservationId ?? "")
|
||||
);
|
||||
formData.append("ReservationId", String(data.reservationId ?? data.ReservationId ?? ""));
|
||||
|
||||
formData.append(
|
||||
"PaymentTypeId",
|
||||
String(data.paymentTypeId ?? data.PaymentTypeId ?? "")
|
||||
);
|
||||
formData.append("PaymentTypeId", String(data.paymentTypeId ?? data.PaymentTypeId ?? ""));
|
||||
|
||||
if (data.comment) {
|
||||
formData.append("Comment", data.comment);
|
||||
@ -725,9 +655,7 @@ export async function payDeposit(data) {
|
||||
}
|
||||
|
||||
export async function getOwnerContactInformation(propertyInformationId) {
|
||||
return apiFetch(
|
||||
`/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}`,
|
||||
);
|
||||
return apiFetch(`/Owner/GetOwnerContactInformation?propertyInformationId=${propertyInformationId}`);
|
||||
}
|
||||
|
||||
export async function getOwnerStatistics() {
|
||||
@ -766,12 +694,9 @@ export async function registerRealEstateAgent(formData) {
|
||||
}
|
||||
|
||||
export async function changePassword(oldPassword, newPassword) {
|
||||
return apiFetch(
|
||||
`/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`,
|
||||
{
|
||||
method: "PUT",
|
||||
},
|
||||
);
|
||||
return apiFetch(`/User/ChangePassword?oldPassword=${encodeURIComponent(oldPassword)}&newPassword=${encodeURIComponent(newPassword)}`, {
|
||||
method: "PUT",
|
||||
});
|
||||
}
|
||||
|
||||
export async function requestForgetPasswordOtp(email) {
|
||||
@ -781,12 +706,9 @@ export async function requestForgetPasswordOtp(email) {
|
||||
}
|
||||
|
||||
export async function verifyForgetPasswordOtp(email, code, newPassword) {
|
||||
return apiFetch(
|
||||
`/User/VerifyForgetPasswordOTP?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code)}&newPassword=${encodeURIComponent(newPassword)}`,
|
||||
{
|
||||
method: "POST",
|
||||
},
|
||||
);
|
||||
return apiFetch(`/User/VerifyForgetPasswordOTP?email=${encodeURIComponent(email)}&code=${encodeURIComponent(code)}&newPassword=${encodeURIComponent(newPassword)}`, {
|
||||
method: "POST",
|
||||
});
|
||||
}
|
||||
|
||||
export async function resetPassword(token) {
|
||||
@ -794,12 +716,9 @@ export async function resetPassword(token) {
|
||||
}
|
||||
|
||||
export async function deleteMyAccount(password) {
|
||||
return apiFetch(
|
||||
`/User/DeleteMyAccount?password=${encodeURIComponent(password)}`,
|
||||
{
|
||||
method: "DELETE",
|
||||
},
|
||||
);
|
||||
return apiFetch(`/User/DeleteMyAccount?password=${encodeURIComponent(password)}`, {
|
||||
method: "DELETE",
|
||||
});
|
||||
}
|
||||
|
||||
export async function setFCMToken(token, deviceType = 2) {
|
||||
@ -815,9 +734,7 @@ export async function filterRentProperties(params = {}) {
|
||||
if (v != null && v !== "") qs.set(k, v);
|
||||
});
|
||||
const query = qs.toString();
|
||||
return apiFetch(
|
||||
`/RentProperties/FilterRentProperties${query ? `?${query}` : ""}`,
|
||||
);
|
||||
return apiFetch(`/RentProperties/FilterRentProperties${query ? `?${query}` : ""}`);
|
||||
}
|
||||
|
||||
export async function sendGeneralReport(subject, reportBody) {
|
||||
@ -867,4 +784,4 @@ export async function addOrUpdateTerms(terms) {
|
||||
method: "POST",
|
||||
body: terms,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user