@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.
package/dist/index.js CHANGED
@@ -30,6 +30,7 @@ var xDatePickers = require('@mui/x-date-pickers');
30
30
  var moment$1 = _interopDefault(require('moment/moment'));
31
31
  var router = require('next/router');
32
32
  var Cards = _interopDefault(require('react-credit-cards'));
33
+ var reactPdfViewer = require('@embedpdf/react-pdf-viewer');
33
34
  var hi = require('react-icons/hi');
34
35
  var bs = require('react-icons/bs');
35
36
  var tfi = require('react-icons/tfi');
@@ -2834,6 +2835,285 @@ var InfoContainer = styled__default.div(_templateObject$9 || (_templateObject$9
2834
2835
  return props.fontColor;
2835
2836
  });
2836
2837
 
2838
+ var DISABLED_CATEGORIES = ['annotation', 'annotation-shape', 'insert', 'form', 'redaction', 'panel-search', 'panel-comment', 'document-open', 'document-close', 'document-export', 'document-capture', 'document-protect'];
2839
+ var EMPTY_UNSUBSCRIBERS = [];
2840
+ var LOAD_TIMEOUT_MS = 20000;
2841
+ var DEFAULT_ERROR_MESSAGE = 'Unable to load this PDF. Please try again later.';
2842
+ var safeCall = function safeCall(fn) {
2843
+ try {
2844
+ return typeof fn === 'function' ? fn() : undefined;
2845
+ } catch (error) {
2846
+ console.error('[ViewPdf]', error);
2847
+ return undefined;
2848
+ }
2849
+ };
2850
+ var clearSubscriptions = function clearSubscriptions(unsubscribersRef) {
2851
+ var list = unsubscribersRef === null || unsubscribersRef === void 0 ? void 0 : unsubscribersRef.current;
2852
+ if (!Array.isArray(list)) return;
2853
+ list.forEach(function (unsubscribe) {
2854
+ safeCall(unsubscribe);
2855
+ });
2856
+ unsubscribersRef.current = [];
2857
+ };
2858
+ var hideEmptyStateOpenButton = function hideEmptyStateOpenButton(container) {
2859
+ try {
2860
+ var shadow = container === null || container === void 0 ? void 0 : container.shadowRoot;
2861
+ if (!shadow || typeof CSSStyleSheet === 'undefined') return;
2862
+ if (typeof shadow.adoptedStyleSheets === 'undefined') return;
2863
+ var sheet = new CSSStyleSheet();
2864
+ if (typeof (sheet === null || sheet === void 0 ? void 0 : sheet.replaceSync) !== 'function') return;
2865
+ 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 ");
2866
+ var existingSheets = Array.isArray(shadow.adoptedStyleSheets) ? shadow.adoptedStyleSheets : [];
2867
+ shadow.adoptedStyleSheets = [].concat(existingSheets, [sheet]);
2868
+ } catch (error) {
2869
+ console.error('[ViewPdf] Failed to hide open-document UI', error);
2870
+ }
2871
+ };
2872
+ var viewerShellStyle = {
2873
+ position: 'relative',
2874
+ width: '100%',
2875
+ minWidth: 900,
2876
+ minHeight: 600,
2877
+ height: '70vh',
2878
+ boxSizing: 'border-box'
2879
+ };
2880
+ var overlayStyle = {
2881
+ position: 'absolute',
2882
+ inset: 0,
2883
+ zIndex: 2,
2884
+ display: 'flex',
2885
+ flexDirection: 'column',
2886
+ alignItems: 'center',
2887
+ justifyContent: 'center',
2888
+ gap: '0.75rem',
2889
+ background: '#f4f5f7',
2890
+ color: '#4b5563',
2891
+ fontSize: '0.95rem',
2892
+ fontWeight: 600,
2893
+ padding: '1.5rem',
2894
+ textAlign: 'center',
2895
+ boxSizing: 'border-box'
2896
+ };
2897
+ var closeButtonStyle = {
2898
+ marginTop: '0.5rem',
2899
+ padding: '0.5rem 1rem',
2900
+ border: '1px solid #d1d5db',
2901
+ borderRadius: 6,
2902
+ background: '#fff',
2903
+ color: '#374151',
2904
+ fontSize: '0.875rem',
2905
+ fontWeight: 600,
2906
+ cursor: 'pointer'
2907
+ };
2908
+ var getErrorMessage = function getErrorMessage(error) {
2909
+ var _error$reason;
2910
+ if (typeof error === 'string' && error.trim()) return error.trim();
2911
+ if (error !== null && error !== void 0 && error.message && typeof error.message === 'string' && error.message.trim()) {
2912
+ return error.message.trim();
2913
+ }
2914
+ 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()) {
2915
+ return error.reason.message.trim();
2916
+ }
2917
+ if (typeof (error === null || error === void 0 ? void 0 : error.reason) === 'string' && error.reason.trim()) {
2918
+ return error.reason.trim();
2919
+ }
2920
+ return DEFAULT_ERROR_MESSAGE;
2921
+ };
2922
+ var syncDocumentStates = function syncDocumentStates(documentManager, onLoaded, onError) {
2923
+ var documents = typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.getOpenDocuments) === 'function' ? documentManager.getOpenDocuments() : [];
2924
+ if (!Array.isArray(documents) || documents.length === 0) return false;
2925
+ var errored = documents.find(function (doc) {
2926
+ return (doc === null || doc === void 0 ? void 0 : doc.status) === 'error';
2927
+ });
2928
+ if (errored) {
2929
+ onError((errored === null || errored === void 0 ? void 0 : errored.error) || DEFAULT_ERROR_MESSAGE);
2930
+ return true;
2931
+ }
2932
+ var loaded = documents.find(function (doc) {
2933
+ return (doc === null || doc === void 0 ? void 0 : doc.status) === 'loaded';
2934
+ });
2935
+ if (loaded) {
2936
+ onLoaded();
2937
+ return true;
2938
+ }
2939
+ return false;
2940
+ };
2941
+ var ViewPdf = function ViewPdf(_ref) {
2942
+ var _ref$src = _ref.src,
2943
+ src = _ref$src === void 0 ? '' : _ref$src,
2944
+ onRequestClose = _ref.onRequestClose;
2945
+ var _useState = React.useState(Boolean(src)),
2946
+ isLoading = _useState[0],
2947
+ setIsLoading = _useState[1];
2948
+ var _useState2 = React.useState(''),
2949
+ loadError = _useState2[0],
2950
+ setLoadError = _useState2[1];
2951
+ var hadLoadErrorRef = React.useRef(false);
2952
+ var isMountedRef = React.useRef(true);
2953
+ var loadFinishedRef = React.useRef(false);
2954
+ var unsubscribersRef = React.useRef(EMPTY_UNSUBSCRIBERS);
2955
+ var timeoutRef = React.useRef(null);
2956
+ var pdfSrc = typeof src === 'string' ? src.trim() : '';
2957
+ var clearLoadTimeout = React.useCallback(function () {
2958
+ if (timeoutRef.current) {
2959
+ clearTimeout(timeoutRef.current);
2960
+ timeoutRef.current = null;
2961
+ }
2962
+ }, []);
2963
+ React.useEffect(function () {
2964
+ isMountedRef.current = true;
2965
+ return function () {
2966
+ isMountedRef.current = false;
2967
+ clearLoadTimeout();
2968
+ clearSubscriptions(unsubscribersRef);
2969
+ };
2970
+ }, [clearLoadTimeout]);
2971
+ React.useEffect(function () {
2972
+ hadLoadErrorRef.current = false;
2973
+ loadFinishedRef.current = false;
2974
+ clearLoadTimeout();
2975
+ setLoadError('');
2976
+ setIsLoading(Boolean(pdfSrc));
2977
+ }, [pdfSrc, clearLoadTimeout]);
2978
+ var finishWithError = React.useCallback(function (error) {
2979
+ if (loadFinishedRef.current || !isMountedRef.current) return;
2980
+ loadFinishedRef.current = true;
2981
+ clearLoadTimeout();
2982
+ hadLoadErrorRef.current = true;
2983
+ setIsLoading(false);
2984
+ setLoadError(getErrorMessage(error));
2985
+ }, [clearLoadTimeout]);
2986
+ var finishWithSuccess = React.useCallback(function () {
2987
+ if (loadFinishedRef.current || !isMountedRef.current) return;
2988
+ loadFinishedRef.current = true;
2989
+ clearLoadTimeout();
2990
+ hadLoadErrorRef.current = false;
2991
+ setLoadError('');
2992
+ setIsLoading(false);
2993
+ }, [clearLoadTimeout]);
2994
+ var handleInit = React.useCallback(function (container) {
2995
+ hideEmptyStateOpenButton(container);
2996
+ }, []);
2997
+ var handleReady = React.useCallback(function (registry) {
2998
+ try {
2999
+ var _registry$getPlugin, _registry$getPlugin$c, _registry$getPlugin$c2;
3000
+ clearSubscriptions(unsubscribersRef);
3001
+ loadFinishedRef.current = false;
3002
+ clearLoadTimeout();
3003
+ 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);
3004
+ if (!documentManager) {
3005
+ finishWithError('Unable to initialize the PDF viewer.');
3006
+ return;
3007
+ }
3008
+ var trackUnsubscribe = function trackUnsubscribe(unsubscribe) {
3009
+ if (typeof unsubscribe !== 'function') return;
3010
+ if (!Array.isArray(unsubscribersRef === null || unsubscribersRef === void 0 ? void 0 : unsubscribersRef.current)) {
3011
+ unsubscribersRef.current = [];
3012
+ }
3013
+ unsubscribersRef.current.push(unsubscribe);
3014
+ };
3015
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentError) === 'function') {
3016
+ trackUnsubscribe(documentManager.onDocumentError(function (error) {
3017
+ finishWithError(error);
3018
+ }));
3019
+ }
3020
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentOpened) === 'function') {
3021
+ trackUnsubscribe(documentManager.onDocumentOpened(function () {
3022
+ finishWithSuccess();
3023
+ }));
3024
+ }
3025
+ if (typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.onDocumentClosed) === 'function') {
3026
+ trackUnsubscribe(documentManager.onDocumentClosed(function () {
3027
+ if (!(hadLoadErrorRef !== null && hadLoadErrorRef !== void 0 && hadLoadErrorRef.current)) return;
3028
+ hadLoadErrorRef.current = false;
3029
+ if (typeof onRequestClose === 'function') {
3030
+ safeCall(onRequestClose);
3031
+ }
3032
+ }));
3033
+ }
3034
+ if (syncDocumentStates(documentManager, finishWithSuccess, finishWithError)) {
3035
+ return;
3036
+ }
3037
+ if (!pdfSrc || typeof (documentManager === null || documentManager === void 0 ? void 0 : documentManager.openDocumentUrl) !== 'function') {
3038
+ finishWithError('No PDF document provided.');
3039
+ return;
3040
+ }
3041
+ timeoutRef.current = setTimeout(function () {
3042
+ finishWithError('The PDF is taking too long to load. Please try again later.');
3043
+ }, LOAD_TIMEOUT_MS);
3044
+ var openTask = documentManager.openDocumentUrl({
3045
+ url: pdfSrc,
3046
+ autoActivate: true
3047
+ });
3048
+ if (!openTask || typeof openTask.wait !== 'function') {
3049
+ finishWithError(DEFAULT_ERROR_MESSAGE);
3050
+ return;
3051
+ }
3052
+ openTask.wait(function (response) {
3053
+ var loadTask = response === null || response === void 0 ? void 0 : response.task;
3054
+ if (!loadTask || typeof loadTask.wait !== 'function') {
3055
+ syncDocumentStates(documentManager, finishWithSuccess, finishWithError);
3056
+ return;
3057
+ }
3058
+ loadTask.wait(function () {
3059
+ finishWithSuccess();
3060
+ }, function (error) {
3061
+ finishWithError(error);
3062
+ });
3063
+ }, function (error) {
3064
+ finishWithError(error);
3065
+ });
3066
+ } catch (error) {
3067
+ console.error('[ViewPdf] Failed during viewer ready setup', error);
3068
+ finishWithError(error);
3069
+ }
3070
+ }, [clearLoadTimeout, finishWithError, finishWithSuccess, onRequestClose, pdfSrc]);
3071
+ if (!pdfSrc) {
3072
+ return /*#__PURE__*/React__default.createElement("div", {
3073
+ style: _extends({}, viewerShellStyle, overlayStyle, {
3074
+ position: 'relative'
3075
+ })
3076
+ }, /*#__PURE__*/React__default.createElement("span", null, "No PDF document provided."), typeof onRequestClose === 'function' ? /*#__PURE__*/React__default.createElement("button", {
3077
+ type: "button",
3078
+ style: closeButtonStyle,
3079
+ onClick: onRequestClose
3080
+ }, "Close") : null);
3081
+ }
3082
+ return /*#__PURE__*/React__default.createElement("div", {
3083
+ style: viewerShellStyle
3084
+ }, isLoading ? /*#__PURE__*/React__default.createElement("div", {
3085
+ style: overlayStyle,
3086
+ "aria-live": "polite",
3087
+ "aria-busy": "true"
3088
+ }, /*#__PURE__*/React__default.createElement(material.CircularProgress, {
3089
+ size: 28
3090
+ }), /*#__PURE__*/React__default.createElement("span", null, "Loading...")) : null, loadError ? /*#__PURE__*/React__default.createElement("div", {
3091
+ style: overlayStyle,
3092
+ role: "alert",
3093
+ "aria-live": "assertive"
3094
+ }, /*#__PURE__*/React__default.createElement("span", null, loadError), typeof onRequestClose === 'function' ? /*#__PURE__*/React__default.createElement("button", {
3095
+ type: "button",
3096
+ style: closeButtonStyle,
3097
+ onClick: onRequestClose
3098
+ }, "Close") : null) : null, /*#__PURE__*/React__default.createElement(reactPdfViewer.PDFViewer, {
3099
+ key: pdfSrc,
3100
+ style: {
3101
+ height: '100%',
3102
+ width: '100%',
3103
+ minHeight: 600
3104
+ },
3105
+ onInit: handleInit,
3106
+ onReady: handleReady,
3107
+ config: {
3108
+ theme: {
3109
+ preference: 'light'
3110
+ },
3111
+ tabBar: 'never',
3112
+ disabledCategories: DISABLED_CATEGORIES
3113
+ }
3114
+ }));
3115
+ };
3116
+
2837
3117
  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;
