@topconsultnpm/sdkui-react 6.22.0-dev2.16 → 6.22.0-dev2.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -26,6 +26,7 @@ import { useTMPanelManagerContext } from '../../layout/panelManager/TMPanelManag
26
26
  import TMPanelManagerContainer from '../../layout/panelManager/TMPanelManagerContainer';
27
27
  import { TMPanelManagerWithPersistenceProvider } from '../../layout/panelManager/TMPanelManagerWithPersistenceProvider';
28
28
  import { useWorkflowApprove } from '../../../hooks/useWorkflowApprove';
29
+ import { useCaseFlowApprove } from '../../../hooks/useCaseFlowApprove';
29
30
  import TMBlogCommentForm from '../blog/TMBlogCommentForm';
30
31
  import WFDiagram from '../workflow/diagram/WFDiagram';
31
32
  import TMTooltip from '../../base/TMTooltip';
@@ -116,6 +117,10 @@ const TMDcmtForm = ({ TID, DID, groupId, layoutMode = LayoutModes.Update, formMo
116
117
  const [wfError, setWfError] = useState(null);
117
118
  const [metadataDcmtOrigin, setMetadataDcmtOrigin] = useState(null);
118
119
  const { workflowApproveData, getWorkItemsByDID } = useWorkflowApprove();
120
+ // Attività delle PRATICHE (CaseFlow) su questo documento. Come per il workflow
121
+ // la scoperta avviene QUI: da qualunque punto si apra il form, l'utente trova
122
+ // le sue azioni nel Toppy.
123
+ const { caseFlowWorkItems, completeCaseFlowWorkItem, rejectCaseFlowWorkItem } = useCaseFlowApprove(TID, DID);
119
124
  // Get the current device type (e.g., mobile, tablet, desktop) using a custom hook.
120
125
  const deviceType = useDeviceType();
121
126
  // This avoids unnecessary re-renders by only recalculating when deviceType changes.
@@ -804,7 +809,10 @@ const TMDcmtForm = ({ TID, DID, groupId, layoutMode = LayoutModes.Update, formMo
804
809
  // Verifica che ci siano riferimenti renderizzabili (solo Dossier o WorkingGroup)
805
810
  return dcmtReferences.some(ref => ref.objClass === ObjectClasses.Dossier || ref.objClass === ObjectClasses.WorkingGroup);
806
811
  }, [allowButtonsRefs, layoutMode, dcmtReferences, isOpenDetails, isOpenMaster]);
807
- const isToppyVisible = useMemo(() => Boolean((showToppyForApprove || showToppyForCompleteMoreInfo || showToppyForReferences) && !openS4TViewer && !showTodoDcmtForm && !editPdfForm), [showToppyForApprove, showToppyForCompleteMoreInfo, showToppyForReferences, openS4TViewer, showTodoDcmtForm, editPdfForm]);
812
+ // Attività di pratica: stesse condizioni dell'approvazione workflow (documento
813
+ // in consultazione, senza errori, non dentro master/detail).
814
+ const showToppyForCaseFlow = useMemo(() => layoutMode === LayoutModes.Update && !fetchError && caseFlowWorkItems.length > 0 && !isOpenDetails && !isOpenMaster, [layoutMode, fetchError, caseFlowWorkItems.length, isOpenDetails, isOpenMaster]);
815
+ const isToppyVisible = useMemo(() => Boolean((showToppyForApprove || showToppyForCompleteMoreInfo || showToppyForReferences || showToppyForCaseFlow) && !openS4TViewer && !showTodoDcmtForm && !editPdfForm), [showToppyForApprove, showToppyForCompleteMoreInfo, showToppyForReferences, showToppyForCaseFlow, openS4TViewer, showTodoDcmtForm, editPdfForm]);
808
816
  const isModified = useMemo(() => calcIsModified(formData, formDataOrig), [formData, formDataOrig]);
809
817
  const formToolbar = useMemo(() => _jsxs("div", { style: { display: 'flex', alignItems: 'center', gap: '10px' }, children: [allowNavigation && canPrev != undefined && _jsx("p", { style: { textAlign: 'center', padding: '1px 4px', display: 'flex' }, children: `${itemIndex}/${count}` }), allowNavigation && canPrev != undefined && _jsx(TMSaveFormButtonPrevious, { btnStyle: 'icon', iconColor: 'white', isModified: isModified, formMode: formMode, canPrev: canPrev, onPrev: onPrev }), allowNavigation && canNext != undefined && _jsx(TMSaveFormButtonNext, { btnStyle: 'icon', iconColor: 'white', isModified: isModified, formMode: formMode, canNext: canNext, onNext: onNext }), layoutMode === LayoutModes.Update &&
810
818
  _jsx(ContextMenu, { items: operationItems, trigger: "left", children: _jsx(IconMenuVertical, { color: 'white', cursor: 'pointer' }) }), layoutMode === LayoutModes.Ark &&
@@ -1571,7 +1579,7 @@ const TMDcmtForm = ({ TID, DID, groupId, layoutMode = LayoutModes.Update, formMo
1571
1579
  isEditable: true,
1572
1580
  value: FormulaHelper.addFormulaTag(newFormula.expression)
1573
1581
  }));
1574
- } }), (isModal && onClose) && _jsx("div", { id: "TMDcmtFormShowConfirmForClose-" + id })] }) }), _jsx(TMToppyDraggableHelpCenter, { isVisible: isToppyVisible, content: _jsx(TMDcmtFormActionButtons, { showToppyForApprove: showToppyForApprove, workItems: workItems, deviceType: deviceType, isMobile: isMobile, handleSignApprove: handleSignApprove, updateShowApprovePopup: updateShowApprovePopup, updateShowRejectPopup: updateShowRejectPopup, updateShowReAssignPopup: updateShowReAssignPopup, updateShowMoreInfoPopup: updateShowMoreInfoPopup, fromDTD: fromDTD, showToppyForCompleteMoreInfo: showToppyForCompleteMoreInfo, moreInfoTasks: moreInfoTasks, setShowCommentForm: setShowCommentForm, showToppyForReferences: showToppyForReferences, dcmtReferences: dcmtReferences, referenceActionMap: referenceActionMap, handleNavigateToReference: handleNavigateToReference, setShowMoreInfoTaskPopup: setShowMoreInfoTaskPopup, setShowMoreInfoTaskTask: setShowMoreInfoTaskTask }) })] }), (showCommentForm && TID && DID) &&
1582
+ } }), (isModal && onClose) && _jsx("div", { id: "TMDcmtFormShowConfirmForClose-" + id })] }) }), _jsx(TMToppyDraggableHelpCenter, { isVisible: isToppyVisible, content: _jsx(TMDcmtFormActionButtons, { showToppyForApprove: showToppyForApprove, workItems: workItems, caseFlowWorkItems: showToppyForCaseFlow ? caseFlowWorkItems : [], onCompleteCaseFlowWorkItem: completeCaseFlowWorkItem, onRejectCaseFlowWorkItem: rejectCaseFlowWorkItem, deviceType: deviceType, isMobile: isMobile, handleSignApprove: handleSignApprove, updateShowApprovePopup: updateShowApprovePopup, updateShowRejectPopup: updateShowRejectPopup, updateShowReAssignPopup: updateShowReAssignPopup, updateShowMoreInfoPopup: updateShowMoreInfoPopup, fromDTD: fromDTD, showToppyForCompleteMoreInfo: showToppyForCompleteMoreInfo, moreInfoTasks: moreInfoTasks, setShowCommentForm: setShowCommentForm, showToppyForReferences: showToppyForReferences, dcmtReferences: dcmtReferences, referenceActionMap: referenceActionMap, handleNavigateToReference: handleNavigateToReference, setShowMoreInfoTaskPopup: setShowMoreInfoTaskPopup, setShowMoreInfoTaskTask: setShowMoreInfoTaskTask }) })] }), (showCommentForm && TID && DID) &&
1575
1583
  _jsx(TMBlogCommentForm, { maxLength: 500, context: blogCommentFormContext, onClose: handleBlogCommentFormClose, onCustomSave: onBlogCommentFormCustomSave, participants: emptyParticipants, showAttachmentsSection: false, allArchivedDocumentsFileItems: emptyArchivedDocumentsFileItems })] }), renderDcmtOperations, renderFloatingBar] }));
