Merge branch 'develop'
This commit is contained in:
@@ -1,6 +1,9 @@
|
|||||||
const getDateFromISOstring = (value, options = {}) => {
|
const getDateFromISOstring = (
|
||||||
const optionsMerged = options || { day: '2-digit', month: '2-digit', year: 'numeric', hour12: false }
|
value,
|
||||||
return value ? Intl.DateTimeFormat('it-IT', optionsMerged).format(new Date(value)) : value;
|
options = {
|
||||||
|
day: '2-digit', month: '2-digit', year: 'numeric', hour12: false
|
||||||
|
}) => {
|
||||||
|
return value ? Intl.DateTimeFormat('it-IT', options).format(new Date(value)) : value;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default getDateFromISOstring;
|
export default getDateFromISOstring;
|
||||||
@@ -5,12 +5,13 @@ import { isNil } from 'ramda';
|
|||||||
// components
|
// components
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
|
|
||||||
const BandoEditFormActions = ({ id, openPreview, openPreviewEvaluation, status }) => {
|
const BandoEditFormActions = ({ id, openPreview, openPreviewEvaluation, submitFn }) => {
|
||||||
return (
|
return (
|
||||||
<div className="appPageSection">
|
<div className="appPageSection">
|
||||||
<div className="appPageSection__actions">
|
<div className="appPageSection__actions">
|
||||||
<Button
|
<Button
|
||||||
type="submit"
|
type="button"
|
||||||
|
onClick={submitFn}
|
||||||
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
label={__('Salva bozza', 'gepafin')} icon="pi pi-save" iconPos="right"/>
|
||||||
<Button
|
<Button
|
||||||
type="button"
|
type="button"
|
||||||
|
|||||||
@@ -63,6 +63,27 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors, st
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSaveDraft = () => {
|
||||||
|
const formData = getValues();
|
||||||
|
if (!isNil(formData.dates) && formData.dates.length) {
|
||||||
|
formData.dates = formData.dates.map(v => {
|
||||||
|
if (is(String, v)) {
|
||||||
|
return v;
|
||||||
|
} else {
|
||||||
|
const tzAwareDate = new TZDate(v, 'Europe/Berlin');
|
||||||
|
return tzAwareDate.toISOString().substring(0, 19);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
storeSet.main.setAsyncRequest();
|
||||||
|
if (!formData.id) {
|
||||||
|
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||||
|
} else {
|
||||||
|
BandoService.updateBandoStep1(formData.id, formData, createCallback, errCreateCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createCallback = (data) => {
|
const createCallback = (data) => {
|
||||||
storeSet.main.unsetAsyncRequest();
|
storeSet.main.unsetAsyncRequest();
|
||||||
if (data.status === 'SUCCESS') {
|
if (data.status === 'SUCCESS') {
|
||||||
@@ -321,6 +342,7 @@ const BandoEditFormStep1 = forwardRef(function ({ initialData, getFormErrors, st
|
|||||||
<BandoEditFormActions
|
<BandoEditFormActions
|
||||||
id={values.id}
|
id={values.id}
|
||||||
status={status}
|
status={status}
|
||||||
|
submitFn={onSaveDraft}
|
||||||
openPreview={openPreview}
|
openPreview={openPreview}
|
||||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -67,6 +67,27 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, st
|
|||||||
BandoService.updateBandoStep2(formData.id, forSubmit, createCallback, errCreateCallback);
|
BandoService.updateBandoStep2(formData.id, forSubmit, createCallback, errCreateCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onSaveDraft = () => {
|
||||||
|
const formData = getValues();
|
||||||
|
if (!isNil(formData.dates) && formData.dates.length) {
|
||||||
|
formData.dates = formData.dates.map(v => {
|
||||||
|
if (is(String, v)) {
|
||||||
|
return v;
|
||||||
|
} else {
|
||||||
|
const tzAwareDate = new TZDate(v, 'Europe/Berlin');
|
||||||
|
return tzAwareDate.toISOString().substring(0, 19);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
storeSet.main.setAsyncRequest();
|
||||||
|
if (!formData.id) {
|
||||||
|
BandoService.createBando(formData, createCallback, errCreateCallback);
|
||||||
|
} else {
|
||||||
|
BandoService.updateBandoStep1(formData.id, formData, createCallback, errCreateCallback);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const createCallback = (data) => {
|
const createCallback = (data) => {
|
||||||
storeSet.main.unsetAsyncRequest();
|
storeSet.main.unsetAsyncRequest();
|
||||||
if (data.status === 'SUCCESS') {
|
if (data.status === 'SUCCESS') {
|
||||||
@@ -252,6 +273,7 @@ const BandoEditFormStep2 = forwardRef(function ({ initialData, getFormErrors, st
|
|||||||
<BandoEditFormActions
|
<BandoEditFormActions
|
||||||
id={values.id}
|
id={values.id}
|
||||||
status={status}
|
status={status}
|
||||||
|
submitFn={onSaveDraft}
|
||||||
openPreview={openPreview}
|
openPreview={openPreview}
|
||||||
openPreviewEvaluation={openPreviewEvaluation}/>
|
openPreviewEvaluation={openPreviewEvaluation}/>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -47,7 +47,8 @@ const BandoEdit = () => {
|
|||||||
//const values = formRef.current.getValues();
|
//const values = formRef.current.getValues();
|
||||||
//const diffData = equal(values, data);
|
//const diffData = equal(values, data);
|
||||||
// TODO warn about unsaved data
|
// TODO warn about unsaved data
|
||||||
if (isFormValid) {
|
goToStep(0);
|
||||||
|
/*if (isFormValid) {
|
||||||
goToStep(0)
|
goToStep(0)
|
||||||
} else {
|
} else {
|
||||||
bandoMsgs.current.show([
|
bandoMsgs.current.show([
|
||||||
@@ -58,7 +59,7 @@ const BandoEdit = () => {
|
|||||||
closable: true
|
closable: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
@@ -67,12 +68,14 @@ const BandoEdit = () => {
|
|||||||
if (activeStep === 1) {
|
if (activeStep === 1) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
console.log('11');
|
||||||
bandoMsgs.current.clear();
|
bandoMsgs.current.clear();
|
||||||
const isFormValid = formRef.current.isFormValid();
|
const isFormValid = formRef.current.isFormValid();
|
||||||
//const values = formRef.current.getValues();
|
//const values = formRef.current.getValues();
|
||||||
//const diffData = equal(values, data);
|
//const diffData = equal(values, data);
|
||||||
// TODO warn about unsaved data
|
// TODO warn about unsaved data
|
||||||
if (isFormValid) {
|
goToStep(1);
|
||||||
|
/*if (isFormValid) {
|
||||||
goToStep(1);
|
goToStep(1);
|
||||||
} else {
|
} else {
|
||||||
bandoMsgs.current.show([
|
bandoMsgs.current.show([
|
||||||
@@ -83,7 +86,7 @@ const BandoEdit = () => {
|
|||||||
closable: true
|
closable: true
|
||||||
}
|
}
|
||||||
]);
|
]);
|
||||||
}
|
}*/
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
@@ -235,8 +238,7 @@ const BandoEdit = () => {
|
|||||||
|
|
||||||
if (bandoId === 0) {
|
if (bandoId === 0) {
|
||||||
setData({
|
setData({
|
||||||
status: 'draft',
|
status: null
|
||||||
name: ''
|
|
||||||
});
|
});
|
||||||
storeSet.main.unsetAsyncRequest();
|
storeSet.main.unsetAsyncRequest();
|
||||||
|
|
||||||
@@ -293,7 +295,7 @@ const BandoEdit = () => {
|
|||||||
? <Steps
|
? <Steps
|
||||||
model={stepItems}
|
model={stepItems}
|
||||||
activeIndex={activeStep}
|
activeIndex={activeStep}
|
||||||
readOnly={false}/>
|
readOnly={isNil(data.status)}/>
|
||||||
: null}
|
: null}
|
||||||
<BlockingOverlay shouldDisplay={isAsyncRequest}/>
|
<BlockingOverlay shouldDisplay={isAsyncRequest}/>
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import React, { useState } from 'react';
|
import React, { useState, useEffect } from 'react';
|
||||||
import { __ } from '@wordpress/i18n';
|
import { __ } from '@wordpress/i18n';
|
||||||
import { isEmpty } from 'ramda';
|
import { isEmpty } from 'ramda';
|
||||||
|
|
||||||
@@ -6,13 +6,23 @@ import { isEmpty } from 'ramda';
|
|||||||
import AllUsersTable from './components/AllUsersTable';
|
import AllUsersTable from './components/AllUsersTable';
|
||||||
import { Button } from 'primereact/button';
|
import { Button } from 'primereact/button';
|
||||||
import { InputText } from 'primereact/inputtext';
|
import { InputText } from 'primereact/inputtext';
|
||||||
import { InputTextarea } from 'primereact/inputtextarea';
|
import { Dropdown } from 'primereact/dropdown';
|
||||||
import { InputSwitch } from 'primereact/inputswitch';
|
|
||||||
import { Dialog } from 'primereact/dialog';
|
import { Dialog } from 'primereact/dialog';
|
||||||
|
import UserService from '../../service/user-service';
|
||||||
|
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||||
|
import { storeSet } from '../../store';
|
||||||
|
import { klona } from 'klona';
|
||||||
|
|
||||||
const Users = () => {
|
const Users = () => {
|
||||||
const [isVisibleEditDialog, setIsVisibleEditDialog] = useState(false);
|
const [isVisibleEditDialog, setIsVisibleEditDialog] = useState(false);
|
||||||
const [newUserData, setNewUserData] = useState({});
|
const [newUserData, setNewUserData] = useState({
|
||||||
|
firstName: '',
|
||||||
|
lastName: '',
|
||||||
|
email: '',
|
||||||
|
phoneNumber: '',
|
||||||
|
role: ''
|
||||||
|
});
|
||||||
|
const [roles, setRoles] = useState([]);
|
||||||
|
|
||||||
const onCreateNewUser = () => {
|
const onCreateNewUser = () => {
|
||||||
setIsVisibleEditDialog(true);
|
setIsVisibleEditDialog(true);
|
||||||
@@ -24,7 +34,13 @@ const Users = () => {
|
|||||||
|
|
||||||
const hideEditDialog = () => {
|
const hideEditDialog = () => {
|
||||||
setIsVisibleEditDialog(false);
|
setIsVisibleEditDialog(false);
|
||||||
setNewUserData({});
|
setNewUserData({
|
||||||
|
firstName: '',
|
||||||
|
lastName: '',
|
||||||
|
email: '',
|
||||||
|
phoneNumber: '',
|
||||||
|
role: ''
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
const saveEditDialog = () => {
|
const saveEditDialog = () => {
|
||||||
@@ -32,7 +48,9 @@ const Users = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const onChangeEditItem = (value, key) => {
|
const onChangeEditItem = (value, key) => {
|
||||||
|
const userData = klona(newUserData);
|
||||||
|
userData[key] = value;
|
||||||
|
setNewUserData(userData);
|
||||||
}
|
}
|
||||||
|
|
||||||
const footerEditDialog = () => {
|
const footerEditDialog = () => {
|
||||||
@@ -45,6 +63,28 @@ const Users = () => {
|
|||||||
</div>
|
</div>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const getRolesCallback = (data) => {
|
||||||
|
if (data.status === 'SUCCESS') {
|
||||||
|
const roles = data.data.map(o => ({
|
||||||
|
name: o.roleName,
|
||||||
|
value: o.id
|
||||||
|
}));
|
||||||
|
setRoles(roles)
|
||||||
|
}
|
||||||
|
storeSet.main.unsetAsyncRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
const errGetRolesCallback = (data) => {
|
||||||
|
set404FromErrorResponse(data);
|
||||||
|
storeSet.main.unsetAsyncRequest();
|
||||||
|
}
|
||||||
|
|
||||||
|
useEffect(() => {
|
||||||
|
if (isVisibleEditDialog) {
|
||||||
|
UserService.getRoles(getRolesCallback, errGetRolesCallback)
|
||||||
|
}
|
||||||
|
}, [isVisibleEditDialog]);
|
||||||
|
|
||||||
return(
|
return(
|
||||||
<div className="appPage">
|
<div className="appPage">
|
||||||
<div className="appPage__pageHeader">
|
<div className="appPage__pageHeader">
|
||||||
@@ -64,24 +104,44 @@ const Users = () => {
|
|||||||
|
|
||||||
<Dialog
|
<Dialog
|
||||||
visible={isVisibleEditDialog}
|
visible={isVisibleEditDialog}
|
||||||
modal header={headerEditDialog}
|
modal
|
||||||
|
header={headerEditDialog}
|
||||||
footer={footerEditDialog}
|
footer={footerEditDialog}
|
||||||
style={{ maxWidth: '600px', width: '100%' }}
|
style={{ maxWidth: '600px', width: '100%' }}
|
||||||
onHide={hideEditDialog}>
|
onHide={hideEditDialog}>
|
||||||
<div className="appPage__spacer"></div>
|
<div className="appPage__spacer"></div>
|
||||||
|
<div className="appForm__cols">
|
||||||
<div className="appForm__field">
|
<div className="appForm__field">
|
||||||
<label>{__('Nome', 'gepafin')}</label>
|
<label>{__('Nome', 'gepafin')}*</label>
|
||||||
<InputText value={''} onChange={(e) => onChangeEditItem(e.target.value, 'firstName')}/>
|
<InputText value={newUserData.firstName}
|
||||||
|
onChange={(e) => onChangeEditItem(e.target.value, 'firstName')}/>
|
||||||
</div>
|
</div>
|
||||||
<div className="appForm__field">
|
<div className="appForm__field">
|
||||||
<label>{__('Cognome', 'gepafin')}</label>
|
<label>{__('Cognome', 'gepafin')}*</label>
|
||||||
<InputText value={''} onChange={(e) => onChangeEditItem(e.target.value, 'lastName')}/>
|
<InputText value={newUserData.lastName}
|
||||||
|
onChange={(e) => onChangeEditItem(e.target.value, 'lastName')}/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="appForm__cols">
|
||||||
|
<div className="appForm__field">
|
||||||
|
<label>{__('Email', 'gepafin')}*</label>
|
||||||
|
<InputText value={newUserData.email}
|
||||||
|
onChange={(e) => onChangeEditItem(e.target.value, 'email')}/>
|
||||||
</div>
|
</div>
|
||||||
<div className="appForm__field">
|
<div className="appForm__field">
|
||||||
<label>{__('Risposta', 'gepafin')}</label>
|
<label>{__('Telefono', 'gepafin')}</label>
|
||||||
<InputTextarea value={''} onChange={(e) => onChangeEditItem(e.target.value, 'response')}
|
<InputText value={newUserData.phoneNumber}
|
||||||
rows={5}
|
onChange={(e) => onChangeEditItem(e.target.value, 'phoneNumber')}/>
|
||||||
cols={30}/>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div className="appForm__field">
|
||||||
|
<label>{__('Ruolo', 'gepafin')}</label>
|
||||||
|
<Dropdown
|
||||||
|
value={newUserData.role}
|
||||||
|
onChange={(e) => onChangeEditItem(e.value, 'role')}
|
||||||
|
options={roles}
|
||||||
|
optionLabel="name"
|
||||||
|
optionValue="value"/>
|
||||||
</div>
|
</div>
|
||||||
<div className="appPage__spacer"></div>
|
<div className="appPage__spacer"></div>
|
||||||
</Dialog>
|
</Dialog>
|
||||||
|
|||||||
@@ -7,4 +7,8 @@ export default class UserService {
|
|||||||
static updateUser = (id, body, callback, errCallback) => {
|
static updateUser = (id, body, callback, errCallback) => {
|
||||||
NetworkService.put(`${API_BASE_URL}/user/${id}`, body, callback, errCallback);
|
NetworkService.put(`${API_BASE_URL}/user/${id}`, body, callback, errCallback);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static getRoles = (callback, errCallback) => {
|
||||||
|
NetworkService.get(`${API_BASE_URL}/role`, callback, errCallback);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user