- updated zustand and react libraries;
- added 'put in draft' btn;
This commit is contained in:
@@ -7,7 +7,7 @@ import { klona } from 'klona';
|
||||
import { isEmpty, pathOr } from 'ramda';
|
||||
|
||||
// store
|
||||
import { storeSet, storeGet, useStore } from '../../store';
|
||||
import { storeSet, storeGet, useStoreValue } from '../../store';
|
||||
|
||||
// components
|
||||
import FormBuilder from './components/FormBuilder';
|
||||
@@ -18,14 +18,16 @@ import { Toast } from 'primereact/toast';
|
||||
import { ConfirmDialog } from 'primereact/confirmdialog';
|
||||
import { Messages } from 'primereact/messages';
|
||||
|
||||
// tools
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
|
||||
// api
|
||||
import FormsService from '../../service/forms-service';
|
||||
import set404FromErrorResponse from '../../helpers/set404FromErrorResponse';
|
||||
import BandoService from '../../service/bando-service';
|
||||
import DocumentCategoryService from '../../service/document-category-service';
|
||||
|
||||
// TODO temp data
|
||||
import { elementItems } from '../../tempData';
|
||||
import DocumentCategoryService from '../../service/document-category-service';
|
||||
//import { elementItems } from '../../tempData';
|
||||
|
||||
const BandoFormsEdit = () => {
|
||||
const { id, formId } = useParams();
|
||||
@@ -33,7 +35,7 @@ const BandoFormsEdit = () => {
|
||||
const [formName, setFormName] = useState('');
|
||||
const [visibleConfirmation, setVisibleConfirmation] = useState(false);
|
||||
const [bandoStatus, setBandoStatus] = useState('');
|
||||
const isAsyncRequest = useStore().main.isAsyncRequest();
|
||||
const isAsyncRequest = useStoreValue('isAsyncRequest');
|
||||
const formMsgs = useRef(null);
|
||||
const toast = useRef(null);
|
||||
|
||||
@@ -52,7 +54,7 @@ const BandoFormsEdit = () => {
|
||||
formMsgs.current.clear();
|
||||
}
|
||||
|
||||
const content = storeGet.main.formElements();
|
||||
const content = storeGet('formElements');
|
||||
|
||||
if (isEmpty(formName) || isEmpty(content)) {
|
||||
if (isEmpty(formName)) {
|
||||
@@ -90,7 +92,7 @@ const BandoFormsEdit = () => {
|
||||
content
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
if (bandoFormId === 0) {
|
||||
FormsService.createFormForCall(
|
||||
bandoId,
|
||||
@@ -127,11 +129,11 @@ const BandoFormsEdit = () => {
|
||||
});
|
||||
}
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errFormCreateCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
if (data.status === 'BAD_REQUEST') {
|
||||
setVisibleConfirmation(true);
|
||||
} else {
|
||||
@@ -146,7 +148,7 @@ const BandoFormsEdit = () => {
|
||||
}
|
||||
|
||||
const acceptModification = () => {
|
||||
const content = storeGet.main.formElements();
|
||||
const content = storeGet('formElements');
|
||||
const parsedFormId = parseInt(formId);
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
const formData = {
|
||||
@@ -154,7 +156,7 @@ const BandoFormsEdit = () => {
|
||||
content
|
||||
}
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
|
||||
FormsService.updateForm(
|
||||
bandoFormId,
|
||||
@@ -198,7 +200,7 @@ const BandoFormsEdit = () => {
|
||||
}*/
|
||||
|
||||
const doDelete = () => {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
FormsService.deleteForm(formId, formDeleteCallback, errFormDeleteCallback)
|
||||
}
|
||||
|
||||
@@ -207,42 +209,42 @@ const BandoFormsEdit = () => {
|
||||
const bandoId = getBandoId();
|
||||
navigate(`/bandi/${bandoId}/forms`);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errFormDeleteCallback = (data) => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const getElementItemsCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.elementItems(elementItems.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
/*storeSet.main.elementItems(data.data
|
||||
//storeSet('elementItems', elementItems.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
storeSet('elementItems', data.data
|
||||
.filter(o => o.id !== 22)
|
||||
.sort((a, b) => a.sortOrder - b.sortOrder));*/
|
||||
.sort((a, b) => a.sortOrder - b.sortOrder));
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errGetElementItemsCallback = () => {
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const getFormCallback = (data) => {
|
||||
if (data.status === 'SUCCESS') {
|
||||
storeSet.main.formId(data.data.id);
|
||||
storeSet.main.formLabel(data.data.label);
|
||||
storeSet('formId', data.data.id);
|
||||
storeSet('formLabel', data.data.label);
|
||||
setFormName(data.data.label);
|
||||
setBandoStatus(data.data.callStatus);
|
||||
const elements = klona(data.data.content);
|
||||
storeSet.main.formElements(elements);
|
||||
storeSet('formElements', elements);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const errGetFormCallbacks = (data) => {
|
||||
set404FromErrorResponse(data);
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
storeSet('unsetAsyncRequest');
|
||||
}
|
||||
|
||||
const getBandoCallback = (data) => {
|
||||
@@ -250,7 +252,7 @@ const BandoFormsEdit = () => {
|
||||
setBandoStatus(data.data.status);
|
||||
const criteria = pathOr([], ['data', 'criteria'], data);
|
||||
const criteriaOptions = criteria.map(o => ({value: o.id, label: o.value}));
|
||||
storeSet.main.bandoCriteria(criteriaOptions);
|
||||
storeSet('bandoCriteria', criteriaOptions);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -260,7 +262,7 @@ const BandoFormsEdit = () => {
|
||||
|
||||
const getCategories = (resp) => {
|
||||
if (resp.status === 'SUCCESS') {
|
||||
storeSet.main.documentCategories(resp.data.map(o => ({value: o.id, label: o.description})));
|
||||
storeSet('documentCategories', resp.data.map(o => ({value: o.id, label: o.description})));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,11 +274,11 @@ const BandoFormsEdit = () => {
|
||||
const parsedFormId = parseInt(formId)
|
||||
const bandoFormId = !isNaN(parsedFormId) ? parsedFormId : 0;
|
||||
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
FormsService.getElementItems(getElementItemsCallback, errGetElementItemsCallback);
|
||||
|
||||
if (bandoFormId) {
|
||||
storeSet.main.setAsyncRequest();
|
||||
storeSet('setAsyncRequest');
|
||||
FormsService.getFormById(bandoFormId, getFormCallback, errGetFormCallbacks);
|
||||
}
|
||||
if (bandoId) {
|
||||
@@ -284,12 +286,12 @@ const BandoFormsEdit = () => {
|
||||
}
|
||||
|
||||
return () => {
|
||||
storeSet.main.formId(0);
|
||||
storeSet.main.formLabel('');
|
||||
storeSet.main.formElements([]);
|
||||
storeSet.main.bandoCriteria([]);
|
||||
storeSet.main.activeElement('');
|
||||
storeSet.main.selectedElement('');
|
||||
storeSet('formId', 0);
|
||||
storeSet('formLabel', '');
|
||||
storeSet('formElements', []);
|
||||
storeSet('bandoCriteria', []);
|
||||
storeSet('activeElement', '');
|
||||
storeSet('selectedElement', '');
|
||||
}
|
||||
}, [id, formId]);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user