From 4d5aa62ca25b51aadc36de84297e8c39a035b9d8 Mon Sep 17 00:00:00 2001 From: ariari04 Date: Fri, 27 Sep 2024 15:40:07 +0600 Subject: [PATCH] Fix bugs --- .../ChangePassword/ChangePassword.tsx | 51 ++++++++++--------- .../ChangePasswordInput.tsx | 7 +-- src/widgets/forms/ProfileForm/ProfileForm.tsx | 4 +- .../forms/ProfileForm/icons/eye-off.svg | 15 ++++++ .../forms/ProfileForm/icons/eye-on.svg | 15 ++++++ 5 files changed, 60 insertions(+), 32 deletions(-) create mode 100644 src/widgets/forms/ProfileForm/icons/eye-off.svg create mode 100644 src/widgets/forms/ProfileForm/icons/eye-on.svg diff --git a/src/widgets/forms/ProfileForm/ChangePassword/ChangePassword.tsx b/src/widgets/forms/ProfileForm/ChangePassword/ChangePassword.tsx index c61442b..70cc993 100644 --- a/src/widgets/forms/ProfileForm/ChangePassword/ChangePassword.tsx +++ b/src/widgets/forms/ProfileForm/ChangePassword/ChangePassword.tsx @@ -19,7 +19,7 @@ const ChangePassword: React.FC = ({ closeWindow, }: IChangePasswordProps) => { const session = useSession(); - const [error, setError] = useState(""); + const [errorServer, setErrorServer] = useState(""); const [loader, setLoader] = useState(false); const [success, setSuccess] = useState(false); @@ -47,31 +47,34 @@ const ChangePassword: React.FC = ({ const onSubmit = async (data: FormFields) => { try { console.log(data); - // console.log("cfvgbhnj"); - // setError(""); - // setLoader(true); + setErrorServer(""); + setLoader(true); - // const Authorization = `Bearer ${session.data?.access_token}`; - // const config = { - // headers: { - // Authorization, - // }, - // }; - // const res = await apiInstance.patch( - // "/auth/password_change/", - // data, - // config - // ); + const Authorization = `Bearer ${session.data?.access_token}`; + const config = { + headers: { + Authorization, + }, + }; + const res = await apiInstance.patch( + "/auth/password_change/", + data, + config + ); - // if ([200, 201].includes(res.status)) return setSuccess(true); + if ([200, 201].includes(res.status)) return setSuccess(true); } catch (error: unknown) { - // if (error instanceof AxiosError) { - // if (error.response?.status === 400) { - // setError("Некорректный старый пароль или недопустимый новый пароль"); - // } - // } else { - // setError("Произошла непредвиденная ошибка"); - // } + if (error instanceof AxiosError) { + if (error.response?.status === 400) { + setErrorServer( + "Некорректный старый пароль или недопустимый новый пароль" + ); + } else if (error.response?.status === 401) { + setErrorServer("Вы не авторизованы"); + } + } else { + setErrorServer("Произошла непредвиденная ошибка"); + } } finally { setLoader(false); } @@ -112,7 +115,7 @@ const ChangePassword: React.FC = ({ placeholder="Повторите новый пароль" label="Потвердить новый пароль" /> - {error ?

{error}

: null} + {errorServer &&

{errorServer}

} {success ? (

Вы успешно поменяли пароль!

) : null} diff --git a/src/widgets/forms/ProfileForm/ChangePassword/ChangePasswordInput/ChangePasswordInput.tsx b/src/widgets/forms/ProfileForm/ChangePassword/ChangePasswordInput/ChangePasswordInput.tsx index 78c9644..66af67f 100644 --- a/src/widgets/forms/ProfileForm/ChangePassword/ChangePasswordInput/ChangePasswordInput.tsx +++ b/src/widgets/forms/ProfileForm/ChangePassword/ChangePasswordInput/ChangePasswordInput.tsx @@ -25,10 +25,7 @@ const ChangePasswordInput: React.FC = ({ register, formState: { errors }, } = useFormContext(); - console.log(name); - const errorText = errors[name]?.message as string; - const [isOpen, setIsOpen] = useState(false); return (
@@ -40,14 +37,14 @@ const ChangePasswordInput: React.FC = ({ )}
- - {openPopup && } - {error ?

{error}

: null} + {openPopup && } ); }; diff --git a/src/widgets/forms/ProfileForm/icons/eye-off.svg b/src/widgets/forms/ProfileForm/icons/eye-off.svg new file mode 100644 index 0000000..99bfa55 --- /dev/null +++ b/src/widgets/forms/ProfileForm/icons/eye-off.svg @@ -0,0 +1,15 @@ + + + Created with Pixso. + + + + + + + + + + + + diff --git a/src/widgets/forms/ProfileForm/icons/eye-on.svg b/src/widgets/forms/ProfileForm/icons/eye-on.svg new file mode 100644 index 0000000..feb18f7 --- /dev/null +++ b/src/widgets/forms/ProfileForm/icons/eye-on.svg @@ -0,0 +1,15 @@ + + + Created with Pixso. + + + + + + + + + + + +