- fiexed redirection to login error;

- refactored the code;
This commit is contained in:
Vitalii Kiiko
2024-12-09 10:31:57 +01:00
parent 2c68b4d1aa
commit 5efe8aa377
4 changed files with 94 additions and 72 deletions

View File

@@ -80,8 +80,8 @@ const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0 }) => {
}
}
}
console.log('submitData', submitData);
//AppointmentService.archiveDocument(applicationId, fileId, submitData, submitCallback, errSubmitCallback)
AppointmentService.archiveDocument(applicationId, fileId, submitData, submitCallback, errSubmitCallback)
}
}

View File

@@ -0,0 +1,72 @@
import React from 'react';
import { Button } from 'primereact/button';
import { __ } from '@wordpress/i18n';
import { isNil } from 'ramda';
import ArchiveDocument from '../ArchiveDocument';
const ListOfFiles = ({ files, updateFn, shouldDisableFieldFn, name, ndg, applicationId }) => {
return (
<ol className="appPageSection__list">
{files.map((o, i) => <li key={o.id} className="appPageSection__listItem">
<div className="appPageSection__listItemRow">
<span>{o.label}</span>
<div className="appPageSection__iconActions">
{o.fileDetail && o.fileDetail.length === 1
? <Button icon="pi pi-eye" rounded
onClick={() => {
window.open(o.fileDetail[0].filePath, '_blank').focus()
}}
outlined severity="info"
aria-label={__('Mostra', 'gepafin')}/> : null}
<Button icon="pi pi-thumbs-up" rounded outlined
disabled={shouldDisableFieldFn(name)}
severity={!isNil(o.valid) && o.valid ? 'success' : 'secondary'}
onClick={() => updateFn(
true,
[name, i, 'valid']
)}
aria-label={__('Su', 'gepafin')}/>
<Button icon="pi pi-thumbs-down" rounded outlined
disabled={shouldDisableFieldFn(name)}
severity={!isNil(o.valid) && !o.valid ? 'danger' : 'secondary'}
onClick={() => updateFn(
false,
[name, i, 'valid']
)}
aria-label={__('Giu', 'gepafin')}/>
</div>
</div>
{o.fileDetail && o.fileDetail.length > 1
? <ul style={{
width: '100%',
paddingLeft: '15px',
display: 'flex',
flexDirection: 'column',
gap: '10px'
}}>
{o.fileDetail.map((k) => <li key={k.id} style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
}}>
<span>{k.name}</span>
<div className="appPageSection__iconActions">
<ArchiveDocument ndg={ndg} applicationId={applicationId} fileId={k.id}/>
<Button icon="pi pi-eye" rounded
onClick={() => {
window.open(k.filePath, '_blank').focus()
}}
outlined severity="info"
aria-label={__('Mostra', 'gepafin')}/>
</div>
</li>)}
</ul>
: null}
</li>)}
</ol>
)
}
export default ListOfFiles;

View File

