@visns-studio/visns-components 5.8.10 → 5.8.12

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/package.json CHANGED
@@ -20,12 +20,12 @@
20
20
  "dayjs": "^1.11.13",
21
21
  "fabric": "^6.6.5",
22
22
  "file-saver": "^2.0.5",
23
- "framer-motion": "^12.11.3",
23
+ "framer-motion": "^12.12.1",
24
24
  "html-react-parser": "^5.2.5",
25
25
  "lodash": "^4.17.21",
26
26
  "lodash.debounce": "^4.0.8",
27
27
  "moment": "^2.30.1",
28
- "motion": "^12.11.3",
28
+ "motion": "^12.12.1",
29
29
  "numeral": "^2.0.6",
30
30
  "pluralize": "^8.0.0",
31
31
  "qrcode.react": "^4.2.0",
@@ -41,7 +41,7 @@
41
41
  "react-promise-tracker": "^2.1.1",
42
42
  "react-quill": "^2.0.0",
43
43
  "react-reveal": "^1.2.2",
44
- "react-router-dom": "^6.30.0",
44
+ "react-router-dom": "^6.30.1",
45
45
  "react-select": "^5.10.1",
46
46
  "react-signature-pad-wrapper": "^4.1.0",
47
47
  "react-slugify": "^4.0.1",
@@ -54,13 +54,13 @@
54
54
  "reactjs-popup": "^2.0.6",
55
55
  "style-loader": "^4.0.0",
56
56
  "swapy": "^1.0.5",
57
- "sweetalert2": "^11.21.0",
57
+ "sweetalert2": "^11.21.2",
58
58
  "truncate": "^3.0.0",
59
59
  "uuid": "^11.1.0",
60
60
  "validator": "^13.15.0",
61
61
  "vite": "^6.3.5",
62
62
  "yarn": "^1.22.22",
63
- "yet-another-react-lightbox": "^3.23.1"
63
+ "yet-another-react-lightbox": "^3.23.2"
64
64
  },
65
65
  "devDependencies": {
66
66
  "@babel/core": "^7.27.1",
@@ -74,7 +74,7 @@
74
74
  "mini-css-extract-plugin": "^2.9.2",
75
75
  "react": "^18.3.1",
76
76
  "react-dom": "^18.3.1",
77
- "sass": "^1.88.0",
77
+ "sass": "^1.89.0",
78
78
  "sass-loader": "^16.0.5"
79
79
  },
80
80
  "peerDependencies": {
@@ -82,7 +82,7 @@
82
82
  "react-dom": "^17.0.0 || ^18.0.0"
83
83
  },
84
84
  "name": "@visns-studio/visns-components",
85
- "version": "5.8.10",
85
+ "version": "5.8.12",
86
86
  "description": "Various packages to assist in the development of our Custom Applications.",
87
87
  "main": "src/index.js",
88
88
  "files": [
@@ -0,0 +1,97 @@
1
+ import React from 'react';
2
+ import Swal from 'sweetalert2';
3
+ import './styles/SweetAlert.module.css';
4
+
5
+ /**
6
+ * A utility function that uses SweetAlert2 for confirmation dialogs
7
+ *
8
+ * @param {Object} options - Configuration options
9
+ * @param {string} options.title - The title of the confirmation dialog
10
+ * @param {string} options.message - The message to display in the dialog
11
+ * @param {string} options.confirmLabel - Label for the confirm button
12
+ * @param {string} options.cancelLabel - Label for the cancel button
13
+ * @param {Function} options.onConfirm - Function to call when confirmed
14
+ * @param {Function} options.onCancel - Function to call when cancelled
15
+ * @param {Object} options.data - Optional data object to pass to the dialog
16
+ * @returns {Promise} - A promise that resolves when the dialog is closed
17
+ */
18
+ export const showConfirmDialog = ({
19
+ title = 'Confirm',
20
+ message = 'Are you sure?',
21
+ confirmLabel = 'Yes',
22
+ cancelLabel = 'No',
23
+ onConfirm = () => {},
24
+ onCancel = () => {},
25
+ data = null,
26
+ }) => {
27
+ // Enhanced message with item details if available
28
+ let enhancedMessage = message;
29
+ let itemDetails = '';
30
+
31
+ // Extract meaningful information from the data object if available
32
+ if (data) {
33
+ // Common identifiers that might be present in data objects
34
+ const identifiers = [
35
+ 'name',
36
+ 'label',
37
+ 'title',
38
+ 'email',
39
+ 'username',
40
+ 'id',
41
+ 'code',
42
+ 'reference',
43
+ 'description',
44
+ ];
45
+
46
+ // Find the first available identifier
47
+ for (const id of identifiers) {
48
+ if (
49
+ data[id] &&
50
+ typeof data[id] === 'string' &&
51
+ data[id].trim() !== ''
52
+ ) {
53
+ itemDetails = data[id];
54
+ break;
55
+ }
56
+ }
57
+
58
+ // If we found an identifier, enhance the message
59
+ if (itemDetails && !message.includes(itemDetails)) {
60
+ // If the message already contains a question mark, add the details before it
61
+ if (message.includes('?')) {
62
+ enhancedMessage = message.replace('?', `"${itemDetails}"?`);
63
+ } else {
64
+ // Otherwise, append the details
65
+ enhancedMessage = `${message} "${itemDetails}"`;
66
+ }
67
+ }
68
+ }
69
+
70
+ // Configure SweetAlert2 options
71
+ const swalOptions = {
72
+ title: title,
73
+ html: enhancedMessage,
74
+ icon: 'question',
75
+ showCancelButton: true,
76
+ confirmButtonText: confirmLabel,
77
+ cancelButtonText: cancelLabel,
78
+ confirmButtonColor: 'var(--primary-color, #4f46e5)',
79
+ cancelButtonColor: '#6b7280',
80
+ allowOutsideClick: true,
81
+ allowEscapeKey: true,
82
+ reverseButtons: true,
83
+ focusCancel: false,
84
+ buttonsStyling: true,
85
+ };
86
+
87
+ // Show SweetAlert2 dialog
88
+ return Swal.fire(swalOptions).then((result) => {
89
+ if (result.isConfirmed) {
90
+ onConfirm();
91
+ } else if (result.dismiss === Swal.DismissReason.cancel) {
92
+ onCancel();
93
+ }
94
+ });
95
+ };
96
+
97
+ export default showConfirmDialog;