@star-insure/sdk 3.3.1 → 4.0.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
  /**
@@ -93,7 +168,7 @@ function gstCalc(input) {
93
168
  * Formats a value nicely
94
169
  */
95
170
 
96
- function formatMoney(value, decimals) {
171
+ function formatMoneyNumerals(value, decimals) {
97
172
  if (decimals === void 0) {
98
173
  decimals = 2;
99
174
  }
@@ -109,6 +184,22 @@ function formatMoney(value, decimals) {
109
184
  maximumFractionDigits: decimals
110
185
  });
111
186
  }
187
+ /**
188
+ * Formats a value nicely
189
+ */
190
+
191
+ function formatMoney(value, decimals) {
192
+ if (decimals === void 0) {
193
+ decimals = 2;
194
+ }
195
+
196
+ if (value === null || value === undefined) {
197
+ return '';
198
+ }
199
+
200
+ return ("$" + formatMoneyNumerals(value, decimals) // If the value is negative, we need to move the negative sign to the front
201
+ ).replace('$-', '- $');
202
+ }
112
203
  /**
113
204
  * Turns a formatted value in to a float
114
205
  */
@@ -1442,7 +1533,7 @@ function Toasts() {
1442
1533
  toasts = _useToast.toasts;
1443
1534
 
1444
1535
  return React__default.createElement("div", {
1445
- className: "fixed bottom-4 right-4 z-[110] flex flex-col gap-6"
1536
+ className: "fixed bottom-4 right-4 z-[120] flex flex-col gap-6"
1446
1537
  }, toasts.map(function (toast) {
1447
1538
  return React__default.createElement(ToastItem, Object.assign({}, toast, {
1448
1539
  key: toast._id
@@ -1630,13 +1721,15 @@ function TableRow(_ref) {
1630
1721
  _ref$className = _ref.className,
1631
1722
  className = _ref$className === void 0 ? '' : _ref$className,
1632
1723
  _ref$onClick = _ref.onClick,
1633
- onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
1724
+ _onClick = _ref$onClick === void 0 ? function () {} : _ref$onClick,
1634
1725
  props = _objectWithoutPropertiesLoose(_ref, _excluded$5);
1635
1726
 
1636
1727
  var bgClass = className.includes('bg') ? '' : 'bg-white even:bg-gray-50';
1637
1728
  return React__default.createElement("tr", Object.assign({}, props, {
1638
1729
  className: cn(className, bgClass, 'hover:bg-gray-100'),
1639
- onClick: onClick
1730
+ onClick: function onClick(e) {
1731
+ return _onClick(e);
1732
+ }
1640
1733
  }), children);
1641
1734
  }
1642
1735
 
@@ -3044,5 +3137,5 @@ function PageHeader(_ref) {
3044
3137
  })))));
3045
3138
  }
3046
3139
 
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 };
3140
+ 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, formatMoneyNumerals, formatNumber, getAddressData, getGst, gstCalc, initialData, round, sanitiseQuoteRequestFormData, sanitiseVehicleType, subtractGst, useAuth, useClickOutside, useInertiaOptions, useLocalStorage, useQuoteRequestForm, useQuoteRequestOptions, useToast };
3048
3141
  //# sourceMappingURL=sdk.esm.js.map