@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.
@@ -1,60 +1,77 @@
1
- import React from "react";
2
- import { Link } from "@inertiajs/inertia-react";
1
+ import React from 'react';
2
+ import { Link } from '@inertiajs/react';
3
3
 
4
4
  interface Props {
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';
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({ className, href, target, onClick, type, children, status = 'default', disabled = false, as }: Props) {
17
- const baseClasses = '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';
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
- const statusClass = status === 'primary' && 'bg-teal'
20
- || status === 'danger' && 'bg-red-500'
21
- || status === 'warning' && 'bg-yellow-400'
22
- || status === 'info' && 'bg-blue-400'
23
- || 'bg-gray-600';
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
- const classes = `${className ?? ''} ${baseClasses} ${statusClass}`;
37
+ const classes = `${className ?? ''} ${baseClasses} ${statusClass}`;
26
38
 
27
- if (onClick) {
28
- return (
29
- <button className={classes} type={type ?? 'button'} onClick={(e: React.MouseEvent) => onClick(e)} disabled={disabled}>
30
- {children}
31
- </button>
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
- if (type) {
36
- return (
37
- <button className={classes} type={type ?? 'button'} disabled={disabled}>
38
- {children}
39
- </button>
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
- if (href) {
44
- if (href.includes('http') || target === '_blank' || as === 'a') {
45
- return (
46
- <a href={href} target={target ?? '_self'} className={classes}>
47
- {children}
48
- </a>
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 <p className="text-red-500 text-sm">[Invalid button]</p>;
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
  }
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { Link } from "@inertiajs/inertia-react";
2
+ import { Link } from "@inertiajs/react";
3
3
  import type { Meta } from "../../types";
4
4
 
5
5
  interface Props {
@@ -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 "@inertiajs/inertia"
3
- import { Card } from "../common";
2
+ import { ErrorBag, Errors } from '@inertiajs/core';
3
+ import { Card } from '../common';
4
4
 
5
5
  interface Props {
6
- heading?: string;
7
- errors?: Errors & ErrorBag;
8
- renderKeys?: boolean;
9
- className?: string;
6
+ heading?: string;
7
+ errors?: Errors & ErrorBag;
8
+ renderKeys?: boolean;
9
+ className?: string;
10
10
  }
11
11
 
12
- export default function ErrorList({ heading = 'There was an error with your submission.', errors = {}, renderKeys = false, className = '' }: Props) {
13
- if (Object.values(errors).length === 0) {
14
- return <></>
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
- return (
18
- <aside className={`${className} col-span-full`}>
19
- <Card className="border border-red-500 !bg-red-50">
20
- <h2 className="font-black text-red-500 mb-2">{heading}</h2>
21
- <ul className="space-y-2 list-disc ml-4">
22
- {Object.entries(errors).map(([field, message]) => (
23
- <li className="font-bold text-red-500" key={field}>
24
- {renderKeys && <strong>{field}: </strong>}
25
- { message }
26
- </li>
27
- ))}
28
- </ul>
29
- </Card>
30
- </aside>
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 "react";
2
- import { Link } from "@inertiajs/inertia-react";
1
+ import React from 'react';
2
+ import { Link } from '@inertiajs/react';
3
3
 
4
4
  interface Props {
5
- children: React.ReactNode;
6
- className?: string;
7
- textAlign?: 'left' | 'right' | 'center';
8
- sort?: string;
5
+ children: React.ReactNode;
6
+ className?: string;
7
+ textAlign?: 'left' | 'right' | 'center';
8
+ sort?: string;
9
9
  }
10
10
 
11
- export default function TableHeader({ children, className = '', sort, textAlign = 'left' }: Props) {
12
- const [sortLink, setSortLink] = React.useState<string>('');
13
-
14
- React.useEffect(() => {
15
- if (typeof window !== 'undefined' && sort) {
16
- const query = new URLSearchParams(window.location.search);
17
-
18
- let direction: 'asc' | 'desc' = 'asc';
19
-
20
- if (query.get('sort')) {
21
- // Choose the opposite direction for sorting
22
- direction = query.get('sort')?.includes('asc') ? 'desc' : 'asc';
23
- }
24
-
25
- query.set('sort', `${sort} ${direction}`);
26
-
27
- setSortLink(`?${query.toString()}`);
28
- }
29
- }, []);
30
-
31
- const textAlignClass = textAlign === 'center' && 'text-center justify-center'
32
- || textAlign === 'right' && 'text-right justify-end'
33
- || 'text-left justify-between';
34
-
35
- return (
36
- <th className={`${className} py-3.5 px-3 text-sm font-semibold text-left`}>
37
- <div className={`flex items-center gap-3 ${textAlignClass}`}>
38
- {children}
39
- {sort && (
40
- <Link href={sortLink}>
41
- <svg xmlns="http://www.w3.org/2000/svg" className="h-5 w-5" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth="2">
42
- <path strokeLinecap="round" strokeLinejoin="round" d="M8 9l4-4 4 4m0 6l-4 4-4-4" />
43
- </svg>
44
- </Link>
45
- )}
46
- </div>
47
- </th>
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/inertia-react';
2
- import type { AuthContext, PageProps } from '../types';
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<PageProps>() as PageProps;
15
+ const { props } = usePage() as AppPage;
6
16
 
7
17
  return props.auth;
8
18
  }
@@ -1,4 +1,4 @@
1
- import { addGst } from ".";
1
+ import { addGst } from "./money";
2
2
  import type { PolicyEnhancement, QuoteRequestPurchaseOption } from "../types";
3
3
 
4
4
  interface CalculationArguments {
@@ -1,4 +1,4 @@
1
- import type { VisitOptions } from '@inertiajs/inertia/types';
1
+ import type { VisitOptions } from '@inertiajs/core';
2
2
  import { useToast } from './toast';
3
3
 
4
4
  interface Options {
@@ -1,13 +1,16 @@
1
1
  import React from 'react';
2
- import { InertiaFormProps, useForm } from "@inertiajs/inertia-react";
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<QuoteRequest>;
9
+ form?: InertiaFormProps<QuoteRequestForm>;
7
10
  handleChange?: (e: React.ChangeEvent<HTMLInputElement|HTMLTextAreaElement|HTMLSelectElement>) => void;
8
11
  }
9
12
 
10
- export const initialData: QuoteRequest = {
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<QuoteRequest>(initialData);
77
+ const form = useForm(initialData);
75
78
 
76
79
  /**
77
80
  * Handle the change event for all form inputs
@@ -1,5 +1,3 @@
1
- export * from './inertia';
2
-
3
1
  export type FormStatus = 'idle' | 'processing' | 'success' | 'error';
4
2
 
5
3
  export interface Toast {
@@ -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
- }