udp-react-enterprise-component-library 25.18.1-beta.77 → 25.18.1-beta.78

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.
@@ -39,7 +39,7 @@ import { i as getLocalizedDateTimeString, t as formatDate } from "./dateUtils-CO
39
39
  import { t as UdpActionCard } from "./UdpActionCard-VtAacuCM.js";
40
40
  import { t as Attachments } from "./uploader-BdeUKdYW.js";
41
41
  import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useMemo, useRef, useState } from "react";
42
- import { CircularProgress, FormControlLabel, LinearProgress, Switch, makeStyles } from "@material-ui/core";
42
+ import { Badge, CircularProgress, FormControlLabel, LinearProgress, Switch, makeStyles } from "@material-ui/core";
43
43
  import { useSnackbar } from "notistack";
44
44
  import { useLocation } from "react-router-dom";
45
45
  import { AddIcon, ContactIcon, DocumentIcon, FileImageIcon, PDFIcon, ViewIcon, WordDocumentIcon } from "@fluentui/react-icons";
@@ -629,7 +629,7 @@ var AttachmentTransaction_default = AttachmentTransaction;
629
629
  //#endregion
630
630
  //#region src/udp/pages/UdpTransactionsPage/components/UdpTransactionCustomPage.jsx
631
631
  const UdpTransactionCustomPage = (props) => {
632
- const { pageId, transactionTypeId, transactionUiActionType, formRef, transaction, transactionTypeTransactionActionId, setHasUnsavedChanges } = props;
632
+ const { pageId, transactionTypeId, transactionUiActionType, formRef, transaction, transactionTypeTransactionActionId, setHasUnsavedChanges, onSubmitSuccess } = props;
633
633
  const { getUiActionRenderPageId, getHiddenFields, getRequiredFields } = useTransactionEngine(transactionTypeId);
634
634
  const { handleErrorSnackbar, handleSuccessSnackbar } = useHandleAxiosSnackbar();
635
635
  const { t } = useTranslation();
@@ -660,8 +660,10 @@ const UdpTransactionCustomPage = (props) => {
660
660
  message = "Action has been submitted successfully";
661
661
  errorMessagePart = "submitting action for";
662
662
  }
663
- if (response?.status === 200) handleSuccessSnackbar(t(`${message} `));
664
- else handleErrorSnackbar(new Error(t(`Error ${errorMessagePart} Transaction. Please try again later.`)));
663
+ if (response?.status === 200) {
664
+ handleSuccessSnackbar(t(`${message} `));
665
+ onSubmitSuccess?.(response);
666
+ } else if (response) handleErrorSnackbar(new Error(t(`Error ${errorMessagePart} Transaction. Please try again later.`)));
665
667
  } catch (error) {
666
668
  handleErrorSnackbar(error);
667
669
  } finally {
@@ -681,7 +683,8 @@ const UdpTransactionCustomPage = (props) => {
681
683
  t,
682
684
  transactionTypeTransactionActionId,
683
685
  setHasUnsavedChanges,
684
- formRef
686
+ formRef,
687
+ onSubmitSuccess
685
688
  ]);
