@star-insure/sdk 1.1.43 → 2.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.
@@ -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 {
@@ -1,84 +1,124 @@
1
- import React from "react";
2
- import { padStart } from "lodash-es";
1
+ import React from 'react';
2
+ import { calculateAge } from '../../lib';
3
+ import { padStart } from 'lodash';
3
4
 
4
5
  interface Props {
5
- value?: string;
6
- onChange: (newValue: string) => void;
6
+ name?: string;
7
+ id?: string;
8
+ onChange: (dateString: string) => void;
9
+ value?: string;
10
+ maxYear?: number;
11
+ showAge?: boolean;
7
12
  }
8
13
 
9
- export default function DateOfBirthField({ value, onChange }: Props) {
10
- const [dateOfBirth, setDateOfBirth] = React.useState({
11
- day: value?.split("-")[2] || '',
12
- month: value?.split("-")[1] || '',
13
- year: value?.split("-")[0] || '',
14
- });
14
+ export default function DateOfBirthField({
15
+ name = 'dob',
16
+ id = 'dob',
17
+ onChange,
18
+ value,
19
+ maxYear = 0,
20
+ showAge = false,
21
+ }: Props) {
22
+ const dayOptions = [...Array.from(Array(31).keys())].map(value => {
23
+ return padStart(`${value + 1}`, 2, '0');
24
+ });
15
25
 
16
- const dayOptions = [...Array.from(Array(31).keys())].map(value => {
17
- return padStart(`${value + 1}`, 2, '0');
18
- });
26
+ const months = [
27
+ 'January',
28
+ 'February',
29
+ 'March',
30
+ 'April',
31
+ 'May',
32
+ 'June',
33
+ 'July',
34
+ 'August',
35
+ 'September',
36
+ 'October',
37
+ 'November',
38
+ 'December',
39
+ ];
40
+ const monthOptions = [...Array.from(Array(12).keys())].map(value => {
41
+ return {
42
+ title: months[value],
43
+ value: padStart(`${value + 1}`, 2, '0'),
44
+ };
45
+ });
19
46
 
20
- const months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
21
- const monthOptions = [...Array.from(Array(12).keys())].map(value => {
22
- return {
23
- title: months[value],
24
- value: padStart(`${value + 1}`, 2, '0')
25
- }
26
- })
47
+ // Create 100 years of options, subtracting the maximum year if provided
48
+ const yearOptions = [...Array.from(Array(100).keys())].map(value => {
49
+ return maxYear ? maxYear - value : new Date().getFullYear() - value;
50
+ });
27
51
 
28
- const thisYear = new Date().getFullYear();
29
- const yearOptions = [...Array.from(Array(100).keys())].map(value => {
30
- return (thisYear - value - 16).toString();
31
- });
52
+ function handleChange(
53
+ e: React.ChangeEvent<
54
+ HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
55
+ >
56
+ ) {
57
+ const { name, value } = e.currentTarget;
32
58
 
33
- function handleSelectChange(e: React.FormEvent<HTMLSelectElement>) {
34
- const { name, value } = e.currentTarget;
59
+ let y = name.includes('year') ? value : year;
60
+ let m = name.includes('month') ? value : month;
61
+ let d = name.includes('day') ? value : day;
35
62
 
36
- const newDob = {
37
- ...dateOfBirth,
38
- [name]: value,
39
- }
63
+ onChange(`${y}-${m}-${d}`);
64
+ }
40
65
 
41
- // Set local state
42
- setDateOfBirth(newDob);
66
+ const [year, month, day] = value ? value.split('-') : ['', '', ''];
67
+ const isValidDate =
68
+ year && month && day && !isNaN(Date.parse(`${year}-${month}-${day}`));
43
69
 
44
- // Format the date for the API
45
- const formattedDate = `${newDob.year}-${newDob.month}-${newDob.day}`;
46
-
47
- // Call the upstream prop if we have all of the date parts
48
- if (Object.values(newDob).every(value => value !== '')) {
49
- onChange(formattedDate);
50
- } else {
51
- // Otherwise, clear the value
52
- onChange('');
53
- }
54
- }
55
-
56
- return (
57
- <label className="w-full">
58
- <span className="relative mr-auto">
59
- <span>Date of birth</span>
60
- </span>
61
-
62
- <span className="flex space-x-4 border border-gray-300 rounded-lg mt-1 bg-white">
63
- <select name="day" value={dateOfBirth.day} className="flex-grow focus:outline-none border-0" onChange={handleSelectChange} required>
64
- <option value="">Day</option>
65
- {dayOptions.map(option => (
66
- <option key={option} value={option}>{option}</option>
67
- ))}
68
- </select>
69
- <select name="month" value={dateOfBirth.month} className="flex-grow focus:outline-none border-0" onChange={handleSelectChange} required>
70
- <option value="">Month</option>
71
- {monthOptions.map(option => (
72
- <option key={option.value} value={option.value}>{option.title}</option>
73
- ))}
74
- </select>
75
- <select name="year" value={dateOfBirth.year} className="flex-grow focus:outline-none border-0" onChange={handleSelectChange} required>
76
- <option value="">Year</option>
77
- {yearOptions.map(option => (
78
- <option key={option} value={option}>{option}</option>
79
- ))}
80
- </select>
81
- </span>
82
- </label>
83
- )
70
+ return (
71
+ <span className="flex flex-col gap-2">
72
+ <span className="flex space-x-4 border border-gray-300 rounded-lg bg-white">
73
+ <select
74
+ name={`${name}_day`}
75
+ id={`${id}_day`}
76
+ value={day}
77
+ className="flex-grow focus:outline-none border-0"
78
+ onChange={handleChange}
79
+ required
80
+ >
81
+ <option value="">Day</option>
82
+ {dayOptions.map(option => (
83
+ <option key={option} value={option}>
84
+ {option}
85
+ </option>
86
+ ))}
87
+ </select>
88
+ <select
89
+ name={`${name}_month`}
90
+ id={`${id}_month`}
91
+ value={month}
92
+ className="flex-grow focus:outline-none border-0"
93
+ onChange={handleChange}
94
+ required
95
+ >
96
+ <option value="">Month</option>
97
+ {monthOptions.map(option => (
98
+ <option key={option.value} value={option.value}>
99
+ {option.title}
100
+ </option>
101
+ ))}
102
+ </select>
103
+ <select
104
+ name={`${name}_year`}
105
+ id={`${id}_year`}
106
+ value={year}
107
+ className="flex-grow focus:outline-none border-0"
108
+ onChange={handleChange}
109
+ required
110
+ >
111
+ <option value="">Year</option>
112
+ {yearOptions.map(option => (
113
+ <option key={option} value={option}>
114
+ {option}
115
+ </option>
116
+ ))}
117
+ </select>
118
+ </span>
119
+ {showAge && value && isValidDate && (
120
+ <span className="font-bold">Age: {calculateAge(value)} years</span>
121
+ )}
122
+ </span>
123
+ );
84
124
  }
@@ -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
- }