1576
1584
  };
1577
1585
  return (_jsxs("div", { style: { width: '100%', height: '100%' }, children: [(isModal && onClose)
@@ -2,9 +2,20 @@ import React from "react";
2
2
  import { DcmtTypeDescriptor, TaskDescriptor, ObjectRef } from "@topconsultnpm/sdk-ts";
3
3
  import { IWorkItemData } from "../../../ts";
4
4
  import { DeviceType } from "../../base/TMDeviceProvider";
5
+ import { CaseFlowDcmtWorkItem } from "../../../hooks/useCaseFlowApprove";
5
6
  interface TMDcmtFormActionButtonsProps {
6
7
  showToppyForApprove: boolean;
7
8
  workItems: Array<IWorkItemData>;
9
+ /** Attività delle PRATICHE (CaseFlow) pendenti su QUESTO documento. */
10
+ caseFlowWorkItems?: Array<CaseFlowDcmtWorkItem>;
11
+ /**
12
+ * Completa l'attività di pratica. NON usato per la FIRMA: là si apre il viewer
13
+ * di firma ed è quello, a firma riuscita, a completare — esattamente come per
14
+ * i work item del workflow.
15
+ */
16
+ onCompleteCaseFlowWorkItem?: (item: CaseFlowDcmtWorkItem, comment?: string) => Promise<void>;
17
+ /** Rifiuta l'attività di pratica con un motivo. */
18
+ onRejectCaseFlowWorkItem?: (item: CaseFlowDcmtWorkItem, reason: string) => Promise<void>;
8
19
  deviceType: DeviceType | undefined;
9
20
  isMobile: boolean;
10
21
  handleSignApprove: () => void;
@@ -1,18 +1,34 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-runtime";
2
2
  import { useCallback, useMemo, useRef, useState } from "react";
3
3
  import { ObjectClasses, SDK_Globals } from "@topconsultnpm/sdk-ts";
4
- import { TASK_MORE_INFO_PREFIX_NAME, SDKUI_Localizator, PDGS_COLORS, calcResponsiveSizes } from "../../../helper";
4
+ import { TASK_MORE_INFO_PREFIX_NAME, SDKUI_Localizator, PDGS_COLORS, calcResponsiveSizes, isSign4TopEnabled } from "../../../helper";
5
5
  import { TMColors } from "../../../utils/theme";
6
6
  import { StyledReferenceButton } from "../../base/Styled";
7
7
  import TMButton from "../../base/TMButton";
8
8
  import TMModal from "../../base/TMModal";
9
9
  import TMTooltip from "../../base/TMTooltip";
10
10
  import { WorkFlowOperationButtons } from "../workflow/TMWorkflowPopup";
11
+ import { getWorkItemActionName, isSignatureWorkItem } from "../../../services/caseflow/caseFlowWorkItemUtils";
11
12
  const TMDcmtFormActionButtons = (props) => {
12
- const { showToppyForApprove, workItems, deviceType, isMobile, handleSignApprove, updateShowApprovePopup, updateShowRejectPopup, updateShowReAssignPopup, updateShowMoreInfoPopup, fromDTD, showToppyForCompleteMoreInfo, moreInfoTasks, setShowCommentForm, showToppyForReferences, dcmtReferences, referenceActionMap, handleNavigateToReference, setShowMoreInfoTaskPopup, setShowMoreInfoTaskTask } = props;
13
+ const { showToppyForApprove, workItems, caseFlowWorkItems, onCompleteCaseFlowWorkItem, onRejectCaseFlowWorkItem, deviceType, isMobile, handleSignApprove, updateShowApprovePopup, updateShowRejectPopup, updateShowReAssignPopup, updateShowMoreInfoPopup, fromDTD, showToppyForCompleteMoreInfo, moreInfoTasks, setShowCommentForm, showToppyForReferences, dcmtReferences, referenceActionMap, handleNavigateToReference, setShowMoreInfoTaskPopup, setShowMoreInfoTaskTask } = props;
13
14
  const [showAllMoreInfoModal, setShowAllMoreInfoModal] = useState(false);
14
15
  const [showAllDossiersModal, setShowAllDossiersModal] = useState(false);
15
16
  const [showAllWorkingGroupsModal, setShowAllWorkingGroupsModal] = useState(false);
17
+ // Rifiuto di un'attività di pratica: il motivo è obbligatorio, quindi si passa
18
+ // da un dialogo. `busyItemId` disabilita i pulsanti dell'attività in corso.
19
+ const [rejectingItem, setRejectingItem] = useState(null);
20
+ const [rejectReason, setRejectReason] = useState('');
21
+ const [busyItemId, setBusyItemId] = useState(null);
22
+ const cfItems = useMemo(() => caseFlowWorkItems ?? [], [caseFlowWorkItems]);
23
+ const runCaseFlowAction = useCallback(async (item, action) => {
24
+ setBusyItemId(item.workItem.id ?? null);
25
+ try {
26
+ await action();
27
+ }
28
+ finally {
29
+ setBusyItemId(null);
30
+ }
31
+ }, []);
16
32
  const tasksNumber = useMemo(() => moreInfoTasks?.length ?? 0, [moreInfoTasks]);
17
33
  const firstTask = useMemo(() => {
18
34
  if (!moreInfoTasks || moreInfoTasks.length === 0)
@@ -31,19 +47,63 @@ const TMDcmtFormActionButtons = (props) => {
31
47
  return false;
32
48
  return true;
33
49
  }, [firstTask]);
34
- const { hasMoreInfo, hasApprove, hasReferences } = useMemo(() => {
50
+ const { hasMoreInfo, hasApprove, hasReferences, hasCaseFlow } = useMemo(() => {
35
51
  const referencesExist = showToppyForReferences && dcmtReferences?.some(ref => ref.objClass === ObjectClasses.Dossier || ref.objClass === ObjectClasses.WorkingGroup);
36
52
  return {
37
53
  hasMoreInfo: Boolean(showToppyForCompleteMoreInfo),
38
54
  hasApprove: Boolean(showToppyForApprove),
39
- hasReferences: Boolean(referencesExist)
55
+ hasReferences: Boolean(referencesExist),
56
+ hasCaseFlow: cfItems.length > 0
40
57
  };
41
58
  }, [
42
59
  showToppyForCompleteMoreInfo,
43
60
  showToppyForApprove,
44
61
  showToppyForReferences,
45
- dcmtReferences
62
+ dcmtReferences,
63
+ cfItems
46
64
  ]);
65
+ /**
66
+ * Attività di pratica: contesto (pratica + testo dell'attività) e gli STESSI
67
+ * pulsanti dei work item del workflow (`WorkFlowOperationButtons`), così le due
68
+ * provenienze si comportano allo stesso modo davanti all'utente.
69
+ *
70
+ * La forma dei pulsanti la decide la CATEGORIA dell'attività, non il tipo
71
+ * documento: un'approvazione su un tipo abilitato alla firma non deve mostrare
72
+ * "Firma e approva" (per questo si passa `signFlow`). La firma richiede comunque
73
+ * il widget Sign4Top sul tipo, altrimenti il viewer non avrebbe come aprirsi.
74
+ *
75
+ * Per la FIRMA il pulsante apre il viewer (`handleSignApprove`, lo stesso del
76
+ * workflow) e il completamento avviene lì a firma riuscita: il form non sa
77
+ * firmare, e completare qui "a fiducia" chiuderebbe l'attività su un documento
78
+ * non firmato.
79
+ */
80
+ const renderCaseFlowWorkItemCard = (item) => {
81
+ const { caseflow, workItem } = item;
82
+ const isBusy = busyItemId === workItem.id;
83
+ const canSign = !!fromDTD?.widgets && isSign4TopEnabled(fromDTD.widgets);
84
+ const requiresSignature = isSignatureWorkItem(workItem) && canSign;
85
+ const description = workItem.description || getWorkItemActionName(caseflow, workItem);
86
+ return (_jsxs("div", { style: {
87
+ display: 'flex',
88
+ flexDirection: 'column',
89
+ alignItems: 'center',
90
+ textAlign: 'center',
91
+ gap: '10px',
92
+ cursor: 'default',
93
+ }, children: [_jsx("div", { style: {
94
+ padding: '8px 10px',
95
+ maxWidth: '240px',
96
+ color: '#FFFFFF',
97
+ background: 'linear-gradient(135deg, #7E57C2 0%, #5E35B1 60%, #4527A0 100%)',
98
+ border: '1px solid rgba(255,255,255,0.15)',
99
+ borderRadius: 10,
100
+ boxShadow: '0 8px 20px rgba(0, 0, 50, 0.4)',
101
+ }, children: description && _jsx("div", { style: { whiteSpace: 'pre-line' }, children: description }) }), _jsx(WorkFlowOperationButtons, { dtd: fromDTD, deviceType: deviceType, signFlow: requiresSignature, approveDisable: isBusy, signApproveDisable: isBusy, rejectDisable: isBusy, onSignApprove: handleSignApprove, onApprove: onCompleteCaseFlowWorkItem
102
+ ? () => void runCaseFlowAction(item, () => onCompleteCaseFlowWorkItem(item))
103
+ : undefined, onReject: onRejectCaseFlowWorkItem
104
+ ? () => { setRejectReason(''); setRejectingItem(item); }
105
+ : undefined })] }, workItem.id));
106
+ };
47
107
  // Raggruppa references per categoria
48
108
  const { dossierRefs, workingGroupRefs } = useMemo(() => {
49
109
  const dossiers = dcmtReferences?.filter(ref => ref.objClass === ObjectClasses.Dossier) ?? [];
@@ -171,10 +231,17 @@ const TMDcmtFormActionButtons = (props) => {
171
231
  e.currentTarget.style.transform = 'translateY(-50%)';
172
232
  }, children: formatBadgeCount(othersCount) }))] }));
173
233
  };
174
- return (_jsxs(_Fragment, { children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px' }, children: [hasMoreInfo && firstTask && isMoreInfoCardVisible && (_jsx("div", { style: { display: 'flex', gap: "10px", flexDirection: 'column', alignItems: 'center', paddingRight: tasksNumber > 1 ? '36px' : '0' }, children: renderMoreInfoCard(firstTask, tasksNumber > 1) })), hasMoreInfo && isMoreInfoCardVisible && hasApprove && _jsx(Divider, {}), hasApprove && (workItems.length === 1 ?
234
+ return (_jsxs(_Fragment, { children: [_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px' }, children: [hasMoreInfo && firstTask && isMoreInfoCardVisible && (_jsx("div", { style: { display: 'flex', gap: "10px", flexDirection: 'column', alignItems: 'center', paddingRight: tasksNumber > 1 ? '36px' : '0' }, children: renderMoreInfoCard(firstTask, tasksNumber > 1) })), hasMoreInfo && isMoreInfoCardVisible && hasCaseFlow && _jsx(Divider, {}), hasCaseFlow && (_jsx("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px', alignItems: 'center' }, children: cfItems.map(item => renderCaseFlowWorkItemCard(item)) })), hasCaseFlow && hasApprove && _jsx(Divider, {}), hasMoreInfo && isMoreInfoCardVisible && !hasCaseFlow && hasApprove && _jsx(Divider, {}), hasApprove && (workItems.length === 1 ?
175
235
  _jsx(WorkFlowOperationButtons, { dtd: fromDTD, deviceType: deviceType, onApprove: () => updateShowApprovePopup(true), onSignApprove: handleSignApprove, onReject: () => updateShowRejectPopup(true), onReAssign: () => updateShowReAssignPopup(true), onMoreInfo: () => updateShowMoreInfoPopup(true) })
176
236
  :
177
- _jsxs("div", { style: { padding: 10, color: 'white', maxWidth: '180px', borderRadius: 10, background: '#1B1464 0% 0% no-repeat padding-box', border: '1px solid #FFFFFF' }, children: [`Questo documento è associato a ${workItems.length} workitem.`, _jsx("br", {}), `Per approvare, vai alla pagina "Approvazione workflow".`] })), (hasApprove && hasReferences) || (hasMoreInfo && isMoreInfoCardVisible && !hasApprove && hasReferences) ? (_jsx(Divider, {})) : null, hasReferences && (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px', alignItems: 'center' }, children: [dossierRefs.length > 0 && (_jsx("div", { style: { paddingRight: dossierRefs.length > 1 ? '36px' : '0' }, children: renderReferenceCard(dossierRefs[0], dossierRefs, dossierRefs.length > 1, () => setShowAllDossiersModal(true)) })), workingGroupRefs.length > 0 && (_jsx("div", { style: { paddingRight: workingGroupRefs.length > 1 ? '36px' : '0' }, children: renderReferenceCard(workingGroupRefs[0], workingGroupRefs, workingGroupRefs.length > 1, () => setShowAllWorkingGroupsModal(true)) }))] }))] }), showAllMoreInfoModal && moreInfoTasks && moreInfoTasks.length > 1 && (_jsx(TMModal, { title: `Altre richieste maggiori informazioni (${moreInfoTasks.length - 1})`, onClose: () => setShowAllMoreInfoModal(false), width: calcResponsiveSizes(deviceType, '450px', '450px', '95%'), height: 'auto', children: _jsx("div", { style: {
237
+ _jsxs("div", { style: { padding: 10, color: 'white', maxWidth: '180px', borderRadius: 10, background: '#1B1464 0% 0% no-repeat padding-box', border: '1px solid #FFFFFF' }, children: [`Questo documento è associato a ${workItems.length} workitem.`, _jsx("br", {}), `Per approvare, vai alla pagina "Approvazione workflow".`] })), (hasApprove && hasReferences) || (hasMoreInfo && isMoreInfoCardVisible && !hasApprove && hasReferences) ? (_jsx(Divider, {})) : null, hasReferences && (_jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: '10px', alignItems: 'center' }, children: [dossierRefs.length > 0 && (_jsx("div", { style: { paddingRight: dossierRefs.length > 1 ? '36px' : '0' }, children: renderReferenceCard(dossierRefs[0], dossierRefs, dossierRefs.length > 1, () => setShowAllDossiersModal(true)) })), workingGroupRefs.length > 0 && (_jsx("div", { style: { paddingRight: workingGroupRefs.length > 1 ? '36px' : '0' }, children: renderReferenceCard(workingGroupRefs[0], workingGroupRefs, workingGroupRefs.length > 1, () => setShowAllWorkingGroupsModal(true)) }))] }))] }), rejectingItem && onRejectCaseFlowWorkItem && (_jsx(TMModal, { title: rejectingItem.workItem.rejectLabel || SDKUI_Localizator.Reject, onClose: () => { setRejectingItem(null); setRejectReason(''); }, width: calcResponsiveSizes(deviceType, '450px', '450px', '95%'), height: 'auto', children: _jsxs("div", { style: { display: 'flex', flexDirection: 'column', gap: 12, padding: 15 }, children: [_jsx("div", { style: { fontSize: 13, color: '#555' }, children: `${SDKUI_Localizator.Description}:` }), _jsx("textarea", { value: rejectReason, onChange: (e) => setRejectReason(e.target.value), rows: 4, style: { width: '100%', resize: 'vertical', fontFamily: 'inherit', fontSize: 13, padding: 8 } }), _jsxs("div", { style: { display: 'flex', justifyContent: 'flex-end', gap: 8 }, children: [_jsx(TMButton, { caption: SDKUI_Localizator.Cancel, showTooltip: false, onClick: () => { setRejectingItem(null); setRejectReason(''); } }), _jsx(TMButton, { caption: rejectingItem.workItem.rejectLabel || SDKUI_Localizator.Reject, color: 'error', showTooltip: false, disabled: !rejectReason.trim() || busyItemId === rejectingItem.workItem.id, onClick: () => {
238
+ const item = rejectingItem;
239
+ void runCaseFlowAction(item, async () => {
240
+ await onRejectCaseFlowWorkItem(item, rejectReason.trim());
241
+ setRejectingItem(null);
242
+ setRejectReason('');
243
+ });
244
+ } })] })] }) })), showAllMoreInfoModal && moreInfoTasks && moreInfoTasks.length > 1 && (_jsx(TMModal, { title: `Altre richieste maggiori informazioni (${moreInfoTasks.length - 1})`, onClose: () => setShowAllMoreInfoModal(false), width: calcResponsiveSizes(deviceType, '450px', '450px', '95%'), height: 'auto', children: _jsx("div", { style: {
178
245
  display: 'flex',
179
246
  flexDirection: 'column',
180
247
  gap: '8px',
@@ -3,6 +3,16 @@ import { DeviceType } from "../../base/TMDeviceProvider";
3
3
  import { WorkItemDetail } from "../../../ts";
4
4
  interface IWorkflowOperationButtonsProps {
5
5
  dtd: DcmtTypeDescriptor | undefined;
6
+ /**
7
+ * Forza la forma dei pulsanti: `true` = flusso di FIRMA (Firma e approva),
8
+ * `false` = flusso di APPROVAZIONE. Se omesso si deduce dal tipo documento
9
+ * (widget Sign4Top), che è il comportamento del workflow.
10
+ *
11
+ * Serve a chi conosce la natura dell'attività meglio del tipo documento: un
12
+ * work item di sola approvazione su un tipo ABILITATO alla firma non deve
13
+ * mostrare "Firma e approva".
14
+ */
15
+ signFlow?: boolean;
6
16
  approveDisable?: boolean;
7
17
  signApproveDisable?: boolean;
8
18
  rejectDisable?: boolean;
@@ -53,16 +53,20 @@ const StyledHorizontalContainer = styled.div `
53
53
  /* align-items: flex-end; */
54
54
  `;
55
55
  export const WorkFlowOperationButtons = (props) => {
56
- const { dtd = undefined, deviceType = DeviceType.DESKTOP, approveDisable = false, signApproveDisable = false, rejectDisable = false, reassignDisable = false, infoDisable = false, onApprove, onSignApprove, onReject, onReAssign, onMoreInfo, } = props;
56
+ const { dtd = undefined, signFlow = undefined, deviceType = DeviceType.DESKTOP, approveDisable = false, signApproveDisable = false, rejectDisable = false, reassignDisable = false, infoDisable = false, onApprove, onSignApprove, onReject, onReAssign, onMoreInfo, } = props;
57
57
  const isMobile = deviceType === DeviceType.MOBILE;
58
- // Calcola direttamente se è un workflow di firma per evitare flickering durante il render
58
+ // Calcola direttamente se è un workflow di firma per evitare flickering durante il render.
59
+ // `signFlow`, se fornito, ha la precedenza: chi lo passa conosce la natura
60
+ // dell'attività (es. categoria del work item) meglio del tipo documento.
59
61
  const isSignWorkflow = useMemo(() => {
62
+ if (signFlow !== undefined)
63
+ return signFlow;
60
64
  if (dtd && dtd.widgets && dtd.widgets.length > 0) {
61
65
  return isSign4TopEnabled(dtd.widgets);
62
66
  }
63
67
  return false;
64
- }, [dtd]);
65
- return (_jsx(StyledWorkFlowOperationButtonsContainer, { "$isMobile": isMobile, children: isSignWorkflow ? (_jsxs(_Fragment, { children: [_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconSignaturePencil, {}), caption: SDKUI_Localizator.SignatureAndApprove, width: "160px", disabled: signApproveDisable, onClick: () => !signApproveDisable && onSignApprove?.(), onMouseDown: e => e.stopPropagation(), advancedColor: "#1a9a49", color: "success" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconCloseOutline, {}), caption: SDKUI_Localizator.Reject, disabled: rejectDisable, onClick: () => !rejectDisable && onReject?.(), onMouseDown: e => e.stopPropagation(), advancedColor: TMColors.error, color: "error" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconInfo, { fontSize: 16 }), caption: SDKUI_Localizator.MoreInformation, width: "180px", disabled: infoDisable, onClick: () => !infoDisable && onMoreInfo?.(), onMouseDown: e => e.stopPropagation(), advancedColor: TMColors.info, color: "info" })] })) : (_jsxs(_Fragment, { children: [_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconApply, {}), caption: SDKUI_Localizator.Approve, disabled: approveDisable, onClick: () => !approveDisable && onApprove?.(), advancedColor: "#1a9a49", color: "success" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconCloseOutline, {}), caption: SDKUI_Localizator.Reject, disabled: rejectDisable, onClick: () => !rejectDisable && onReject?.(), advancedColor: TMColors.error, color: "error" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconUser, { fontSize: 16 }), caption: SDKUI_Localizator.Reassign, disabled: reassignDisable, onClick: () => !reassignDisable && onReAssign?.(), advancedColor: TMColors.tertiary, color: "tertiary" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconInfo, { fontSize: 16 }), caption: SDKUI_Localizator.MoreInformation, width: "180px", disabled: infoDisable, onClick: () => !infoDisable && onMoreInfo?.(), advancedColor: TMColors.info, color: "info" })] })) }));
68
+ }, [dtd, signFlow]);
69
+ return (_jsx(StyledWorkFlowOperationButtonsContainer, { "$isMobile": isMobile, children: isSignWorkflow ? (_jsxs(_Fragment, { children: [_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconSignaturePencil, {}), caption: SDKUI_Localizator.SignatureAndApprove, width: "160px", disabled: signApproveDisable, onClick: () => !signApproveDisable && onSignApprove?.(), onMouseDown: e => e.stopPropagation(), advancedColor: "#1a9a49", color: "success" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconCloseOutline, {}), caption: SDKUI_Localizator.Reject, disabled: rejectDisable, onClick: () => !rejectDisable && onReject?.(), onMouseDown: e => e.stopPropagation(), advancedColor: TMColors.error, color: "error" }), onMoreInfo && (_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconInfo, { fontSize: 16 }), caption: SDKUI_Localizator.MoreInformation, width: "180px", disabled: infoDisable, onClick: () => !infoDisable && onMoreInfo?.(), onMouseDown: e => e.stopPropagation(), advancedColor: TMColors.info, color: "info" }))] })) : (_jsxs(_Fragment, { children: [_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconApply, {}), caption: SDKUI_Localizator.Approve, disabled: approveDisable, onClick: () => !approveDisable && onApprove?.(), advancedColor: "#1a9a49", color: "success" }), _jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconCloseOutline, {}), caption: SDKUI_Localizator.Reject, disabled: rejectDisable, onClick: () => !rejectDisable && onReject?.(), advancedColor: TMColors.error, color: "error" }), onReAssign && (_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconUser, { fontSize: 16 }), caption: SDKUI_Localizator.Reassign, disabled: reassignDisable, onClick: () => !reassignDisable && onReAssign?.(), advancedColor: TMColors.tertiary, color: "tertiary" })), onMoreInfo && (_jsx(TMButton, { btnStyle: isMobile ? 'toolbar' : 'advanced', showTooltip: isMobile, icon: _jsx(IconInfo, { fontSize: 16 }), caption: SDKUI_Localizator.MoreInformation, width: "180px", disabled: infoDisable, onClick: () => !infoDisable && onMoreInfo?.(), advancedColor: TMColors.info, color: "info" }))] })) }));
66
70
  };
