@star-insure/sdk 3.3.1 → 4.1.0

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/sdk.esm.js CHANGED
@@ -1,4 +1,4 @@
1
- import { parse, format, subYears } from 'date-fns';
1
+ import { format, parse, subYears } from 'date-fns';
2
2
  import { usePage as usePage$1, useForm, Link, router } from '@inertiajs/react';
3
3
  import React__default, { useEffect, useContext, createContext, useState, createElement, Fragment } from 'react';
4
4
  import { v4 } from 'uuid';
@@ -10,13 +10,6 @@ import { Tooltip } from 'react-tooltip';
10
10
  import Select from 'react-select';
11
11
  import { router as router$1 } from '@inertiajs/core';
12
12
 
13
- function parseDate(dateString) {
14
- // Make sure we've only got 10 characters
15
- return parse(dateString.substring(0, 10), 'yyyy-MM-dd', new Date());
16
- }
17
- function parseDateTime(dateTimeString) {
18
- return parse(dateTimeString, 'yyyy-MM-dd HH:mm:ss', new Date());
19
- }
20
13
  /**
21
14
  * Formats a date like "Jan 1, 2022 at 9:50am"
22
15
  */
@@ -27,11 +20,11 @@ function formatDateNice(date, includeTime) {
27
20
  }
28
21
 
29
22
  var formatString = includeTime ? "MMM d, yyyy 'at' h:mma" : 'MMM d, yyyy';
30
- var parsed = includeTime ? parseDateTime(date) : parseDate(date);
31
- return format(parsed, formatString);
23
+ var formatFunc = includeTime ? formatDateTime : formatDate;
24
+ return formatFunc(date, formatString);
32
25
  }
33
26
  /**
34
- * Formats a date like "01/01/2022 9:50AM"
27
+ * Formats a date like "01/01/2022 09:50"
35
28
  */
36
29
 
37
30
  function formatDateForTable(date, includeTime) {
@@ -39,9 +32,91 @@ function formatDateForTable(date, includeTime) {
39
32
  includeTime = true;
40
33
  }
41
34
 
42
- var formatString = includeTime ? 'dd/MM/yyyy h:mma' : 'dd/MM/yyyy';
43
- var parsed = includeTime ? parseDateTime(date) : parseDate(date);
44
- return format(parsed, formatString);
35
+ return includeTime ? formatDateTime(date) : formatDate(date);
36
+ }
37
+ /**
38
+ * Formats a date to Star Insure standard format - dd/mm/yyyy
39
+ */
40
+
41
+ function formatDate(date, overrideFormatString) {
42
+ // If date is undefined or null
43
+ if (!date) {
44
+ return '';
45
+ }
46
+
47
+ var formatString = overrideFormatString || 'dd/MM/yyyy'; // If date is a date object
48
+
49
+ if (date instanceof Date) {
50
+ return format(date, formatString);
51
+ }
52
+ /*
53
+ * If date is a string, first attempt to parse it in non-standard formats
54
+ * Only parse the first 10 characters of the string
55
+ * dd/MM/yyyy, dd-MM-yyyy, dd.MM.yyyy
56
+ */
57
+
58
+
59
+ var nonStandardDate = date.substring(0, 10).split('-').join('/').split('.').join('/');
60
+ var parsedDate = parse(nonStandardDate, 'dd/MM/yyyy', new Date());
61
+
62
+ if (parsedDate.toString() !== 'Invalid Date') {
63
+ return format(parsedDate, formatString);
64
+ } // Then attempt to parse it natively
65
+
66
+
67
+ var nativelyParsedDate = new Date(date);
68
+
69
+ if (nativelyParsedDate.toString() !== 'Invalid Date') {
70
+ return format(nativelyParsedDate, formatString);
71
+ }
72
+
73
+ return '';
74
+ }
75
+ /**
76
+ * Formats a dateTime to Star Insure standard format - dd/mm/yyyy hh:mm
77
+ */
78
+
79
+ function formatDateTime(dateTime, overrideFormatString) {
80
+ // If date is undefined or null
81
+ if (!dateTime) {
82
+ return '';
83
+ }
84
+
85
+ var formatString = overrideFormatString || 'dd/MM/yyyy HH:mm'; // If date is a date object
86
+
87
+ if (dateTime instanceof Date) {
88
+ return format(dateTime, formatString);
89
+ }
90
+ /*
91
+ * If date is a string, first attempt to parse it in non-standard formats
92
+ * dd/MM/yyyy HH:mm, dd-MM-yyyy HH:mm, dd.MM.yyyy HH:mm,
93
+ * dd/MM/yyyy hh:mm a, dd-MM-yyyy hh:mm a, dd.MM.yyyy hh:mm a,
94
+ * dd/MM/yyyy HH:mm:ss, dd-MM-yyyy HH:mm:ss, dd.MM.yyyy HH:mm:ss,
95
+ * dd/MM/yyyy hh:mm:ss a, dd-MM-yyyy hh:mm:ss a, dd.MM.yyyy hh:mm:ss a
96
+ */
97
+
98
+
99
+ var nonStandardDateTime = dateTime // Remove commas between date and time
100
+ .split(',').join('') // Only parse the first 22 characters of the string
101
+ .substring(0, 22) // Replace dashes and dots with slashes
102
+ .split('-').join('/').split('.').join('/');
103
+ var is12Hour = ['AM', 'PM'].includes(nonStandardDateTime.slice(-2).toUpperCase());
104
+ var hasSeconds = nonStandardDateTime.split(':').length === 3;
105
+ var nonStandardFormat = ("dd/MM/yyyy " + (is12Hour ? 'hh' : 'HH') + ":mm" + (hasSeconds ? ':ss' : '') + " " + (is12Hour ? 'a' : '')).trim();
106
+ var parsedDateTime = parse(nonStandardDateTime, nonStandardFormat, new Date());
107
+
108
+ if (parsedDateTime.toString() !== 'Invalid Date') {
109
+ return format(parsedDateTime, formatString);
110
+ } // Then attempt to parse it natively
111
+
112
+
113
+ var nativelyParsedDateTime = new Date(dateTime);
114
+
115
+ if (nativelyParsedDateTime.toString() !== 'Invalid Date') {
116
+ return format(nativelyParsedDateTime, formatString);
117
+ }
118
+
119
+ return '';
45
120
  }
