@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/README.md +31 -0
- package/dist/components/common/Modal.d.ts +2 -1
- package/dist/components/tables/TableRow.d.ts +1 -1
- package/dist/lib/dates.d.ts +11 -5
- package/dist/lib/money.d.ts +1 -1
- package/dist/sdk.cjs.development.js +102 -19
- package/dist/sdk.cjs.development.js.map +1 -1
- package/dist/sdk.cjs.production.min.js +1 -1
- package/dist/sdk.cjs.production.min.js.map +1 -1
- package/dist/sdk.esm.js +102 -19
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/misc/index.d.ts +1 -1
- package/package.json +2 -2
- package/src/components/common/Modal.tsx +3 -2
- package/src/components/common/Toasts.tsx +1 -1
- package/src/components/tables/TableRow.tsx +2 -2
- package/src/lib/dates.ts +96 -15
- package/src/lib/money.ts +5 -1
- package/src/types/misc/index.ts +1 -1
|
@@ -9,7 +9,7 @@ export interface FilterOption {
|
|
|
9
9
|
label: string;
|
|
10
10
|
name: string;
|
|
11
11
|
options?: FilterValue[];
|
|
12
|
-
type?: 'options' | 'date' | 'greaterThan' | 'scope' | 'select' | 'datalist';
|
|
12
|
+
type?: 'options' | 'date' | 'greaterThan' | 'scope' | 'select' | 'datalist' | 'column';
|
|
13
13
|
}
|
|
14
14
|
export interface FilterValue {
|
|
15
15
|
label: string;
|
package/package.json
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
"name": "@star-insure/sdk",
|
|
3
3
|
"description": "The SDK for Star Insure client apps with shared helper functions and TypeScript definitions.",
|
|
4
4
|
"author": "alexclark_nz",
|
|
5
|
-
"version": "
|
|
5
|
+
"version": "4.1.0",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"repository": {
|
|
8
8
|
"type": "git",
|
|
@@ -21,7 +21,7 @@
|
|
|
21
21
|
"dev": "tsdx watch",
|
|
22
22
|
"start": "tsdx watch",
|
|
23
23
|
"build": "tsdx build",
|
|
24
|
-
"test": "tsdx test --passWithNoTests",
|
|
24
|
+
"test": "TZ='Pacific/Auckland' tsdx test --passWithNoTests",
|
|
25
25
|
"lint": "tsdx lint",
|
|
26
26
|
"prepare": "tsdx build",
|
|
27
27
|
"size": "size-limit",
|
|
@@ -7,10 +7,11 @@ interface Props {
|
|
|
7
7
|
isActive?: boolean;
|
|
8
8
|
onClose: () => void;
|
|
9
9
|
title?: string;
|
|
10
|
+
width?: string;
|
|
10
11
|
className?: string;
|
|
11
12
|
}
|
|
12
13
|
|
|
13
|
-
export default function Modal({ children, isActive = false, onClose, title, className = '' }: Props) {
|
|
14
|
+
export default function Modal({ children, isActive = false, onClose, title, width = '', className = '' }: Props) {
|
|
14
15
|
return (
|
|
15
16
|
<Transition.Root show={isActive} as={Fragment}>
|
|
16
17
|
<Dialog as="div" className="fixed z-[110] inset-0 overflow-y-auto" onClose={onClose}>
|
|
@@ -36,7 +37,7 @@ export default function Modal({ children, isActive = false, onClose, title, clas
|
|
|
36
37
|
leaveFrom="opacity-100 translate-y-0 sm:scale-100"
|
|
37
38
|
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
|
|
38
39
|
>
|
|
39
|
-
<div 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-
|
|
40
|
+
<div 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}`}>
|
|
40
41
|
<div className={`flex gap-4 mb-4 text-asphalt ${title ? 'border-b-2 border-asphalt pb-4' : ''}`}>
|
|
41
42
|
{title && <h3 className="font-black text-lg">{title}</h3>}
|
|
42
43
|
<button type="button" onClick={onClose} className="ml-auto transition-all hover:opacity-50">
|
|
@@ -7,7 +7,7 @@ export default function Toasts() {
|
|
|
7
7
|
const { toasts } = useToast();
|
|
8
8
|
|
|
9
9
|
return (
|
|
10
|
-
<div className="fixed bottom-4 right-4 z-[
|
|
10
|
+
<div className="fixed bottom-4 right-4 z-[120] flex flex-col gap-6">
|
|
11
11
|
{toasts.map((toast: Toast) => (
|
|
12
12
|
<ToastItem {...toast} key={toast._id} />
|
|
13
13
|
))}
|
|
@@ -4,14 +4,14 @@ import cn from 'classnames';
|
|
|
4
4
|
interface Props extends React.DetailedHTMLProps<React.HTMLAttributes<HTMLTableRowElement>, HTMLTableRowElement> {
|
|
5
5
|
children: React.ReactNode;
|
|
6
6
|
className?: string;
|
|
7
|
-
onClick?: () => void;
|
|
7
|
+
onClick?: (e?: React.SyntheticEvent) => void;
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
export default function TableRow({ children, className = '', onClick = () => {}, ...props }: Props) {
|
|
11
11
|
const bgClass = className.includes('bg') ? '' : 'bg-white even:bg-gray-50'
|
|
12
12
|
|
|
13
13
|
return (
|
|
14
|
-
<tr {...props} className={cn(className, bgClass, 'hover:bg-gray-100')} onClick={onClick}>
|
|
14
|
+
<tr {...props} className={cn(className, bgClass, 'hover:bg-gray-100')} onClick={(e) => onClick(e)}>
|
|
15
15
|
{children}
|
|
16
16
|
</tr>
|
|
17
17
|
)
|
package/src/lib/dates.ts
CHANGED
|
@@ -1,30 +1,111 @@
|
|
|
1
1
|
import { format, parse } from "date-fns";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Formats a date like "Jan 1, 2022 at 9:50am"
|
|
5
|
+
*/
|
|
6
|
+
export function formatDateNice(date: string|null|undefined, includeTime: boolean = true) {
|
|
7
|
+
const formatString = includeTime ? "MMM d, yyyy 'at' h:mma" : 'MMM d, yyyy';
|
|
8
|
+
const formatFunc = includeTime ? formatDateTime : formatDate;
|
|
9
|
+
|
|
10
|
+
return formatFunc(date, formatString);
|
|
6
11
|
}
|
|
7
12
|
|
|
8
|
-
|
|
9
|
-
|
|
13
|
+
/**
|
|
14
|
+
* Formats a date like "01/01/2022 09:50"
|
|
15
|
+
*/
|
|
16
|
+
export function formatDateForTable(date: string|null|undefined, includeTime: boolean = true) {
|
|
17
|
+
return includeTime ? formatDateTime(date) : formatDate(date);
|
|
10
18
|
}
|
|
11
19
|
|
|
12
20
|
/**
|
|
13
|
-
* Formats a date
|
|
21
|
+
* Formats a date to Star Insure standard format - dd/mm/yyyy
|
|
14
22
|
*/
|
|
15
|
-
export function
|
|
16
|
-
|
|
17
|
-
|
|
23
|
+
export function formatDate(date: Date|string|null|undefined, overrideFormatString?: string) {
|
|
24
|
+
// If date is undefined or null
|
|
25
|
+
if (!date) {
|
|
26
|
+
return '';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const formatString = overrideFormatString || 'dd/MM/yyyy';
|
|
30
|
+
|
|
31
|
+
// If date is a date object
|
|
32
|
+
if (date instanceof Date) {
|
|
33
|
+
return format(date, formatString);
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/*
|
|
37
|
+
* If date is a string, first attempt to parse it in non-standard formats
|
|
38
|
+
* Only parse the first 10 characters of the string
|
|
39
|
+
* dd/MM/yyyy, dd-MM-yyyy, dd.MM.yyyy
|
|
40
|
+
*/
|
|
41
|
+
const nonStandardDate = date
|
|
42
|
+
.substring(0, 10)
|
|
43
|
+
.split('-').join('/')
|
|
44
|
+
.split('.').join('/');
|
|
18
45
|
|
|
19
|
-
|
|
46
|
+
const parsedDate = parse(nonStandardDate, 'dd/MM/yyyy', new Date());
|
|
47
|
+
if (parsedDate.toString() !== 'Invalid Date') {
|
|
48
|
+
return format(parsedDate, formatString);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
// Then attempt to parse it natively
|
|
52
|
+
const nativelyParsedDate = new Date(date);
|
|
53
|
+
if (nativelyParsedDate.toString() !== 'Invalid Date') {
|
|
54
|
+
return format(nativelyParsedDate, formatString);
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
return '';
|
|
20
58
|
}
|
|
21
59
|
|
|
22
60
|
/**
|
|
23
|
-
* Formats a
|
|
61
|
+
* Formats a dateTime to Star Insure standard format - dd/mm/yyyy hh:mm
|
|
24
62
|
*/
|
|
25
|
-
export function
|
|
26
|
-
|
|
27
|
-
|
|
63
|
+
export function formatDateTime(dateTime: Date|string|null|undefined, overrideFormatString?: string) {
|
|
64
|
+
// If date is undefined or null
|
|
65
|
+
if (!dateTime) {
|
|
66
|
+
return '';
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const formatString = overrideFormatString || 'dd/MM/yyyy HH:mm';
|
|
70
|
+
|
|
71
|
+
// If date is a date object
|
|
72
|
+
if (dateTime instanceof Date) {
|
|
73
|
+
return format(dateTime, formatString);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/*
|
|
77
|
+
* If date is a string, first attempt to parse it in non-standard formats
|
|
78
|
+
* dd/MM/yyyy HH:mm, dd-MM-yyyy HH:mm, dd.MM.yyyy HH:mm,
|
|
79
|
+
* dd/MM/yyyy hh:mm a, dd-MM-yyyy hh:mm a, dd.MM.yyyy hh:mm a,
|
|
80
|
+
* dd/MM/yyyy HH:mm:ss, dd-MM-yyyy HH:mm:ss, dd.MM.yyyy HH:mm:ss,
|
|
81
|
+
* dd/MM/yyyy hh:mm:ss a, dd-MM-yyyy hh:mm:ss a, dd.MM.yyyy hh:mm:ss a
|
|
82
|
+
*/
|
|
83
|
+
const nonStandardDateTime = dateTime
|
|
84
|
+
// Remove commas between date and time
|
|
85
|
+
.split(',').join('')
|
|
86
|
+
|
|
87
|
+
// Only parse the first 22 characters of the string
|
|
88
|
+
.substring(0, 22)
|
|
89
|
+
|
|
90
|
+
// Replace dashes and dots with slashes
|
|
91
|
+
.split('-').join('/')
|
|
92
|
+
.split('.').join('/');
|
|
93
|
+
|
|
94
|
+
const is12Hour = ['AM', 'PM'].includes(nonStandardDateTime.slice(-2).toUpperCase());
|
|
95
|
+
const hasSeconds = nonStandardDateTime.split(':').length === 3;
|
|
96
|
+
|
|
97
|
+
const nonStandardFormat = (`dd/MM/yyyy ${is12Hour ? 'hh' : 'HH'}:mm${hasSeconds ? ':ss' : ''} ${is12Hour ? 'a' : ''}`).trim();
|
|
98
|
+
|
|
99
|
+
const parsedDateTime = parse(nonStandardDateTime, nonStandardFormat, new Date());
|
|
100
|
+
if (parsedDateTime.toString() !== 'Invalid Date') {
|
|
101
|
+
return format(parsedDateTime, formatString);
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
// Then attempt to parse it natively
|
|
105
|
+
const nativelyParsedDateTime = new Date(dateTime);
|
|
106
|
+
if (nativelyParsedDateTime.toString() !== 'Invalid Date') {
|
|
107
|
+
return format(nativelyParsedDateTime, formatString);
|
|
108
|
+
}
|
|
28
109
|
|
|
29
|
-
return
|
|
110
|
+
return '';
|
|
30
111
|
}
|
package/src/lib/money.ts
CHANGED
|
@@ -52,7 +52,11 @@ export function gstCalc(input: number|string): {
|
|
|
52
52
|
/**
|
|
53
53
|
* Formats a value nicely
|
|
54
54
|
*/
|
|
55
|
-
|
|
55
|
+
export function formatMoney(value: string|number|null|undefined, decimals: number = 2): string {
|
|
56
|
+
if (value === null || value === undefined) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
|
|
56
60
|
let toFormat = value;
|
|
57
61
|
if (typeof value === 'string') {
|
|
58
62
|
toFormat = value.replace(/[^\d.-]/g, '')
|
package/src/types/misc/index.ts
CHANGED
|
@@ -11,7 +11,7 @@ export interface FilterOption {
|
|
|
11
11
|
label: string;
|
|
12
12
|
name: string;
|
|
13
13
|
options?: FilterValue[];
|
|
14
|
-
type?: 'options' | 'date' | 'greaterThan' | 'scope' | 'select' | 'datalist';
|
|
14
|
+
type?: 'options' | 'date' | 'greaterThan' | 'scope' | 'select' | 'datalist' | 'column';
|
|
15
15
|
}
|
|
16
16
|
|
|
17
17
|
export interface FilterValue {
|