fix auth errors and add tracker-registration

This commit is contained in:
Mikola
2024-03-11 18:24:03 +03:00
parent 012ef7d4b6
commit 2ed0be6664
6 changed files with 64 additions and 42 deletions

View File

@ -15,9 +15,13 @@ import authImg from "assets/images/partnerProfile/authCandidateFormImg.png";
import registrationImg from "assets/images/trackerRegistrationImg.png";
import "./trackerRegistration.scss";
import { Loader } from "@components/Common/Loader/Loader";
import BaseButton from "@components/Common/BaseButton/BaseButton";
export const TrackerRegistration = () => {
const [modalConfirmOpen, setModalConfirm] = useState(false);
const [loader, setLoader] = useState(false);
const [isPartner, setIsPartner] = useState(false);
const fields = {
username: "",
email: "",
@ -28,10 +32,10 @@ export const TrackerRegistration = () => {
const apiEndpoint = "/register/sign-up";
const { showNotification } = useNotification();
const showNotificationError = () => {
const showNotificationError = (error) => {
showNotification({
show: true,
text: "Аккаунт с таким логином или email уже существует",
text: error,
type: "error"
});
};
@ -43,14 +47,19 @@ export const TrackerRegistration = () => {
});
};
const { formData, validationErrors, handleChange, handleSubmit } =
useFormValidation(
apiEndpoint,
fields,
showNotificationError,
showNotificationTrue
);
const {
formData,
validationErrors,
handleChange,
handleSubmit,
} = useFormValidation(
apiEndpoint,
fields,
showNotificationError,
showNotificationTrue,
isPartner,
setLoader,
);
return (
<div className="tracker-registration">
<AuthHeader />
@ -115,17 +124,19 @@ export const TrackerRegistration = () => {
</div>
</div>
<div className="tracker-registration__form__submit">
<button
onClick={async (e) => {
e.preventDefault();
const result = await handleSubmit(e);
if (result === true) {
setModalConfirm(true);
}
}}
>
Отправить
</button>
{loader ? (
<Loader />
) : (
<BaseButton
onClick={async (e) => {
e.preventDefault();
await handleSubmit(e);
}}
styles="button-box__submit"
>
Отправить
</BaseButton>
)}
<div className="tracker-registration__form__info">
<img src={authImg} alt="img" />
<p>