- re done login con uuid;
- re done reset password con uuid; - re done user management con uuid;
This commit is contained in:
@@ -1,6 +1,16 @@
|
||||
import React, { useState, useEffect } from 'react';
|
||||
import React, { useState, useEffect, useRef } from 'react';
|
||||
import { __ } from '@wordpress/i18n';
|
||||
import { isEmpty, isNil } from 'ramda';
|
||||
import { klona } from 'klona';
|
||||
|
||||
// store
|
||||
import { storeSet } from '../../store';
|
||||
|
||||
// service
|
||||
import UserService from '../../service/user-service';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
|
||||
// components
|
||||
import AllUsersTable from './components/AllUsersTable';
|
||||
@@ -8,13 +18,13 @@ 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 { Toast } from 'primereact/toast';
|
||||
|
||||
const APP_HUB_ID = process.env.REACT_APP_HUB_ID;
|
||||
|
||||
const Users = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isVisibleEditDialog, setIsVisibleEditDialog] = useState(false);
|
||||
const [newUserData, setNewUserData] = useState({
|
||||
firstName: '',
|
||||
@@ -24,6 +34,7 @@ const Users = () => {
|
||||
role: ''
|
||||
});
|
||||
const [roles, setRoles] = useState([]);
|
||||
const toast = useRef(null);
|
||||
|
||||
const onCreateNewUser = () => {
|
||||
setIsVisibleEditDialog(true);
|
||||
@@ -45,7 +56,32 @@ const Users = () => {
|
||||
}
|
||||
|
||||
const saveEditDialog = () => {
|
||||
setLoading(true);
|
||||
const body = {
|
||||
...newUserData,
|
||||
hubUuid: APP_HUB_ID
|
||||
}
|
||||
|
||||
UserService.createUser(body, createUserCallback, errCreateUserCallback);
|
||||
}
|
||||
|
||||
const createUserCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
|
||||
}
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
const errCreateUserCallback = (data) => {
|
||||
setLoading(false);
|
||||
if (toast.current) {
|
||||
toast.current.show({
|
||||
severity: 'error',
|
||||
summary: '',
|
||||
detail: data.message
|
||||
});
|
||||
}
|
||||
set404FromErrorResponse(data);
|
||||
}
|
||||
|
||||
const onChangeEditItem = (value, key) => {
|
||||
@@ -59,17 +95,19 @@ const Users = () => {
|
||||
<Button type="button" label={__('Anulla', 'gepafin')} onClick={hideEditDialog} outlined/>
|
||||
<Button
|
||||
type="button"
|
||||
disabled={isEmpty(newUserData)}
|
||||
disabled={isEmpty(newUserData) || loading}
|
||||
label={__('Salva', 'gepafin')} onClick={saveEditDialog}/>
|
||||
</div>
|
||||
}
|
||||
|
||||
const getRolesCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
const roles = data.data.map(o => ({
|
||||
name: o.roleName,
|
||||
value: o.id
|
||||
}));
|
||||
const roles = data.data
|
||||
.filter(o => ['ROLE_SUPER_ADMIN', 'ROLE_PRE_INSTRUCTOR'].includes(o.roleType))
|
||||
.map(o => ({
|
||||
name: o.roleName,
|
||||
value: o.id
|
||||
}));
|
||||
setRoles(roles)
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
@@ -86,13 +124,14 @@ const Users = () => {
|
||||
}
|
||||
}, [isVisibleEditDialog]);
|
||||
|
||||
return(
|
||||
return (
|
||||
<div className="appPage">
|
||||
<div className="appPage__pageHeader">
|
||||
<h1>{__('Gestione utenti', 'gepafin')}</h1>
|
||||
</div>
|
||||
|
||||
<div className="appPage__spacer"></div>
|
||||
<Toast ref={toast} />
|
||||
|
||||
<div className="appPageSection">
|
||||
<div className="appPageSection__actions">
|
||||
@@ -113,13 +152,15 @@ 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': isEmpty(newUserData.firstName) || isNil(newUserData.firstName) })}>{__('Nome', 'gepafin')}*</label>
|
||||
<InputText value={newUserData.firstName}
|
||||
invalid={isEmpty(newUserData.firstName) || isNil(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': isEmpty(newUserData.lastName) || isNil(newUserData.lastName) })}>{__('Cognome', 'gepafin')}*</label>
|
||||
<InputText value={newUserData.lastName}
|
||||
invalid={isEmpty(newUserData.lastName) || isNil(newUserData.lastName)}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'lastName')}/>
|
||||
@@ -127,20 +168,23 @@ const Users = () => {
|
||||
</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) })}>{__('Email', 'gepafin')}*</label>
|
||||
<InputText value={newUserData.email}
|
||||
invalid={isEmpty(newUserData.email) || isNil(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': isEmpty(newUserData.phoneNumber) || isNil(newUserData.phoneNumber) })}>{__('Telefono', 'gepafin')}</label>
|
||||
<InputText value={newUserData.phoneNumber}
|
||||
invalid={isEmpty(newUserData.phoneNumber) || isNil(newUserData.phoneNumber)}
|
||||
onChange={(e) => onChangeEditItem(e.target.value, 'phoneNumber')}/>
|
||||
</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.role) || isNil(newUserData.role) })}>{__('Ruolo', 'gepafin')}</label>
|
||||
<Dropdown
|
||||
value={newUserData.role}
|
||||
invalid={isEmpty(newUserData.role) || isNil(newUserData.role)}
|
||||
|
||||
Reference in New Issue
Block a user