@@ -36,6 +36,7 @@ import DownloadApplicationArchive from './components/DownloadApplicationArchive'
import DownloadCompanyDelegation from './components/DownloadCompanyDelegation';
import DownloadSignedApplication from './components/DownloadSignedApplication';
import AppointmentService from '../../service/appointment-service';
import ListOfFiles from './components/ListOfFiles';
const APP_EVALUATION_FLOW_ID = process.env.REACT_APP_EVALUATION_FLOW_ID;
@@ -140,15 +141,14 @@ const DomandaEditPreInstructor = () => {
const header = renderHeader();
const updateEvaluationValue = (value, path, maxValue) => {
const pathEls = path.split('.');
const updateEvaluationValue = (value, path, maxValue = null) => {
let finalValue = value;
if (maxValue || maxValue === 0) {
finalValue = value > maxValue ? maxValue : value;
}
const newData = wrap(data).set(pathEls, finalValue).value();
const newData = wrap(data).set(path, finalValue).value();
setData(newData);
updateFlagsForSoccorso(newData);
}
@@ -548,7 +548,7 @@ const DomandaEditPreInstructor = () => {
inputId={`checklist_${o.id}`}
onChange={(e) => updateEvaluationValue(
e.checked,
`checklist.${i}.valid`
['checklist', i, 'valid']
)}
checked={o.valid}></Checkbox>
<label htmlFor={`checklist_${o.id}`}>{o.label}</label>
@@ -565,7 +565,7 @@ const DomandaEditPreInstructor = () => {
headerTemplate={header}
onTextChange={(e) => updateEvaluationValue(
e.htmlValue,
'note'
['note']
)}
style={{ height: 80 * 3, width: '100%' }}
/>
@@ -573,65 +573,13 @@ const DomandaEditPreInstructor = () => {
</div>
<div>
<h3>{__('Documenti allegati', 'gepafin')}</h3>
<ol className="appPageSection__list">
{data.files.map((o, i) => <li key={o.id} className="appPageSection__listItem">
<div className="appPageSection__listItemRow">
<span>{o.label}</span>
<div className="appPageSection__iconActions">
{o.fileDetail && o.fileDetail.length === 1
? <Button icon="pi pi-eye" rounded
onClick={() => {
window.open(o.fileDetail[0].filePath, '_blank').focus()
}}
outlined severity="info"
aria-label={__('Mostra', 'gepafin')}/> : null}
<Button icon="pi pi-thumbs-up" rounded outlined
disabled={shouldDisableField('files')}
severity={!isNil(o.valid) && o.valid ? 'success' : 'secondary'}
onClick={() => updateEvaluationValue(
true,
`files.${i}.valid`
)}
aria-label={__('Su', 'gepafin')}/>
<Button icon="pi pi-thumbs-down" rounded outlined
disabled={shouldDisableField('files')}
severity={!isNil(o.valid) && !o.valid ? 'danger' : 'secondary'}
onClick={() => updateEvaluationValue(
false,
`files.${i}.valid`
)}
aria-label={__('Giu', 'gepafin')}/>
</div>
</div>
{o.fileDetail && o.fileDetail.length > 1
? <ul style={{
width: '100%',
paddingLeft: '15px',
display: 'flex',
flexDirection: 'column',
gap: '10px'
}}>
{o.fileDetail.map((k, i) => <li key={k.id} style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
justifyContent: 'space-between'
}}>
<span>{k.name}</span>
<div className="appPageSection__iconActions">
<ArchiveDocument ndg={data.ndg} applicationId={id} fileId={k.id}/>
<Button icon="pi pi-eye" rounded
onClick={() => {
window.open(k.filePath, '_blank').focus()
}}
outlined severity="info"
aria-label={__('Mostra', 'gepafin')}/>
</div>
</li>)}
</ul>
: null}
</li>)}
</ol>
<ListOfFiles
files={data.files}
updateFn={updateEvaluationValue}
shouldDisableFieldFn={shouldDisableField}
name="files"
ndg={data.ndg}
applicationId={id}/>
</div>
</div>
</div>
@@ -660,8 +608,8 @@ const DomandaEditPreInstructor = () => {
max={o.maxScore}
onChange={(e) => updateEvaluationValue(
e.value,
`criteria.${i}.score`,
o.maxScore
['criteria', i, 'score'],
o.criteria
)}/>
<span className="p-inputgroup-addon">
/ {o.maxScore}
@@ -680,7 +628,7 @@ const DomandaEditPreInstructor = () => {
severity={!isNil(o.valid) && o.valid ? 'success' : 'secondary'}
onClick={() => updateEvaluationValue(
true,
`criteria.${i}.valid`
['criteria', i, 'valid']
)}
aria-label={__('Su', 'gepafin')}/>
<Button icon="pi pi-thumbs-down" rounded outlined
@@ -688,7 +636,7 @@ const DomandaEditPreInstructor = () => {
severity={!isNil(o.valid) && !o.valid ? 'danger' : 'secondary'}
onClick={() => updateEvaluationValue(
false,
`criteria.${i}.valid`
['criteria', i, 'valid']
)}
aria-label={__('Giu', 'gepafin')}/>
</div>

View File

@@ -3,6 +3,7 @@ import { __, sprintf } from '@wordpress/i18n';
import { classNames } from 'primereact/utils';
import { isEmpty, isNil } from 'ramda';
import hotkeys from 'hotkeys-js';
import { useSearchParams } from 'react-router-dom';
// store
import { storeSet, useStore } from '../../store';
@@ -13,7 +14,6 @@ import AuthenticationService from '../../service/authentication-service';
// components
import LogoIcon from '../../icons/LogoIcon';
import { Messages } from 'primereact/messages';
import { useSearchParams } from 'react-router-dom';
import { Dialog } from 'primereact/dialog';
import { Accordion } from 'primereact/accordion';
import { AccordionTab } from 'primereact/accordion';
@@ -98,7 +98,9 @@ const Login = () => {
}, [isMaintenance])
useEffect(() => {
if (!isEmpty(token)) {
const queryParams = Object.fromEntries(searchParams);
if (!isEmpty(token) && isNil(queryParams.redirectReason)) {
window.location.replace('/')
}
}, [token]);