@star-insure/sdk 1.2.0 → 2.0.1
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/components/common/Button.d.ts +2 -2
- package/dist/components/common/SimplePagination.d.ts +9 -0
- package/dist/components/common/index.d.ts +2 -1
- package/dist/components/forms/ErrorList.d.ts +2 -2
- package/dist/components/tables/TableHeader.d.ts +2 -2
- package/dist/lib/inertiaOptions.d.ts +1 -1
- package/dist/lib/quoteRequestForm.d.ts +4 -3
- package/dist/sdk.cjs.development.js +109 -14
- 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 +96 -2
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/misc/index.d.ts +0 -1
- package/package.json +2 -3
- package/src/components/common/Button.tsx +65 -48
- package/src/components/common/Pagination.tsx +1 -1
- package/src/components/common/SimplePagination.tsx +78 -0
- package/src/components/common/index.ts +2 -0
- package/src/components/forms/ErrorList.tsx +30 -25
- package/src/components/tables/TableHeader.tsx +61 -44
- package/src/lib/auth.tsx +13 -3
- package/src/lib/calculatePricing.tsx +1 -1
- package/src/lib/inertiaOptions.tsx +1 -1
- package/src/lib/quoteRequestForm.tsx +7 -4
- package/src/types/misc/index.ts +0 -2
- package/dist/types/misc/inertia.d.ts +0 -8
- package/src/types/misc/inertia.ts +0 -9
|
@@ -1,60 +1,77 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { Link } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from '@inertiajs/react';
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
5
|
+
className?: string;
|
|
6
|
+
href?: string;
|
|
7
|
+
target?: '_blank' | '_self';
|
|
8
|
+
onClick?: Function;
|
|
9
|
+
type?: 'button' | 'submit';
|
|
10
|
+
status?: 'primary' | 'danger' | 'warning' | 'info' | 'default';
|
|
11
|
+
children: React.ReactNode;
|
|
12
|
+
disabled?: boolean;
|
|
13
|
+
as?: 'link' | 'button' | 'a';
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
export default function Button({
|
|
17
|
-
|
|
16
|
+
export default function Button({
|
|
17
|
+
className,
|
|
18
|
+
href,
|
|
19
|
+
target,
|
|
20
|
+
onClick,
|
|
21
|
+
type,
|
|
22
|
+
children,
|
|
23
|
+
status = 'default',
|
|
24
|
+
disabled = false,
|
|
25
|
+
as,
|
|
26
|
+
}: Props) {
|
|
27
|
+
const baseClasses =
|
|
28
|
+
'font-black inline-flex items-center gap-3 justify-center text-white text-center px-5 py-2 rounded-md min-w-[120px] transition-all hover:opacity-75';
|
|
18
29
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
30
|
+
const statusClass =
|
|
31
|
+
(status === 'primary' && 'bg-teal') ||
|
|
32
|
+
(status === 'danger' && 'bg-red-500') ||
|
|
33
|
+
(status === 'warning' && 'bg-yellow-400') ||
|
|
34
|
+
(status === 'info' && 'bg-blue-400') ||
|
|
35
|
+
'bg-gray-600';
|
|
24
36
|
|
|
25
|
-
|
|
37
|
+
const classes = `${className ?? ''} ${baseClasses} ${statusClass}`;
|
|
26
38
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
)
|
|
33
|
-
|
|
39
|
+
if (onClick) {
|
|
40
|
+
return (
|
|
41
|
+
<button
|
|
42
|
+
className={classes}
|
|
43
|
+
type={type ?? 'button'}
|
|
44
|
+
onClick={(e: React.MouseEvent) => onClick(e)}
|
|
45
|
+
disabled={disabled}
|
|
46
|
+
>
|
|
47
|
+
{children}
|
|
48
|
+
</button>
|
|
49
|
+
);
|
|
50
|
+
}
|
|
34
51
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
52
|
+
if (type) {
|
|
53
|
+
return (
|
|
54
|
+
<button className={classes} type={type ?? 'button'} disabled={disabled}>
|
|
55
|
+
{children}
|
|
56
|
+
</button>
|
|
57
|
+
);
|
|
58
|
+
}
|
|
42
59
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
return (
|
|
53
|
-
<Link href={href} className={classes}>
|
|
54
|
-
{children}
|
|
55
|
-
</Link>
|
|
56
|
-
);
|
|
60
|
+
if (href) {
|
|
61
|
+
if (href.includes('http') || target === '_blank' || as === 'a') {
|
|
62
|
+
return (
|
|
63
|
+
<a href={href} target={target ?? '_self'} className={classes}>
|
|
64
|
+
{children}
|
|
65
|
+
</a>
|
|
66
|
+
);
|
|
57
67
|
}
|
|
58
68
|
|
|
59
|
-
return
|
|
69
|
+
return (
|
|
70
|
+
<Link href={href} className={classes}>
|
|
71
|
+
{children}
|
|
72
|
+
</Link>
|
|
73
|
+
);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return <p className="text-red-500 text-sm">[Invalid button]</p>;
|
|
60
77
|
}
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Link } from "@inertiajs/react";
|
|
3
|
+
import { Meta } from "../../types";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
className?: string;
|
|
7
|
+
meta: Meta;
|
|
8
|
+
showPerPageSelector?: boolean;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default function SimplePagination({ meta, className, showPerPageSelector = false }: Props) {
|
|
12
|
+
const { current_page, per_page, to, from } = meta;
|
|
13
|
+
const results_on_page = to - from + 1;
|
|
14
|
+
const has_more_pages = results_on_page === per_page;
|
|
15
|
+
|
|
16
|
+
function getNextPageLink() {
|
|
17
|
+
if (typeof window !== 'undefined') {
|
|
18
|
+
const search = new URLSearchParams(window.location.search);
|
|
19
|
+
search.set('page', String(current_page + 1));
|
|
20
|
+
|
|
21
|
+
return `?${search.toString()}`;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
return '';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function getPrevPageLink() {
|
|
28
|
+
if (typeof window !== 'undefined') {
|
|
29
|
+
const search = new URLSearchParams(window.location.search);
|
|
30
|
+
search.set('page', String(current_page - 1));
|
|
31
|
+
|
|
32
|
+
return `?${search.toString()}`;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
return '';
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const nextPageLink = getNextPageLink();
|
|
39
|
+
const prevPageLink = getPrevPageLink();
|
|
40
|
+
|
|
41
|
+
function handlePerPageChange(e: React.SyntheticEvent<HTMLSelectElement>) {
|
|
42
|
+
const search = new URLSearchParams(window?.location.search);
|
|
43
|
+
search.set('limit', e.currentTarget.value);
|
|
44
|
+
search.set('page', '1');
|
|
45
|
+
|
|
46
|
+
window.location.href = `?${search.toString()}`;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return (
|
|
50
|
+
<div className={`${className ?? ''}`}>
|
|
51
|
+
<nav className="font-bold flex justify-between items-center gap-6">
|
|
52
|
+
<Link href={prevPageLink} className="flex items-center gap-2" disabled={current_page === 1}>
|
|
53
|
+
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2">
|
|
54
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M10 19l-7-7m0 0l7-7m-7 7h18" />
|
|
55
|
+
</svg>
|
|
56
|
+
Prev
|
|
57
|
+
</Link>
|
|
58
|
+
<div className="flex gap-6 items-center">
|
|
59
|
+
<p>Page {current_page}</p>
|
|
60
|
+
{showPerPageSelector ? (
|
|
61
|
+
<select value={per_page} onChange={handlePerPageChange}>
|
|
62
|
+
<option value="10">10 per page</option>
|
|
63
|
+
<option value="25">25 per page</option>
|
|
64
|
+
<option value="50">50 per page</option>
|
|
65
|
+
<option value="100">100 per page</option>
|
|
66
|
+
</select>
|
|
67
|
+
) : ''}
|
|
68
|
+
</div>
|
|
69
|
+
<Link href={nextPageLink} className="flex items-center gap-2" disabled={!has_more_pages}>
|
|
70
|
+
Next
|
|
71
|
+
<svg xmlns="http://www.w3.org/2000/svg" className="h-4 w-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2">
|
|
72
|
+
<path strokeLinecap="round" strokeLinejoin="round" d="M14 5l7 7m0 0l-7 7m7-7H3" />
|
|
73
|
+
</svg>
|
|
74
|
+
</Link>
|
|
75
|
+
</nav>
|
|
76
|
+
</div>
|
|
77
|
+
)
|
|
78
|
+
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import Button from './Button';
|
|
2
2
|
import Card from './Card';
|
|
3
3
|
import Pagination from './Pagination';
|
|
4
|
+
import SimplePagination from './SimplePagination';
|
|
4
5
|
import ToastItem from './ToastItem';
|
|
5
6
|
import Toasts from './Toasts';
|
|
6
7
|
import Modal from './Modal';
|
|
@@ -9,6 +10,7 @@ export {
|
|
|
9
10
|
Button,
|
|
10
11
|
Card,
|
|
11
12
|
Pagination,
|
|
13
|
+
SimplePagination,
|
|
12
14
|
ToastItem,
|
|
13
15
|
Toasts,
|
|
14
16
|
Modal,
|
|
@@ -1,32 +1,37 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { ErrorBag, Errors } from
|
|
3
|
-
import { Card } from
|
|
2
|
+
import { ErrorBag, Errors } from '@inertiajs/core';
|
|
3
|
+
import { Card } from '../common';
|
|
4
4
|
|
|
5
5
|
interface Props {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
6
|
+
heading?: string;
|
|
7
|
+
errors?: Errors & ErrorBag;
|
|
8
|
+
renderKeys?: boolean;
|
|
9
|
+
className?: string;
|
|
10
10
|
}
|
|
11
11
|
|
|
12
|
-
export default function ErrorList({
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
12
|
+
export default function ErrorList({
|
|
13
|
+
heading = 'There was an error with your submission.',
|
|
14
|
+
errors = {},
|
|
15
|
+
renderKeys = false,
|
|
16
|
+
className = '',
|
|
17
|
+
}: Props) {
|
|
18
|
+
if (Object.values(errors).length === 0) {
|
|
19
|
+
return <></>;
|
|
20
|
+
}
|
|
16
21
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
22
|
+
return (
|
|
23
|
+
<aside className={`${className} col-span-full`}>
|
|
24
|
+
<Card className="border border-red-500 !bg-red-50">
|
|
25
|
+
<h2 className="font-black text-red-500 mb-2">{heading}</h2>
|
|
26
|
+
<ul className="space-y-2 list-disc ml-4">
|
|
27
|
+
{Object.entries(errors).map(([field, message]) => (
|
|
28
|
+
<li className="font-bold text-red-500" key={field}>
|
|
29
|
+
{renderKeys && <strong>{field}: </strong>}
|
|
30
|
+
{message}
|
|
31
|
+
</li>
|
|
32
|
+
))}
|
|
33
|
+
</ul>
|
|
34
|
+
</Card>
|
|
35
|
+
</aside>
|
|
36
|
+
);
|
|
32
37
|
}
|
|
@@ -1,49 +1,66 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import { Link } from
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { Link } from '@inertiajs/react';
|
|
3
3
|
|
|
4
4
|
interface Props {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
5
|
+
children: React.ReactNode;
|
|
6
|
+
className?: string;
|
|
7
|
+
textAlign?: 'left' | 'right' | 'center';
|
|
8
|
+
sort?: string;
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
-
export default function TableHeader({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
11
|
+
export default function TableHeader({
|
|
12
|
+
children,
|
|
13
|
+
className = '',
|
|
14
|
+
sort,
|
|
15
|
+
textAlign = 'left',
|
|
16
|
+
}: Props) {
|
|
17
|
+
const [sortLink, setSortLink] = React.useState<string>('');
|
|
18
|
+
|
|
19
|
+
React.useEffect(() => {
|
|
20
|
+
if (typeof window !== 'undefined' && sort) {
|
|
21
|
+
const query = new URLSearchParams(window.location.search);
|
|
22
|
+
|
|
23
|
+
let direction: 'asc' | 'desc' = 'asc';
|
|
24
|
+
|
|
25
|
+
if (query.get('sort')) {
|
|
26
|
+
// Choose the opposite direction for sorting
|
|
27
|
+
direction = query.get('sort')?.includes('asc') ? 'desc' : 'asc';
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
query.set('sort', `${sort} ${direction}`);
|
|
31
|
+
|
|
32
|
+
setSortLink(`?${query.toString()}`);
|
|
33
|
+
}
|
|
34
|
+
}, []);
|
|
35
|
+
|
|
36
|
+
const textAlignClass =
|
|
37
|
+
(textAlign === 'center' && 'text-center justify-center') ||
|
|
38
|
+
(textAlign === 'right' && 'text-right justify-end') ||
|
|
39
|
+
'text-left justify-between';
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<th className={`${className} py-3.5 px-3 text-sm font-semibold text-left`}>
|
|
43
|
+
<div className={`flex items-center gap-3 ${textAlignClass}`}>
|
|
44
|
+
{children}
|
|
45
|
+
{sort && (
|
|
46
|
+
<Link href={sortLink}>
|
|
47
|
+
<svg
|
|
48
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
49
|
+
className="h-5 w-5"
|
|
50
|
+
fill="none"
|
|
51
|
+
viewBox="0 0 24 24"
|
|
52
|
+
stroke="currentColor"
|
|
53
|
+
strokeWidth="2"
|
|
54
|
+
>
|
|
55
|
+
<path
|
|
56
|
+
strokeLinecap="round"
|
|
57
|
+
strokeLinejoin="round"
|
|
58
|
+
d="M8 9l4-4 4 4m0 6l-4 4-4-4"
|
|
59
|
+
/>
|
|
60
|
+
</svg>
|
|
61
|
+
</Link>
|
|
62
|
+
)}
|
|
63
|
+
</div>
|
|
64
|
+
</th>
|
|
65
|
+
);
|
|
49
66
|
}
|
package/src/lib/auth.tsx
CHANGED
|
@@ -1,8 +1,18 @@
|
|
|
1
|
-
import { usePage } from '@inertiajs/
|
|
2
|
-
import type { AuthContext
|
|
1
|
+
import { usePage } from '@inertiajs/react';
|
|
2
|
+
import type { AuthContext } from '../types';
|
|
3
|
+
import type { ErrorBag, Errors, Page, PageProps } from '@inertiajs/core';
|
|
4
|
+
|
|
5
|
+
interface SharedProps {
|
|
6
|
+
auth: AuthContext;
|
|
7
|
+
errors: Errors & ErrorBag;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
interface AppPage extends Page {
|
|
11
|
+
props: PageProps & SharedProps;
|
|
12
|
+
}
|
|
3
13
|
|
|
4
14
|
export function useAuth(): AuthContext {
|
|
5
|
-
const { props } = usePage
|
|
15
|
+
const { props } = usePage() as AppPage;
|
|
6
16
|
|
|
7
17
|
return props.auth;
|
|
8
18
|
}
|
|
@@ -1,13 +1,16 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { useForm } from "@inertiajs/react";
|
|
3
|
+
import { InertiaFormProps } from "@inertiajs/react/types/useForm";
|
|
3
4
|
import type { QuoteRequest } from '../types';
|
|
4
5
|
|
|
6
|
+
type QuoteRequestForm = QuoteRequest & Record<string, any>;
|
|
7
|
+
|
|
5
8
|
interface QuoteRequestFormContextInterface {
|
|
6
|
-
form?: InertiaFormProps<
|
|
9
|
+
form?: InertiaFormProps<QuoteRequestForm>;
|
|
7
10
|
handleChange?: (e: React.ChangeEvent<HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement>) => void;
|
|
8
11
|
}
|
|
9
12
|
|
|
10
|
-
export const initialData:
|
|
13
|
+
export const initialData: QuoteRequestForm = {
|
|
11
14
|
id: undefined,
|
|
12
15
|
status: 'new',
|
|
13
16
|
source: 'phone',
|
|
@@ -71,7 +74,7 @@ export const initialData: QuoteRequest = {
|
|
|
71
74
|
export const QuoteRequestFormContext = React.createContext<QuoteRequestFormContextInterface>({});
|
|
72
75
|
|
|
73
76
|
export function QuoteRequestFormProvider({ children }: { children: React.ReactNode }) {
|
|
74
|
-
const form = useForm
|
|
77
|
+
const form = useForm(initialData);
|
|
75
78
|
|
|
76
79
|
/**
|
|
77
80
|
* Handle the change event for all form inputs
|
package/src/types/misc/index.ts
CHANGED
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type { ErrorBag, Errors, Page, PageProps as PagePropsInterface } from "@inertiajs/inertia";
|
|
2
|
-
import { AuthContext } from '../../types';
|
|
3
|
-
export interface PageProps extends Page<PagePropsInterface> {
|
|
4
|
-
props: {
|
|
5
|
-
auth: AuthContext;
|
|
6
|
-
errors: Errors & ErrorBag;
|
|
7
|
-
};
|
|
8
|
-
}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import type { ErrorBag, Errors, Page, PageProps as PagePropsInterface } from "@inertiajs/inertia";
|
|
2
|
-
import { AuthContext } from '../../types';
|
|
3
|
-
|
|
4
|
-
export interface PageProps extends Page<PagePropsInterface> {
|
|
5
|
-
props: {
|
|
6
|
-
auth: AuthContext;
|
|
7
|
-
errors: Errors & ErrorBag;
|
|
8
|
-
}
|
|
9
|
-
}
|