@salesgenterp/ui-components 0.4.548 → 0.4.549

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.
@@ -1,7 +1,7 @@
1
1
  import { Skeleton as Skeleton$1, CircularProgress, TextField, Button, IconButton, Stack, Typography, Grid, InputAdornment, Popover, TableHead, TableRow, TableSortLabel, Paper, TableContainer as TableContainer$3, Table, TableBody, TableCell, TablePagination, Dialog, DialogContent, DialogActions, DialogTitle, RadioGroup, Radio, FormControlLabel, FormLabel, FormControl, FormHelperText, Select as Select$1, InputLabel, MenuItem, CardMedia, Divider, Tabs, Box, Tab, CardContent, ListItemIcon, ListItem, Collapse, List, ListItemText, Checkbox as Checkbox$1, Card as Card$1, CardHeader, CssBaseline, Toolbar, Drawer, useMediaQuery as useMediaQuery$1, Pagination, Tooltip, CardActionArea, Avatar as Avatar$1, alpha, Stepper, Step, StepLabel, StepContent, Container as Container$4 } from '@mui/material';
2
2
  import { styled as styled$1 } from '@mui/material/styles';
3
3
  import useMediaQuery from '@mui/material/useMediaQuery';
4
- import React__default, { useState, useEffect, forwardRef, createElement, useCallback, memo, Fragment as Fragment$1, useRef, useMemo } from 'react';
4
+ import React__default, { useState, useEffect, forwardRef, useRef, useCallback, createElement, memo, Fragment as Fragment$1, useMemo } from 'react';
5
5
  import { MdVisibilityOff, MdVisibility, MdClose, MdMonetizationOn, MdOutlineStorefront, MdRemoveRedEye, MdOutlineFileDownload, MdPersonOutline, MdOutlineCall, MdMailOutline, MdExpandMore, MdExpandLess, MdStore, MdOutlineMenuOpen, MdMenu, MdDarkMode, MdOutlineDarkMode, MdDelete, MdCheckCircle, MdArrowBack, MdOutlineCircle, MdOutlineStickyNote2, MdOutlineNumbers, MdDateRange, MdOutlineWarehouse } from 'react-icons/md';
6
6
  import styled, { css, ThemeProvider } from 'styled-components';
7
7
  import { isEmpty, isString, toNumber, reduce, concat, omit, replace, template, isArray, some, toLower, isPlainObject, includes, values, cloneDeep, filter, sortBy, isObject, sumBy, get, isNumber, remove } from 'lodash';
@@ -26,6 +26,7 @@ import { LocalizationProvider } from '@mui/x-date-pickers';
26
26
  import moment$1 from 'moment/moment';
27
27
  import { useRouter } from 'next/router';
28
28
  import Cards from 'react-credit-cards';
29
+ import { PDFViewer } from '@embedpdf/react-pdf-viewer';
29
30
  import { HiOutlineLocationMarker, HiOutlineChevronDown } from 'react-icons/hi';
30
31
  import { BsFileEarmarkImage, BsFileEarmarkPdf, BsCartX } from 'react-icons/bs';
31
32
  import { TfiMenuAlt } from 'react-icons/tfi';
@@ -2830,6 +2831,285 @@ var InfoContainer = styled.div(_templateObject$9 || (_templateObject$9 = _tagged
2830
2831
  return props.fontColor;
2831
2832
  });
2832
2833
 
