- finished new flow builder UI;

- fixed reset pass functionality;
This commit is contained in:
Vitalii Kiiko
2025-01-10 12:18:53 +01:00
parent a418548e45
commit f2f844d388
6 changed files with 138 additions and 164 deletions

View File

@@ -1,9 +1,9 @@
import React, { useRef, useState, useEffect } from 'react';
import React, { useRef, useState, useEffect, useMemo } from 'react';
import { __, sprintf } from '@wordpress/i18n';
import { useForm } from 'react-hook-form';
import { classNames } from 'primereact/utils';
import { isEmpty } from 'ramda';
import { useNavigate } from 'react-router-dom';
import { isEmpty, isNil } from 'ramda';
import { useNavigate, useSearchParams } from 'react-router-dom';
// tools
import AuthenticationService from '../../service/authentication-service';
@@ -24,7 +24,9 @@ const ResetPassword = () => {
const token = useStore().main.token();
const [loading, setLoading] = useState(false);
const [resetPassToken, setResetPassToken] = useState('');
const [resetPassEmail, setResetPassEmail] = useState('');
const errorMsgs = useRef(null);
let [searchParams] = useSearchParams();
const {
control,
handleSubmit,
@@ -47,12 +49,33 @@ const ResetPassword = () => {
}
if (request.token && !isEmpty(request.token)) {
AuthenticationService.resetPassword(request, getCallback, errCallback);
AuthenticationService.resetPassword(request, getCallbackReset, errCallback);
} else {
AuthenticationService.forgotPassword(request, getCallback, errCallback);
}
};
const getCallbackReset = (data) => {
if (data.status === 'SUCCESS') {
errorMsgs.current.show([
{
sticky: true, severity: 'success', summary: '',
detail: data.message,
closable: true
}
]);
} else {
errorMsgs.current.show([
{
sticky: true, severity: 'error', summary: '',
detail: data.message,
closable: true
}
]);
}
setLoading(false);
}
const getCallback = (data) => {
if (data.status === 'SUCCESS') {
setResetPassToken(data.data)
@@ -87,9 +110,18 @@ const ResetPassword = () => {
}, [token]);
useEffect(() => {
setValue('token', resetPassToken);
console.log(resetPassToken, resetPassEmail);
reset();
}, [resetPassToken])
setValue('token', resetPassToken);
setValue('email', resetPassEmail);
}, [resetPassToken, resetPassEmail]);
useEffect(() => {
const token = searchParams.get('token');
const email = searchParams.get('email');
setResetPassToken(token);
setResetPassEmail(email);
}, [searchParams]);
return (
<div className={classNames(['appPage', 'appPageLogin'])}>
@@ -113,7 +145,7 @@ const ResetPassword = () => {
placeholder="sample@example.com"
/>
{!isEmpty(resetPassToken)
{resetPassToken && !isEmpty(resetPassToken)
? <input
type="hidden"
name="token"
@@ -122,10 +154,9 @@ const ResetPassword = () => {
})}
/> : null}
{!isEmpty(resetPassToken)
{resetPassToken && !isEmpty(resetPassToken)
? <FormField
type="textinput"
inputtype="password"
type="password"
fieldName="newPassword"
label={__('Password', 'gepafin')}
control={control}
@@ -138,9 +169,9 @@ const ResetPassword = () => {
}}
/> : null}
{!isEmpty(resetPassToken)
{resetPassToken && !isEmpty(resetPassToken)
? <FormField
type="textinput"
type="password"
inputtype="password"
fieldName="confirmPassword"
label={__('Conferma password', 'gepafin')}