Browse Source

fix/change-password (#8)

BANK-1138: При зміні паролю іншому користувачу змінюється власний пароль
Reviewed-on: #8
Co-authored-by: Oksana Stepanenko <oksana.stepanenko@jetup.team>
Co-committed-by: Oksana Stepanenko <oksana.stepanenko@jetup.team>
pull/9/head
Oksana Stepanenko 9 months ago committed by Vitalik Yatsenko
parent
commit
2b3afbe63a
  1. 28
      src/containers/Profile/components/form-user/form-user.component.tsx
  2. 6
      src/containers/Profile/components/form-user/hooks/use-profile-form.hook.ts

28
src/containers/Profile/components/form-user/form-user.component.tsx

@ -28,7 +28,6 @@ interface IProps { @@ -28,7 +28,6 @@ interface IProps {
export const FormUser: FC<IProps> = ({
profile,
authProfileId,
factory,
onSuccessUpdate,
onError,
}) => {
@ -45,9 +44,9 @@ export const FormUser: FC<IProps> = ({ @@ -45,9 +44,9 @@ export const FormUser: FC<IProps> = ({
validateEmail,
isErrorModal,
isDisableBtns,
sendPasswordToEmail,
getValues,
setError,
setValue,
} = useProfileForm({
profile,
authId: authProfileId,
@ -59,6 +58,16 @@ export const FormUser: FC<IProps> = ({ @@ -59,6 +58,16 @@ export const FormUser: FC<IProps> = ({
return moment().add(0, "days") <= current;
};
const submitAndSendPassword = (sendTo: "email" | "sms") => {
setValue("sendPasswordBy", sendTo);
onSubmit();
};
const submitChanges = () => {
setValue("sendPasswordBy", null);
onSubmit();
};
return (
<>
<Modal show={isErrorModal.isShow} title={"Профіль не збережено"}>
@ -70,7 +79,7 @@ export const FormUser: FC<IProps> = ({ @@ -70,7 +79,7 @@ export const FormUser: FC<IProps> = ({
<ModalValidationUserName submitChageAccount={submitChageAccount} />
<form
className="form"
onSubmit={onSubmit}
onSubmit={submitChanges}
style={{ flexDirection: "column" }}
>
<div style={{ display: "flex", flexDirection: "row", width: "100%" }}>
@ -358,9 +367,8 @@ export const FormUser: FC<IProps> = ({ @@ -358,9 +367,8 @@ export const FormUser: FC<IProps> = ({
<div style={{ paddingLeft: 0, marginTop: 30, display: "flex" }}>
<Button
onClick={onSubmit}
onClick={submitChanges}
color="primary"
type="submit"
className="btn save-profile__btn"
>
Зберегти
@ -371,10 +379,7 @@ export const FormUser: FC<IProps> = ({ @@ -371,10 +379,7 @@ export const FormUser: FC<IProps> = ({
color="primary"
type="button"
disabled={isDisableBtns}
onClick={() => {
sendPasswordToEmail(true);
onSubmit();
}}
onClick={() => submitAndSendPassword("email")}
>
Зберегти{" "}
<i style={{ marginLeft: 10 }} className="fal fa-envelope" />
@ -385,10 +390,7 @@ export const FormUser: FC<IProps> = ({ @@ -385,10 +390,7 @@ export const FormUser: FC<IProps> = ({
color="primary"
type="button"
disabled={isDisableBtns}
onClick={() => {
sendPasswordToEmail(false);
onSubmit();
}}
onClick={() => submitAndSendPassword("sms")}
>
Зберегти <i style={{ marginLeft: 10 }} className="fal fa-sms" />
</Button>

6
src/containers/Profile/components/form-user/hooks/use-profile-form.hook.ts

@ -41,6 +41,7 @@ interface IProfileForm { @@ -41,6 +41,7 @@ interface IProfileForm {
login: string;
newPassword: string;
confirmPassword: string;
sendPasswordBy: "sms" | "email";
}
interface IProfileProps {
@ -96,6 +97,7 @@ export const useProfileForm = ({ @@ -96,6 +97,7 @@ export const useProfileForm = ({
login,
newPassword: "",
confirmPassword: "",
sendPasswordBy: null,
};
}, [profile]);
@ -303,6 +305,7 @@ export const useProfileForm = ({ @@ -303,6 +305,7 @@ export const useProfileForm = ({
setError(defaultErrorsState);
catchErrorSubmit();
setValue("sendPasswordBy", null);
}
};
@ -350,7 +353,7 @@ export const useProfileForm = ({ @@ -350,7 +353,7 @@ export const useProfileForm = ({
choiceToSaveUserName(existUser, updateUserInfoValue);
};
const sendPasswordToEmail = (flag) => {
const sendPasswordToEmail = (flag: boolean) => {
const { newPassword, confirmPassword } = getValues();
try {
if (flag) {
@ -390,5 +393,6 @@ export const useProfileForm = ({ @@ -390,5 +393,6 @@ export const useProfileForm = ({
sendPasswordToEmail,
getValues,
setError,
setValue,
};
};

Loading…
Cancel
Save