2834
+ var DISABLED_CATEGORIES = ['annotation', 'annotation-shape', 'insert', 'form', 'redaction', 'panel-search', 'panel-comment', 'document-open', 'document-close', 'document-export', 'document-capture', 'document-protect'];
2835
+ var EMPTY_UNSUBSCRIBERS = [];
2836
+ var LOAD_TIMEOUT_MS = 20000;
2837
+ var DEFAULT_ERROR_MESSAGE = 'Unable to load this PDF. Please try again later.';
2838
+ var safeCall = function safeCall(fn) {
2839
+ try {
2840
+ return typeof fn === 'function' ? fn() : undefined;
2841
+ } catch (error) {
2842
+ console.error('[ViewPdf]', error);
2843
+ return undefined;
2844
+ }
2845
+ };
2846
+ var clearSubscriptions = function clearSubscriptions(unsubscribersRef) {
2847
+ var list = unsubscribersRef === null || unsubscribersRef === void 0 ? void 0 : unsubscribersRef.current;
2848
+ if (!Array.isArray(list)) return;
2849
+ list.forEach(function (unsubscribe) {
2850
+ safeCall(unsubscribe);
2851
+ });
2852
+ unsubscribersRef.current = [];
2853
+ };
2854
+ var hideEmptyStateOpenButton = function hideEmptyStateOpenButton(container) {
2855
+ try {
2856
+ var shadow = container === null || container === void 0 ? void 0 : container.shadowRoot;
2857
+ if (!shadow || typeof CSSStyleSheet === 'undefined') return;
2858
+ if (typeof shadow.adoptedStyleSheets === 'undefined') return;
2859
+ var sheet = new CSSStyleSheet();
2860
+ if (typeof (sheet === null || sheet === void 0 ? void 0 : sheet.replaceSync) !== 'function') return;
2861
+ sheet.replaceSync("\n button[aria-label=\"Open File\"],\n button[aria-label=\"Open Document\"],\n button[aria-label*=\"Open Document\"],\n button.bg-accent.inline-flex {\n display: none !important;\n pointer-events: none !important;\n }\n p.text-fg-muted.mt-4.text-xs {\n display: none !important;\n }\n ");
2862
+ var existingSheets = Array.isArray(shadow.adoptedStyleSheets) ? shadow.adoptedStyleSheets : [];
2863
+ shadow.adoptedStyleSheets = [].concat(existingSheets, [sheet]);
2864
+ } catch (error) {
2865
+ console.error('[ViewPdf] Failed to hide open-document UI', error);
2866
+ }
2867
+ };
2868
+ var viewerShellStyle = {
2869
+ position: 'relative',
2870
+ width: '100%',
2871
+ minWidth: 900,
2872
+ minHeight: 600,
2873
+ height: '70vh',
2874
+ boxSizing: 'border-box'
2875
+ };
2876
+ var overlayStyle = {
2877
+ position: 'absolute',
2878
+ inset: 0,
2879
+ zIndex: 2,
2880
+ display: 'flex',
2881
+ flexDirection: 'column',
2882
+ alignItems: 'center',
2883
+ justifyContent: 'center',
2884
+ gap: '0.75rem',
2885
+ background: '#f4f5f7',
2886
+ color: '#4b5563',
2887
+ fontSize: '0.95rem',
2888
+ fontWeight: 600,
2889
+ padding: '1.5rem',
2890
+ textAlign: 'center',
2891
+ boxSizing: 'border-box'
2892
+ };
2893
+ var closeButtonStyle = {
2894
+ marginTop: '0.5rem',
2895
+ padding: '0.5rem 1rem',
2896
+ border: '1px solid #d1d5db',
2897
+ borderRadius: 6,
2898
+ background: '#fff',
2899
+ color: '#374151',
2900
+ fontSize: '0.875rem',
2901
+ fontWeight: 600,
2902
+ cursor: 'pointer'
2903
+ };
2904
+ var getErrorMessage = function getErrorMessage(error) {
2905
+ var _error$reason;
2906
+ if (typeof error === 'string' && error.trim()) return error.trim();
2907
+ if (error !== null && error !== void 0 && error.message && typeof error.message === 'string' && error.message.trim()) {
2908
+ return error.message.trim();
2909
+ }
2910
+ if (error !== null && error !== void 0 && (_error$reason = error.reason) !== null && _error$reason !== void 0 && _error$reason.message && typeof error.reason.message === 'string' && error.reason.message.trim()) {
2911
+ return error.reason.message.trim();
2912
+ }
2913
+ if (typeof (error === null || error === void 0 ? void 0 : error.reason) === 'string' && error.reason.trim()) {
2914
+ return error.reason.trim();
2915
+ }
2916
+ return DEFAULT_ERROR_MESSAGE;
2917
+ };
2918
+ var syncDocumentStates = function syncDocumentStates(documentManager, onLoaded, onError) {
2919
+ var documents = typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.getOpenDocuments) === 'function' ? documentManager.getOpenDocuments() : [];
2920
+ if (!Array.isArray(documents) || documents.length === 0) return false;
2921
+ var errored = documents.find(function (doc) {
2922
+ return (doc === null || doc === void 0 ? void 0 : doc.status) === 'error';
2923
+ });
2924
+ if (errored) {
2925
+ onError((errored === null || errored === void 0 ? void 0 : errored.error) || DEFAULT_ERROR_MESSAGE);
2926
+ return true;
2927
+ }
2928
+ var loaded = documents.find(function (doc) {
2929
+ return (doc === null || doc === void 0 ? void 0 : doc.status) === 'loaded';
2930
+ });
2931
+ if (loaded) {
2932
+ onLoaded();
2933
+ return true;
2934
+ }
2935
+ return false;
2936
+ };
2937
+ var ViewPdf = function ViewPdf(_ref) {
2938
+ var _ref$src = _ref.src,
2939
+ src = _ref$src === void 0 ? '' : _ref$src,
2940
+ onRequestClose = _ref.onRequestClose;
2941
+ var _useState = useState(Boolean(src)),
2942
+ isLoading = _useState[0],
2943
+ setIsLoading = _useState[1];
2944
+ var _useState2 = useState(''),
2945
+ loadError = _useState2[0],
2946
+ setLoadError = _useState2[1];
2947
+ var hadLoadErrorRef = useRef(false);
2948
+ var isMountedRef = useRef(true);
2949
+ var loadFinishedRef = useRef(false);
2950
+ var unsubscribersRef = useRef(EMPTY_UNSUBSCRIBERS);
2951
+ var timeoutRef = useRef(null);
2952
+ var pdfSrc = typeof src === 'string' ? src.trim() : '';
2953
+ var clearLoadTimeout = useCallback(function () {
2954
+ if (timeoutRef.current) {
2955
+ clearTimeout(timeoutRef.current);
2956
+ timeoutRef.current = null;
2957
+ }
2958
+ }, []);
2959
+ useEffect(function () {
2960
+ isMountedRef.current = true;
2961
+ return function () {
2962
+ isMountedRef.current = false;
2963
+ clearLoadTimeout();
2964
+ clearSubscriptions(unsubscribersRef);
2965
+ };
2966
+ }, [clearLoadTimeout]);
2967
+ useEffect(function () {
2968
+ hadLoadErrorRef.current = false;
2969
+ loadFinishedRef.current = false;
2970
+ clearLoadTimeout();
2971
+ setLoadError('');
2972
+ setIsLoading(Boolean(pdfSrc));
2973
+ }, [pdfSrc, clearLoadTimeout]);
2974
+ var finishWithError = useCallback(function (error) {
2975
+ if (loadFinishedRef.current || !isMountedRef.current) return;
2976
+ loadFinishedRef.current = true;
2977
+ clearLoadTimeout();
2978
+ hadLoadErrorRef.current = true;
2979
+ setIsLoading(false);
2980
+ setLoadError(getErrorMessage(error));
2981
+ }, [clearLoadTimeout]);
2982
+ var finishWithSuccess = useCallback(function () {
2983
+ if (loadFinishedRef.current || !isMountedRef.current) return;
2984
+ loadFinishedRef.current = true;
2985
+ clearLoadTimeout();
2986
+ hadLoadErrorRef.current = false;
2987
+ setLoadError('');
2988
+ setIsLoading(false);
2989
+ }, [clearLoadTimeout]);
2990
+ var handleInit = useCallback(function (container) {
2991
+ hideEmptyStateOpenButton(container);
2992
+ }, []);
2993
+ var handleReady = useCallback(function (registry) {
2994
+ try {
2995
+ var _registry$getPlugin, _registry$getPlugin$c, _registry$getPlugin$c2;
2996
+ clearSubscriptions(unsubscribersRef);
2997
+ loadFinishedRef.current = false;
2998
+ clearLoadTimeout();
2999
+ var documentManager = registry === null || registry === void 0 ? void 0 : (_registry$getPlugin = registry.getPlugin) === null || _registry$getPlugin === void 0 ? void 0 : (_registry$getPlugin$c = _registry$getPlugin.call(registry, 'document-manager')) === null || _registry$getPlugin$c === void 0 ? void 0 : (_registry$getPlugin$c2 = _registry$getPlugin$c.provides) === null || _registry$getPlugin$c2 === void 0 ? void 0 : _registry$getPlugin$c2.call(_registry$getPlugin$c);
3000
+ if (!documentManager) {
3001
+ finishWithError('Unable to initialize the PDF viewer.');
3002
+ return;
3003
+ }
3004
+ var trackUnsubscribe = function trackUnsubscribe(unsubscribe) {
3005
+ if (typeof unsubscribe !== 'function') return;
3006
+ if (!Array.isArray(unsubscribersRef === null || unsubscribersRef === void 0 ? void 0 : unsubscribersRef.current)) {
3007
+ unsubscribersRef.current = [];
3008
+ }
3009
+ unsubscribersRef.current.push(unsubscribe);
3010
+ };
3011
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentError) === 'function') {
3012
+ trackUnsubscribe(documentManager.onDocumentError(function (error) {
3013
+ finishWithError(error);
3014
+ }));
3015
+ }
3016
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentOpened) === 'function') {
3017
+ trackUnsubscribe(documentManager.onDocumentOpened(function () {
3018
+ finishWithSuccess();
3019
+ }));
3020
+ }
3021
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentClosed) === 'function') {
3022
+ trackUnsubscribe(documentManager.onDocumentClosed(function () {
3023
+ if (!(hadLoadErrorRef !== null && hadLoadErrorRef !== void 0 && hadLoadErrorRef.current)) return;
3024
+ hadLoadErrorRef.current = false;
3025
+ if (typeof onRequestClose === 'function') {
3026
+ safeCall(onRequestClose);
3027
+ }
3028
+ }));
3029
+ }
3030
+ if (syncDocumentStates(documentManager, finishWithSuccess, finishWithError)) {
3031
+ return;
3032
+ }
3033
+ if (!pdfSrc || typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.openDocumentUrl) !== 'function') {
3034
+ finishWithError('No PDF document provided.');
3035
+ return;
3036
+ }
3037
+ timeoutRef.current = setTimeout(function () {
3038
+ finishWithError('The PDF is taking too long to load. Please try again later.');
3039
+ }, LOAD_TIMEOUT_MS);
3040
+ var openTask = documentManager.openDocumentUrl({
3041
+ url: pdfSrc,
3042
+ autoActivate: true
3043
+ });
3044
+ if (!openTask || typeof openTask.wait !== 'function') {
3045
+ finishWithError(DEFAULT_ERROR_MESSAGE);
3046
+ return;
3047
+ }
3048
+ openTask.wait(function (response) {
3049
+ var loadTask = response === null || response === void 0 ? void 0 : response.task;
3050
+ if (!loadTask || typeof loadTask.wait !== 'function') {
3051
+ syncDocumentStates(documentManager, finishWithSuccess, finishWithError);
3052
+ return;
3053
+ }
3054
+ loadTask.wait(function () {
3055
+ finishWithSuccess();
3056
+ }, function (error) {
3057
+ finishWithError(error);
3058
+ });
3059
+ }, function (error) {
3060
+ finishWithError(error);
3061
+ });
3062
+ } catch (error) {
3063
+ console.error('[ViewPdf] Failed during viewer ready setup', error);
3064
+ finishWithError(error);
3065
+ }
3066
+ }, [clearLoadTimeout, finishWithError, finishWithSuccess, onRequestClose, pdfSrc]);
3067
+ if (!pdfSrc) {
3068
+ return /*#__PURE__*/React__default.createElement("div", {
3069
+ style: _extends({}, viewerShellStyle, overlayStyle, {
3070
+ position: 'relative'
3071
+ })
3072
+ }, /*#__PURE__*/React__default.createElement("span", null, "No PDF document provided."), typeof onRequestClose === 'function' ? /*#__PURE__*/React__default.createElement("button", {
3073
+ type: "button",
3074
+ style: closeButtonStyle,
3075
+ onClick: onRequestClose
3076
+ }, "Close") : null);
3077
+ }
3078
+ return /*#__PURE__*/React__default.createElement("div", {
3079
+ style: viewerShellStyle
3080
+ }, isLoading ? /*#__PURE__*/React__default.createElement("div", {
3081
+ style: overlayStyle,
3082
+ "aria-live": "polite",
3083
+ "aria-busy": "true"
3084
+ }, /*#__PURE__*/React__default.createElement(CircularProgress, {
3085
+ size: 28
3086
+ }), /*#__PURE__*/React__default.createElement("span", null, "Loading...")) : null, loadError ? /*#__PURE__*/React__default.createElement("div", {
3087
+ style: overlayStyle,
3088
+ role: "alert",
3089
+ "aria-live": "assertive"
3090
+ }, /*#__PURE__*/React__default.createElement("span", null, loadError), typeof onRequestClose === 'function' ? /*#__PURE__*/React__default.createElement("button", {
3091
+ type: "button",
3092
+ style: closeButtonStyle,
3093
+ onClick: onRequestClose
3094
+ }, "Close") : null) : null, /*#__PURE__*/React__default.createElement(PDFViewer, {
3095
+ key: pdfSrc,
3096
+ style: {
3097
+ height: '100%',
3098
+ width: '100%',
3099
+ minHeight: 600
3100
+ },
3101
+ onInit: handleInit,
3102
+ onReady: handleReady,
3103
+ config: {
3104
+ theme: {
3105
+ preference: 'light'
3106
+ },
3107
+ tabBar: 'never',
3108
+ disabledCategories: DISABLED_CATEGORIES
3109
+ }
3110
+ }));
3111
+ };
3112
+
2833
3113
  var _templateObject$a, _templateObject2$5, _templateObject3$3, _templateObject4$2, _templateObject5$1, _templateObject6$1, _templateObject7$1, _templateObject8$1, _templateObject9$1, _templateObject10$1, _templateObject11$1, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18, _templateObject19;