46
121
 
47
122
  /**
@@ -98,6 +173,10 @@ function formatMoney(value, decimals) {
98
173
  decimals = 2;
99
174
  }
100
175
 
176
+ if (value === null || value === undefined) {
177
+ return '';
178
+ }
179
+
101
180
  var toFormat = value;
102
181
 
103
182
  if (typeof value === 'string') {
@@ -1442,7 +1521,7 @@ function Toasts() {
1442
1521
  toasts = _useToast.toasts;
1443
1522
 
1444
1523
  return React__default.createElement("div", {
1445
- className: "fixed bottom-4 right-4 z-[110] flex flex-col gap-6"
1524
+ className: "fixed bottom-4 right-4 z-[120] flex flex-col gap-6"
1446
1525
  }, toasts.map(function (toast) {
1447
1526
  return React__default.createElement(ToastItem, Object.assign({}, toast, {
1448
1527
  key: toast._id
@@ -1456,6 +1535,8 @@ function Modal(_ref) {
1456
1535
  isActive = _ref$isActive === void 0 ? false : _ref$isActive,
1457
1536
  onClose = _ref.onClose,
1458
1537
  title = _ref.title,
1538
+ _ref$width = _ref.width,
1539
+ width = _ref$width === void 0 ? '' : _ref$width,
1459
1540
  _ref$className = _ref.className,
1460
1541
  className = _ref$className === void 0 ? '' : _ref$className;
1461
1542
  return React__default.createElement(Transition.Root, {
@@ -1486,7 +1567,7 @@ function Modal(_ref) {
1486
1567
  leaveFrom: "opacity-100 translate-y-0 sm:scale-100",
1487
1568
  leaveTo: "opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
1488
1569
  }, React__default.createElement("div", {
1489
- className: className + " w-full align-start inline-block bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-3xl sm:p-6"
1570
+ className: className + " w-full align-start inline-block bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-7xl sm:p-6 " + width
1490
1571
  }, React__default.createElement("div", {
1491
1572
  className: "flex gap-4 mb-4 text-asphalt " + (title ? 'border-b-2 border-asphalt pb-4' : '')
1492
1573
  }, title && React__default.createElement("h3", {
@@ -1630,13 +1711,15 @@ function TableRow(_ref) {
1630
1711
  _ref$className = _ref.className,
1631
1712
  className = _ref$className === void 0 ? '' : _ref$className,
1632
1713
  _ref$onClick = _ref.onClick,
1633
- onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
1714
+ _onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
1634
1715
  props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
1635
1716
 
1636
1717
  var bgClass = className.includes('bg') ? '' : 'bg-white even:bg-gray-50';
1637
1718
  return React__default.createElement("tr", Object.assign({}, props, {
1638
1719
  className: cn(className, bgClass, 'hover:bg-gray-100'),
1639
- onClick: onClick
1720
+ onClick: function onClick(e) {
1721
+ return _onClick(e);
1722
+ }
1640
1723
  }), children);
1641
1724
  }
1642
1725
 
@@ -3044,5 +3127,5 @@ function PageHeader(_ref) {
3044
3127
  })))));
3045
3128
  }
3046
3129
 
3047
- export { Button, Card, DateOfBirthField, ErrorList, FormTester, Modal, MoneyField, PageHeader, Pagination, QuoteRequestFormContext, QuoteRequestFormProvider, QuoteRequestOptionsProvider, RegistrationSearchField, SimplePagination, Table, TableActions, TableBody, TableCell, TableHead, TableHeader, TableRow, ToastItem, ToastProvider, Toasts, addGst, autocomplete, calcMonthlyEnhancementPrice, calcPurchaseOptionPricing, calculateAge, fixRoundingError, formatDateForTable, formatDateNice, formatMoney, formatNumber, getAddressData, getGst, gstCalc, initialData, parseDate, parseDateTime, round, sanitiseQuoteRequestFormData, sanitiseVehicleType, subtractGst, useAuth, useClickOutside, useInertiaOptions, useLocalStorage, useQuoteRequestForm, useQuoteRequestOptions, useToast };
3130
+ export { Button, Card, DateOfBirthField, ErrorList, FormTester, Modal, MoneyField, PageHeader, Pagination, QuoteRequestFormContext, QuoteRequestFormProvider, QuoteRequestOptionsProvider, RegistrationSearchField, SimplePagination, Table, TableActions, TableBody, TableCell, TableHead, TableHeader, TableRow, ToastItem, ToastProvider, Toasts, addGst, autocomplete, calcMonthlyEnhancementPrice, calcPurchaseOptionPricing, calculateAge, fixRoundingError, formatDate, formatDateForTable, formatDateNice, formatDateTime, formatMoney, formatNumber, getAddressData, getGst, gstCalc, initialData, round, sanitiseQuoteRequestFormData, sanitiseVehicleType, subtractGst, useAuth, useClickOutside, useInertiaOptions, useLocalStorage, useQuoteRequestForm, useQuoteRequestOptions, useToast };
3048
3131
  //# sourceMappingURL=sdk.esm.js.map