2838
3118
  var totalIcons = [{
2839
3119
  name: '',
@@ -2877,7 +3157,8 @@ var Dashboard = function Dashboard(_ref) {
2877
3157
  showOnlyRecentOrder = _ref$showOnlyRecentOr === void 0 ? false : _ref$showOnlyRecentOr,
2878
3158
  hidePayActionButton = _ref.hidePayActionButton,
2879
3159
  hideInvoiceTab = _ref.hideInvoiceTab,
2880
- hideSalesOrderTab = _ref.hideSalesOrderTab;
3160
+ hideSalesOrderTab = _ref.hideSalesOrderTab,
3161
+ showPdfViewer = _ref.showPdfViewer;
2881
3162
  var _useState = React.useState({}),
2882
3163
  customerData = _useState[0],
2883
3164
  setCustomerData = _useState[1];
@@ -3328,8 +3609,15 @@ var Dashboard = function Dashboard(_ref) {
3328
3609
  maxWidth: "lg"
3329
3610
  }, /*#__PURE__*/React__default.createElement(material.DialogContent, {
3330
3611
  dividers: true
3331
- }, /*#__PURE__*/React__default.createElement("iframe", {
3332
- src: invoiceModal.url
3612
+ }, showPdfViewer ? /*#__PURE__*/React__default.createElement(ViewPdf, {
3613
+ src: invoiceModal === null || invoiceModal === void 0 ? void 0 : invoiceModal.url,
3614
+ onRequestClose: function onRequestClose() {
3615
+ return setInvoiceModal({
3616
+ open: false
3617
+ });
3618
+ }
3619
+ }) : /*#__PURE__*/React__default.createElement("iframe", {
3620
+ src: invoiceModal === null || invoiceModal === void 0 ? void 0 : invoiceModal.url
3333
3621
  }))), /*#__PURE__*/React__default.createElement(APITable, {
3334
3622
  key: value,
3335
3623
  cacheFilters: true,
@@ -3596,7 +3884,7 @@ var StatusContainer = styled__default(material.Stack)(_templateObject16 || (_tem
3596
3884
  return props.primaryColor;
3597
3885
  });
3598
3886
  var TableContainer = styled__default.div(_templateObject17 || (_templateObject17 = _taggedTemplateLiteralLoose(["\n margin-top: 2rem;\n border-radius: 14px;\n"])));
3599
- var InvoiceDialog = styled__default(material.Dialog)(_templateObject18 || (_templateObject18 = _taggedTemplateLiteralLoose(["\n iframe {\n width: 900px;\n border: none;\n height: 600px;\n }\n"])));
3887
+ var InvoiceDialog = styled__default(material.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"])));
3600
3888
  var TabsContainer = styled__default(material.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) {
3601
3889
  return props.fontColor;
3602
3890
  }, function (props) {
@@ -5300,7 +5588,9 @@ var AccountDetails = function AccountDetails(_ref) {
5300
5588
  _ref$hideSalesOrderTa = _ref.hideSalesOrderTab,
5301
5589
  hideSalesOrderTab = _ref$hideSalesOrderTa === void 0 ? false : _ref$hideSalesOrderTa,
5302
5590
  _ref$hideInvoiceTab = _ref.hideInvoiceTab,
5303
- hideInvoiceTab = _ref$hideInvoiceTab === void 0 ? false : _ref$hideInvoiceTab;
5591
+ hideInvoiceTab = _ref$hideInvoiceTab === void 0 ? false : _ref$hideInvoiceTab,
5592
+ _ref$showPdfViewer = _ref.showPdfViewer,
5593
+ showPdfViewer = _ref$showPdfViewer === void 0 ? false : _ref$showPdfViewer;
5304
5594
  var _useAllSystemFeatureV = useAllSystemFeatureValues({
5305
5595
  apiEndPoint: apiEndPoint,
5306
5596
  token: token
@@ -5473,7 +5763,8 @@ var AccountDetails = function AccountDetails(_ref) {
5473
5763
  showOnlyRecentOrder: showOnlyRecentOrder,
5474
5764
  hidePayActionButton: hidePayActionButton,
5475
5765
  hideSalesOrderTab: hideSalesOrderTab,
5476
- hideInvoiceTab: hideInvoiceTab
5766
+ hideInvoiceTab: hideInvoiceTab,
5767
+ showPdfViewer: showPdfViewer
5477
5768
  });
5478
5769
  case 'myProfile':
5479
5770
  return /*#__PURE__*/React__default.createElement(MyProfile, {