1
0
mirror of https://github.com/LaCasemate/fab-manager.git synced 2025-03-15 12:29:16 +01:00

(bug) do send user edition form when confirming password

This commit is contained in:
Sylvain 2022-05-04 15:29:01 +02:00
parent 1f2d3867aa
commit aa767cfbd2
4 changed files with 28 additions and 18 deletions

View File

@ -16,7 +16,7 @@ interface Oauth2FormProps<TFieldValues> {
export const Oauth2Form = <TFieldValues extends FieldValues>({ register, strategyName }: Oauth2FormProps<TFieldValues>) => {
const { t } = useTranslation('admin');
// regular expression to validate the the input fields
// regular expression to validate the input fields
const endpointRegex = /^\/?([-._~:?#[\]@!$&'()*+,;=%\w]+\/?)*$/;
const urlRegex = /^(https?:\/\/)([\da-z.-]+)\.([-a-z0-9.]{2,30})([/\w .-]*)*\/?$/;

View File

@ -39,7 +39,7 @@ export const OpenidConnectForm = <TFieldValues extends FieldValues, TContext ext
checkForDiscoveryEndpoint({ target: { value: currentFormValues?.issuer } } as React.ChangeEvent<HTMLInputElement>);
}, []);
// regular expression to validate the the input fields
// regular expression to validate the input fields
const endpointRegex = /^\/?([-._~:?#[\]@!$&'()*+,;=%\w]+\/?)*$/;
const urlRegex = /^(https?:\/\/)([\da-z.-]+)\.([-a-z0-9.]{2,30})([/\w .-]*)*\/?$/;

View File

@ -26,7 +26,7 @@ export const ChangePassword = <TFieldValues extends FieldValues>({ register, onE
const [isModalOpen, setIsModalOpen] = React.useState<boolean>(false);
const [isConfirmedPassword, setIsConfirmedPassword] = React.useState<boolean>(false);
const passwordConfirmationForm = useForm<{ password: string }>();
const { handleSubmit, register: passwordRegister } = useForm<{ password: string }>();
/**
* Opens/closes the dialog asking to confirm the current password before changing it.
@ -38,17 +38,23 @@ export const ChangePassword = <TFieldValues extends FieldValues>({ register, onE
/**
* Callback triggered when the user confirms his current password.
*/
const onSubmit = (data: { password: string }) => {
Authentication.verifyPassword(data.password).then(res => {
if (res) {
setIsConfirmedPassword(true);
toggleConfirmationModal();
} else {
onError(t('app.shared.change_password.wrong_password'));
}
}).catch(err => {
onError(err);
});
const onSubmit = (event: React.FormEvent<HTMLFormElement>) => {
if (event) {
event.stopPropagation();
event.preventDefault();
}
return handleSubmit((data: { password: string }) => {
Authentication.verifyPassword(data.password).then(res => {
if (res) {
setIsConfirmedPassword(true);
toggleConfirmationModal();
} else {
onError(t('app.shared.change_password.wrong_password'));
}
}).catch(err => {
onError(err);
});
})(event);
};
return (
@ -59,9 +65,13 @@ export const ChangePassword = <TFieldValues extends FieldValues>({ register, onE
{isConfirmedPassword && <div className="password-fields">
<PasswordInput register={register} currentFormPassword={currentFormPassword} formState={formState} />
</div>}
<FabModal isOpen={isModalOpen} toggleModal={toggleConfirmationModal} title={t('app.shared.change_password.change_my_password')}>
<form onSubmit={passwordConfirmationForm.handleSubmit(onSubmit)}>
<FormInput id="password" type="password" register={passwordConfirmationForm.register} rules={{ required: true }} label={t('app.shared.change_password.confirm_current')} />
<FabModal isOpen={isModalOpen} toggleModal={toggleConfirmationModal} title={t('app.shared.change_password.change_my_password')} closeButton>
<form onSubmit={onSubmit}>
<FormInput id="password"
type="password"
register={passwordRegister}
rules={{ required: true }}
label={t('app.shared.change_password.confirm_current')} />
<FabButton type="submit">
{t('app.shared.change_password.confirm')}
</FabButton>

View File

@ -30,7 +30,7 @@ interface UserProfileFormProps {
export const UserProfileForm: React.FC<UserProfileFormProps> = ({ action, size, user, className, onError, onSuccess }) => {
const { t } = useTranslation('shared');
// regular expression to validate the the input fields
// regular expression to validate the input fields
const phoneRegex = /^((00|\+)\d{2,3})?\d{4,14}$/;
const urlRegex = /^(https?:\/\/)([\da-z.-]+)\.([-a-z\d.]{2,30})([/\w .-]*)*\/?$/;