2834
3114
  var totalIcons = [{
2835
3115
  name: '',
@@ -2873,7 +3153,8 @@ var Dashboard = function Dashboard(_ref) {
2873
3153
  showOnlyRecentOrder = _ref$showOnlyRecentOr === void 0 ? false : _ref$showOnlyRecentOr,
2874
3154
  hidePayActionButton = _ref.hidePayActionButton,
2875
3155
  hideInvoiceTab = _ref.hideInvoiceTab,
2876
- hideSalesOrderTab = _ref.hideSalesOrderTab;
3156
+ hideSalesOrderTab = _ref.hideSalesOrderTab,
3157
+ showPdfViewer = _ref.showPdfViewer;
2877
3158
  var _useState = useState({}),
2878
3159
  customerData = _useState[0],
2879
3160
  setCustomerData = _useState[1];
@@ -3324,8 +3605,15 @@ var Dashboard = function Dashboard(_ref) {
3324
3605
  maxWidth: "lg"
3325
3606
  }, /*#__PURE__*/React__default.createElement(DialogContent, {
3326
3607
  dividers: true
3327
- }, /*#__PURE__*/React__default.createElement("iframe", {
3328
- src: invoiceModal.url
3608
+ }, showPdfViewer ? /*#__PURE__*/React__default.createElement(ViewPdf, {
3609
+ src: invoiceModal === null || invoiceModal === void 0 ? void 0 : invoiceModal.url,
3610
+ onRequestClose: function onRequestClose() {
3611
+ return setInvoiceModal({
3612
+ open: false
3613
+ });
3614
+ }
3615
+ }) : /*#__PURE__*/React__default.createElement("iframe", {
3616
+ src: invoiceModal === null || invoiceModal === void 0 ? void 0 : invoiceModal.url
3329
3617
  }))), /*#__PURE__*/React__default.createElement(APITable, {
3330
3618
  key: value,
3331
3619
  cacheFilters: true,
@@ -3592,7 +3880,7 @@ var StatusContainer = styled(Stack)(_templateObject16 || (_templateObject16 = _t
3592
3880
  return props.primaryColor;
3593
3881
  });
3594
3882
  var TableContainer = styled.div(_templateObject17 || (_templateObject17 = _taggedTemplateLiteralLoose(["\n margin-top: 2rem;\n border-radius: 14px;\n"])));
3595
- var InvoiceDialog = styled(Dialog)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteralLoose(["\n iframe {\n width: 900px;\n border: none;\n height: 600px;\n }\n"])));
3883
+ var InvoiceDialog = styled(Dialog)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteralLoose(["\n .MuiDialog-paper {\n width: 100%;\n max-width: 900px;\n }\n\n iframe {\n width: 900px;\n max-width: 100%;\n border: none;\n height: 600px;\n }\n"])));
3596
3884
  var TabsContainer = styled(Tabs)(_templateObject19 || (_templateObject19 = _taggedTemplateLiteralLoose(["\n button {\n color: ", " !important;\n font-size: 1.1rem;\n font-weight: 600;\n }\n .Mui-selected {\n color: ", " !important;\n }\n .MuiTabs-indicator {\n background-color: ", " !important;\n }\n"])), function (props) {
3597
3885
  return props.fontColor;
3598
3886
  }, function (props) {
@@ -5296,7 +5584,9 @@ var AccountDetails = function AccountDetails(_ref) {
5296
5584
  _ref$hideSalesOrderTa = _ref.hideSalesOrderTab,
5297
5585
  hideSalesOrderTab = _ref$hideSalesOrderTa === void 0 ? false : _ref$hideSalesOrderTa,
5298
5586
  _ref$hideInvoiceTab = _ref.hideInvoiceTab,
5299
- hideInvoiceTab = _ref$hideInvoiceTab === void 0 ? false : _ref$hideInvoiceTab;
5587
+ hideInvoiceTab = _ref$hideInvoiceTab === void 0 ? false : _ref$hideInvoiceTab,
5588
+ _ref$showPdfViewer = _ref.showPdfViewer,
5589
+ showPdfViewer = _ref$showPdfViewer === void 0 ? false : _ref$showPdfViewer;
5300
5590
  var _useAllSystemFeatureV = useAllSystemFeatureValues({
5301
5591
  apiEndPoint: apiEndPoint,
5302
5592
  token: token
@@ -5469,7 +5759,8 @@ var AccountDetails = function AccountDetails(_ref) {
5469
5759
  showOnlyRecentOrder: showOnlyRecentOrder,
5470
5760
  hidePayActionButton: hidePayActionButton,
5471
5761
  hideSalesOrderTab: hideSalesOrderTab,
5472
- hideInvoiceTab: hideInvoiceTab
5762
+ hideInvoiceTab: hideInvoiceTab,
5763
+ showPdfViewer: showPdfViewer
5473
5764
  });
5474
5765
  case 'myProfile':
5475
5766
  return /*#__PURE__*/React__default.createElement(MyProfile, {