axitech-widget 0.0.2
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 +203 -0
- package/dist/Modal-fab2abfa.mjs +4 -0
- package/dist/axitech-widget.es.js +7 -0
- package/dist/axitech-widget.iife.js +698 -0
- package/dist/axitech-widget.umd.js +698 -0
- package/dist/index-2839010c.mjs +30306 -0
- package/dist/style.css +1 -0
- package/dist/types/components/base/ActionCard.vue.d.ts +36 -0
- package/dist/types/components/base/Button.vue.d.ts +9 -0
- package/dist/types/components/base/Collapse.vue.d.ts +2 -0
- package/dist/types/components/base/DatePicker.vue.d.ts +70 -0
- package/dist/types/components/base/GoogleAutocomplete.vue.d.ts +23 -0
- package/dist/types/components/base/GoogleMap.vue.d.ts +26 -0
- package/dist/types/components/base/Input.vue.d.ts +43 -0
- package/dist/types/components/base/Modal.vue.d.ts +55 -0
- package/dist/types/components/base/SelectButton.vue.d.ts +56 -0
- package/dist/types/components/base/Spinner.vue.d.ts +34 -0
- package/dist/types/components/base/uploader/ImageUpload.vue.d.ts +23 -0
- package/dist/types/components/base/uploader/Upload.vue.d.ts +4 -0
- package/dist/types/components/claims-widget/ClaimsWidget.ce.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/Error.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/SkeletonLoader.vue.d.ts +56 -0
- package/dist/types/components/claims-widget/components/StepConfirm.vue.d.ts +6 -0
- package/dist/types/components/claims-widget/components/StepSelector.vue.d.ts +6 -0
- package/dist/types/components/claims-widget/components/accident/Accident.vue.d.ts +8 -0
- package/dist/types/components/claims-widget/components/accident/ImageSection.vue.d.ts +29 -0
- package/dist/types/components/claims-widget/components/accident/MapSection.vue.d.ts +29 -0
- package/dist/types/components/claims-widget/components/accident/NoteSection.vue.d.ts +21 -0
- package/dist/types/components/claims-widget/components/accident/SectionWrapper.vue.d.ts +23 -0
- package/dist/types/components/claims-widget/components/accident/YourVehicle.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/fireWater/FireWater.vue.d.ts +6 -0
- package/dist/types/components/claims-widget/components/illustration/Accident.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/illustration/Location.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/illustration/SubmittedSuccessfully.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/illustration/Unsupported.vue.d.ts +2 -0
- package/dist/types/components/claims-widget/components/windscreen/Windscreen.vue.d.ts +6 -0
- package/dist/types/components/claims-widget/components/windscreen/WindscreenLoading.vue.d.ts +2 -0
- package/dist/types/components/index.d.ts +2 -0
- package/dist/types/composables/googleMaps.d.ts +11 -0
- package/dist/types/constants/index.d.ts +1 -0
- package/dist/types/index.d.ts +34 -0
- package/dist/types/plugins/firebase.d.ts +2 -0
- package/dist/types/plugins/firebaseCloudStorage.d.ts +16 -0
- package/dist/types/utils/autocomplete.d.ts +2 -0
- package/dist/types/utils/colorHelpers.d.ts +7 -0
- package/dist/types/utils/config.d.ts +131 -0
- package/dist/types/utils/customElementRegister.d.ts +1 -0
- package/dist/types/utils/fontUtils.d.ts +1 -0
- package/dist/types/utils/index.d.ts +141 -0
- package/dist/types/utils/map.d.ts +21 -0
- package/dist/types/utils/request.d.ts +30 -0
- package/dist/types/utils/svgUtils.d.ts +0 -0
- package/dist/types/utils/themeUtils.d.ts +9 -0
- package/package.json +77 -0
- package/src/assets/fonts/Volvo Novum-Italic.eot +0 -0
- package/src/assets/fonts/Volvo Novum-Italic.svg +723 -0
- package/src/assets/fonts/Volvo Novum-Italic.woff +0 -0
- package/src/assets/fonts/Volvo Novum-Italic.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-Light.eot +0 -0
- package/src/assets/fonts/Volvo Novum-Light.svg +707 -0
- package/src/assets/fonts/Volvo Novum-Light.woff +0 -0
- package/src/assets/fonts/Volvo Novum-Light.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-LightItalic.eot +0 -0
- package/src/assets/fonts/Volvo Novum-LightItalic.svg +723 -0
- package/src/assets/fonts/Volvo Novum-LightItalic.woff +0 -0
- package/src/assets/fonts/Volvo Novum-LightItalic.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-Medium.eot +0 -0
- package/src/assets/fonts/Volvo Novum-Medium.svg +706 -0
- package/src/assets/fonts/Volvo Novum-Medium.woff +0 -0
- package/src/assets/fonts/Volvo Novum-Medium.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-MediumItalic.eot +0 -0
- package/src/assets/fonts/Volvo Novum-MediumItalic.svg +724 -0
- package/src/assets/fonts/Volvo Novum-MediumItalic.woff +0 -0
- package/src/assets/fonts/Volvo Novum-MediumItalic.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-Regular.eot +0 -0
- package/src/assets/fonts/Volvo Novum-Regular.svg +707 -0
- package/src/assets/fonts/Volvo Novum-Regular.woff +0 -0
- package/src/assets/fonts/Volvo Novum-Regular.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLight.eot +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLight.svg +706 -0
- package/src/assets/fonts/Volvo Novum-SemiLight.woff +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLight.woff2 +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLightItalic.eot +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLightItalic.svg +722 -0
- package/src/assets/fonts/Volvo Novum-SemiLightItalic.woff +0 -0
- package/src/assets/fonts/Volvo Novum-SemiLightItalic.woff2 +0 -0
- package/src/assets/styles/collapse.sass +20 -0
- package/src/assets/styles/datepicker.sass +14 -0
- package/src/assets/styles/main.sass +182 -0
- package/src/assets/styles/map.sass +41 -0
- package/src/assets/styles/togglebutton.sass +4 -0
- package/src/components/base/ActionCard.vue +49 -0
- package/src/components/base/Button.vue +16 -0
- package/src/components/base/Collapse.vue +41 -0
- package/src/components/base/DatePicker.vue +94 -0
- package/src/components/base/GoogleAutocomplete.vue +116 -0
- package/src/components/base/GoogleMap.vue +114 -0
- package/src/components/base/Input.vue +44 -0
- package/src/components/base/Modal.vue +117 -0
- package/src/components/base/SelectButton.vue +67 -0
- package/src/components/base/Spinner.vue +39 -0
- package/src/components/base/uploader/ImageUpload.vue +85 -0
- package/src/components/base/uploader/Upload.vue +14 -0
- package/src/components/claims-widget/ClaimsWidget.ce.vue +117 -0
- package/src/components/claims-widget/assets/accident.svg +181 -0
- package/src/components/claims-widget/assets/car.svg +6 -0
- package/src/components/claims-widget/assets/currentlocation.svg +3 -0
- package/src/components/claims-widget/assets/door.svg +3 -0
- package/src/components/claims-widget/assets/location.svg +20 -0
- package/src/components/claims-widget/assets/marker.svg +1 -0
- package/src/components/claims-widget/assets/unsupported.svg +107 -0
- package/src/components/claims-widget/assets/windscreen.svg +3 -0
- package/src/components/claims-widget/assets/zoomin.svg +3 -0
- package/src/components/claims-widget/assets/zoomout.svg +3 -0
- package/src/components/claims-widget/components/Error.vue +21 -0
- package/src/components/claims-widget/components/SkeletonLoader.vue +77 -0
- package/src/components/claims-widget/components/StepConfirm.vue +85 -0
- package/src/components/claims-widget/components/StepSelector.vue +58 -0
- package/src/components/claims-widget/components/accident/Accident.vue +267 -0
- package/src/components/claims-widget/components/accident/ImageSection.vue +82 -0
- package/src/components/claims-widget/components/accident/MapSection.vue +72 -0
- package/src/components/claims-widget/components/accident/NoteSection.vue +83 -0
- package/src/components/claims-widget/components/accident/SectionWrapper.vue +16 -0
- package/src/components/claims-widget/components/accident/YourVehicle.vue +60 -0
- package/src/components/claims-widget/components/fireWater/FireWater.vue +42 -0
- package/src/components/claims-widget/components/illustration/Accident.vue +735 -0
- package/src/components/claims-widget/components/illustration/Location.vue +74 -0
- package/src/components/claims-widget/components/illustration/SubmittedSuccessfully.vue +2270 -0
- package/src/components/claims-widget/components/illustration/Unsupported.vue +393 -0
- package/src/components/claims-widget/components/windscreen/Windscreen.vue +44 -0
- package/src/components/claims-widget/components/windscreen/WindscreenLoading.vue +34 -0
- package/src/components/index.ts +3 -0
- package/src/composables/googleMaps.ts +157 -0
- package/src/constants/index.ts +1 -0
- package/src/index.ts +76 -0
- package/src/plugins/firebase.ts +18 -0
- package/src/plugins/firebaseCloudStorage.ts +88 -0
- package/src/utils/autocomplete.ts +57 -0
- package/src/utils/colorHelpers.ts +96 -0
- package/src/utils/config.ts +140 -0
- package/src/utils/customElementRegister.ts +40 -0
- package/src/utils/fontUtils.ts +24 -0
- package/src/utils/index.ts +5 -0
- package/src/utils/map.ts +212 -0
- package/src/utils/request.ts +76 -0
- package/src/utils/svgUtils.ts +0 -0
- package/src/utils/themeUtils.ts +40 -0
package/src/utils/map.ts
ADDED
|
@@ -0,0 +1,212 @@
|
|
|
1
|
+
import ZoomInMap from 'src/components/claims-widget/assets/zoomin.svg';
|
|
2
|
+
import ZoomOutMap from 'src/components/claims-widget/assets/zoomout.svg';
|
|
3
|
+
import CurrentLocation from 'src/components/claims-widget/assets/currentlocation.svg';
|
|
4
|
+
|
|
5
|
+
export function getUserBrowser() {
|
|
6
|
+
let browserDocumentation = '';
|
|
7
|
+
const userAgent = navigator.userAgent;
|
|
8
|
+
if (userAgent.match(/chrome|chromium|crios/i)) {
|
|
9
|
+
browserDocumentation = 'https://support.google.com/chrome/answer/142065?co=GENIE.Platform%3DDesktop&hl=en';
|
|
10
|
+
} else if (userAgent.match(/firefox|fxios/i)) {
|
|
11
|
+
browserDocumentation = 'https://yandex.com/support/common/browsers-settings/geo-firefox.html';
|
|
12
|
+
} else if (userAgent.match(/safari/i)) {
|
|
13
|
+
browserDocumentation = 'https://support.apple.com/en-us/HT204690';
|
|
14
|
+
} else if (userAgent.match(/opr\//i)) {
|
|
15
|
+
browserDocumentation = 'https://help.opera.com/en/latest/web-preferences/#location';
|
|
16
|
+
} else if (userAgent.match(/edg/i)) {
|
|
17
|
+
browserDocumentation = 'https://support.google.com/chrome/answer/142065?co=GENIE.Platform%3DDesktop&hl=en';
|
|
18
|
+
} else if (userAgent.match(/SamsungBrowser/i)) {
|
|
19
|
+
browserDocumentation =
|
|
20
|
+
'https://www.samsung.com/latin_en/support/mobile-devices/how-to-activate-my-location-and-change-settings-for-location-permissions/#:~:text=Launch%20the%20Settings%20app%2C%20and,enable%20or%20disable%20location%20services.';
|
|
21
|
+
}
|
|
22
|
+
return browserDocumentation;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
let isApproximateLocation = false;
|
|
26
|
+
|
|
27
|
+
export async function getLocationByIP() {
|
|
28
|
+
try {
|
|
29
|
+
const result = await fetch('https://get.geojs.io/v1/ip/geo.json').then((res) => res.json());
|
|
30
|
+
return [result, null];
|
|
31
|
+
} catch (error) {
|
|
32
|
+
return [null, error];
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
export function getPosition(options: PositionOptions) {
|
|
37
|
+
return new Promise((resolve: PositionCallback, reject: PositionErrorCallback) =>
|
|
38
|
+
navigator.geolocation.getCurrentPosition(resolve, reject, options)
|
|
39
|
+
);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export async function getLocationInfo(location: google.maps.LatLng) {
|
|
43
|
+
const geoCoder = new google.maps.Geocoder();
|
|
44
|
+
if (typeof location.lat === 'number' || typeof location.lng === 'number') {
|
|
45
|
+
location = new google.maps.LatLng(location);
|
|
46
|
+
}
|
|
47
|
+
const address: ILocationInfo = {
|
|
48
|
+
latitude: location.lat(),
|
|
49
|
+
longitude: location.lng(),
|
|
50
|
+
formatted_address: '',
|
|
51
|
+
address_line: '',
|
|
52
|
+
city: '',
|
|
53
|
+
state: '',
|
|
54
|
+
country: '',
|
|
55
|
+
postal_code: '',
|
|
56
|
+
};
|
|
57
|
+
if (isApproximateLocation) {
|
|
58
|
+
isApproximateLocation = false;
|
|
59
|
+
return address;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
const resp = (
|
|
63
|
+
await geoCoder.geocode({
|
|
64
|
+
location: { lat: location.lat(), lng: location.lng() },
|
|
65
|
+
})
|
|
66
|
+
)?.results?.[0];
|
|
67
|
+
if (!!resp && ['ROOFTOP', 'RANGE_INTERPOLATED'].includes(resp.geometry.location_type)) {
|
|
68
|
+
address.formatted_address = resp.formatted_address;
|
|
69
|
+
address.address_line = `${
|
|
70
|
+
resp.address_components?.find(({ types }) => types.includes('route'))?.long_name || ''
|
|
71
|
+
}, ${resp.address_components?.find(({ types }) => types.includes('street_number'))?.long_name || ''}`;
|
|
72
|
+
address.city = resp.address_components?.find(({ types }) => types.includes('locality'))?.long_name || '';
|
|
73
|
+
address.state =
|
|
74
|
+
resp.address_components?.find(({ types }) => types.includes('administrative_area_level_1'))?.long_name || '';
|
|
75
|
+
address.country = resp.address_components?.find(({ types }) => types.includes('country'))?.long_name || '';
|
|
76
|
+
address.postal_code = resp.address_components?.find(({ types }) => types.includes('postal_code'))?.long_name || '';
|
|
77
|
+
}
|
|
78
|
+
return address;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
type AtLeast<T, K extends keyof T> = Partial<T> & Pick<T, K>;
|
|
82
|
+
|
|
83
|
+
export interface ILocation {
|
|
84
|
+
latitude: number;
|
|
85
|
+
longitude: number;
|
|
86
|
+
formatted_address: string;
|
|
87
|
+
address_line: string;
|
|
88
|
+
city: string;
|
|
89
|
+
state: string;
|
|
90
|
+
country: string;
|
|
91
|
+
postal_code: string;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export type ILocationInfo = AtLeast<ILocation, 'latitude' | 'longitude'>;
|
|
95
|
+
|
|
96
|
+
export async function getLocation(
|
|
97
|
+
defaultZoom = 8,
|
|
98
|
+
defaultLocation: ILocationInfo = { latitude: 0, longitude: 0 }
|
|
99
|
+
): Promise<[ILocationInfo, number, boolean]> {
|
|
100
|
+
let locationObject: ILocationInfo;
|
|
101
|
+
try {
|
|
102
|
+
if (!navigator.geolocation) {
|
|
103
|
+
throw new Error('Loaction access not allowed or device is not supported. Using IP based geolocation');
|
|
104
|
+
}
|
|
105
|
+
const coords = (
|
|
106
|
+
await getPosition({
|
|
107
|
+
enableHighAccuracy: true,
|
|
108
|
+
maximumAge: 0,
|
|
109
|
+
})
|
|
110
|
+
).coords;
|
|
111
|
+
locationObject =
|
|
112
|
+
(await getLocationInfo(new google.maps.LatLng(coords.latitude, coords.longitude))) || defaultLocation;
|
|
113
|
+
return [locationObject, defaultZoom, true];
|
|
114
|
+
} catch (error) {
|
|
115
|
+
const [ipLocation, err] = await getLocationByIP();
|
|
116
|
+
if (!ipLocation?.latitude || !ipLocation?.longitude || err) {
|
|
117
|
+
locationObject = defaultLocation;
|
|
118
|
+
defaultZoom = 8;
|
|
119
|
+
return [locationObject, defaultZoom, false];
|
|
120
|
+
}
|
|
121
|
+
locationObject =
|
|
122
|
+
(await getLocationInfo(new google.maps.LatLng(Number(ipLocation.latitude), Number(ipLocation.longitude)))) ||
|
|
123
|
+
defaultLocation;
|
|
124
|
+
defaultZoom = 8;
|
|
125
|
+
return [locationObject, defaultZoom, false];
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
export function zoomControl(controlDiv: HTMLDivElement, map: google.maps.Map) {
|
|
130
|
+
controlDiv.style.margin = '0px 24px 18px 0px';
|
|
131
|
+
|
|
132
|
+
// Set CSS for the control wrapper
|
|
133
|
+
const controlWrapper = document.createElement('div');
|
|
134
|
+
controlWrapper.style.backgroundColor = 'white';
|
|
135
|
+
controlWrapper.style.borderRadius = '20px';
|
|
136
|
+
controlWrapper.style.cursor = 'pointer';
|
|
137
|
+
controlWrapper.style.textAlign = 'center';
|
|
138
|
+
controlWrapper.style.width = '40px';
|
|
139
|
+
controlWrapper.style.height = '80px';
|
|
140
|
+
controlDiv.appendChild(controlWrapper);
|
|
141
|
+
|
|
142
|
+
// Set CSS for the zoomIn
|
|
143
|
+
const zoomInButton = document.createElement('div');
|
|
144
|
+
zoomInButton.style.width = '40px';
|
|
145
|
+
zoomInButton.style.height = '40px';
|
|
146
|
+
zoomInButton.style.backgroundImage = `url(${ZoomInMap})`;
|
|
147
|
+
zoomInButton.style.backgroundPosition = 'center';
|
|
148
|
+
zoomInButton.style.backgroundRepeat = 'no-repeat';
|
|
149
|
+
zoomInButton.style.borderBottom = 'solid 1px #F4F4F4';
|
|
150
|
+
controlWrapper.appendChild(zoomInButton);
|
|
151
|
+
|
|
152
|
+
// Set CSS for the zoomOut
|
|
153
|
+
const zoomOutButton = document.createElement('div');
|
|
154
|
+
zoomOutButton.style.width = '40px';
|
|
155
|
+
zoomOutButton.style.height = '40px';
|
|
156
|
+
zoomOutButton.style.backgroundImage = `url(${ZoomOutMap})`;
|
|
157
|
+
zoomOutButton.style.backgroundPosition = 'center';
|
|
158
|
+
zoomOutButton.style.backgroundRepeat = 'no-repeat';
|
|
159
|
+
controlWrapper.appendChild(zoomOutButton);
|
|
160
|
+
|
|
161
|
+
// Setup the click event listener - zoomIn
|
|
162
|
+
zoomInButton.addEventListener('click', () => {
|
|
163
|
+
const actualZoom = map?.getZoom();
|
|
164
|
+
if (!actualZoom) {
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
map.setZoom(actualZoom + 1);
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// Setup the click event listener - zoomOut
|
|
171
|
+
zoomOutButton.addEventListener('click', () => {
|
|
172
|
+
const actualZoom = map?.getZoom();
|
|
173
|
+
if (!actualZoom) {
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
map.setZoom(actualZoom - 1);
|
|
177
|
+
});
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
export function addYourLocationButton(controlDiv: HTMLDivElement, map: google.maps.Map) {
|
|
181
|
+
controlDiv.style.margin = '0px 24px 18px 0px';
|
|
182
|
+
|
|
183
|
+
// Set CSS for the control button
|
|
184
|
+
const controlButton = document.createElement('button');
|
|
185
|
+
controlButton.style.border = 'none';
|
|
186
|
+
controlButton.style.outline = 'none';
|
|
187
|
+
controlButton.style.backgroundColor = '#fff';
|
|
188
|
+
controlButton.style.width = '40px';
|
|
189
|
+
controlButton.style.height = '40px';
|
|
190
|
+
controlButton.style.borderRadius = '20px';
|
|
191
|
+
controlButton.style.boxShadow = '0 1px 4px rgba(0,0,0,0.3)';
|
|
192
|
+
controlButton.style.cursor = 'pointer';
|
|
193
|
+
controlButton.style.padding = '0';
|
|
194
|
+
controlButton.title = 'Your Location';
|
|
195
|
+
controlDiv.appendChild(controlButton);
|
|
196
|
+
|
|
197
|
+
// Set CSS for the icon
|
|
198
|
+
const icon = document.createElement('div');
|
|
199
|
+
icon.style.width = '40px';
|
|
200
|
+
icon.style.height = '40px';
|
|
201
|
+
icon.style.backgroundImage = `url(${CurrentLocation})`;
|
|
202
|
+
icon.style.backgroundPosition = 'center';
|
|
203
|
+
icon.style.backgroundRepeat = 'no-repeat';
|
|
204
|
+
controlButton.appendChild(icon);
|
|
205
|
+
|
|
206
|
+
// Setup the click event listener - move
|
|
207
|
+
controlButton.addEventListener('click', async () => {
|
|
208
|
+
const [location] = await getLocation();
|
|
209
|
+
map.panTo(new google.maps.LatLng(location.latitude, location.longitude));
|
|
210
|
+
map.setZoom(16);
|
|
211
|
+
});
|
|
212
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { config, getBaseUrl } from './config';
|
|
2
|
+
import { Theme } from './themeUtils';
|
|
3
|
+
const unknownError = 'Unknown error happened check your api-key and config';
|
|
4
|
+
export const ApiPaths = {
|
|
5
|
+
config: 'config',
|
|
6
|
+
submission: 'submission',
|
|
7
|
+
} as const;
|
|
8
|
+
|
|
9
|
+
export type IApiPath = keyof typeof ApiPaths;
|
|
10
|
+
type ApiError = {
|
|
11
|
+
message: string;
|
|
12
|
+
};
|
|
13
|
+
export type ResponseTypeMap = {
|
|
14
|
+
[ApiPaths.config]: {
|
|
15
|
+
id: string;
|
|
16
|
+
name: string;
|
|
17
|
+
theme: Theme;
|
|
18
|
+
correspondenceEmails: string[];
|
|
19
|
+
};
|
|
20
|
+
[ApiPaths.submission]: { recieved: true };
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export const request = {
|
|
24
|
+
get,
|
|
25
|
+
post,
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
async function makeFetch(input: RequestInfo | URL, init?: RequestInit | undefined) {
|
|
29
|
+
try {
|
|
30
|
+
config.value.clientId;
|
|
31
|
+
const res = await fetch(input, {
|
|
32
|
+
headers: {
|
|
33
|
+
'X-API-KEY': config.value.apiKey,
|
|
34
|
+
},
|
|
35
|
+
...init,
|
|
36
|
+
}).then(async (res) => {
|
|
37
|
+
const result = await res.json();
|
|
38
|
+
if (!res.ok) {
|
|
39
|
+
throw result;
|
|
40
|
+
}
|
|
41
|
+
return result;
|
|
42
|
+
});
|
|
43
|
+
return [res, null] as const;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.log('error :>> ', error);
|
|
46
|
+
if (error && typeof error === 'object' && 'statusMessage' in error && typeof error?.statusMessage === 'string') {
|
|
47
|
+
return [null, { message: error.statusMessage }] as const;
|
|
48
|
+
}
|
|
49
|
+
return [null, { message: unknownError }] as const;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function get<Endpoint extends keyof typeof ApiPaths>(
|
|
54
|
+
endpoint: Endpoint,
|
|
55
|
+
payload?: { params?: string; query?: string }
|
|
56
|
+
) {
|
|
57
|
+
return makeFetch(
|
|
58
|
+
`${getBaseUrl(endpoint)}${payload?.params ? `/${payload.params}` : ''}${payload?.query ? `?${payload.query}` : ''}`,
|
|
59
|
+
{
|
|
60
|
+
method: 'GET',
|
|
61
|
+
headers: {
|
|
62
|
+
'X-API-KEY': config.value.apiKey,
|
|
63
|
+
},
|
|
64
|
+
}
|
|
65
|
+
) as Promise<[ResponseTypeMap[Endpoint], null] | [null, ApiError]>;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
async function post<Body, Endpoint extends keyof typeof ApiPaths>(endpoint: Endpoint, body?: Body) {
|
|
69
|
+
return makeFetch(getBaseUrl(endpoint), {
|
|
70
|
+
method: 'POST',
|
|
71
|
+
headers: {
|
|
72
|
+
'X-API-KEY': config.value.apiKey,
|
|
73
|
+
},
|
|
74
|
+
body: JSON.stringify(body),
|
|
75
|
+
}) as Promise<[ResponseTypeMap[Endpoint], null] | [null, ApiError]>;
|
|
76
|
+
}
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { defaultShades, generateShades } from './colorHelpers';
|
|
2
|
+
export interface Theme {
|
|
3
|
+
primary: string;
|
|
4
|
+
secondary: string;
|
|
5
|
+
positive: string;
|
|
6
|
+
negative: string;
|
|
7
|
+
fontPrimary: string;
|
|
8
|
+
fontSecondary: string;
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
const baseVariables = {
|
|
12
|
+
'--color-dark-blue-10': '242 242 245',
|
|
13
|
+
'--color-dark-blue': '0 0 0',
|
|
14
|
+
'--color-dark-grey': '97 95 110',
|
|
15
|
+
'--color-light-grey': '0 79 188',
|
|
16
|
+
'--color-dark': '29 29 29',
|
|
17
|
+
'--color-dark-page': '18 18 18',
|
|
18
|
+
'--font-24': '24px',
|
|
19
|
+
'--font-20': '20px',
|
|
20
|
+
'--font-16': '16px',
|
|
21
|
+
'--color-bg': '#ffffff',
|
|
22
|
+
'--color-bg-soft': '#f3f4f6',
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export function applyTheme(theme: Theme, element: HTMLElement) {
|
|
26
|
+
if (!element) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
Object.entries(theme).forEach(([key, value]) => {
|
|
30
|
+
const shades = value ? generateShades(value) : defaultShades;
|
|
31
|
+
Object.keys(shades)
|
|
32
|
+
.map(Number)
|
|
33
|
+
.forEach((shade) => {
|
|
34
|
+
element.style.setProperty(`--${key}-color-${shade}`, shades[shade]);
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
Object.entries(baseVariables).forEach(([key, value]) => {
|
|
38
|
+
element.style.setProperty(`${key}`, value);
|
|
39
|
+
});
|
|
40
|
+
}
|