@star-insure/sdk 1.1.42 → 1.2.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/components/forms/DateOfBirthField.d.ts +6 -2
- package/dist/sdk.cjs.development.js +45 -51
- 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 +42 -48
- package/dist/sdk.esm.js.map +1 -1
- package/dist/types/models/quotes/QuoteRequestIncident.d.ts +1 -0
- package/dist/types/models/quotes/QuoteRequestLog.d.ts +1 -0
- package/dist/types/models/quotes/QuoteRequestReferrer.d.ts +1 -0
- package/dist/types/models/quotes/QuoteRequestReferrerCategory.d.ts +1 -0
- package/package.json +1 -1
- package/src/components/forms/DateOfBirthField.tsx +112 -72
- package/src/types/models/quotes/QuoteRequestIncident.ts +1 -0
- package/src/types/models/quotes/QuoteRequestLog.ts +1 -0
- package/src/types/models/quotes/QuoteRequestReferrer.ts +1 -0
- package/src/types/models/quotes/QuoteRequestReferrerCategory.ts +1 -0
|
@@ -1,84 +1,124 @@
|
|
|
1
|
-
import React from
|
|
2
|
-
import {
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { calculateAge } from '../../lib';
|
|
3
|
+
import { padStart } from 'lodash';
|
|
3
4
|
|
|
4
5
|
interface Props {
|
|
5
|
-
|
|
6
|
-
|
|
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({
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
17
|
-
|
|
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
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
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
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
52
|
+
function handleChange(
|
|
53
|
+
e: React.ChangeEvent<
|
|
54
|
+
HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement
|
|
55
|
+
>
|
|
56
|
+
) {
|
|
57
|
+
const { name, value } = e.currentTarget;
|
|
32
58
|
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
37
|
-
|
|
38
|
-
[name]: value,
|
|
39
|
-
}
|
|
63
|
+
onChange(`${y}-${m}-${d}`);
|
|
64
|
+
}
|
|
40
65
|
|
|
41
|
-
|
|
42
|
-
|
|
66
|
+
const [year, month, day] = value ? value.split('-') : ['', '', ''];
|
|
67
|
+
const isValidDate =
|
|
68
|
+
year && month && day && !isNaN(Date.parse(`${year}-${month}-${day}`));
|
|
43
69
|
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
}
|