diff --git a/environments/prod/prod.env b/environments/prod/prod.env
index b470092..eef4c1c 100644
--- a/environments/prod/prod.env
+++ b/environments/prod/prod.env
@@ -1,3 +1,3 @@
REACT_APP_TAB_TITLE=Gepafin
-REACT_APP_API_EXECUTION_ADDRESS=http://bandi.gepafin.it/v1
+REACT_APP_API_EXECUTION_ADDRESS=http://bandi-api.gepafin.it/v1
REACT_APP_LOGO_FILENAME=logo.svg
\ No newline at end of file
diff --git a/src/assets/scss/components/appForm.scss b/src/assets/scss/components/appForm.scss
index 142c6df..8051ea1 100644
--- a/src/assets/scss/components/appForm.scss
+++ b/src/assets/scss/components/appForm.scss
@@ -41,6 +41,10 @@
background: var(--button-secondary-borderColor);
}
}
+
+ input[disabled], div.p-disabled {
+ background-color: #e3e3e3;
+ }
}
.appForm__fieldItem {
diff --git a/src/components/TopBarProfileMenu/index.js b/src/components/TopBarProfileMenu/index.js
index ab98319..e574e61 100644
--- a/src/components/TopBarProfileMenu/index.js
+++ b/src/components/TopBarProfileMenu/index.js
@@ -1,5 +1,6 @@
import React, { useRef } from 'react';
import { __ } from '@wordpress/i18n';
+import { useNavigate } from 'react-router-dom';
// store
import { storeSet, useTrackedStore } from '../../store';
@@ -9,6 +10,7 @@ import { Menu } from 'primereact/menu';
import { Avatar } from 'primereact/avatar';
const TopBarProfileMenu = ({ menuLeftRef }) => {
+ const navigate = useNavigate();
const userData = useTrackedStore().main.userData();
const fulleName = `${userData.firstName} ${userData.lastName}`;
@@ -26,12 +28,18 @@ const TopBarProfileMenu = ({ menuLeftRef }) => {
);
}
},
- /*{
+ {
label: __('Il mio profilo', 'gepafin'),
command: () => {
- console.log('go to profile page')
+ navigate('/profilo')
}
- },*/
+ },
+ {
+ label: __('Profilo aziendale', 'gepafin'),
+ command: () => {
+ navigate('/profilo-aziendale')
+ }
+ },
{
separator: true
},
diff --git a/src/pages/BandoApplication/index.js b/src/pages/BandoApplication/index.js
index 8fd6167..308b60b 100644
--- a/src/pages/BandoApplication/index.js
+++ b/src/pages/BandoApplication/index.js
@@ -379,7 +379,7 @@ const BandoApplication = () => {
iconPos="right"/> : null}
diff --git a/src/pages/Login/index.js b/src/pages/Login/index.js
index c57ac60..996e666 100644
--- a/src/pages/Login/index.js
+++ b/src/pages/Login/index.js
@@ -1,5 +1,5 @@
-import React, { useRef, useEffect } from 'react';
-import { __ } from '@wordpress/i18n';
+import React, { useRef, useEffect, useState } from 'react';
+import { __, sprintf } from '@wordpress/i18n';
import { classNames } from 'primereact/utils';
import { isEmpty } from 'ramda';
@@ -9,17 +9,50 @@ import { storeSet, useStore } from '../../store';
// components
import LogoIcon from '../../icons/LogoIcon';
import { Messages } from 'primereact/messages';
-import { useParams } from 'react-router-dom';
+import { useSearchParams } from 'react-router-dom';
+import AuthenticationService from '../../service/authentication-service';
const API_BASE_URL = process.env.REACT_APP_API_EXECUTION_ADDRESS;
const Login = () => {
const token = useStore().main.token();
const errorMsgs = useRef(null);
- let { temp_token } = useParams();
+ const [loading, setLoading] = useState(false);
+ let [searchParams] = useSearchParams();
const loginWithSpid = () => {
- window.location.replace(`${API_BASE_URL}/saml2/authenticate/loginumbria`);
+ if (!loading) {
+ window.location.replace(`${API_BASE_URL}/saml2/authenticate/loginumbria`);
+ }
+ }
+
+ const validateCallback = (data) => {
+ if (data.status === 'SUCCESS') {
+ storeSet.main.setAuthData({
+ token: data.data.token,
+ userData: data.data.user
+ });
+ } 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: '',
+ detail: sprintf(__('%s', 'gepafin'), err.message),
+ closable: true
+ }
+ ]);
+ setLoading(false);
}
useEffect(() => {
@@ -29,8 +62,12 @@ const Login = () => {
}, [token]);
useEffect(() => {
- console.log('temp_token', temp_token)
- }, [temp_token]);
+ const temp_token = searchParams.get('temp_token');
+ if (temp_token) {
+ errorMsgs.current.clear();
+ AuthenticationService.validateExistingUser(temp_token, validateCallback, validateError);
+ }
+ }, [searchParams]);
return (
diff --git a/src/pages/Profile/index.js b/src/pages/Profile/index.js
index 3cfa151..d9ddcca 100644
--- a/src/pages/Profile/index.js
+++ b/src/pages/Profile/index.js
@@ -1,7 +1,5 @@
-import React, { useState, useEffect, useRef } from 'react';
-import { __, sprintf } from '@wordpress/i18n';
-import { useNavigate, useParams } from 'react-router-dom';
-import { is } from 'ramda';
+import React, { useMemo, useRef } from 'react';
+import { __ } from '@wordpress/i18n';
// store
import { storeSet, useStore } from '../../store';
@@ -9,41 +7,190 @@ import { storeSet, useStore } from '../../store';
// components
import { Messages } from 'primereact/messages';
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
+import FormField from '../../components/FormField';
+import { Button } from 'primereact/button';
+import { useForm } from 'react-hook-form';
+
+// api
+import UserService from '../../service/user-service';
+import getDateFromISOstring from '../../helpers/getDateFromISOstring';
const Profile = () => {
const isAsyncRequest = useStore().main.isAsyncRequest();
- const { id } = useParams();
- const [data, setData] = useState({});
+ const userData = useStore().main.userData();
const infoMsgs = useRef(null);
- const getCallback = (data) => {
+ const {
+ control,
+ handleSubmit,
+ formState: { errors },
+ setValue
+ } = useForm({
+ defaultValues: useMemo(() => {
+ return userData;
+ }, [userData]),
+ mode: 'onChange'
+ });
+
+ const onSubmit = (formData) => {
+ infoMsgs.current.clear();
+ storeSet.main.setAsyncRequest();
+
+ UserService.updateUser(formData, updateCallback, updateError);
+ };
+
+ const updateCallback = (data) => {
if (data.status === 'SUCCESS') {
//setData(getFormattedBandiData(data.data));
}
storeSet.main.unsetAsyncRequest();
}
- const errGetCallback = (data) => {
+ const updateError = (data) => {
set404FromErrorResponse(data);
storeSet.main.unsetAsyncRequest();
}
- useEffect(() => {
- //BandoService.getBando(bandoId, getCallback, errGetCallback);
- }, [id]);
-
return (
-
{data.name}
-
- {__('Profilo utente', 'gepafin')}
-
+
{__('Profilo utente', 'gepafin')}
+
)
diff --git a/src/pages/ProfileCompany/index.js b/src/pages/ProfileCompany/index.js
new file mode 100644
index 0000000..8192a9f
--- /dev/null
+++ b/src/pages/ProfileCompany/index.js
@@ -0,0 +1,111 @@
+import React, { useMemo, useRef } from 'react';
+import { __ } from '@wordpress/i18n';
+
+// store
+import { storeSet, useStore } from '../../store';
+
+// components
+import { Messages } from 'primereact/messages';
+import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
+import FormField from '../../components/FormField';
+import { Button } from 'primereact/button';
+import { useForm } from 'react-hook-form';
+
+// api
+import UserService from '../../service/user-service';
+import getDateFromISOstring from '../../helpers/getDateFromISOstring';
+
+const ProfileCompany = () => {
+ const isAsyncRequest = useStore().main.isAsyncRequest();
+ const userData = useStore().main.userData();
+ const infoMsgs = useRef(null);
+
+ const {
+ control,
+ handleSubmit,
+ formState: { errors },
+ setValue
+ } = useForm({
+ defaultValues: useMemo(() => {
+ return userData;
+ }, [userData]),
+ mode: 'onChange'
+ });
+
+ const onSubmit = (formData) => {
+ infoMsgs.current.clear();
+ storeSet.main.setAsyncRequest();
+
+ UserService.updateUser(formData, updateCallback, updateError);
+ };
+
+ const updateCallback = (data) => {
+ if (data.status === 'SUCCESS') {
+ //setData(getFormattedBandiData(data.data));
+ }
+ storeSet.main.unsetAsyncRequest();
+ }
+
+ const updateError = (data) => {
+ set404FromErrorResponse(data);
+ storeSet.main.unsetAsyncRequest();
+ }
+
+ return (
+
+
+
{__('Profilo aziendale', 'gepafin')}
+
+
+
+
+
+
+
+
+ )
+
+}
+
+export default ProfileCompany;
\ No newline at end of file
diff --git a/src/pages/Registration/index.js b/src/pages/Registration/index.js
index bee30c4..0907aab 100644
--- a/src/pages/Registration/index.js
+++ b/src/pages/Registration/index.js
@@ -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 (
@@ -95,7 +127,8 @@ const Registration = () => {
{
{
{
{
{
return (
@@ -74,6 +75,10 @@ const routes = ({ role }) => {
{'ROLE_SUPER_ADMIN' === role ? : null}
{'ROLE_BENEFICIARY' === role ? : null}
}/>
+
+ {'ROLE_SUPER_ADMIN' === role ? : null}
+ {'ROLE_BENEFICIARY' === role ? : null}
+ }/>
}/>
}/>
diff --git a/src/service/authentication-service.js b/src/service/authentication-service.js
index 0271a5d..7b42997 100644
--- a/src/service/authentication-service.js
+++ b/src/service/authentication-service.js
@@ -72,4 +72,12 @@ export default class AuthenticationService {
static me = (callback, errCallback) => {
NetworkService.get(`${API_BASE_URL}/user/me`, callback, errCallback);
};
+
+ static validateNewUser = (token, callback, errCallback) => {
+ NetworkService.get(`${API_BASE_URL}/user/sso/validate/new-user/${token}`, callback, errCallback);
+ };
+
+ static validateExistingUser = (token, callback, errCallback) => {
+ NetworkService.get(`${API_BASE_URL}/user/sso/validate/existing-user/${token}`, callback, errCallback);
+ };
}
diff --git a/src/service/user-service.js b/src/service/user-service.js
new file mode 100644
index 0000000..91346d8
--- /dev/null
+++ b/src/service/user-service.js
@@ -0,0 +1,10 @@
+import { NetworkService } from './network-service';
+
+const API_BASE_URL = process.env.REACT_APP_API_EXECUTION_ADDRESS;
+
+export default class UserService {
+
+ static updateUser = (id, body, callback, errCallback) => {
+ NetworkService.put(`${API_BASE_URL}/user/${id}`, body, callback, errCallback);
+ };
+}