686
689
  const isFieldRequired = useCallback((fieldName) => {
687
690
  return getRequiredFields(transaction)?.includes(fieldName);
@@ -1456,15 +1459,10 @@ var EditTransactionDetailsForm_default = EditTransactionDetailsForm;
1456
1459
  //#endregion
1457
1460
  //#region src/udp/pages/UdpTransactionsPage/sidesheets/EditTransaction.jsx
1458
1461
  const EditTransaction = (props) => {
1459
- const { transaction: initialTransaction, transactionTypeId, transactionIsClosed, openInnerSidesheetState, setOpenInnerSidesheetState, refreshGridData, closeSideSheet, setSidesheetLoading, setHasUnsavedChanges } = props;
1462
+ const { transaction: initialTransaction, transactionTypeId, transactionIsClosed, openInnerSidesheetState, setOpenInnerSidesheetState, refreshGridData, closeSideSheet, setSidesheetLoading, setHasUnsavedChanges, attachmentType, setAttachmentType, currentAttachments, setCurrentAttachments, attachmentProgress, setAttachmentProgress, transactionAttachmentTypes, transactionAttachments, setTransactionAttachments, filePreview, setFilePreview } = props;
1460
1463
  const { t } = useTranslation();
1461
1464
  const [selectedTab, setSelectedTab] = useState(0);
1462
1465
  const [transaction, setTransaction] = useState(initialTransaction);
1463
- const [transactionAttachments, setTransactionAttachments] = useState([]);
1464
- const [filePreview, setFilePreview] = useState(false);
1465
- const [currentAttachments, setCurrentAttachments] = useState([]);
1466
- const [attachmentType, setAttachmentType] = useState(null);
1467
- const [attachmentProgress, setAttachmentProgress] = useState(false);
1468
1466
  const [refreshNotes, setRefreshNotes] = useState(false);
1469
1467
  const [{ data: noteTypes, loading: fetchNoteTypesLoading }] = useAxiosGet(ConfigService$1.productV1ApiUrl, `UdpNoteType`, {});
1470
1468
  const { getUiActionRenderPageId, transactionTypeStatusColorsMap } = useTransactionEngine(transactionTypeId);
@@ -1507,17 +1505,6 @@ const EditTransaction = (props) => {
1507
1505
  }]
1508
1506
  }
1509
1507
  });
1510
- const [{ data: transactionAttachmentTypes }, fetchTransactionAttachmentType] = useAxiosMutate(process.env.REACT_APP_PRODUCT_API_BASE, `UdpTransactionAttachmentType/search`, {
1511
- method: "post",
1512
- data: {
1513
- pageSize: 50,
1514
- filterElements: [{
1515
- searchField: "TransactionTypeId",
1516
- searchValue: transaction.transactionTypeId,
1517
- searchOperator: "="
1518
- }]
1519
- }
1520
- });
1521
1508
  const { enqueueSnackbar } = useSnackbar();
