- updated page of evaluation editing for instructor;
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { head, isNil, pathOr } from 'ramda';
|
||||
import { head, is, isNil, pathOr } from 'ramda';
|
||||
import getNumberFormatted from '../../../../../../../helpers/getNumberFormatted';
|
||||
|
||||
const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, tableValue = []}) => {
|
||||
@@ -9,7 +9,7 @@ const LastRowCell = ({columnId, lastRowCfg, columnMeta = {}, tableValue = []}) =
|
||||
cellValue = pathOr(0, ['total'], tableValue);
|
||||
}
|
||||
|
||||
return <td>{getNumberFormatted(cellValue)}</td>;
|
||||
return <td>{is(Number, cellValue) ? getNumberFormatted(cellValue) : cellValue}</td>;
|
||||
};
|
||||
|
||||
export default LastRowCell;
|
||||
@@ -121,7 +121,7 @@ const DomandaEditPreInstructor = () => {
|
||||
navigate('/domande');
|
||||
}
|
||||
|
||||
const updateFlagsForSoccorso = (data) => {
|
||||
const updateFlagsForSoccorso = useCallback((data) => {
|
||||
let nonRatedFilesLength = 0;
|
||||
|
||||
if (data.files) {
|
||||
@@ -140,14 +140,28 @@ const DomandaEditPreInstructor = () => {
|
||||
|
||||
setAllFilesRated(nonRatedFilesLength === 0);
|
||||
|
||||
if (data.checklist) {
|
||||
const checkedChecklistItems = data.checklist
|
||||
.map(el => el.valid)
|
||||
.filter(v => v);
|
||||
setAtLeastOneChecked(checkedChecklistItems.length > 0);
|
||||
setAllChecksChecked(checkedChecklistItems.length === data.checklist.length)
|
||||
if (data.evaluationVersion === 'V1') {
|
||||
if (data.checklist) {
|
||||
const checkedChecklistItems = data.checklist
|
||||
.map(el => el.valid)
|
||||
.filter(v => v);
|
||||
setAtLeastOneChecked(checkedChecklistItems.length > 0);
|
||||
setAllChecksChecked(checkedChecklistItems.length === data.checklist.length)
|
||||
}
|
||||
} else if (data.evaluationVersion === 'V2') {
|
||||
const minChecks = data.numberOfCheck;
|
||||
const formFieldsChecklist = formData
|
||||
.filter(o => head(o.settings.filter(s => s.name === 'isChecklistItem' && s.value)))
|
||||
.map(o => o.id);
|
||||
|
||||
if (formFieldsChecklist.length >= minChecks) {
|
||||
const valuesTotal = formFieldsChecklist.map(v => formValues[v]);
|
||||
const valuesFirst = valuesTotal.toSpliced(minChecks);
|
||||
setAtLeastOneChecked(valuesTotal.filter(v => v === true).length === valuesTotal.length);
|
||||
setAllChecksChecked(valuesFirst.filter(v => v === true).length === valuesFirst.length)
|
||||
}
|
||||
}
|
||||
}
|
||||
}, [formValues]);
|
||||
|
||||
const doNewSoccorso = () => {
|
||||
if (connectedSoccorsoId !== 0) {
|
||||
@@ -191,25 +205,28 @@ const DomandaEditPreInstructor = () => {
|
||||
setData(getFormattedData(resp.data));
|
||||
setMotivation(resp.data.motivation);
|
||||
updateFlagsForSoccorso(resp.data);
|
||||
setFormData(resp.data.applicationEvaluationFormResponse.content);
|
||||
setFormId(resp.data.applicationEvaluationFormResponse.id);
|
||||
let formDataInitial = {};
|
||||
|
||||
if (resp.data.applicationEvaluationFormResponse.formFields) {
|
||||
const submitData = resp.data.applicationEvaluationFormResponse.formFields.map((o) => ({
|
||||
fieldId: o.fieldId,
|
||||
fieldValue: o.fieldValue
|
||||
}));
|
||||
formDataInitial = submitData.reduce((acc, cur) => {
|
||||
if (cur.fieldValue) {
|
||||
acc[cur.fieldId] = cur.fieldValue;
|
||||
}
|
||||
return acc;
|
||||
}, formDataInitial);
|
||||
if (resp.data.evaluationVersion === 'V2') {
|
||||
setFormData(resp.data.applicationEvaluationFormResponse.content);
|
||||
setFormId(resp.data.applicationEvaluationFormResponse.id);
|
||||
let formDataInitial = {};
|
||||
|
||||
if (resp.data.applicationEvaluationFormResponse.formFields) {
|
||||
const submitData = resp.data.applicationEvaluationFormResponse.formFields.map((o) => ({
|
||||
fieldId: o.fieldId,
|
||||
fieldValue: o.fieldValue
|
||||
}));
|
||||
formDataInitial = submitData.reduce((acc, cur) => {
|
||||
if (cur.fieldValue) {
|
||||
acc[cur.fieldId] = cur.fieldValue;
|
||||
}
|
||||
return acc;
|
||||
}, formDataInitial);
|
||||
}
|
||||
|
||||
reset();
|
||||
setFormInitialData(formDataInitial);
|
||||
}
|
||||
|
||||
reset();
|
||||
setFormInitialData(formDataInitial);
|
||||
}
|
||||
storeSet.main.unsetAsyncRequest();
|
||||
}
|
||||
@@ -848,6 +865,8 @@ const DomandaEditPreInstructor = () => {
|
||||
if (!isEmpty(updatedFormValues) && !equal(updatedFormValues, formValues)) {
|
||||
reset(updatedFormValues);
|
||||
}
|
||||
|
||||
updateFlagsForSoccorso(data);
|
||||
}, [formValues]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
Reference in New Issue
Block a user