- updated Users page;
This commit is contained in:
135
src/pages/EvaluationEdit/index.js
Normal file
135
src/pages/EvaluationEdit/index.js
Normal file
@@ -0,0 +1,135 @@
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { useNavigate, useParams } from 'react-router-dom';
|
||||
import { is, isEmpty, isNil } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet, useStore } from '../../store';
|
||||
|
||||
// tools
|
||||
import getNumberWithCurrency from '../../helpers/getNumberWithCurrency';
|
||||
//import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
||||
|
||||
// components
|
||||
import { Skeleton } from 'primereact/skeleton';
|
||||
import { Button } from 'primereact/button';
|
||||
import { Messages } from 'primereact/messages';
|
||||
|
||||
const EvaluationEdit = () => {
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const { id } = useParams();
|
||||
const navigate = useNavigate();
|
||||
const [data, setData] = useState({});
|
||||
const pageMsgs = useRef(null);
|
||||
|
||||
const goToEvaluationsPage = () => {
|
||||
navigate('/valutazioni');
|
||||
}
|
||||
|
||||
/*const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
setData(getFormattedBandiData(data.data));
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const errGetCallback = (data) => {
|
||||
if (pageMsgs.current && data.message) {
|
||||
pageMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: data.message,
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
}
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}*/
|
||||
|
||||
/*const getFormattedBandiData = (data) => {
|
||||
data.dates = data.dates.map(v => is(String, v) ? new Date(v) : (v ? v : ''));
|
||||
return data;
|
||||
};*/
|
||||
|
||||
useEffect(() => {
|
||||
const parsed = parseInt(id)
|
||||
const entityId = !isNaN(parsed) ? parsed : 0;
|
||||
|
||||
setData({
|
||||
id: 'DOM_2024_001',
|
||||
callTitle: 'Innovazione 2024',
|
||||
beneficiario: 'Azienda Alpha SRL',
|
||||
createdAt: '2024-08-01',
|
||||
scadenzaAt: '2024-08-05',
|
||||
status: 'In Valutazione'
|
||||
})
|
||||
//BandoService.getBando(entityId, getCallback, errGetCallback);
|
||||
}, [id]);
|
||||
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
<h1>{__('Valuta domanda', 'gepafin')}</h1>
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
<Messages ref={pageMsgs}/>
|
||||
|
||||
<div className="appPageSection__row">
|
||||
<Button
|
||||
type="button"
|
||||
outlined
|
||||
onClick={goToEvaluationsPage}
|
||||
label={__('Indietro', 'gepafin')}
|
||||
icon="pi pi-arrow-left" iconPos="left"/>
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
|
||||
{!isAsyncRequest && !isEmpty(data)
|
||||
? <div className="appPage__content">
|
||||
<div className="appPageSection__withBorder columns">
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('ID domanda', 'gepafin')}</span>
|
||||
<span>{data.id}</span>
|
||||
</p>
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('Bando', 'gepafin')}</span>
|
||||
<span>{data.callTitle}</span>
|
||||
</p>
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('Beneficiario', 'gepafin')}</span>
|
||||
<span>{data.beneficiario}</span>
|
||||
</p>
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('Data ricezione', 'gepafin')}</span>
|
||||
<span>{data.createdAt}</span>
|
||||
</p>
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('Scadenza Valutazione', 'gepafin')}</span>
|
||||
<span>{data.scadenzaAt}</span>
|
||||
</p>
|
||||
<p className="appPageSection__pMeta">
|
||||
<span>{__('Stato', 'gepafin')}</span>
|
||||
<span>{data.status}</span>
|
||||
</p>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
: <>
|
||||
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
||||
<Skeleton width="100%" height="2rem" className="mb-8"></Skeleton>
|
||||
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
||||
<Skeleton width="100%" height="4rem" className="mb-8"></Skeleton>
|
||||
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
||||
<Skeleton width="100%" height="2rem" className="mb-8"></Skeleton>
|
||||
<Skeleton width="20%" height="1rem" className="mb-2"></Skeleton>
|
||||
<Skeleton width="100%" height="4rem"></Skeleton>
|
||||
</>}
|
||||
</div>
|
||||
)
|
||||
|
||||
}
|
||||
|
||||
export default EvaluationEdit;
|
||||
@@ -21,10 +21,12 @@ import { Button } from 'primereact/button';
|
||||
import { Messages } from 'primereact/messages';
|
||||
import { Panel } from 'primereact/panel';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import getDateFromISOstring from '../../helpers/getDateFromISOstring';
|
||||
|
||||
const Registration = () => {
|
||||
const token = useStore().main.token();
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [originalDateOfBirth, setOriginalDateOfBirth] = useState('')
|
||||
const [visibleTerms, setVisibleTerms] = useState(false);
|
||||
const errorMsgs = useRef(null);
|
||||
let [searchParams] = useSearchParams();
|
||||
@@ -43,8 +45,12 @@ const Registration = () => {
|
||||
errorMsgs.current.clear();
|
||||
const temp_token = searchParams.get('temp_token');
|
||||
setLoading(true);
|
||||
const newFormData = {
|
||||
...formData,
|
||||
dateOfBirth: originalDateOfBirth
|
||||
}
|
||||
|
||||
AuthenticationService.registerUser(formData, regCallback, regError, [
|
||||
AuthenticationService.registerUser(newFormData, regCallback, regError, [
|
||||
['tempToken', temp_token]
|
||||
]);
|
||||
};
|
||||
@@ -59,7 +65,7 @@ const Registration = () => {
|
||||
errorMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: data.data.join(', '),
|
||||
detail: data.data.message,
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
@@ -81,11 +87,11 @@ const Registration = () => {
|
||||
const validateCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const { codiceFiscale, firstName, lastName, dateOfBirth } = data.data;
|
||||
const dateOfBirthObj = new Date(dateOfBirth);
|
||||
setOriginalDateOfBirth(dateOfBirth);
|
||||
setValue('codiceFiscale', codiceFiscale);
|
||||
setValue('firstName', firstName);
|
||||
setValue('lastName', lastName);
|
||||
setValue('dateOfBirth', dateOfBirthObj);
|
||||
setValue('dateOfBirth', getDateFromISOstring(dateOfBirth));
|
||||
} else {
|
||||
errorMsgs.current.show([
|
||||
{
|
||||
@@ -102,7 +108,7 @@ const Registration = () => {
|
||||
errorMsgs.current.show([
|
||||
{
|
||||
sticky: true, severity: 'error', summary: '',
|
||||
detail: sprintf(__('%s', 'gepafin'), err),
|
||||
detail: sprintf(__('%s', 'gepafin'), err.message),
|
||||
closable: true
|
||||
}
|
||||
]);
|
||||
@@ -197,7 +203,7 @@ const Registration = () => {
|
||||
/>
|
||||
|
||||
<FormField
|
||||
type="datepicker"
|
||||
type="textinput"
|
||||
disabled={true}
|
||||
fieldName="dateOfBirth"
|
||||
label={__('Data di nascita', 'gepafin')}
|
||||
@@ -232,7 +238,7 @@ const Registration = () => {
|
||||
errors={errors}
|
||||
config={{
|
||||
required: __('È obbligatorio', 'gepafin'),
|
||||
positive: v => parseInt(v) > 0
|
||||
pattern: /^[\d]{5,12}$/
|
||||
}}
|
||||
placeholder=""
|
||||
/>
|
||||
|
||||
@@ -130,7 +130,7 @@ const ResetPassword = () => {
|
||||
type="textinput"
|
||||
inputtype="password"
|
||||
fieldName="confirmPassword"
|
||||
label={__('Conferma Password', 'gepafin')}
|
||||
label={__('Conferma password', 'gepafin')}
|
||||
control={control}
|
||||
errors={errors}
|
||||
config={{
|
||||
|
||||
@@ -1,6 +1,17 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, isNil } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// api
|
||||
import UserService from '../../service/user-service';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import { isEmail } from '../../helpers/validators';
|
||||
|
||||
// store
|
||||
import { storeSet } from '../../store';
|
||||
|
||||
// components
|
||||
import AllUsersTable from './components/AllUsersTable';
|
||||
@@ -8,21 +19,19 @@ import { Button } from 'primereact/button';
|
||||
import { InputText } from 'primereact/inputtext';
|
||||
import { Dropdown } from 'primereact/dropdown';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import UserService from '../../service/user-service';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import { storeSet } from '../../store';
|
||||
import { klona } from 'klona';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { isEmail } from '../../helpers/validators';
|
||||
|
||||
const Users = () => {
|
||||
const [isVisibleEditDialog, setIsVisibleEditDialog] = useState(false);
|
||||
const [isCreatingUserRequest, setIsCreatingUserRequest] = useState(false);
|
||||
const [newUserData, setNewUserData] = useState({
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
email: '',
|
||||
phoneNumber: '',
|
||||
role: ''
|
||||
password: '',
|
||||
confPassword: '',
|
||||
roleId: 0
|
||||
});
|
||||
const [roles, setRoles] = useState([]);
|
||||
|
||||
@@ -41,14 +50,18 @@ const Users = () => {
|
||||
lastName: '',
|
||||
email: '',
|
||||
phoneNumber: '',
|
||||
role: ''
|
||||
password: '',
|
||||
confPassword: '',
|
||||
roleId: 0
|
||||
});
|
||||
}
|
||||
|
||||
const saveEditDialog = () => {
|
||||
const emptyValues = Object.values(newUserData).filter(v => isEmpty(v));
|
||||
if (isEmpty(emptyValues)) {
|
||||
console.log(newUserData)
|
||||
console.log(isEmpty(emptyValues), newUserData.password === newUserData.confPassword, !isCreatingUserRequest)
|
||||
if (isEmpty(emptyValues) && newUserData.password === newUserData.confPassword && !isCreatingUserRequest) {
|
||||
setIsCreatingUserRequest(true);
|
||||
UserService.createUser(newUserData, createUserCallback, errCreateUserCallback);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,7 +83,9 @@ const Users = () => {
|
||||
|
||||
const getRolesCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const roles = data.data.map(o => ({
|
||||
const roles = data.data
|
||||
.filter(o => ['ROLE_SUPER_ADMIN', 'ROLE_PRE_INSTRUCTOR'].includes(o.roleType))
|
||||
.map(o => ({
|
||||
name: o.roleName,
|
||||
value: o.id
|
||||
}));
|
||||
@@ -84,6 +99,19 @@ const Users = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
|
||||
const createUserCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
console.log('data.data', data.data)
|
||||
}
|
||||
setIsCreatingUserRequest(false);
|
||||
}
|
||||
|
||||
const errCreateUserCallback = (data) => {
|
||||
setIsCreatingUserRequest(false);
|
||||
}
|
||||
|
||||
const isInvalidField = (data, key) => isEmpty(data[key]) || isNil(data[key])
|
||||
|
||||
useEffect(() => {
|
||||
if (isVisibleEditDialog) {
|
||||
UserService.getRoles(getRolesCallback, errGetRolesCallback)
|
||||
@@ -117,39 +145,74 @@ const Users = () => {
|
||||
<div className="appPage__spacer"></div>
|
||||
<div className="appForm__cols">
|
||||
<div className="appForm__field">
|
||||
<label className={classNames({ 'p-error': isEmpty(newUserData.firstName) || isNil(newUserData.firstName) })}>{__('Nome', 'gepafin')}*</label>
|
||||
<label
|
||||
className={classNames({ 'p-error': isInvalidField(newUserData, 'firstName') })}>
|
||||
{__('Nome', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newUserData.firstName}
|
||||
invalid={isEmpty(newUserData.firstName) || isNil(newUserData.firstName)}
|
||||
invalid={isInvalidField(newUserData, 'firstName')}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'firstName')}/>
|
||||
</div>
|
||||
<div className="appForm__field">
|
||||
<label className={classNames({ 'p-error': isEmpty(newUserData.lastName) || isNil(newUserData.lastName) })}>{__('Cognome', 'gepafin')}*</label>
|
||||
<label
|
||||
className={classNames({ 'p-error': isInvalidField(newUserData, 'lastName') })}>
|
||||
{__('Cognome', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newUserData.lastName}
|
||||
invalid={isEmpty(newUserData.lastName) || isNil(newUserData.lastName)}
|
||||
invalid={isInvalidField(newUserData, 'lastName')}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'lastName')}/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="appForm__cols">
|
||||
<div className="appForm__field">
|
||||
<label className={classNames({ 'p-error': isEmpty(newUserData.email) || isNil(newUserData.email) })}>{__('Email', 'gepafin')}*</label>
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newUserData.email) || isNil(newUserData.email) || !isEmail(newUserData.email) })}>
|
||||
{__('Email', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newUserData.email}
|
||||
invalid={isEmpty(newUserData.email) || isNil(newUserData.email) || !isEmail(newUserData.email)}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'email')}/>
|
||||
</div>
|
||||
<div className="appForm__field">
|
||||
<label className={classNames({ 'p-error': isEmpty(newUserData.phoneNumber) || isNil(newUserData.phoneNumber) })}>{__('Telefono', 'gepafin')}</label>
|
||||
<label
|
||||
className={classNames({ 'p-error': isInvalidField(newUserData, 'phoneNumber') })}>
|
||||
{__('Telefono', 'gepafin')}
|
||||
</label>
|
||||
<InputText value={newUserData.phoneNumber}
|
||||
keyfilter="int"
|
||||
invalid={isEmpty(newUserData.phoneNumber) || isNil(newUserData.phoneNumber)}
|
||||
invalid={isInvalidField(newUserData, 'phoneNumber')}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'phoneNumber')}/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="appForm__cols">
|
||||
<div className="appForm__field">
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newUserData.password) || isNil(newUserData.password) || newUserData.password !== newUserData.confPassword })}>
|
||||
{__('Password', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newUserData.password}
|
||||
invalid={isEmpty(newUserData.password) || isNil(newUserData.password) || newUserData.password !== newUserData.confPassword}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'password')}/>
|
||||
</div>
|
||||
<div className="appForm__field">
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newUserData.confPassword) || isNil(newUserData.confPassword) || newUserData.password !== newUserData.confPassword })}>
|
||||
{__('Conferma password', 'gepafin')}*
|
||||
</label>
|
||||
<InputText value={newUserData.confPassword}
|
||||
invalid={isEmpty(newUserData.confPassword) || isNil(newUserData.confPassword) || newUserData.password !== newUserData.confPassword}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'confPassword')}/>
|
||||
</div>
|
||||
</div>
|
||||
<div className="appForm__field">
|
||||
<label className={classNames({ 'p-error': isEmpty(newUserData.role) || isNil(newUserData.role) })}>{__('Ruolo', 'gepafin')}</label>
|
||||
<label
|
||||
className={classNames({ 'p-error': isEmpty(newUserData.roleId) || isNil(newUserData.roleId) || newUserData.roleId === 0 })}>
|
||||
{__('Ruolo', 'gepafin')}*
|
||||
</label>
|
||||
<Dropdown
|
||||
value={newUserData.role}
|
||||
invalid={isEmpty(newUserData.role) || isNil(newUserData.role)}
|
||||
onChange={(e) => onChangeEditItem(e.value, 'role')}
|
||||
value={newUserData.roleId}
|
||||
invalid={isEmpty(newUserData.roleId) || isNil(newUserData.roleId) || newUserData.roleId === 0}
|
||||
onChange={(e) => onChangeEditItem(e.value, 'roleId')}
|
||||
options={roles}
|
||||
optionLabel="name"
|
||||
optionValue="value"/>
|
||||
|
||||
Reference in New Issue
Block a user