- updates to teh flow;

This commit is contained in:
Vitalii Kiiko
2024-12-19 15:54:53 +01:00
parent 23525141b1
commit 099ac72563
8 changed files with 142 additions and 57 deletions

View File

@@ -1,8 +1,14 @@
import React, { useEffect, useRef, useState } from 'react';
import { __ } from '@wordpress/i18n';
import { isEmpty } from 'ramda';
import { isEmpty, pathOr, isNil } from 'ramda';
import { wrap } from 'object-path-immutable';
// store
import AppointmentService from '../../../../service/appointment-service';
// tools
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
// components
import { Button } from 'primereact/button';
import { Dialog } from 'primereact/dialog';
@@ -11,14 +17,11 @@ import { Dropdown } from 'primereact/dropdown';
import { classNames } from 'primereact/utils';
import { InputSwitch } from 'primereact/inputswitch';
import { InputText } from 'primereact/inputtext';
import { classificationType, protocolType } from '../../../../configData';
import AppointmentService from '../../../../service/appointment-service';
import set404FromErrorResponse from '../../../../helpers/set404FromErrorResponse';
import { storeSet } from '../../../../store';
import { Toast } from 'primereact/toast';
const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0, docAttachmentId = null }) => {
import { classificationType, protocolType } from '../../../../configData';
const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0, docAttachmentId = null, updateFn = () => {} }) => {
const [loading, setLoading] = useState(false);
const [isVisibleDialog, setIsVisibleDialog] = useState(false);
const [modalData, setModalData] = useState({});
@@ -87,19 +90,29 @@ const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0, docAttachmentId
const submitCallback = (data) => {
if (data.status === 'SUCCESS') {
console.log(data.data);
if (toast.current && data.message) {
toast.current.show({
severity: 'success',
summary: '',
detail: data.message
});
}
const documentAttachmentId = pathOr('fake_id', ['documentAttachmentId'], data.data);
updateFn(documentAttachmentId);
}
setIsVisibleDialog(false);
setLoading(false);
}
const errSubmitCallback = (data) => {
if (toast.current && data.message) {
toast.current.show({
severity: 'error',
severity: data.status === 'SUCCESS' ? 'info' : 'error',
summary: '',
detail: data.message
});
}
setIsVisibleDialog(false);
set404FromErrorResponse(data);
setLoading(false);
}
@@ -119,7 +132,7 @@ const ArchiveDocument = ({ applicationId, ndg = '', fileId = 0, docAttachmentId
setTypes(protocolType.map(o => ({ value: o.id, label: o.name })));
}, []);
return (!isEmpty(ndg) && !docAttachmentId
return (!isEmpty(ndg) && !isNil(ndg) && !docAttachmentId
? <>
<Toast ref={toast}/>
<Button icon="pi pi-file-export"

View File

@@ -4,22 +4,34 @@ import { __ } from '@wordpress/i18n';
import { isNil } from 'ramda';
import ArchiveDocument from '../ArchiveDocument';
import renderHtmlContent from '../../../../helpers/renderHtmlContent';
import uniqid from '../../../../helpers/uniqid';
const ListOfFiles = ({ files, updateFn, shouldDisableFieldFn, name, ndg, applicationId }) => {
return (
<ol className="appPageSection__list">
{files.map((o, i) => <li key={o.id} className="appPageSection__listItem">
{files.map((o, i) => <li key={`${o.id}_${uniqid('f')}`} className="appPageSection__listItem">
<div className="appPageSection__listItemRow">
<div>{renderHtmlContent(o.label)}</div>
<div className="appPageSection__iconActions">
{o.fileDetail && o.fileDetail.length === 1
? <Button icon="pi pi-eye" rounded
? <>
<Button icon="pi pi-eye" rounded
onClick={() => {
window.open(o.fileDetail[0].filePath, '_blank').focus()
}}
outlined severity="info"
aria-label={__('Mostra', 'gepafin')}/> : null}
aria-label={__('Mostra', 'gepafin')}/>
<ArchiveDocument
ndg={ndg}
applicationId={applicationId}
fileId={o.fileDetail[0].id}
updateFn={(val) => updateFn(
val,
[name, i, 'fileDetail', 0, 'documentAttachmentId']
)}
docAttachmentId={o.fileDetail[0].documentAttachmentId}/>
</> : null}
<Button icon="pi pi-thumbs-up" rounded outlined
disabled={shouldDisableFieldFn(name)}
severity={!isNil(o.valid) && o.valid ? 'success' : 'secondary'}
@@ -46,7 +58,7 @@ const ListOfFiles = ({ files, updateFn, shouldDisableFieldFn, name, ndg, applica
flexDirection: 'column',
gap: '10px'
}}>
{o.fileDetail.map((k) => <li key={k.id} style={{
{o.fileDetail.map((k, ind) => <li key={k.id} style={{
display: 'flex',
flexDirection: 'row',
alignItems: 'center',
@@ -54,8 +66,15 @@ const ListOfFiles = ({ files, updateFn, shouldDisableFieldFn, name, ndg, applica
}}>
<span>{k.name}</span>
<div className="appPageSection__iconActions">
<ArchiveDocument ndg={ndg} applicationId={applicationId} fileId={k.id}
docAttachmentId={k.documentAttachmentId}/>
<ArchiveDocument
ndg={ndg}
applicationId={applicationId}
fileId={k.id}
updateFn={(val) => updateFn(
val,
[name, i, 'fileDetail', ind, 'documentAttachmentId']
)}
docAttachmentId={k.documentAttachmentId}/>
<Button icon="pi pi-eye" rounded
onClick={() => {
window.open(k.filePath, '_blank').focus()