2026-08-05 23:27:34 +03:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
import { useState } from "react";
|
|
|
|
|
import { motion, AnimatePresence } from "framer-motion";
|
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
|
import toast, { Toaster } from "react-hot-toast";
|
|
|
|
|
import { addCustomer, loginWithEmail } from "../../utils/api";
|
|
|
|
|
import AuthService from "../../services/AuthService";
|
|
|
|
|
import { CustomerType } from "../../enums";
|
|
|
|
|
import { fadeInUp } from "../../components/Animation/OwnerPageAnimation";
|
|
|
|
|
import { staggerContainer } from "../../components/Animation/OwnerPageAnimation";
|
|
|
|
|
import InteractiveBackground from "@/app/components/Animation/Background";
|
|
|
|
|
import HeaderOfSteps from "@/app/components/OwnerComponents/HeaderOfSteps";
|
|
|
|
|
import HeaderOfForm from "@/app/components/OwnerComponents/HeaderOfForm";
|
|
|
|
|
import OwnerFormStepOne from "@/app/components/OwnerComponents/OwnerFormStepOne";
|
|
|
|
|
import Policy from "@/app/components/OwnerComponents/PolicyAgree";
|
|
|
|
|
import ButtomStepOne from "@/app/components/OwnerComponents/ButtomStepOne";
|
|
|
|
|
import ButtomStepTwo from "@/app/components/OwnerComponents/ButtomStepTwo";
|
|
|
|
|
import HavAccount from "@/app/components/HavAccount";
|
|
|
|
|
import OtpDialog from "@/app/components/OwnerComponents/OtpDialog";
|
|
|
|
|
import { validateStep1 } from "@/app/validations/OwnerValidatoin";
|
2026-03-17 20:36:59 +03:00
|
|
|
export default function TenantRegisterPage() {
|
2026-07-01 15:43:58 +03:00
|
|
|
const { t } = useTranslation();
|
|
|
|
|
const [step, setStep] = useState(1);
|
2026-03-27 18:19:32 +00:00
|
|
|
const [showOtpModal, setShowOtpModal] = useState(false);
|
2026-03-17 20:36:59 +03:00
|
|
|
const [isLoading, setIsLoading] = useState(false);
|
|
|
|
|
const [formData, setFormData] = useState({
|
2026-08-05 23:27:34 +03:00
|
|
|
firstName: "",
|
|
|
|
|
lastName: "",
|
|
|
|
|
email: "",
|
|
|
|
|
phone: "",
|
|
|
|
|
whatsapp: "",
|
|
|
|
|
phone2: "",
|
|
|
|
|
nationalNumber: "",
|
|
|
|
|
password: "",
|
|
|
|
|
confirmPassword: "",
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
customerType: CustomerType.PERSONAL,
|
2026-08-05 23:27:34 +03:00
|
|
|
agreeTerms: false,
|
2026-03-17 20:36:59 +03:00
|
|
|
});
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
const [errors, setErrors] = useState({});
|
2026-03-17 20:36:59 +03:00
|
|
|
|
2026-03-27 18:19:32 +00:00
|
|
|
const handleNextStep = () => {
|
2026-08-05 23:27:34 +03:00
|
|
|
if (validateStep1(formData, setErrors, t)) {
|
2026-03-27 18:19:32 +00:00
|
|
|
setStep(2);
|
2026-08-05 23:27:34 +03:00
|
|
|
window.scrollTo({ top: 0, behavior: "smooth" });
|
2026-03-27 18:19:32 +00:00
|
|
|
} else {
|
2026-08-05 23:27:34 +03:00
|
|
|
toast.error(t("validation.correctErrors"));
|
2026-03-27 18:19:32 +00:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2026-03-17 20:36:59 +03:00
|
|
|
const handleSubmit = async (e) => {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
if (!formData.agreeTerms) {
|
2026-08-05 23:27:34 +03:00
|
|
|
toast.error(t("validation.agreeToTerms"));
|
2026-03-17 20:36:59 +03:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
setIsLoading(true);
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
const payload = {
|
2026-03-28 15:29:06 +00:00
|
|
|
firstName: formData.firstName,
|
|
|
|
|
lastName: formData.lastName,
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
email: formData.email,
|
|
|
|
|
phoneNumber: formData.phone,
|
2026-03-28 15:38:40 +00:00
|
|
|
whatsAppNumber: formData.whatsapp,
|
2026-03-28 15:41:18 +00:00
|
|
|
phone: formData.phone2,
|
2026-03-28 15:38:40 +00:00
|
|
|
nationalNumber: formData.nationalNumber,
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
password: formData.password,
|
|
|
|
|
customerType: formData.customerType,
|
|
|
|
|
};
|
|
|
|
|
try {
|
2026-05-10 16:21:32 +03:00
|
|
|
const res = await addCustomer(payload, null, null);
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
if (res.status === 200 || res.ok) {
|
|
|
|
|
const apiMessage = res.message || res.data?.message;
|
2026-08-05 23:27:34 +03:00
|
|
|
toast.success(apiMessage || t("register.accountCreated"), { duration: 4000 });
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
const loginRes = await loginWithEmail(formData.email, formData.password);
|
|
|
|
|
if (loginRes.status === 206) {
|
|
|
|
|
const otpToken = loginRes.data;
|
2026-03-27 18:19:32 +00:00
|
|
|
if (otpToken) AuthService.addToken(otpToken);
|
2026-08-05 23:27:34 +03:00
|
|
|
toast(loginRes.message || t("register.otpSentEmail"), { icon: "📧" });
|
2026-03-27 18:19:32 +00:00
|
|
|
setShowOtpModal(true);
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
} else if (loginRes.status === 200) {
|
|
|
|
|
const loginToken = loginRes.data;
|
2026-03-27 18:19:32 +00:00
|
|
|
if (loginToken) AuthService.addToken(loginToken);
|
2026-08-05 23:27:34 +03:00
|
|
|
toast.success(loginRes.message || t("register.loginSuccess"));
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
}
|
|
|
|
|
} else {
|
2026-08-05 23:27:34 +03:00
|
|
|
const errMsg = res.message || res.data?.message || t("register.accountCreationFailed");
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
toast.error(errMsg);
|
|
|
|
|
}
|
|
|
|
|
} catch (err) {
|
2026-08-05 23:27:34 +03:00
|
|
|
toast.error(err.message || t("register.registrationError"));
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
} finally {
|
|
|
|
|
setIsLoading(false);
|
|
|
|
|
}
|
|
|
|
|
};
|
2026-03-17 20:36:59 +03:00
|
|
|
return (
|
2026-08-05 23:27:34 +03:00
|
|
|
<div className="min-h-screen flex items-center justify-center p-4 relative overflow-hidden">
|
2026-03-17 20:36:59 +03:00
|
|
|
<Toaster position="top-center" reverseOrder={false} />
|
2026-08-05 23:27:34 +03:00
|
|
|
<div className="absolute inset-0 overflow-hidden">
|
|
|
|
|
<InteractiveBackground />{" "}
|
|
|
|
|
</div>
|
2026-05-10 16:21:32 +03:00
|
|
|
<motion.div initial={{ opacity: 0, scale: 0.95 }} animate={{ opacity: 1, scale: 1 }} transition={{ duration: 0.5 }} className="relative z-10 w-full max-w-md">
|
2026-08-05 23:27:34 +03:00
|
|
|
<HeaderOfSteps step={step} colors={"bg-blue-500"} numberStep={[1, 2]} />
|
2026-03-17 20:36:59 +03:00
|
|
|
<div className="bg-white/5 backdrop-blur-xl rounded-3xl shadow-2xl border border-white/10 overflow-hidden">
|
2026-08-05 23:27:34 +03:00
|
|
|
<HeaderOfForm num={1} step={step} />
|
2026-03-17 20:36:59 +03:00
|
|
|
<div className="p-8">
|
2026-08-05 23:27:34 +03:00
|
|
|
<motion.form
|
|
|
|
|
variants={staggerContainer}
|
|
|
|
|
initial="initial"
|
|
|
|
|
animate="animate"
|
|
|
|
|
onSubmit={ step === 1? (e) => { e.preventDefault(); handleNextStep(); }: handleSubmit }
|
|
|
|
|
className="space-y-6"
|
|
|
|
|
>
|
|
|
|
|
{step === 1 && <OwnerFormStepOne setErrors={setErrors} setFormData={setFormData} formData={formData} errors={errors} type={"customer"} />}
|
|
|
|
|
{step === 2 && <Policy formData={formData} setFormData={setFormData} type={"customer"} />}
|
Add enums, AuthService, and integrate backend registration endpoints
- Add separate enum files: BuildingType, PropertyStatus, BookingStatus, CommissionType, IdentityType, UserRole, City, LoginMethod, OwnerType, CustomerType
- Add AuthService (addToken/getToken/deleteToken)
- Update api.js: use AuthService, add Owner/Add and Customer/Add endpoints
- Update login page to use AuthService for token storage
- Rewrite owner register: 3-step flow with OwnerType dropdown, backend integration, OTP verification
- Rewrite tenant register: 2-step flow with CustomerType dropdown, backend integration, OTP verification
- Update homepage and property detail to use enums instead of hardcoded maps
- Update AddPropertyForm to import from enums directly
- Add console logs and status toasts linked to API response messages
2026-03-27 18:01:42 +00:00
|
|
|
<motion.div variants={fadeInUp} className="flex gap-3 pt-4">
|
2026-08-05 23:27:34 +03:00
|
|
|
{step === 1 ? <ButtomStepOne type={"custoemr"} /> : <ButtomStepTwo formData={formData} setFormData={setFormData} isLoading={isLoading} type={"type"} />}
|
2026-03-17 20:36:59 +03:00
|
|
|
</motion.div>
|
2026-08-05 23:27:34 +03:00
|
|
|
{step === 1 && <HavAccount />}
|
2026-03-17 20:36:59 +03:00
|
|
|
</motion.form>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</motion.div>
|
2026-08-05 23:27:34 +03:00
|
|
|
<AnimatePresence>{showOtpModal && <OtpDialog formData={formData} setShowOtpModal={setShowOtpModal} type={"customer"} />}</AnimatePresence>
|
2026-03-17 20:36:59 +03:00
|
|
|
</div>
|
|
|
|
|
);
|
2026-07-01 15:43:58 +03:00
|
|
|
}
|