1522
1509
  const getAttachments = useCallback(async () => {
1523
1510
  try {
@@ -1536,7 +1523,8 @@ const EditTransaction = (props) => {
1536
1523
  }, [
1537
1524
  fetchTransactionAttachments,
1538
1525
  enqueueSnackbar,
1539
- refetchTransaction
1526
+ refetchTransaction,
1527
+ setTransactionAttachments
1540
1528
  ]);
1541
1529
  const tabNames = [
1542
1530
  t("Details"),
@@ -1601,7 +1589,9 @@ const EditTransaction = (props) => {
1601
1589
  enqueueSnackbar,
1602
1590
  getAttachments,
1603
1591
  setOpenInnerSidesheetState,
1604
- transaction.transactionId
1592
+ transaction.transactionId,
1593
+ setCurrentAttachments,
1594
+ setAttachmentProgress
1605
1595
  ]);
1606
1596
  const innerSidesheetList = useMemo(() => [
1607
1597
  {
@@ -1680,7 +1670,12 @@ const EditTransaction = (props) => {
1680
1670
  fetchNoteTypesLoading,
1681
1671
  setOpenInnerSidesheetState,
1682
1672
  refetchTransaction,
1683
- handleUploadFiles
1673
+ handleUploadFiles,
1674
+ setAttachmentType,
1675
+ setCurrentAttachments,
1676
+ setAttachmentProgress,
1677
+ setTransactionAttachments,
1678
+ setFilePreview
1684
1679
  ]);
1685
1680
  const transactionDetailPageId = useMemo(() => {
1686
1681
  return getUiActionRenderPageId(TransactionUiActionTypeEnums.Render_Transaction_Details_Page);
@@ -1690,14 +1685,6 @@ const EditTransaction = (props) => {
1690
1685
  if (!transactionAttachmentsData) getAttachments();
1691
1686
  })();
1692
1687
  }, [transactionAttachmentsData, getAttachments]);
1693
- useEffect(() => {
1694
- if (!transactionAttachmentTypes) {
1695
- setAttachmentProgress(true);
1696
- fetchTransactionAttachmentType().then(() => {
1697
- setAttachmentProgress(false);
1698
- });
1699
- }
1700
- }, [fetchTransactionAttachmentType, transactionAttachmentTypes]);
1701
1688
  return /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement("div", { className: "edit-transaction-sidesheet" }, /* @__PURE__ */ React.createElement("div", { className: `edit-transaction-sidesheet-header 'is-sticky'` }, /* @__PURE__ */ React.createElement("div", { className: "edit-transaction-sidesheet-header-title" }), /* @__PURE__ */ React.createElement("div", { className: "edit-transaction-sidesheet-header-content" }, /* @__PURE__ */ React.createElement("div", { className: "edit-transaction-sidesheet-header-items" }, headerItemInfo.map((headerItem) => {
1702
1689
  return /* @__PURE__ */ React.createElement(EditTransactionHeaderItem_default, {
1703
1690
  key: headerItem.label,
@@ -1797,19 +1784,47 @@ const UdpTransactionSidesheet = (props) => {
1797
1784
  const [dialogOpen, setDialogOpen] = useState(false);
1798
1785
  const [unsavedChangesDialogOpen, setUnsavedChangesDialogOpen] = useState(false);
1799
1786
  const [hasUnsavedChanges, setHasUnsavedChanges] = useState(false);
1787
+ const [createTransactionOpenInnerSidesheetState, setCreateTransactionOpenInnerSidesheetState] = useState({ attachments: false });
1788
+ const [attachmentType, setAttachmentType] = useState(null);
1789
+ const [currentAttachments, setCurrentAttachments] = useState([]);
1790
+ const [attachmentProgress, setAttachmentProgress] = useState(false);
1791
+ const [transactionAttachments, setTransactionAttachments] = useState([]);
1792
+ const [filePreview, setFilePreview] = useState(false);
1800
1793
  const { handleSuccessSnackbar, handleErrorSnackbar } = useHandleAxiosSnackbar();
1801
1794
  const { hasClosedStatus, checkIfTransactionIsClosed, getTransactionTypeLabel, getUiActionRenderPageId } = useTransactionEngine(transactionTypeId);
1802
1795
  const { t } = useTranslation();
1803
1796
  const formRef = useRef(null);
1797
+ const createdTransactionIdRef = useRef(null);
1804
1798
  const attachmentRef = useRef();
1805
1799
  const sidesheetWidth = openStates?.width ?? 800;
1806
1800
  const transactionTypeEntry = transaction?.entityBusinessObject;
1801
+ const { enqueueSnackbar } = useSnackbar();
1802
+ const [{ data: transactionAttachmentTypes }, fetchTransactionAttachmentType] = useAxiosMutate(process.env.REACT_APP_PRODUCT_API_BASE, `UdpTransactionAttachmentType/search`, {
1803
+ method: "post",
1804
+ data: {
1805
+ pageSize: 50,
1806
+ filterElements: [{
1807
+ searchField: "TransactionTypeId",
1808
+ searchValue: transactionTypeId,
1809
+ searchOperator: "="
1810
+ }]
1811
+ }
1812
+ });
1807
1813
  const handleDialogClose = () => {
1808
1814
  setDialogOpen(false);
1809
1815
  };
1810
1816
  const handleUnsavedChangesDialogClose = () => {
1811
1817
  setUnsavedChangesDialogOpen(false);
1812
1818
  };
1819
+ const handleResetAttachmentState = useCallback((resetSavedAttachmentsState) => {
1820
+ if (resetSavedAttachmentsState) {
1821
+ setAttachmentType(null);
1822
+ setCurrentAttachments([]);
1823
+ }
1824
+ setAttachmentProgress(false);
1825
+ setTransactionAttachments([]);
1826
+ setFilePreview(false);
1827
+ }, []);
1813
1828
  const executeCloseTransaction = useCallback(async () => {
1814
1829
  if ((await apiMutate(ConfigService$1.productV1ApiUrl, `udpTransaction/${transaction?.transactionId}/closeTransaction`, { method: "post" }))?.status === 200) {
1815
1830
  handleSidesheet("edit", false);
@@ -1836,16 +1851,79 @@ const UdpTransactionSidesheet = (props) => {
1836
1851
  }
1837
1852
  }, [executeCloseTransaction, handleErrorSnackbar]);
1838
1853
  const formattedBusinesskey = transactionTypeEntry?.businessObjectKey?.split("|")?.pop();
1854
+ const handleTransactionCreationSuccess = useCallback((response) => {
1855
+ createdTransactionIdRef.current = response?.data?.transactionId ?? null;
1856
+ }, []);
1857
+ const handleFilesSelectedForUpload = useCallback(() => {
1858
+ setCreateTransactionOpenInnerSidesheetState({ attachments: false });
1859
+ enqueueSnackbar(`${currentAttachments.length} file(s) added for upload`, {
1860
+ variant: "success",
1861
+ anchorOrigin: {
1862
+ vertical: "top",
1863
+ horizontal: "center"
1864
+ }
1865
+ });
1866
+ }, [enqueueSnackbar, currentAttachments.length]);
1867
+ const handleUploadFilesForCreateTransaction = useCallback(async (transactionId) => {
1868
+ if (!currentAttachments.length) throw new Error("No files added for upload");
1869
+ const formData = new FormData();
1870
+ currentAttachments.forEach((file) => formData.append("files", file));
1871
+ formData.append("attachmentTypeId", attachmentType.transactionAttachmentTypeId);
1872
+ try {
1873
+ setAttachmentProgress(true);
1874
+ await apiMutate(ConfigService$1.productV1ApiUrl, `UdpTransactionAttachment/transaction/${transactionId}/upload`, {
1875
+ method: "post",
1876
+ headers: {
1877
+ transactionId,
1878
+ attachmentTypeId: attachmentType.transactionAttachmentTypeId
1879
+ },
1880
+ data: formData
1881
+ });
1882
+ setCurrentAttachments([]);
1883
+ setCreateTransactionOpenInnerSidesheetState({ attachments: false });
1884
+ enqueueSnackbar("Files uploaded successfully", {
1885
+ variant: "success",
1886
+ anchorOrigin: {
1887
+ vertical: "top",
1888
+ horizontal: "center"
1889
+ }
1890
+ });
1891
+ } catch (error) {
1892
+ enqueueSnackbar(`File upload failed: We encountered a system error. Please try again or contact support if the issue persists.`, {
1893
+ variant: "error",
1894
+ anchorOrigin: {
1895
+ vertical: "top",
1896
+ horizontal: "center"
1897
+ }
1898
+ });
1899
+ throw error;
1900
+ } finally {
1901
+ setAttachmentProgress(false);
1902
+ }
1903
+ }, [
1904
+ attachmentType,
1905
+ currentAttachments,
1906
+ enqueueSnackbar,
1907
+ setCurrentAttachments,
1908
+ setAttachmentProgress
1909
+ ]);
1839
1910
  const handleTransactionCreation = useCallback(async () => {
1840
1911
  setSidesheetLoading(true);
1912
+ createdTransactionIdRef.current = null;
1841
1913
  await formRef.current?.form?.submit();
1914
+ const newTransactionId = createdTransactionIdRef.current;
1915
+ if (newTransactionId && currentAttachments.length > 0) await handleUploadFilesForCreateTransaction(newTransactionId);
1842
1916
  setSidesheetLoading(false);
1843
1917
  handleSidesheet("add", false);
1918
+ handleResetAttachmentState(true);
1844
1919
  refreshGridData();
1845
1920
  }, [
1846
1921
  handleSidesheet,
1847
1922
  refreshGridData,
1848
- formRef
1923
+ formRef,
1924
+ handleResetAttachmentState,
1925
+ currentAttachments.length,
1926
+ handleUploadFilesForCreateTransaction
1849
1927
  ]);
1850
1928
  const handleCreateRevision = useCallback(async () => {
1851
1929
  setSidesheetLoading(true);
@@ -1890,16 +1968,53 @@ const UdpTransactionSidesheet = (props) => {
1890
1968
  return [
1891
1969
  {
1892
1970
  open: openStates.addTransaction,
1893
- closeSheet: () => handleSidesheet("add", false),
1971
+ closeSheet: () => {
1972
+ handleSidesheet("add", false);
1973
+ handleResetAttachmentState(true);
1974
+ },
1894
1975
  title: domainName,
1895
1976
  width: sidesheetWidth,
1896
1977
  onSubmit: handleTransactionCreation,
1897
- children: /* @__PURE__ */ React.createElement(UdpTransactionCustomPage_default, {
1978
+ children: /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(UdpTransactionCustomPage_default, {
1898
1979
  transactionTypeId,
1899
1980
  transactionUiActionType: TransactionUiActionTypeEnums.Render_Create_Transaction_Page,
1900
- formRef
1901
- }),
1902
- buttonLabel: "Add"
1981
+ formRef,
1982
+ onSubmitSuccess: handleTransactionCreationSuccess
1983
+ }), /* @__PURE__ */ React.createElement(SideSheet, {
1984
+ key: "Create Transaction: Add Attachment",
1985
+ open: createTransactionOpenInnerSidesheetState?.attachments,
1986
+ width: 600,
1987
+ title: t("Add Attachment"),
1988
+ onClose: () => {
1989
+ setCreateTransactionOpenInnerSidesheetState({ attachments: false });
1990
+ handleResetAttachmentState(true);
1991
+ },
1992
+ buttonLabel: t("Save"),
1993
+ buttonOneDisabled: !attachmentType || currentAttachments.length <= 0,
1994
+ onSubmit: handleFilesSelectedForUpload,
1995
+ color: "primary"
1996
+ }, /* @__PURE__ */ React.createElement(Attachments, {
1997
+ attachmentTypes: transactionAttachmentTypes,
1998
+ attachmentType,
1999
+ setAttachmentType,
2000
+ attachmentProgress,
2001
+ setAttachmentProgress,
2002
+ currentAttachments,
2003
+ setCurrentAttachments,
2004
+ transaction,
2005
+ previousAttachments: transactionAttachments,
2006
+ setPreviousAttachments: setTransactionAttachments,
2007
+ MAX_FILE_SIZE_MB,
2008
+ allowedExtensions,
2009
+ filePreview,
2010
+ setFilePreview
2011
+ }))),
2012
+ buttonLabel: "Add",
2013
+ buttonTwoLabel: /* @__PURE__ */ React.createElement(Badge, {
2014
+ badgeContent: currentAttachments?.length,
2015
+ color: "primary"
2016
+ }, "Add Attachment"),
2017
+ buttonTwoAction: () => setCreateTransactionOpenInnerSidesheetState({ attachments: true })
1903
2018
  },
1904
2019
  {
1905
2020
  open: openStates.viewTransaction,
@@ -1941,7 +2056,10 @@ const UdpTransactionSidesheet = (props) => {
1941
2056
  },
1942
2057
  {
1943
2058
  open: openStates.editTransaction,
1944
- closeSheet: () => handleSidesheet("edit", false),
2059
+ closeSheet: () => {
2060
+ handleSidesheet("edit", false);
2061
+ handleResetAttachmentState(true);
2062
+ },
1945
2063
  title: `Edit ${domainName} ${transactionLabel}`,
1946
2064
  width: sidesheetWidth,
1947
2065
  buttonLabel: "Next Steps",
@@ -1957,9 +2075,23 @@ const UdpTransactionSidesheet = (props) => {
1957
2075
  openInnerSidesheetState: editTransactionopenInnerSidesheetState,
1958
2076
  setOpenInnerSidesheetState: setEditTransactionOpenInnerSidesheetState,
1959
2077
  refreshGridData,
1960
- closeSideSheet: () => handleSidesheet("edit", false),
2078
+ closeSideSheet: () => {
2079
+ handleSidesheet("edit", false);
2080
+ handleResetAttachmentState(true);
2081
+ },
1961
2082
  setSidesheetLoading,
1962
- setHasUnsavedChanges
2083
+ setHasUnsavedChanges,
2084
+ attachmentType,
2085
+ setAttachmentType,
2086
+ currentAttachments,
2087
+ setCurrentAttachments,
2088
+ attachmentProgress,
2089
+ setAttachmentProgress,
2090
+ transactionAttachmentTypes,
2091
+ transactionAttachments,
2092
+ setTransactionAttachments,
2093
+ filePreview,
2094
+ setFilePreview
1963
2095
  })
1964
2096
  },
1965
2097
  {
@@ -1989,13 +2121,42 @@ const UdpTransactionSidesheet = (props) => {
1989
2121
  refreshGridData,
1990
2122
  transactionTypeId,
1991
2123
  handleTransactionCreation,
2124
+ handleTransactionCreationSuccess,
1992
2125
  hasClosedStatus,
1993
2126
  handleCreateRevision,
1994
2127
  transactionIsClosed,
1995
2128
  viewTransactionPage,
1996
2129
  pdfViewPageId,
1997
2130
  sidesheetWidth,
1998
- handleNextStepsAction
2131
+ handleNextStepsAction,
2132
+ createTransactionOpenInnerSidesheetState,
2133
+ t,
2134
+ attachmentType,
2135
+ setAttachmentType,
2136
+ currentAttachments,
2137
+ setCurrentAttachments,
2138
+ attachmentProgress,
2139
+ setAttachmentProgress,
2140
+ transactionAttachmentTypes,
2141
+ transactionAttachments,
2142
+ setTransactionAttachments,
2143
+ filePreview,
2144
+ setFilePreview,
2145
+ handleResetAttachmentState,
2146
+ handleFilesSelectedForUpload
2147
+ ]);
2148
+ useEffect(() => {
2149
+ if ((openStates?.addTransaction || openStates?.editTransaction) && !transactionAttachmentTypes) {
2150
+ setAttachmentProgress(true);
2151
+ fetchTransactionAttachmentType().then(() => {
2152
+ setAttachmentProgress(false);
2153
+ });
2154
+ }
2155
+ }, [
2156
+ fetchTransactionAttachmentType,
2157
+ transactionAttachmentTypes,
2158
+ openStates.addTransaction,
2159
+ openStates.editTransaction
1999
2160
  ]);
2000
2161
  return /* @__PURE__ */ React.createElement(React.Fragment, null, openStates && sidesheetList.map((item) => {
2001
2162
  return /* @__PURE__ */ React.createElement(SideSheet, {
@@ -2266,4 +2427,4 @@ var UdpTransactionsPage_exports = /* @__PURE__ */ __exportAll({ default: () => U
2266
2427
 
2267
2428
  //#endregion
2268
2429
  export { UdpTransactionsPage_default as n, UdpTransactionsPage_exports as t };
2269
- //# sourceMappingURL=UdpTransactionsPage-Dr3XbvFa.js.map
2430
+ //# sourceMappingURL=UdpTransactionsPage-CRGdk2Mv.js.map