- updated login page;

- updated registration page;
- created profile page;
- created company profile page;
This commit is contained in:
Vitalii Kiiko
2024-09-27 09:09:48 +02:00
parent 1bd00def4b
commit 478af11cb9
11 changed files with 406 additions and 41 deletions

View File

@@ -3,7 +3,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { useForm } from 'react-hook-form';
import { classNames } from 'primereact/utils';
import { isEmpty } from 'ramda';
import { useParams } from 'react-router-dom';
import { useSearchParams } from 'react-router-dom';
// api
import AuthenticationService from '../../service/authentication-service';
@@ -24,19 +24,19 @@ const Registration = () => {
const token = useStore().main.token();
const [loading, setLoading] = useState(false);
const errorMsgs = useRef(null);
let { temp_token } = useParams();
let [searchParams] = useSearchParams();
const {
control,
handleSubmit,
formState: { errors },
setValue
} = useForm({ mode: 'onChange' });
const onSubmit = (formData) => {
errorMsgs.current.clear();
//setLoading(true);
console.log('formData', formData, errors);
setLoading(true);
//AuthenticationService.login(request, regCallback, regError);
AuthenticationService.registerUser(formData, regCallback, regError);
};
const regCallback = (data) => {
@@ -49,7 +49,7 @@ const Registration = () => {
errorMsgs.current.show([
{
sticky: true, severity: 'error', summary: '',
detail: data.message,
detail: data.data.join(', '),
closable: true
}
]);
@@ -58,6 +58,35 @@ const Registration = () => {
}
const regError = (err) => {
errorMsgs.current.show([
{
sticky: true, severity: 'error', summary: '',
detail: sprintf(__('%s', 'gepafin'), err.message),
closable: true
}
]);
setLoading(false);
}
const validateCallback = (data) => {
if (data.status === 'SUCCESS') {
const { codiceFiscale, firstName, lastName } = data.data;
setValue('codiceFiscale', codiceFiscale);
setValue('firstName', firstName);
setValue('lastName', lastName);
} else {
errorMsgs.current.show([
{
sticky: true, severity: 'error', summary: '',
detail: data.message,
closable: true
}
]);
}
setLoading(false);
}
const validateError = (err) => {
errorMsgs.current.show([
{
sticky: true, severity: 'error', summary: '',
@@ -76,8 +105,11 @@ const Registration = () => {
}, [token]);
useEffect(() => {
console.log('temp_token', temp_token)
}, [temp_token]);
const temp_token = searchParams.get('temp_token');
if (temp_token) {
AuthenticationService.validateNewUser(temp_token, validateCallback, validateError);
}
}, [searchParams]);
return (
<div className={classNames(['appPage', 'appPageLogin'])}>
@@ -95,7 +127,8 @@ const Registration = () => {
<div className="appForm__cols">
<FormField
type="textinput"
fieldName="first_name"
disabled={true}
fieldName="firstName"
label={__('Nome', 'gepafin')}
control={control}
errors={errors}
@@ -105,7 +138,8 @@ const Registration = () => {
<FormField
type="textinput"
fieldName="second_name"
disabled={true}
fieldName="lastName"
label={__('Cognome', 'gepafin')}
control={control}
errors={errors}
@@ -117,7 +151,8 @@ const Registration = () => {
<div className="appForm__cols">
<FormField
type="textinput"
fieldName="fiscal_code"
disabled={true}
fieldName="codiceFiscale"
label={__('Codice fiscale', 'gepafin')}
control={control}
errors={errors}
@@ -132,7 +167,7 @@ const Registration = () => {
<FormField
type="datepicker"
fieldName="birth_date"
fieldName="birthDate"
label={__('Data di nascita', 'gepafin')}
control={control}
errors={errors}
@@ -159,7 +194,7 @@ const Registration = () => {
<FormField
type="textinput"
fieldName="phone"
fieldName="phoneNumber"
label={__('Telefono', 'gepafin')}
control={control}
errors={errors}