2023-10-19 11:44:56 +03:30
|
|
|
|
"use client";
|
|
|
|
|
|
|
|
|
|
|
|
import AppContext from "@ctx/AppContext";
|
|
|
|
|
|
import { useRouter } from "next/navigation";
|
|
|
|
|
|
import Buttonbriz from "plugins/Buttonbriz/page";
|
|
|
|
|
|
import Input from "plugins/Input/page";
|
|
|
|
|
|
import PersianNumber from "plugins/PersianNumber";
|
|
|
|
|
|
import React, { useContext, useEffect, useRef, useState } from "react";
|
|
|
|
|
|
import { toast } from "react-toastify";
|
|
|
|
|
|
import SimpleReactValidator from "simple-react-validator";
|
|
|
|
|
|
import { useSearchParams } from "next/navigation";
|
2024-11-02 04:48:38 +03:30
|
|
|
|
import { useLocale, useTranslations } from "next-intl";
|
2023-10-19 11:44:56 +03:30
|
|
|
|
|
|
|
|
|
|
const SignUp = (props) => {
|
|
|
|
|
|
const CTX = useContext(AppContext);
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
const query = useSearchParams();
|
|
|
|
|
|
|
2024-11-02 04:48:38 +03:30
|
|
|
|
const t = useTranslations("login");
|
|
|
|
|
|
const locale = useLocale();
|
|
|
|
|
|
const isRTL = locale === "fa";
|
|
|
|
|
|
|
2023-10-19 11:44:56 +03:30
|
|
|
|
const [firstName, setFirstName] = useState("");
|
|
|
|
|
|
const [lastName, setLastName] = useState("");
|
|
|
|
|
|
const [complexName, setComplexName] = useState("");
|
|
|
|
|
|
const [supportPhoneNumber, setSupportPhoneNumber] = useState(
|
|
|
|
|
|
CTX.state.phoneNumber
|
|
|
|
|
|
);
|
|
|
|
|
|
const [complexAddress, setComplexAddress] = useState("");
|
|
|
|
|
|
const [, forceUpdate] = useState();
|
|
|
|
|
|
|
|
|
|
|
|
const validator = useRef(
|
|
|
|
|
|
new SimpleReactValidator({
|
|
|
|
|
|
messages: {
|
|
|
|
|
|
required: "پر کردن این فیلد الزامی میباشد",
|
|
|
|
|
|
},
|
|
|
|
|
|
element: (message) => (
|
|
|
|
|
|
<>
|
|
|
|
|
|
<div className="text-right px-1 ">
|
|
|
|
|
|
<small className="text-red-600 t-ig-small ">{message}</small>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
</>
|
|
|
|
|
|
),
|
|
|
|
|
|
})
|
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
|
|
const body = {
|
|
|
|
|
|
firstName,
|
|
|
|
|
|
lastName,
|
|
|
|
|
|
complexName,
|
|
|
|
|
|
supportPhoneNumber,
|
|
|
|
|
|
complexAddress,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
|
if (!!query.get("phoneNumber")) {
|
|
|
|
|
|
setSupportPhoneNumber(query.get("phoneNumber"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
|
|
|
|
const handleSingnUp = () => {
|
|
|
|
|
|
if (validator.current.allValid()) {
|
|
|
|
|
|
CTX.SignUpLogin(body);
|
|
|
|
|
|
} else {
|
|
|
|
|
|
toast.error("پرکردن همه ی فیلد ها واجب است", {
|
|
|
|
|
|
position: "bottom-right",
|
|
|
|
|
|
autoClose: 2000,
|
|
|
|
|
|
hideProgressBar: false,
|
|
|
|
|
|
closeOnClick: true,
|
|
|
|
|
|
pauseOnHover: true,
|
|
|
|
|
|
draggable: true,
|
|
|
|
|
|
progress: undefined,
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
validator.current.showMessages();
|
|
|
|
|
|
forceUpdate(1);
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
return (
|
2024-09-16 03:01:51 +03:30
|
|
|
|
<div className="px-5 pt-6">
|
2024-11-02 04:48:38 +03:30
|
|
|
|
<p
|
|
|
|
|
|
className={`mb-0 text-white mt-1 text-sm ${
|
|
|
|
|
|
isRTL ? "text-right" : "text-left"
|
|
|
|
|
|
} `}
|
|
|
|
|
|
>
|
|
|
|
|
|
{t("singUpDesc")}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mt-8">
|
|
|
|
|
|
<Input
|
2024-11-02 04:48:38 +03:30
|
|
|
|
lable={t("singUpFirstNameInput")}
|
2024-06-12 18:44:06 +03:30
|
|
|
|
mt={5}
|
|
|
|
|
|
theme={1}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
id="firstName-id"
|
|
|
|
|
|
name="firstName"
|
|
|
|
|
|
type={"text"}
|
|
|
|
|
|
value={firstName}
|
|
|
|
|
|
inputEvent={(e) => {
|
|
|
|
|
|
setFirstName(e.target.value);
|
|
|
|
|
|
validator.current.showMessageFor("firstName");
|
|
|
|
|
|
}}
|
|
|
|
|
|
style="text-right"
|
|
|
|
|
|
validator={true}
|
|
|
|
|
|
validatorData={validator.current.message(
|
|
|
|
|
|
"firstName",
|
|
|
|
|
|
firstName,
|
|
|
|
|
|
"required"
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-8">
|
|
|
|
|
|
<Input
|
2024-11-02 04:48:38 +03:30
|
|
|
|
lable={t("signUpLastNameInput")}
|
2024-06-12 18:44:06 +03:30
|
|
|
|
mt={5}
|
|
|
|
|
|
theme={1}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
id="lastName-id"
|
|
|
|
|
|
name="lastName"
|
|
|
|
|
|
type={"text"}
|
|
|
|
|
|
value={lastName}
|
|
|
|
|
|
inputEvent={(e) => {
|
|
|
|
|
|
setLastName(e.target.value);
|
|
|
|
|
|
validator.current.showMessageFor("lastName");
|
|
|
|
|
|
}}
|
|
|
|
|
|
style="text-right"
|
|
|
|
|
|
validator={true}
|
|
|
|
|
|
validatorData={validator.current.message(
|
|
|
|
|
|
"lastName",
|
|
|
|
|
|
lastName,
|
|
|
|
|
|
"required"
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<div className="mt-8">
|
|
|
|
|
|
<Input
|
2024-11-02 04:48:38 +03:30
|
|
|
|
lable={t("signUpComplexNameInput")}
|
2024-06-12 18:44:06 +03:30
|
|
|
|
mt={5}
|
|
|
|
|
|
theme={1}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
id="complexName-id"
|
|
|
|
|
|
name="complexName"
|
|
|
|
|
|
type={"text"}
|
|
|
|
|
|
value={complexName}
|
|
|
|
|
|
inputEvent={(e) => {
|
|
|
|
|
|
setComplexName(e.target.value);
|
|
|
|
|
|
validator.current.showMessageFor("complexName");
|
|
|
|
|
|
}}
|
|
|
|
|
|
style="text-right"
|
|
|
|
|
|
validator={true}
|
|
|
|
|
|
validatorData={validator.current.message(
|
|
|
|
|
|
"complexName",
|
|
|
|
|
|
complexName,
|
|
|
|
|
|
"required"
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Input
|
2024-11-02 04:48:38 +03:30
|
|
|
|
lable={t("signUpSupportPhoneNumberInput")}
|
2024-06-12 18:44:06 +03:30
|
|
|
|
mt={5}
|
|
|
|
|
|
theme={1}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
id="supportPhoneNumber-id"
|
|
|
|
|
|
name="supportPhoneNumber"
|
|
|
|
|
|
type={"number"}
|
|
|
|
|
|
value={supportPhoneNumber}
|
|
|
|
|
|
inputEvent={(e) => setSupportPhoneNumber(e.target.value)}
|
|
|
|
|
|
style="text-right"
|
|
|
|
|
|
readOnly={true}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
<div className="mt-3">
|
|
|
|
|
|
<Input
|
2024-11-02 04:48:38 +03:30
|
|
|
|
lable={t("signUpComplexAddressInput")}
|
2024-06-12 18:44:06 +03:30
|
|
|
|
mt={5}
|
|
|
|
|
|
theme={1}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
id="complexAddress-id"
|
|
|
|
|
|
name="complexAddress"
|
|
|
|
|
|
type={"text"}
|
|
|
|
|
|
value={complexAddress}
|
|
|
|
|
|
inputEvent={(e) => {
|
|
|
|
|
|
setComplexAddress(e.target.value);
|
|
|
|
|
|
validator.current.showMessageFor("complexAddress");
|
|
|
|
|
|
}}
|
|
|
|
|
|
style="text-right"
|
|
|
|
|
|
validator={true}
|
|
|
|
|
|
validatorData={validator.current.message(
|
|
|
|
|
|
"complexAddress",
|
|
|
|
|
|
complexAddress,
|
|
|
|
|
|
"required"
|
|
|
|
|
|
)}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
<Buttonbriz
|
2024-11-02 04:48:38 +03:30
|
|
|
|
title={t("signUpButton")}
|
2023-10-19 11:44:56 +03:30
|
|
|
|
color="PRIMARY"
|
|
|
|
|
|
icon="CHECK"
|
|
|
|
|
|
buttonEvent={() => handleSingnUp()}
|
|
|
|
|
|
/>
|
|
|
|
|
|
</div>
|
|
|
|
|
|
);
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export default SignUp;
|