@skalfa/skalfa-app 1.0.0 → 1.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/.env.example +43 -43
- package/.github/workflows/publish.yml +39 -0
- package/CONTRIBUTING.md +45 -0
- package/LICENSE +21 -0
- package/README.md +91 -28
- package/app/auth/edit/page.tsx +65 -65
- package/app/auth/login/page.tsx +63 -63
- package/app/auth/me/page.tsx +58 -58
- package/app/auth/register/page.tsx +69 -69
- package/app/auth/verify/page.tsx +53 -53
- package/app/dashboard/user/page.tsx +76 -76
- package/app/layout.tsx +37 -37
- package/app/manifest.ts +25 -0
- package/app/page.tsx +13 -13
- package/barrels.json +5 -5
- package/blueprints/starter.blueprint.json +102 -102
- package/bun.lock +916 -0
- package/components/base.components/chip/Chip.component.tsx +39 -39
- package/components/base.components/document/DocumentViewer.component.tsx +163 -163
- package/components/base.components/document/ExportExcel.component.tsx +340 -340
- package/components/base.components/document/ImportExcel.component.tsx +315 -315
- package/components/base.components/document/PrintTable.component.tsx +204 -204
- package/components/base.components/document/RenderPDF.component.tsx +415 -415
- package/components/base.components/input/Checkbox.component.tsx +109 -109
- package/components/base.components/input/Input.component.tsx +332 -332
- package/components/base.components/input/InputCheckbox.component.tsx +174 -174
- package/components/base.components/input/InputCurrency.component.tsx +163 -163
- package/components/base.components/input/InputDate.component.tsx +352 -352
- package/components/base.components/input/InputDatetime.component.tsx +260 -260
- package/components/base.components/input/InputDocument.component.tsx +351 -351
- package/components/base.components/input/InputImage.component.tsx +533 -533
- package/components/base.components/input/InputMap.component.tsx +317 -317
- package/components/base.components/input/InputNumber.component.tsx +192 -192
- package/components/base.components/input/InputOtp.component.tsx +169 -169
- package/components/base.components/input/InputPassword.component.tsx +236 -236
- package/components/base.components/input/InputRadio.component.tsx +175 -175
- package/components/base.components/input/InputTime.component.tsx +275 -275
- package/components/base.components/input/InputValues.component.tsx +68 -68
- package/components/base.components/input/Radio.component.tsx +102 -102
- package/components/base.components/input/Select.component.tsx +541 -541
- package/components/base.components/modal/BottomSheet.component.tsx +245 -245
- package/components/base.components/supervision/FormSupervision.component.tsx +433 -433
- package/components/base.components/supervision/TableSupervision.component.tsx +697 -697
- package/components/base.components/table/ControlBar.component.tsx +497 -497
- package/components/base.components/table/FilterComponent.tsx +518 -518
- package/components/base.components/table/Table.component.tsx +469 -469
- package/components/base.components/typography/TypographyArticle.component.tsx +26 -26
- package/components/base.components/typography/TypographyColumn.component.tsx +20 -20
- package/components/base.components/typography/TypographyContent.component.tsx +20 -20
- package/components/base.components/typography/TypographyTips.component.tsx +20 -20
- package/components/base.components/wrap/Draggable.component.tsx +303 -303
- package/components/base.components/wrap/IDBProvider.tsx +12 -12
- package/components/base.components/wrap/Image.component.tsx +9 -9
- package/components/base.components/wrap/ShortcutProvider.tsx +57 -57
- package/components/base.components/wrap/Swipe.component.tsx +93 -93
- package/components/index.ts +2 -2
- package/contexts/AppProvider.tsx +11 -11
- package/contexts/Auth.context.tsx +64 -64
- package/contexts/Toggle.context.tsx +44 -44
- package/next.config.ts +15 -1
- package/package.json +14 -13
- package/public/204.svg +19 -19
- package/public/500.svg +39 -39
- package/public/icon-192.png +0 -0
- package/public/icon-512.png +0 -0
- package/public/images/logo-fill.png +0 -0
- package/public/images/logo-full-fill.png +0 -0
- package/public/images/logo-full.png +0 -0
- package/public/images/logo.png +0 -0
- package/schema/idb/app.schema.ts +8 -8
- package/src-tauri/Cargo.toml +14 -0
- package/src-tauri/build.rs +3 -0
- package/src-tauri/capabilities/default.json +11 -0
- package/src-tauri/icons/128x128.png +0 -0
- package/src-tauri/icons/128x128@2x.png +0 -0
- package/src-tauri/icons/32x32.png +0 -0
- package/src-tauri/icons/icon.icns +0 -0
- package/src-tauri/icons/icon.ico +0 -0
- package/src-tauri/src/main.rs +7 -0
- package/src-tauri/tauri.conf.json +36 -0
- package/styles/globals.css +231 -231
- package/styles/tailwind.safelist +68 -68
- package/utils/commands/barrels.ts +27 -27
- package/utils/commands/light.ts +21 -21
- package/utils/commands/logger.ts +42 -42
- package/utils/commands/stubs/table-blueprint.stub +12 -12
- package/utils/commands/use-pdf.ts +29 -29
|
@@ -1,318 +1,318 @@
|
|
|
1
|
-
"use client"
|
|
2
|
-
|
|
3
|
-
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
-
import axios from "axios";
|
|
5
|
-
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
6
|
-
import { faLocationDot, faLocationCrosshairs } from "@fortawesome/free-solid-svg-icons";
|
|
7
|
-
import { GoogleMap, LoadScript } from "@react-google-maps/api";
|
|
8
|
-
import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
|
|
9
|
-
import { BottomSheetComponent, ButtonComponent, OutsideClickComponent } from "@components";
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
type CT = "label" | "tip" | "error" | "input" | "icon";
|
|
14
|
-
|
|
15
|
-
export interface ValueMapProps {
|
|
16
|
-
lat : number | null;
|
|
17
|
-
lng : number | null;
|
|
18
|
-
address ?: string;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export interface InputMapProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
22
|
-
label ?: string;
|
|
23
|
-
tip ?: string | React.ReactNode;
|
|
24
|
-
leftIcon ?: any;
|
|
25
|
-
rightIcon ?: any;
|
|
26
|
-
|
|
27
|
-
value ?: any;
|
|
28
|
-
invalid ?: string;
|
|
29
|
-
validations ?: ValidationRules;
|
|
30
|
-
|
|
31
|
-
onChange ?: (value: any) => any;
|
|
32
|
-
register ?: (name: string, validations?: ValidationRules) => void;
|
|
33
|
-
unregister ?: (name: string) => void;
|
|
34
|
-
|
|
35
|
-
className ?: string;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
export function InputMapComponent({
|
|
41
|
-
label,
|
|
42
|
-
tip,
|
|
43
|
-
leftIcon,
|
|
44
|
-
rightIcon,
|
|
45
|
-
|
|
46
|
-
value,
|
|
47
|
-
invalid,
|
|
48
|
-
validations,
|
|
49
|
-
|
|
50
|
-
register,
|
|
51
|
-
unregister,
|
|
52
|
-
onChange,
|
|
53
|
-
|
|
54
|
-
className = "",
|
|
55
|
-
...props
|
|
56
|
-
}: InputMapProps) {
|
|
57
|
-
const { isSm } = useResponsive();
|
|
58
|
-
|
|
59
|
-
// =========================>
|
|
60
|
-
// ## Invalid handler
|
|
61
|
-
// =========================>
|
|
62
|
-
const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
|
|
63
|
-
const randomId = useInputRandomId()
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
// =========================>
|
|
67
|
-
// ## Invalid handler
|
|
68
|
-
// =========================>
|
|
69
|
-
const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
return (
|
|
73
|
-
<>
|
|
74
|
-
<div className="relative flex flex-col gap-y-0.5">
|
|
75
|
-
{label && (
|
|
76
|
-
<label
|
|
77
|
-
htmlFor={randomId}
|
|
78
|
-
className={cn(
|
|
79
|
-
"input-label",
|
|
80
|
-
pcn<CT>(className, "label"),
|
|
81
|
-
props.disabled && "opacity-50",
|
|
82
|
-
inputHandler.focus && "text-primary",
|
|
83
|
-
!!invalidMessage && "text-danger",
|
|
84
|
-
)}
|
|
85
|
-
>
|
|
86
|
-
{label}
|
|
87
|
-
{validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
|
|
88
|
-
</label>
|
|
89
|
-
)}
|
|
90
|
-
|
|
91
|
-
{tip && (
|
|
92
|
-
<small
|
|
93
|
-
className={cn(
|
|
94
|
-
"input-tip",
|
|
95
|
-
pcn<CT>(className, "tip"),
|
|
96
|
-
props.disabled && "opacity-60",
|
|
97
|
-
)}
|
|
98
|
-
>{tip}</small>
|
|
99
|
-
)}
|
|
100
|
-
|
|
101
|
-
<OutsideClickComponent onOutsideClick={!isSm ? () => inputHandler.setFocus(false) : undefined}>
|
|
102
|
-
<div className="relative">
|
|
103
|
-
<input
|
|
104
|
-
{...props}
|
|
105
|
-
id={randomId}
|
|
106
|
-
className={cn(
|
|
107
|
-
"input",
|
|
108
|
-
leftIcon && "pl-12",
|
|
109
|
-
rightIcon && "pr-12",
|
|
110
|
-
pcn<CT>(className, "input"),
|
|
111
|
-
!!invalidMessage && "input-error",
|
|
112
|
-
)}
|
|
113
|
-
value={inputHandler.value?.address || ""}
|
|
114
|
-
readOnly
|
|
115
|
-
onFocus={(e) => {
|
|
116
|
-
props.onFocus?.(e);
|
|
117
|
-
inputHandler.setFocus(true);
|
|
118
|
-
inputHandler.setIdle(false);
|
|
119
|
-
}}
|
|
120
|
-
autoComplete="off"
|
|
121
|
-
/>
|
|
122
|
-
|
|
123
|
-
{leftIcon && (
|
|
124
|
-
<FontAwesomeIcon
|
|
125
|
-
className={cn(
|
|
126
|
-
"left-4 input-icon",
|
|
127
|
-
pcn<CT>(className, "icon"),
|
|
128
|
-
props.disabled && "opacity-60",
|
|
129
|
-
inputHandler.focus && "text-primary",
|
|
130
|
-
)}
|
|
131
|
-
icon={leftIcon}
|
|
132
|
-
/>
|
|
133
|
-
)}
|
|
134
|
-
|
|
135
|
-
{rightIcon && (
|
|
136
|
-
<FontAwesomeIcon
|
|
137
|
-
className={cn(
|
|
138
|
-
"right-4 input-icon",
|
|
139
|
-
pcn<CT>(className, "icon"),
|
|
140
|
-
props.disabled && "opacity-60",
|
|
141
|
-
inputHandler.focus && "text-primary",
|
|
142
|
-
)}
|
|
143
|
-
icon={rightIcon}
|
|
144
|
-
/>
|
|
145
|
-
)}
|
|
146
|
-
|
|
147
|
-
{!isSm && inputHandler.focus && (
|
|
148
|
-
<div
|
|
149
|
-
className="absolute top-full left-0 mt-2 w-full z-50 bg-background border border-light-border rounded-md overflow-hidden shadow-lg"
|
|
150
|
-
style={{ height: 300 }}
|
|
151
|
-
>
|
|
152
|
-
<InputMapPickerComponent
|
|
153
|
-
value={inputHandler.value}
|
|
154
|
-
onChange={(e) => {
|
|
155
|
-
inputHandler.setValue(e)
|
|
156
|
-
onChange?.(e)
|
|
157
|
-
}}
|
|
158
|
-
/>
|
|
159
|
-
</div>
|
|
160
|
-
)}
|
|
161
|
-
</div>
|
|
162
|
-
</OutsideClickComponent>
|
|
163
|
-
|
|
164
|
-
{invalidMessage && (
|
|
165
|
-
<small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
|
|
166
|
-
)}
|
|
167
|
-
</div>
|
|
168
|
-
|
|
169
|
-
{isSm && (
|
|
170
|
-
<BottomSheetComponent
|
|
171
|
-
show={inputHandler.focus}
|
|
172
|
-
onClose={() => inputHandler.setFocus(false)}
|
|
173
|
-
size={450}
|
|
174
|
-
footer={
|
|
175
|
-
<div className="p-4">
|
|
176
|
-
<ButtonComponent
|
|
177
|
-
label="Selesai"
|
|
178
|
-
variant="outline"
|
|
179
|
-
onClick={() => inputHandler.setFocus(false)}
|
|
180
|
-
block
|
|
181
|
-
/>
|
|
182
|
-
</div>
|
|
183
|
-
}
|
|
184
|
-
>
|
|
185
|
-
<div className="p-4">
|
|
186
|
-
<InputMapPickerComponent
|
|
187
|
-
onChange={(e) => {
|
|
188
|
-
inputHandler.setValue(e);
|
|
189
|
-
onChange?.(e);
|
|
190
|
-
}}
|
|
191
|
-
/>
|
|
192
|
-
</div>
|
|
193
|
-
</BottomSheetComponent>
|
|
194
|
-
)}
|
|
195
|
-
</>
|
|
196
|
-
);
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
export interface MapPickerProps {
|
|
201
|
-
value ?: any;
|
|
202
|
-
onChange ?: (value: any) => any;
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
export const InputMapPickerComponent: React.FC<MapPickerProps> = ({
|
|
206
|
-
onChange,
|
|
207
|
-
value
|
|
208
|
-
}) => {
|
|
209
|
-
const mapRef = useRef<google.maps.Map | null>(null);
|
|
210
|
-
|
|
211
|
-
const [addressLoading, setAddressLoading] = useState(false);
|
|
212
|
-
const [drag, setDrag] = useState(false);
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
// =========================>
|
|
216
|
-
// ## Map Events
|
|
217
|
-
// =========================>
|
|
218
|
-
const setCurrentPosition = () => {
|
|
219
|
-
if (navigator.geolocation) {
|
|
220
|
-
navigator.geolocation.getCurrentPosition((pos) => {
|
|
221
|
-
const newPos = {
|
|
222
|
-
lat: pos.coords.latitude,
|
|
223
|
-
lng: pos.coords.longitude,
|
|
224
|
-
address: "",
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
onChange?.(newPos);
|
|
228
|
-
mapRef.current?.panTo(new google.maps.LatLng(newPos.lat, newPos.lng));
|
|
229
|
-
});
|
|
230
|
-
}
|
|
231
|
-
};
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
const handleDragEnd = useCallback(() => {
|
|
235
|
-
if (mapRef.current) {
|
|
236
|
-
const center = mapRef.current.getCenter();
|
|
237
|
-
|
|
238
|
-
if (center) {
|
|
239
|
-
onChange?.({
|
|
240
|
-
lat: center.lat(),
|
|
241
|
-
lng: center.lng(),
|
|
242
|
-
address: "",
|
|
243
|
-
});
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
setDrag(false);
|
|
247
|
-
}
|
|
248
|
-
}, []);
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
// =========================>
|
|
252
|
-
// ## Reverse Geocode
|
|
253
|
-
// =========================>
|
|
254
|
-
useEffect(() => {
|
|
255
|
-
if (value?.lat && value?.lng) {
|
|
256
|
-
setAddressLoading(true);
|
|
257
|
-
onChange?.((prev: any) => ({ ...prev, address: "" }));
|
|
258
|
-
|
|
259
|
-
axios.get(`https://api.geoapify.com/v1/geocode/reverse?lat=${value?.lat}&lon=${value?.lng}&apiKey=${process.env.NEXT_PUBLIC_GEOAPIFY_KEY}`)
|
|
260
|
-
.then((res: any) => {
|
|
261
|
-
if (res.status === 200 && !res.data.error) {
|
|
262
|
-
const data = res.data.features?.at(0)?.properties;
|
|
263
|
-
const address =(data?.address_line1 || "") + " " + (data?.address_line2 || "");
|
|
264
|
-
|
|
265
|
-
onChange?.((prev: any) => ({ ...prev, address }));
|
|
266
|
-
onChange?.({ ...value, address });
|
|
267
|
-
}
|
|
268
|
-
})
|
|
269
|
-
.finally(() => setAddressLoading(false));
|
|
270
|
-
}
|
|
271
|
-
}, [value?.lat, value?.lng]);
|
|
272
|
-
|
|
273
|
-
return (
|
|
274
|
-
<div className="relative w-full">
|
|
275
|
-
<LoadScript googleMapsApiKey={process.env.NEXT_PUBLIC_MAP_KEY || ""}>
|
|
276
|
-
<GoogleMap
|
|
277
|
-
mapContainerStyle={{ width: "100%", height: "100%" }}
|
|
278
|
-
center={{
|
|
279
|
-
lat: value?.lat || -6.208,
|
|
280
|
-
lng: value?.lng || 106.689,
|
|
281
|
-
}}
|
|
282
|
-
zoom={18}
|
|
283
|
-
options={{
|
|
284
|
-
streetViewControl: false,
|
|
285
|
-
mapTypeControl: false,
|
|
286
|
-
fullscreenControl: false,
|
|
287
|
-
}}
|
|
288
|
-
onLoad={(map) => {mapRef.current = map}}
|
|
289
|
-
onDrag={() => setDrag(true)}
|
|
290
|
-
onDragEnd={handleDragEnd}
|
|
291
|
-
/>
|
|
292
|
-
</LoadScript>
|
|
293
|
-
|
|
294
|
-
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 pointer-events-none">
|
|
295
|
-
<FontAwesomeIcon
|
|
296
|
-
icon={faLocationDot}
|
|
297
|
-
className={cn(
|
|
298
|
-
"text-3xl text-primary drop-shadow-md transition-transform",
|
|
299
|
-
drag && "scale-125 -translate-y-2",
|
|
300
|
-
)}
|
|
301
|
-
/>
|
|
302
|
-
</div>
|
|
303
|
-
|
|
304
|
-
<div className="absolute top-3 left-3 bg-background px-3 py-2 rounded-lg shadow">
|
|
305
|
-
{addressLoading && !value?.address ? (
|
|
306
|
-
<div className="py-4 w-[200px]" />
|
|
307
|
-
) : (
|
|
308
|
-
<span className="text-sm">{value?.address}</span>
|
|
309
|
-
)}
|
|
310
|
-
</div>
|
|
311
|
-
|
|
312
|
-
<div
|
|
313
|
-
className="absolute top-3 right-3 bg-background p-3 rounded-lg cursor-pointer shadow"
|
|
314
|
-
onClick={() => setCurrentPosition()}
|
|
315
|
-
><FontAwesomeIcon icon={faLocationCrosshairs} className="text-lg" /></div>
|
|
316
|
-
</div>
|
|
317
|
-
)
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
4
|
+
import axios from "axios";
|
|
5
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
6
|
+
import { faLocationDot, faLocationCrosshairs } from "@fortawesome/free-solid-svg-icons";
|
|
7
|
+
import { GoogleMap, LoadScript } from "@react-google-maps/api";
|
|
8
|
+
import { cn, pcn, useInputHandler, useInputRandomId, useResponsive, useValidation, validation, ValidationRules } from "@utils";
|
|
9
|
+
import { BottomSheetComponent, ButtonComponent, OutsideClickComponent } from "@components";
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
type CT = "label" | "tip" | "error" | "input" | "icon";
|
|
14
|
+
|
|
15
|
+
export interface ValueMapProps {
|
|
16
|
+
lat : number | null;
|
|
17
|
+
lng : number | null;
|
|
18
|
+
address ?: string;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export interface InputMapProps extends Omit<React.InputHTMLAttributes<HTMLInputElement>, "onChange"> {
|
|
22
|
+
label ?: string;
|
|
23
|
+
tip ?: string | React.ReactNode;
|
|
24
|
+
leftIcon ?: any;
|
|
25
|
+
rightIcon ?: any;
|
|
26
|
+
|
|
27
|
+
value ?: any;
|
|
28
|
+
invalid ?: string;
|
|
29
|
+
validations ?: ValidationRules;
|
|
30
|
+
|
|
31
|
+
onChange ?: (value: any) => any;
|
|
32
|
+
register ?: (name: string, validations?: ValidationRules) => void;
|
|
33
|
+
unregister ?: (name: string) => void;
|
|
34
|
+
|
|
35
|
+
className ?: string;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
export function InputMapComponent({
|
|
41
|
+
label,
|
|
42
|
+
tip,
|
|
43
|
+
leftIcon,
|
|
44
|
+
rightIcon,
|
|
45
|
+
|
|
46
|
+
value,
|
|
47
|
+
invalid,
|
|
48
|
+
validations,
|
|
49
|
+
|
|
50
|
+
register,
|
|
51
|
+
unregister,
|
|
52
|
+
onChange,
|
|
53
|
+
|
|
54
|
+
className = "",
|
|
55
|
+
...props
|
|
56
|
+
}: InputMapProps) {
|
|
57
|
+
const { isSm } = useResponsive();
|
|
58
|
+
|
|
59
|
+
// =========================>
|
|
60
|
+
// ## Invalid handler
|
|
61
|
+
// =========================>
|
|
62
|
+
const inputHandler = useInputHandler(props.name, value, validations, register, unregister, false)
|
|
63
|
+
const randomId = useInputRandomId()
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
// =========================>
|
|
67
|
+
// ## Invalid handler
|
|
68
|
+
// =========================>
|
|
69
|
+
const [invalidMessage] = useValidation(inputHandler.value, validations, invalid, inputHandler.idle);
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
return (
|
|
73
|
+
<>
|
|
74
|
+
<div className="relative flex flex-col gap-y-0.5">
|
|
75
|
+
{label && (
|
|
76
|
+
<label
|
|
77
|
+
htmlFor={randomId}
|
|
78
|
+
className={cn(
|
|
79
|
+
"input-label",
|
|
80
|
+
pcn<CT>(className, "label"),
|
|
81
|
+
props.disabled && "opacity-50",
|
|
82
|
+
inputHandler.focus && "text-primary",
|
|
83
|
+
!!invalidMessage && "text-danger",
|
|
84
|
+
)}
|
|
85
|
+
>
|
|
86
|
+
{label}
|
|
87
|
+
{validations && validation.hasRules(validations, "required") && <span className="text-danger ml-1">*</span>}
|
|
88
|
+
</label>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{tip && (
|
|
92
|
+
<small
|
|
93
|
+
className={cn(
|
|
94
|
+
"input-tip",
|
|
95
|
+
pcn<CT>(className, "tip"),
|
|
96
|
+
props.disabled && "opacity-60",
|
|
97
|
+
)}
|
|
98
|
+
>{tip}</small>
|
|
99
|
+
)}
|
|
100
|
+
|
|
101
|
+
<OutsideClickComponent onOutsideClick={!isSm ? () => inputHandler.setFocus(false) : undefined}>
|
|
102
|
+
<div className="relative">
|
|
103
|
+
<input
|
|
104
|
+
{...props}
|
|
105
|
+
id={randomId}
|
|
106
|
+
className={cn(
|
|
107
|
+
"input",
|
|
108
|
+
leftIcon && "pl-12",
|
|
109
|
+
rightIcon && "pr-12",
|
|
110
|
+
pcn<CT>(className, "input"),
|
|
111
|
+
!!invalidMessage && "input-error",
|
|
112
|
+
)}
|
|
113
|
+
value={inputHandler.value?.address || ""}
|
|
114
|
+
readOnly
|
|
115
|
+
onFocus={(e) => {
|
|
116
|
+
props.onFocus?.(e);
|
|
117
|
+
inputHandler.setFocus(true);
|
|
118
|
+
inputHandler.setIdle(false);
|
|
119
|
+
}}
|
|
120
|
+
autoComplete="off"
|
|
121
|
+
/>
|
|
122
|
+
|
|
123
|
+
{leftIcon && (
|
|
124
|
+
<FontAwesomeIcon
|
|
125
|
+
className={cn(
|
|
126
|
+
"left-4 input-icon",
|
|
127
|
+
pcn<CT>(className, "icon"),
|
|
128
|
+
props.disabled && "opacity-60",
|
|
129
|
+
inputHandler.focus && "text-primary",
|
|
130
|
+
)}
|
|
131
|
+
icon={leftIcon}
|
|
132
|
+
/>
|
|
133
|
+
)}
|
|
134
|
+
|
|
135
|
+
{rightIcon && (
|
|
136
|
+
<FontAwesomeIcon
|
|
137
|
+
className={cn(
|
|
138
|
+
"right-4 input-icon",
|
|
139
|
+
pcn<CT>(className, "icon"),
|
|
140
|
+
props.disabled && "opacity-60",
|
|
141
|
+
inputHandler.focus && "text-primary",
|
|
142
|
+
)}
|
|
143
|
+
icon={rightIcon}
|
|
144
|
+
/>
|
|
145
|
+
)}
|
|
146
|
+
|
|
147
|
+
{!isSm && inputHandler.focus && (
|
|
148
|
+
<div
|
|
149
|
+
className="absolute top-full left-0 mt-2 w-full z-50 bg-background border border-light-border rounded-md overflow-hidden shadow-lg"
|
|
150
|
+
style={{ height: 300 }}
|
|
151
|
+
>
|
|
152
|
+
<InputMapPickerComponent
|
|
153
|
+
value={inputHandler.value}
|
|
154
|
+
onChange={(e) => {
|
|
155
|
+
inputHandler.setValue(e)
|
|
156
|
+
onChange?.(e)
|
|
157
|
+
}}
|
|
158
|
+
/>
|
|
159
|
+
</div>
|
|
160
|
+
)}
|
|
161
|
+
</div>
|
|
162
|
+
</OutsideClickComponent>
|
|
163
|
+
|
|
164
|
+
{invalidMessage && (
|
|
165
|
+
<small className={cn("input-error-message", pcn<CT>(className, "error"))}>{invalidMessage}</small>
|
|
166
|
+
)}
|
|
167
|
+
</div>
|
|
168
|
+
|
|
169
|
+
{isSm && (
|
|
170
|
+
<BottomSheetComponent
|
|
171
|
+
show={inputHandler.focus}
|
|
172
|
+
onClose={() => inputHandler.setFocus(false)}
|
|
173
|
+
size={450}
|
|
174
|
+
footer={
|
|
175
|
+
<div className="p-4">
|
|
176
|
+
<ButtonComponent
|
|
177
|
+
label="Selesai"
|
|
178
|
+
variant="outline"
|
|
179
|
+
onClick={() => inputHandler.setFocus(false)}
|
|
180
|
+
block
|
|
181
|
+
/>
|
|
182
|
+
</div>
|
|
183
|
+
}
|
|
184
|
+
>
|
|
185
|
+
<div className="p-4">
|
|
186
|
+
<InputMapPickerComponent
|
|
187
|
+
onChange={(e) => {
|
|
188
|
+
inputHandler.setValue(e);
|
|
189
|
+
onChange?.(e);
|
|
190
|
+
}}
|
|
191
|
+
/>
|
|
192
|
+
</div>
|
|
193
|
+
</BottomSheetComponent>
|
|
194
|
+
)}
|
|
195
|
+
</>
|
|
196
|
+
);
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
export interface MapPickerProps {
|
|
201
|
+
value ?: any;
|
|
202
|
+
onChange ?: (value: any) => any;
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
export const InputMapPickerComponent: React.FC<MapPickerProps> = ({
|
|
206
|
+
onChange,
|
|
207
|
+
value
|
|
208
|
+
}) => {
|
|
209
|
+
const mapRef = useRef<google.maps.Map | null>(null);
|
|
210
|
+
|
|
211
|
+
const [addressLoading, setAddressLoading] = useState(false);
|
|
212
|
+
const [drag, setDrag] = useState(false);
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
// =========================>
|
|
216
|
+
// ## Map Events
|
|
217
|
+
// =========================>
|
|
218
|
+
const setCurrentPosition = () => {
|
|
219
|
+
if (navigator.geolocation) {
|
|
220
|
+
navigator.geolocation.getCurrentPosition((pos) => {
|
|
221
|
+
const newPos = {
|
|
222
|
+
lat: pos.coords.latitude,
|
|
223
|
+
lng: pos.coords.longitude,
|
|
224
|
+
address: "",
|
|
225
|
+
};
|
|
226
|
+
|
|
227
|
+
onChange?.(newPos);
|
|
228
|
+
mapRef.current?.panTo(new google.maps.LatLng(newPos.lat, newPos.lng));
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
|
|
234
|
+
const handleDragEnd = useCallback(() => {
|
|
235
|
+
if (mapRef.current) {
|
|
236
|
+
const center = mapRef.current.getCenter();
|
|
237
|
+
|
|
238
|
+
if (center) {
|
|
239
|
+
onChange?.({
|
|
240
|
+
lat: center.lat(),
|
|
241
|
+
lng: center.lng(),
|
|
242
|
+
address: "",
|
|
243
|
+
});
|
|
244
|
+
}
|
|
245
|
+
|
|
246
|
+
setDrag(false);
|
|
247
|
+
}
|
|
248
|
+
}, []);
|
|
249
|
+
|
|
250
|
+
|
|
251
|
+
// =========================>
|
|
252
|
+
// ## Reverse Geocode
|
|
253
|
+
// =========================>
|
|
254
|
+
useEffect(() => {
|
|
255
|
+
if (value?.lat && value?.lng) {
|
|
256
|
+
setAddressLoading(true);
|
|
257
|
+
onChange?.((prev: any) => ({ ...prev, address: "" }));
|
|
258
|
+
|
|
259
|
+
axios.get(`https://api.geoapify.com/v1/geocode/reverse?lat=${value?.lat}&lon=${value?.lng}&apiKey=${process.env.NEXT_PUBLIC_GEOAPIFY_KEY}`)
|
|
260
|
+
.then((res: any) => {
|
|
261
|
+
if (res.status === 200 && !res.data.error) {
|
|
262
|
+
const data = res.data.features?.at(0)?.properties;
|
|
263
|
+
const address =(data?.address_line1 || "") + " " + (data?.address_line2 || "");
|
|
264
|
+
|
|
265
|
+
onChange?.((prev: any) => ({ ...prev, address }));
|
|
266
|
+
onChange?.({ ...value, address });
|
|
267
|
+
}
|
|
268
|
+
})
|
|
269
|
+
.finally(() => setAddressLoading(false));
|
|
270
|
+
}
|
|
271
|
+
}, [value?.lat, value?.lng]);
|
|
272
|
+
|
|
273
|
+
return (
|
|
274
|
+
<div className="relative w-full">
|
|
275
|
+
<LoadScript googleMapsApiKey={process.env.NEXT_PUBLIC_MAP_KEY || ""}>
|
|
276
|
+
<GoogleMap
|
|
277
|
+
mapContainerStyle={{ width: "100%", height: "100%" }}
|
|
278
|
+
center={{
|
|
279
|
+
lat: value?.lat || -6.208,
|
|
280
|
+
lng: value?.lng || 106.689,
|
|
281
|
+
}}
|
|
282
|
+
zoom={18}
|
|
283
|
+
options={{
|
|
284
|
+
streetViewControl: false,
|
|
285
|
+
mapTypeControl: false,
|
|
286
|
+
fullscreenControl: false,
|
|
287
|
+
}}
|
|
288
|
+
onLoad={(map) => {mapRef.current = map}}
|
|
289
|
+
onDrag={() => setDrag(true)}
|
|
290
|
+
onDragEnd={handleDragEnd}
|
|
291
|
+
/>
|
|
292
|
+
</LoadScript>
|
|
293
|
+
|
|
294
|
+
<div className="absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 pointer-events-none">
|
|
295
|
+
<FontAwesomeIcon
|
|
296
|
+
icon={faLocationDot}
|
|
297
|
+
className={cn(
|
|
298
|
+
"text-3xl text-primary drop-shadow-md transition-transform",
|
|
299
|
+
drag && "scale-125 -translate-y-2",
|
|
300
|
+
)}
|
|
301
|
+
/>
|
|
302
|
+
</div>
|
|
303
|
+
|
|
304
|
+
<div className="absolute top-3 left-3 bg-background px-3 py-2 rounded-lg shadow">
|
|
305
|
+
{addressLoading && !value?.address ? (
|
|
306
|
+
<div className="py-4 w-[200px]" />
|
|
307
|
+
) : (
|
|
308
|
+
<span className="text-sm">{value?.address}</span>
|
|
309
|
+
)}
|
|
310
|
+
</div>
|
|
311
|
+
|
|
312
|
+
<div
|
|
313
|
+
className="absolute top-3 right-3 bg-background p-3 rounded-lg cursor-pointer shadow"
|
|
314
|
+
onClick={() => setCurrentPosition()}
|
|
315
|
+
><FontAwesomeIcon icon={faLocationCrosshairs} className="text-lg" /></div>
|
|
316
|
+
</div>
|
|
317
|
+
)
|
|
318
318
|
}
|