67
71
  export const WorkFlowApproveRejectPopUp = ({ TID = 0, DID = 0, deviceType = DeviceType.DESKTOP, isReject, selectedItems = [], onClose, onCompleted }) => {
68
72
  const { refreshWorkflowApprove } = useWorkflowApprove();
@@ -0,0 +1,56 @@
1
+ import { CaseFlowInstanceDescriptor, CaseFlowWorkItem } from '@topconsultnpm/sdk-ts';
2
+ /**
3
+ * Attività (workitem) delle PRATICHE assegnate all'utente, con il documento su
4
+ * cui lavorano già risolto.
5
+ *
6
+ * Gemello di `useWorkflowApprove` per il modulo CaseFlow: i dati stanno in una
7
+ * cache di modulo e le istanze del hook si sincronizzano con un evento, così il
8
+ * form del documento — da qualunque punto venga aperto — sa che su quel TID/DID
9
+ * c'è una firma da fare o un'approvazione da dare, senza che il chiamante debba
10
+ * passargli nulla.
11
+ */
12
+ /** Workitem di pratica già risolto sul documento cui si riferisce. */
13
+ export interface CaseFlowDcmtWorkItem {
14
+ caseflow: CaseFlowInstanceDescriptor;
15
+ workItem: CaseFlowWorkItem;
16
+ tid: number;
17
+ did: number;
18
+ }
19
+ /**
20
+ * Ricarica i workitem di pratica dell'utente. Con `force` ignora la finestra
21
+ * anti-raffica (da usare dopo un'operazione che li ha modificati).
22
+ */
23
+ export declare const refreshCaseFlowApproveData: (force?: boolean) => Promise<void>;
24
+ /**
25
+ * Workitem di pratica pendenti su quel documento (lettura sincrona dalla cache).
26
+ *
27
+ * TID/DID vanno NORMALIZZATI: pur essendo tipati `number`, arrivano come stringhe
28
+ * quando il documento è aperto da una griglia (righe di datagrid) — per lo stesso
29
+ * motivo il resto della libreria fa `Number(TID)`/`Number(DID)` in ogni confronto.
30
+ * Senza normalizzazione il confronto stretto falliva, e l'attività risultava
31
+ * assente aprendo il documento dalla ricerca mentre compariva dal widget "Per te".
32
+ */
33
+ export declare const getCaseFlowWorkItemsByDcmt: (tid?: number | string, did?: number | string) => CaseFlowDcmtWorkItem[];
34
+ /** Svuota la cache (logout / cambio archivio). */
35
+ export declare const clearCaseFlowApproveData: () => void;
36
+ /** Completa il workitem di pratica e ricarica la cache. */
37
+ export declare const completeCaseFlowWorkItem: (item: CaseFlowDcmtWorkItem, comment?: string) => Promise<void>;
38
+ /** Rifiuta il workitem di pratica (motivo obbligatorio) e ricarica la cache. */
39
+ export declare const rejectCaseFlowWorkItem: (item: CaseFlowDcmtWorkItem, reason: string) => Promise<void>;
40
+ /**
41
+ * Completa l'attività di FIRMA di una pratica sul documento indicato, se esiste.
42
+ * La chiama il viewer di firma quando la firma è riuscita: è il gemello di quanto
43
+ * già avviene per i workitem del workflow legacy.
44
+ * @returns true se un'attività è stata completata.
45
+ */
46
+ export declare const completeCaseFlowSignatureForDcmt: (tid: number | string, did: number | string, comment?: string) => Promise<boolean>;
47
+ /**
48
+ * Attività di pratica sul documento indicato. Senza sessione o senza attività
49
+ * l'elenco è vuoto e nulla cambia nella UI.
50
+ */
51
+ export declare const useCaseFlowApprove: (tid?: number | string, did?: number | string) => {
52
+ caseFlowWorkItems: CaseFlowDcmtWorkItem[];
53
+ refreshCaseFlowApprove: (force?: boolean) => Promise<void>;
54
+ completeCaseFlowWorkItem: (item: CaseFlowDcmtWorkItem, comment?: string) => Promise<void>;
55
+ rejectCaseFlowWorkItem: (item: CaseFlowDcmtWorkItem, reason: string) => Promise<void>;
56
+ };
@@ -0,0 +1,157 @@
1
+ import { useCallback, useEffect, useState } from 'react';
2
+ import { SDK_Globals } from '@topconsultnpm/sdk-ts';
3
+ import { CaseFlowService } from '../services/caseflow/CaseFlowService';
4
+ import { getWorkItemTargetDoc, isMoreInfoWorkItem, isSignatureWorkItem } from '../services/caseflow/caseFlowWorkItemUtils';
5
+ const CASEFLOW_APPROVE_CHANGED_EVENT = 'onCaseFlowApproveChange';
6
+ let cache = [];
7
+ let inFlight;
8
+ let lastLoadedAt = 0;
9
+ /**
10
+ * Finestra minima fra due ricariche: il form del documento chiede un refresh a
11
+ * ogni apertura e la lista è una scansione delle istanze, non una query puntuale.
12
+ */
13
+ const MIN_RELOAD_INTERVAL_MS = 15000;
14
+ const notifyChanged = () => {
15
+ if (typeof window === 'undefined')
16
+ return;
17
+ window.dispatchEvent(new CustomEvent(CASEFLOW_APPROVE_CHANGED_EVENT));
18
+ };
19
+ /**
20
+ * Ricarica la cache: i workitem pendenti dell'utente, risolti sul documento su
21
+ * cui lavorano. Le richieste di informazioni sono escluse (si rispondono nella
22
+ * pratica, non sul documento) come i workitem senza documento.
23
+ */
24
+ const reload = async () => {
25
+ const userId = SDK_Globals.tmSession?.SessionDescr?.userID;
26
+ if (userId == null) {
27
+ cache = [];
28
+ return;
29
+ }
30
+ const groups = await CaseFlowService.getMyPendingWorkItems(userId);
31
+ const resolved = [];
32
+ for (const { caseflow, workItems } of groups) {
33
+ // Le richieste di informazioni si rispondono nella pratica, non sul documento.
34
+ const relevant = workItems.filter(wi => !isMoreInfoWorkItem(wi));
35
+ if (relevant.length === 0)
36
+ continue;
37
+ // Il TID dell'azione è autorato sul TEMPLATE e non materializzato
38
+ // sull'istanza: senza template risolto il documento non è calcolabile.
39
+ if (caseflow.cftid != null) {
40
+ await CaseFlowService.getTemplate(caseflow.cftid);
41
+ }
42
+ // I DOCUMENTI AGGANCIATI non arrivano dalla RetrieveAll (che porta solo i
43
+ // dati delle card): serve la Retrieve completa, altrimenti `dcmts` è vuoto
44
+ // e nessun workitem risulterebbe associato a un documento.
45
+ let instance = caseflow;
46
+ if ((instance.dcmts?.length ?? 0) === 0 && instance.id != null) {
47
+ instance = (await CaseFlowService.getCaseflow(instance.id, instance.cftid)) ?? instance;
48
+ }
49
+ for (const wi of relevant) {
50
+ const target = getWorkItemTargetDoc(instance, wi);
51
+ if (!target)
52
+ continue;
53
+ resolved.push({ caseflow: instance, workItem: wi, tid: target.tid, did: target.did });
54
+ }
55
+ }
56
+ cache = resolved;
57
+ lastLoadedAt = Date.now();
58
+ // Diagnostica del bring-up: se il Toppy non compare, qui si vede a che punto
59
+ // la catena si interrompe (nessun workitem / nessun documento risolto).
60
+ // Rimuovibile una volta stabilizzato il flusso.
61
+ console.debug('[CaseFlow] attività su documenti:', {
62
+ istanzeConPendenti: groups.length,
63
+ workItemPendenti: groups.reduce((n, g) => n + g.workItems.length, 0),
64
+ risolteSuDocumento: resolved.length,
65
+ documenti: resolved.map(r => `${r.tid}/${r.did}`),
66
+ });
67
+ };
68
+ /**
69
+ * Ricarica i workitem di pratica dell'utente. Con `force` ignora la finestra
70
+ * anti-raffica (da usare dopo un'operazione che li ha modificati).
71
+ */
72
+ export const refreshCaseFlowApproveData = async (force = false) => {
73
+ if (inFlight)
74
+ return inFlight;
75
+ if (!force && lastLoadedAt > 0 && Date.now() - lastLoadedAt < MIN_RELOAD_INTERVAL_MS)
76
+ return;
77
+ inFlight = reload()
78
+ .catch(error => { console.error('Errore nel caricare le attività di pratica sui documenti', error); })
79
+ .finally(() => { inFlight = undefined; notifyChanged(); });
80
+ return inFlight;
81
+ };
82
+ /**
83
+ * Workitem di pratica pendenti su quel documento (lettura sincrona dalla cache).
84
+ *
85
+ * TID/DID vanno NORMALIZZATI: pur essendo tipati `number`, arrivano come stringhe
86
+ * quando il documento è aperto da una griglia (righe di datagrid) — per lo stesso
87
+ * motivo il resto della libreria fa `Number(TID)`/`Number(DID)` in ogni confronto.
88
+ * Senza normalizzazione il confronto stretto falliva, e l'attività risultava
89
+ * assente aprendo il documento dalla ricerca mentre compariva dal widget "Per te".
90
+ */
91
+ export const getCaseFlowWorkItemsByDcmt = (tid, did) => {
92
+ const t = Number(tid);
93
+ const d = Number(did);
94
+ if (!Number.isFinite(t) || !Number.isFinite(d))
95
+ return [];
96
+ return cache.filter(r => Number(r.tid) === t && Number(r.did) === d);
97
+ };
98
+ /** Svuota la cache (logout / cambio archivio). */
99
+ export const clearCaseFlowApproveData = () => {
100
+ cache = [];
101
+ lastLoadedAt = 0;
102
+ notifyChanged();
103
+ };
104
+ /** Completa il workitem di pratica e ricarica la cache. */
105
+ export const completeCaseFlowWorkItem = async (item, comment) => {
106
+ if (item.caseflow.id == null || item.workItem.id == null)
107
+ return;
108
+ await CaseFlowService.completeWorkItem(item.caseflow.id, item.workItem.id, comment?.trim() || undefined);
109
+ await refreshCaseFlowApproveData(true);
110
+ };
111
+ /** Rifiuta il workitem di pratica (motivo obbligatorio) e ricarica la cache. */
112
+ export const rejectCaseFlowWorkItem = async (item, reason) => {
113
+ if (item.caseflow.id == null || item.workItem.id == null)
114
+ return;
115
+ await CaseFlowService.rejectWorkItem(item.caseflow.id, item.workItem.id, reason);
116
+ await refreshCaseFlowApproveData(true);
117
+ };
118
+ /**
119
+ * Completa l'attività di FIRMA di una pratica sul documento indicato, se esiste.
120
+ * La chiama il viewer di firma quando la firma è riuscita: è il gemello di quanto
121
+ * già avviene per i workitem del workflow legacy.
122
+ * @returns true se un'attività è stata completata.
123
+ */
124
+ export const completeCaseFlowSignatureForDcmt = async (tid, did, comment) => {
125
+ const target = getCaseFlowWorkItemsByDcmt(tid, did).find(r => isSignatureWorkItem(r.workItem));
126
+ if (!target)
127
+ return false;
128
+ await completeCaseFlowWorkItem(target, comment);
129
+ return true;
130
+ };
131
+ /**
132
+ * Attività di pratica sul documento indicato. Senza sessione o senza attività
133
+ * l'elenco è vuoto e nulla cambia nella UI.
134
+ */
135
+ export const useCaseFlowApprove = (tid, did) => {
136
+ const readItems = useCallback(() => getCaseFlowWorkItemsByDcmt(tid, did), [tid, did]);
137
+ const [caseFlowWorkItems, setCaseFlowWorkItems] = useState(readItems);
138
+ useEffect(() => { setCaseFlowWorkItems(readItems()); }, [readItems]);
139
+ useEffect(() => {
140
+ const handleChange = () => setCaseFlowWorkItems(readItems());
141
+ window.addEventListener(CASEFLOW_APPROVE_CHANGED_EVENT, handleChange);
142
+ return () => window.removeEventListener(CASEFLOW_APPROVE_CHANGED_EVENT, handleChange);
143
+ }, [readItems]);
144
+ // All'apertura di un documento la cache può essere vecchia (attività assegnate
145
+ // dopo l'ultimo caricamento) o non ancora popolata.
146
+ useEffect(() => {
147
+ if (tid == null || did == null)
148
+ return;
149
+ void refreshCaseFlowApproveData();
150
+ }, [tid, did]);
151
+ return {
152
+ caseFlowWorkItems,
153
+ refreshCaseFlowApprove: refreshCaseFlowApproveData,
154
+ completeCaseFlowWorkItem,
155
+ rejectCaseFlowWorkItem,
156
+ };
157
+ };
package/lib/index.d.ts CHANGED
@@ -8,6 +8,7 @@ export * from './hooks/useQueryParametersDialog';
8
8
  export * from './hooks/useDcmtOperations';
9
9
  export * from './hooks/useResizeObserver';
10
10
  export * from './hooks/useWorkflowApprove';
11
+ export * from './hooks/useCaseFlowApprove';
11
12
  export * from './hooks/useRelatedDocuments';
12
13
  export * from './hooks/useSettingsFeedback';
13
14
  export * from './hooks/useBetaFeatures';
package/lib/index.js CHANGED
@@ -8,6 +8,7 @@ export * from './hooks/useQueryParametersDialog';
8
8
  export * from './hooks/useDcmtOperations';
9
9
  export * from './hooks/useResizeObserver';
10
10
  export * from './hooks/useWorkflowApprove';
11
+ export * from './hooks/useCaseFlowApprove';
11
12
  export * from './hooks/useRelatedDocuments';
12
13
  export * from './hooks/useSettingsFeedback';
13
14
  export * from './hooks/useBetaFeatures';