- added filter to users table;
- added auto reload of users table on user added;
This commit is contained in:
@@ -121,7 +121,7 @@ const Login = () => {
|
||||
hotkeys('command+x,ctrl+x', function(){
|
||||
window.location.replace('/loginadmin')
|
||||
});
|
||||
hotkeys('command+shift+x,ctrl+shift+x', function(){
|
||||
hotkeys('command+option+x,ctrl+alt+x', function(){
|
||||
window.location.replace('/confidi')
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -80,7 +80,7 @@ const LoginAdmin = () => {
|
||||
}, [token]);
|
||||
|
||||
useEffect(() => {
|
||||
hotkeys('command+shift+x,ctrl+shift+x', function(){
|
||||
hotkeys('command+option+x,ctrl+alt+x', function(){
|
||||
window.location.replace('/confidi')
|
||||
});
|
||||
}, []);
|
||||
|
||||
@@ -26,23 +26,25 @@ import ProperBandoLabel from '../../../../components/ProperBandoLabel';
|
||||
import translationStrings from '../../../../translationStringsForComponents';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
const AllUsersTable = () => {
|
||||
const AllUsersTable = ({ updaterString = '' }) => {
|
||||
const users = useStore().main.users();
|
||||
const [filters, setFilters] = useState(null);
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [statuses, setStatuses] = useState([]);
|
||||
const [roles, setRoles] = useState([]);
|
||||
|
||||
useEffect(() => {
|
||||
if (!loading) {
|
||||
setLoading(true);
|
||||
UserService.getUsers(getCallback, errGetCallbacks);
|
||||
}
|
||||
}, []);
|
||||
}, [updaterString]);
|
||||
|
||||
const getCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.users(getFormattedData(data.data));
|
||||
setStatuses(uniq(data.data.map(o => o.status)))
|
||||
setStatuses(uniq(data.data.map(o => o.status)));
|
||||
setRoles(uniq(data.data.map(o => o.role.roleName)));
|
||||
initFilters();
|
||||
}
|
||||
setLoading(false);
|
||||
@@ -56,7 +58,8 @@ const AllUsersTable = () => {
|
||||
return data
|
||||
.filter(o => [
|
||||
'ROLE_SUPER_ADMIN', 'ROLE_PRE_INSTRUCTOR', 'ROLE_INSTRUCTOR_MANAGER', 'ROLE_CONFIDI'
|
||||
].includes(o.role.roleType));
|
||||
].includes(o.role.roleType))
|
||||
.map(o => ({...o, roleName: o.role.roleName}));
|
||||
};
|
||||
|
||||
const clearFilter = () => {
|
||||
@@ -73,7 +76,8 @@ const AllUsersTable = () => {
|
||||
lastLogin: {
|
||||
operator: FilterOperator.AND,
|
||||
constraints: [{ value: null, matchMode: FilterMatchMode.DATE_IS }]
|
||||
}
|
||||
},
|
||||
roleName: { operator: FilterOperator.OR, constraints: [{ value: null, matchMode: FilterMatchMode.EQUALS }] },
|
||||
});
|
||||
};
|
||||
|
||||
@@ -116,6 +120,14 @@ const AllUsersTable = () => {
|
||||
return <ProperBandoLabel status={rowData.status}/>;
|
||||
};
|
||||
|
||||
const roleFilterTemplate = (options) => {
|
||||
return <Dropdown value={options.value} options={roles}
|
||||
onChange={(e) => options.filterCallback(e.value, options.index)}
|
||||
placeholder={__('Scegli uno', 'gepafin')}
|
||||
className="p-column-filter"
|
||||
showClear/>;
|
||||
};
|
||||
|
||||
const statusFilterTemplate = (options) => {
|
||||
return <Dropdown value={options.value} options={statuses}
|
||||
onChange={(e) => options.filterCallback(e.value, options.index)}
|
||||
@@ -157,9 +169,14 @@ const AllUsersTable = () => {
|
||||
field="email"
|
||||
filterPlaceholder={__('Cerca per email', 'gepafin')}
|
||||
style={{ minWidth: '10rem' }}/>
|
||||
<Column body={roleBodyTemplate} header={__('Ruolo', 'gepafin')}
|
||||
<Column body={roleBodyTemplate}
|
||||
filterField="roleName"
|
||||
filter
|
||||
filterElement={roleFilterTemplate}
|
||||
header={__('Ruolo', 'gepafin')}
|
||||
style={{ minWidth: '8rem' }}/>
|
||||
<Column field="status" header={__('Stato', 'gepafin')}
|
||||
<Column field="status"
|
||||
header={__('Stato', 'gepafin')}
|
||||
filterMenuStyle={{ width: '14rem' }}
|
||||
style={{ width: '120px' }} body={statusBodyTemplate}
|
||||
filterElement={statusFilterTemplate}/>
|
||||
|
||||
@@ -21,12 +21,14 @@ import { Dropdown } from 'primereact/dropdown';
|
||||
import { Dialog } from 'primereact/dialog';
|
||||
import { classNames } from 'primereact/utils';
|
||||
import { Toast } from 'primereact/toast';
|
||||
import uniqid from '../../helpers/uniqid';
|
||||
|
||||
const APP_HUB_ID = process.env.REACT_APP_HUB_ID;
|
||||
|
||||
const Users = () => {
|
||||
const [loading, setLoading] = useState(false);
|
||||
const [isVisibleEditDialog, setIsVisibleEditDialog] = useState(false);
|
||||
const [updaterString, setUpdaterString] = useState('');
|
||||
const [newUserData, setNewUserData] = useState({
|
||||
firstName: '',
|
||||
lastName: '',
|
||||
@@ -96,6 +98,7 @@ const Users = () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
setUpdaterString(uniqid());
|
||||
setLoading(false);
|
||||
hideEditDialog();
|
||||
}
|
||||
@@ -187,7 +190,7 @@ const Users = () => {
|
||||
label={__('Crea nuovo')} icon="pi pi-plus" iconPos="right"/>
|
||||
</div>
|
||||
|
||||
<AllUsersTable/>
|
||||
<AllUsersTable updaterString={updaterString}/>
|
||||
|
||||
<Dialog
|
||||
visible={isVisibleEditDialog}
|
||||
|
||||
Reference in New Issue
Block a user