@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.
Files changed (87) hide show
  1. package/.env.example +43 -43
  2. package/.github/workflows/publish.yml +39 -0
  3. package/CONTRIBUTING.md +45 -0
  4. package/LICENSE +21 -0
  5. package/README.md +91 -28
  6. package/app/auth/edit/page.tsx +65 -65
  7. package/app/auth/login/page.tsx +63 -63
  8. package/app/auth/me/page.tsx +58 -58
  9. package/app/auth/register/page.tsx +69 -69
  10. package/app/auth/verify/page.tsx +53 -53
  11. package/app/dashboard/user/page.tsx +76 -76
  12. package/app/layout.tsx +37 -37
  13. package/app/manifest.ts +25 -0
  14. package/app/page.tsx +13 -13
  15. package/barrels.json +5 -5
  16. package/blueprints/starter.blueprint.json +102 -102
  17. package/bun.lock +916 -0
  18. package/components/base.components/chip/Chip.component.tsx +39 -39
  19. package/components/base.components/document/DocumentViewer.component.tsx +163 -163
  20. package/components/base.components/document/ExportExcel.component.tsx +340 -340
  21. package/components/base.components/document/ImportExcel.component.tsx +315 -315
  22. package/components/base.components/document/PrintTable.component.tsx +204 -204
  23. package/components/base.components/document/RenderPDF.component.tsx +415 -415
  24. package/components/base.components/input/Checkbox.component.tsx +109 -109
  25. package/components/base.components/input/Input.component.tsx +332 -332
  26. package/components/base.components/input/InputCheckbox.component.tsx +174 -174
  27. package/components/base.components/input/InputCurrency.component.tsx +163 -163
  28. package/components/base.components/input/InputDate.component.tsx +352 -352
  29. package/components/base.components/input/InputDatetime.component.tsx +260 -260
  30. package/components/base.components/input/InputDocument.component.tsx +351 -351
  31. package/components/base.components/input/InputImage.component.tsx +533 -533
  32. package/components/base.components/input/InputMap.component.tsx +317 -317
  33. package/components/base.components/input/InputNumber.component.tsx +192 -192
  34. package/components/base.components/input/InputOtp.component.tsx +169 -169
  35. package/components/base.components/input/InputPassword.component.tsx +236 -236
  36. package/components/base.components/input/InputRadio.component.tsx +175 -175
  37. package/components/base.components/input/InputTime.component.tsx +275 -275
  38. package/components/base.components/input/InputValues.component.tsx +68 -68
  39. package/components/base.components/input/Radio.component.tsx +102 -102
  40. package/components/base.components/input/Select.component.tsx +541 -541
  41. package/components/base.components/modal/BottomSheet.component.tsx +245 -245
  42. package/components/base.components/supervision/FormSupervision.component.tsx +433 -433
  43. package/components/base.components/supervision/TableSupervision.component.tsx +697 -697
  44. package/components/base.components/table/ControlBar.component.tsx +497 -497
  45. package/components/base.components/table/FilterComponent.tsx +518 -518
  46. package/components/base.components/table/Table.component.tsx +469 -469
  47. package/components/base.components/typography/TypographyArticle.component.tsx +26 -26
  48. package/components/base.components/typography/TypographyColumn.component.tsx +20 -20
  49. package/components/base.components/typography/TypographyContent.component.tsx +20 -20
  50. package/components/base.components/typography/TypographyTips.component.tsx +20 -20
  51. package/components/base.components/wrap/Draggable.component.tsx +303 -303
  52. package/components/base.components/wrap/IDBProvider.tsx +12 -12
  53. package/components/base.components/wrap/Image.component.tsx +9 -9
  54. package/components/base.components/wrap/ShortcutProvider.tsx +57 -57
  55. package/components/base.components/wrap/Swipe.component.tsx +93 -93
  56. package/components/index.ts +2 -2
  57. package/contexts/AppProvider.tsx +11 -11
  58. package/contexts/Auth.context.tsx +64 -64
  59. package/contexts/Toggle.context.tsx +44 -44
  60. package/next.config.ts +15 -1
  61. package/package.json +14 -13
  62. package/public/204.svg +19 -19
  63. package/public/500.svg +39 -39
  64. package/public/icon-192.png +0 -0
  65. package/public/icon-512.png +0 -0
  66. package/public/images/logo-fill.png +0 -0
  67. package/public/images/logo-full-fill.png +0 -0
  68. package/public/images/logo-full.png +0 -0
  69. package/public/images/logo.png +0 -0
  70. package/schema/idb/app.schema.ts +8 -8
  71. package/src-tauri/Cargo.toml +14 -0
  72. package/src-tauri/build.rs +3 -0
  73. package/src-tauri/capabilities/default.json +11 -0
  74. package/src-tauri/icons/128x128.png +0 -0
  75. package/src-tauri/icons/128x128@2x.png +0 -0
  76. package/src-tauri/icons/32x32.png +0 -0
  77. package/src-tauri/icons/icon.icns +0 -0
  78. package/src-tauri/icons/icon.ico +0 -0
  79. package/src-tauri/src/main.rs +7 -0
  80. package/src-tauri/tauri.conf.json +36 -0
  81. package/styles/globals.css +231 -231
  82. package/styles/tailwind.safelist +68 -68
  83. package/utils/commands/barrels.ts +27 -27
  84. package/utils/commands/light.ts +21 -21
  85. package/utils/commands/logger.ts +42 -42
  86. package/utils/commands/stubs/table-blueprint.stub +12 -12
  87. package/utils/commands/use-pdf.ts +29 -29
@@ -1,518 +1,518 @@
1
- "use client"
2
-
3
- import { useState, useEffect } from "react";
4
- import { faChevronUp, faEllipsisH, faPlus, faRotate, faTimes } from "@fortawesome/free-solid-svg-icons";
5
- import { ApiFilterType, cn, pcn, useResponsive } from "@utils";
6
- import {ButtonComponent, ChipComponent, IconButtonComponent, InputComponent, InputCurrencyComponent, InputDateComponent, InputNumberComponent, ModalComponent, SelectComponent} from "@components";
7
- import { useToggleContext } from "@contexts";
8
- import { faBookmark } from "@fortawesome/free-regular-svg-icons";
9
-
10
-
11
-
12
- type CT = "base" | "title";
13
-
14
- export type FilterColumnOption = {
15
- label: string;
16
- selector: string;
17
- type: "text" | "number" | "currency" | "date";
18
- } | {
19
- label: string;
20
- selector: string;
21
- type: "select";
22
- options: { label: string; value: any }[];
23
- };
24
-
25
- export type FilterBookmark = {
26
- id: string;
27
- name: string;
28
- filters: ApiFilterType[];
29
- createdAt: number;
30
- };
31
-
32
- export interface AdvancedFilterProps {
33
- columns : FilterColumnOption[];
34
- onChange ?: (filters: ApiFilterType[]) => void;
35
- value ?: ApiFilterType[];
36
- onMinimize ?: () => void;
37
-
38
- /** Use custom class with: "title::". */
39
- className ?: string;
40
- }
41
-
42
- const FILTER_OPERATORS = [
43
- { label: "Cari", value: "li" },
44
- { label: "Sama", value: "eq" },
45
- { label: "Tidak Sama", value: "ne" },
46
- { label: "Termasuk", value: "in" },
47
- { label: "Tidak Termasuk", value: "ni" },
48
- { label: "Antara", value: "bw" },
49
- ];
50
-
51
- const LOGIC_OPTIONS = [
52
- { label: "Dan", value: "and" },
53
- { label: "Atau", value: "or" },
54
- ];
55
-
56
- const BOOKMARK_KEY = "filter-bookmarks";
57
-
58
-
59
-
60
- export function FilterComponent({
61
- columns,
62
- onChange,
63
- value,
64
- onMinimize,
65
- className = "",
66
- }: AdvancedFilterProps) {
67
- const { isSm } = useResponsive();
68
- const { toggle, setToggle } = useToggleContext()
69
- const [filters, setFilters] = useState<ApiFilterType[]>([]);
70
-
71
- const [bookmarks, setBookmarks] = useState<FilterBookmark[]>([]);
72
-
73
- const handleChange = (index: number, key: keyof ApiFilterType, value: any) => {
74
- const updated = [...filters];
75
- updated[index][key] = value;
76
-
77
- if (key === "column") {
78
- updated[index].type = "";
79
- updated[index].value = "";
80
- }
81
-
82
- setFilters(updated);
83
- };
84
-
85
- const addFilter = () => {
86
- setFilters([
87
- ...filters,
88
- { column: "", type: "", value: "", logic: filters.length ? "and" : undefined },
89
- ]);
90
- };
91
-
92
- const removeFilter = (index: number) => {
93
- const updated = filters.filter((_, i) => i !== index);
94
- setFilters(updated);
95
- };
96
-
97
- useEffect(() => {
98
- if (onChange) onChange(filters);
99
- }, [filters]);
100
-
101
-
102
- useEffect(() => {}, [value]);
103
-
104
-
105
- useEffect(() => {
106
- setBookmarks(JSON.parse(localStorage.getItem(BOOKMARK_KEY) || "[]"));
107
- }, []);
108
-
109
- useEffect(() => {
110
- localStorage.setItem(BOOKMARK_KEY, JSON.stringify(bookmarks));
111
- }, [bookmarks]);
112
-
113
-
114
- return (
115
- <>
116
- <div className={cn("p-4 border rounded-sm", pcn<CT>(className, "base"))}>
117
- <div className="flex justify-between items-center mb-4">
118
- <p className={cn(pcn<CT>(className, "title"))}>Filter</p>
119
- <div className="flex gap-4 items-center">
120
- <div className="flex gap-2 items-center">
121
- <IconButtonComponent
122
- icon={faBookmark}
123
- variant="outline"
124
- paint="primary"
125
- className="text-slate-400 icon::text-slate-400"
126
- size="xs"
127
- onClick={() => setToggle("MODAL_BOOKMARK", { bookmark_id: "new" })}
128
- />
129
-
130
- {!!bookmarks?.length && (
131
- <ChipComponent
132
- items={bookmarks.slice(0, 5).map((b) => b.name)}
133
- onClick={(_, index) => setFilters(bookmarks[index]?.filters)}
134
- onDelete={(_, index) => setBookmarks(bookmarks.filter(( _, bi: number) => bi != index))}
135
- />
136
- )}
137
-
138
- {bookmarks?.length > 5 && (
139
- <IconButtonComponent
140
- icon={faEllipsisH}
141
- variant="outline"
142
- paint="primary"
143
- className="text-slate-400 icon::text-slate-400"
144
- size="xs"
145
- onClick={() => setToggle("MODAL_BOOKMARK_LIST")}
146
- />
147
- )}
148
- </div>
149
-
150
- <ButtonComponent
151
- icon={faRotate}
152
- label="Bersihkan"
153
- variant="outline"
154
- paint="primary"
155
- className="text-slate-400 icon::text-slate-400"
156
- size="xs"
157
- onClick={() => setFilters([])}
158
- />
159
-
160
- {onMinimize && (
161
- <IconButtonComponent
162
- icon={faChevronUp}
163
- variant="outline"
164
- paint="primary"
165
- className="text-slate-400 icon::text-slate-400"
166
- size="xs"
167
- onClick={onMinimize}
168
- />
169
- )}
170
- </div>
171
- </div>
172
-
173
- {filters.map((f, i) => {
174
- const column = columns.find((c) => c.selector === f.column);
175
-
176
- return (
177
- <div key={i} className="flex flex-wrap items-center gap-2 mb-2">
178
- {i > 0 && (
179
- <div className="w-[20%] md:w-[10%]">
180
- <SelectComponent
181
- name={`filter_logic_${i}`}
182
- options={LOGIC_OPTIONS}
183
- placeholder="Dan/Atau"
184
- value={f.logic}
185
- onChange={(e) => handleChange(i, "logic", e as "and" | "or")}
186
- className="text-sm p-2 px-3"
187
- />
188
- </div>
189
- )}
190
-
191
- <div className={i > 0 ? "w-[30%] md:w-[20%]" : "w-[52.5%] md:w-[30.7%]"}>
192
- <SelectComponent
193
- name={`filter_column_${i}`}
194
- options={columns.map((c) => ({
195
- label: c.label,
196
- value: c.selector,
197
- }))}
198
- placeholder="Kolom"
199
- value={f.column}
200
- onChange={(e) => handleChange(i, "column", e)}
201
- className="text-sm p-2 px-3"
202
- />
203
- </div>
204
-
205
- <div className="w-[35%] md:w-[18%]">
206
- <SelectComponent
207
- name={`filter_operator_${i}`}
208
- options={FILTER_OPERATORS}
209
- placeholder="Operator"
210
- value={f.type}
211
- onChange={(e) => handleChange(i, "type", e)}
212
- className="text-sm p-2 px-3"
213
- />
214
- </div>
215
-
216
- {isSm && (
217
- <IconButtonComponent
218
- icon={faTimes}
219
- paint="danger"
220
- variant="outline"
221
- onClick={() => removeFilter(i)}
222
- size="xs"
223
- />
224
- )}
225
-
226
- {column && (
227
- <div className="w-full md:w-[45%]">
228
- <InputFilterValueComponent
229
- type={column.type}
230
- name={`filter_value_${i}`}
231
- placeholder="..."
232
- value={f.value || ""}
233
- onChange={(e: any) => handleChange(i, "value", e)}
234
- options={column.type === "select" && column.options ? column.options : []}
235
- className="text-sm p-2 px-3"
236
- between={f.type === "bw"}
237
- multiple={["in", "ni"].includes(f.type || "")}
238
- />
239
- </div>
240
- )}
241
-
242
- {!isSm && (
243
- <IconButtonComponent
244
- icon={faTimes}
245
- paint="danger"
246
- variant="outline"
247
- onClick={() => removeFilter(i)}
248
- size="xs"
249
- />
250
- )}
251
- </div>
252
- );
253
- })}
254
-
255
- <ButtonComponent
256
- label="Tambahkan"
257
- icon={faPlus}
258
- variant="outline"
259
- paint="primary"
260
- size={isSm ? "xs" : "sm"}
261
- onClick={addFilter}
262
- className="md:mt-4"
263
- />
264
- </div>
265
-
266
- <ModalComponent
267
- show={!!toggle["MODAL_BOOKMARK_LIST"]}
268
- onClose={() => setToggle("MODAL_BOOKMARK_LIST", false)}
269
- title="Bookmark Filter"
270
- >
271
- <div className="p-4 flex flex-col gap-2">
272
- {bookmarks?.length ? bookmarks?.map((b, key) => (
273
- <div className="p-2 border rounded-sm flex justify-between" key={key}>
274
- <p className="pl-1">{b.name}</p>
275
- <div className="flex gap-2">
276
- <IconButtonComponent
277
- icon={faPlus}
278
- variant="outline"
279
- paint="primary"
280
- className=""
281
- size="xs"
282
- onClick={() => {
283
- setFilters(b.filters)
284
- setToggle("MODAL_BOOKMARK_LIST", false)
285
- }}
286
- />
287
- <IconButtonComponent
288
- icon={faTimes}
289
- variant="outline"
290
- paint="danger"
291
- className=""
292
- size="xs"
293
- onClick={() => setBookmarks(bookmarks.filter(( _, bi: number) => bi != key))}
294
- />
295
- </div>
296
- </div>
297
- )) : (
298
- <div className="text-center text-light-foreground py-4"> -- Tidak ada Bookmark --</div>
299
- )}
300
- </div>
301
- </ModalComponent>
302
-
303
- <ModalComponent
304
- show={!!toggle["MODAL_BOOKMARK"]}
305
- onClose={() => setToggle("MODAL_BOOKMARK", false)}
306
- title="Bookmark Filter"
307
- footer={
308
- <div className="flex justify-end">
309
- <ButtonComponent
310
- label="Terapkan"
311
- onClick={() => {
312
- let updated: FilterBookmark[] = [];
313
-
314
- if ((toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id == "new") {
315
- const newBookmark: FilterBookmark = {
316
- id: crypto.randomUUID(),
317
- name: (toggle["MODAL_BOOKMARK"] as { bookmark_name: string })?.bookmark_name || "Tanpa Nama",
318
- filters,
319
- createdAt: Date.now(),
320
- };
321
-
322
- updated = [newBookmark, ...bookmarks];
323
- } else {
324
- updated = bookmarks.map(b =>
325
- b.id === (toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id
326
- ? { ...b, filters, createdAt: Date.now() }
327
- : b
328
- );
329
- }
330
-
331
- setBookmarks(updated)
332
- setToggle("MODAL_BOOKMARK", false)
333
- }}
334
- />
335
- </div>
336
- }
337
- >
338
- <div className="p-4">
339
- <SelectComponent
340
- name={`bookmark_id`}
341
- placeholder="Pilih bookmark filter..."
342
- value={(toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id ?? ""}
343
- onChange={e => setToggle("MODAL_BOOKMARK", {...(toggle["MODAL_BOOKMARK"] as object), bookmark_id: e})}
344
- options={[
345
- {
346
- label: "-- BOOKMARK BARU --",
347
- value: "new",
348
- },
349
- ...bookmarks.map((b) => ({
350
- label: b.name,
351
- value: b.id,
352
- }))
353
- ]}
354
- />
355
-
356
- {(toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id == "new" && (
357
- <InputComponent
358
- name="bookmark_name"
359
- placeholder="Masukkan nama bookmark..."
360
- value={(toggle["MODAL_BOOKMARK"] as { bookmark_name: string })?.bookmark_name ?? ""}
361
- onChange={e => setToggle("MODAL_BOOKMARK", {...(toggle["MODAL_BOOKMARK"] as object), bookmark_name: e})}
362
- className="mt-4"
363
- />
364
- )}
365
- </div>
366
- </ModalComponent>
367
- </>
368
- );
369
- }
370
-
371
-
372
-
373
- interface FilterInputProps {
374
- type ?: string | null;
375
- name : string;
376
- value : string | number | number[] | string[] | null;
377
- onChange : (value: any) => void;
378
- options ?: { label: string; value: any }[];
379
- placeholder ?: string;
380
- className ?: string;
381
- between ?: boolean;
382
- multiple ?: boolean;
383
- }
384
-
385
- export function InputFilterValueComponent({
386
- type,
387
- name,
388
- value,
389
- onChange,
390
- options = [],
391
- placeholder = "",
392
- className = "",
393
- between,
394
- multiple,
395
- }: FilterInputProps) {
396
- const resolvedType = type || "text";
397
-
398
- if (!between) {
399
- switch (resolvedType) {
400
- case "select":
401
- return (
402
- <SelectComponent
403
- name={name}
404
- options={options}
405
- placeholder={placeholder}
406
- value={options.find((o) => o.value === value)?.label}
407
- onChange={onChange}
408
- className={className}
409
- />
410
- );
411
-
412
- case "number":
413
- return (
414
- <InputNumberComponent
415
- name={name}
416
- value={Number(value) || 0}
417
- onChange={onChange}
418
- placeholder={placeholder}
419
- className={className}
420
- multiple={multiple}
421
- />
422
- );
423
-
424
- case "currency":
425
- return (
426
- <InputCurrencyComponent
427
- name={name}
428
- value={Number(value) || 0}
429
- onChange={onChange}
430
- placeholder={placeholder}
431
- className={className}
432
- />
433
- );
434
-
435
- case "date":
436
- return (
437
- <InputDateComponent
438
- name={name}
439
- value={value as string || ""}
440
- onChange={onChange}
441
- placeholder={placeholder}
442
- className={className}
443
- />
444
- );
445
-
446
- default:
447
- return (
448
- <InputComponent
449
- name={name}
450
- value={value || ""}
451
- onChange={onChange}
452
- placeholder={placeholder}
453
- className={className}
454
- multiple={multiple}
455
- />
456
- );
457
- }
458
- }
459
-
460
- const val = Array.isArray(value) ? value : ["", ""];
461
- const [from, to] = val;
462
-
463
- const renderInput = (pos: "from" | "to") => {
464
- const currentValue = pos === "from" ? from : to;
465
- const handle = (v: any) => onChange(pos === "from" ? [v, to] : [from, v]);
466
-
467
- switch (resolvedType) {
468
- case "number":
469
- return (
470
- <InputNumberComponent
471
- name={`${name}_${pos}`}
472
- value={Number(currentValue) || 0}
473
- onChange={handle}
474
- placeholder={pos === "from" ? "Dari" : "Sampai"}
475
- className={className}
476
- />
477
- );
478
- case "currency":
479
- return (
480
- <InputCurrencyComponent
481
- name={`${name}_${pos}`}
482
- value={Number(currentValue) || 0}
483
- onChange={handle}
484
- placeholder={pos === "from" ? "Dari" : "Sampai"}
485
- className={className}
486
- />
487
- );
488
- case "date":
489
- return (
490
- <InputDateComponent
491
- name={`${name}_${pos}`}
492
- value={currentValue as string || ""}
493
- onChange={handle}
494
- placeholder={pos === "from" ? "Dari" : "Sampai"}
495
- className={className}
496
- />
497
- );
498
- default:
499
- return (
500
- <InputComponent
501
- name={`${name}_${pos}`}
502
- value={currentValue || ""}
503
- onChange={(e: any) => handle(e.target.value)}
504
- placeholder={pos === "from" ? "Dari" : "Sampai"}
505
- className={className}
506
- />
507
- );
508
- }
509
- };
510
-
511
- return (
512
- <div className="flex items-center gap-2 flex-1">
513
- {renderInput("from")}
514
- <span>s/d</span>
515
- {renderInput("to")}
516
- </div>
517
- );
518
- }
1
+ "use client"
2
+
3
+ import { useState, useEffect } from "react";
4
+ import { faChevronUp, faEllipsisH, faPlus, faRotate, faTimes } from "@fortawesome/free-solid-svg-icons";
5
+ import { ApiFilterType, cn, pcn, useResponsive } from "@utils";
6
+ import {ButtonComponent, ChipComponent, IconButtonComponent, InputComponent, InputCurrencyComponent, InputDateComponent, InputNumberComponent, ModalComponent, SelectComponent} from "@components";
7
+ import { useToggleContext } from "@contexts";
8
+ import { faBookmark } from "@fortawesome/free-regular-svg-icons";
9
+
10
+
11
+
12
+ type CT = "base" | "title";
13
+
14
+ export type FilterColumnOption = {
15
+ label: string;
16
+ selector: string;
17
+ type: "text" | "number" | "currency" | "date";
18
+ } | {
19
+ label: string;
20
+ selector: string;
21
+ type: "select";
22
+ options: { label: string; value: any }[];
23
+ };
24
+
25
+ export type FilterBookmark = {
26
+ id: string;
27
+ name: string;
28
+ filters: ApiFilterType[];
29
+ createdAt: number;
30
+ };
31
+
32
+ export interface AdvancedFilterProps {
33
+ columns : FilterColumnOption[];
34
+ onChange ?: (filters: ApiFilterType[]) => void;
35
+ value ?: ApiFilterType[];
36
+ onMinimize ?: () => void;
37
+
38
+ /** Use custom class with: "title::". */
39
+ className ?: string;
40
+ }
41
+
42
+ const FILTER_OPERATORS = [
43
+ { label: "Cari", value: "li" },
44
+ { label: "Sama", value: "eq" },
45
+ { label: "Tidak Sama", value: "ne" },
46
+ { label: "Termasuk", value: "in" },
47
+ { label: "Tidak Termasuk", value: "ni" },
48
+ { label: "Antara", value: "bw" },
49
+ ];
50
+
51
+ const LOGIC_OPTIONS = [
52
+ { label: "Dan", value: "and" },
53
+ { label: "Atau", value: "or" },
54
+ ];
55
+
56
+ const BOOKMARK_KEY = "filter-bookmarks";
57
+
58
+
59
+
60
+ export function FilterComponent({
61
+ columns,
62
+ onChange,
63
+ value,
64
+ onMinimize,
65
+ className = "",
66
+ }: AdvancedFilterProps) {
67
+ const { isSm } = useResponsive();
68
+ const { toggle, setToggle } = useToggleContext()
69
+ const [filters, setFilters] = useState<ApiFilterType[]>([]);
70
+
71
+ const [bookmarks, setBookmarks] = useState<FilterBookmark[]>([]);
72
+
73
+ const handleChange = (index: number, key: keyof ApiFilterType, value: any) => {
74
+ const updated = [...filters];
75
+ updated[index][key] = value;
76
+
77
+ if (key === "column") {
78
+ updated[index].type = "";
79
+ updated[index].value = "";
80
+ }
81
+
82
+ setFilters(updated);
83
+ };
84
+
85
+ const addFilter = () => {
86
+ setFilters([
87
+ ...filters,
88
+ { column: "", type: "", value: "", logic: filters.length ? "and" : undefined },
89
+ ]);
90
+ };
91
+
92
+ const removeFilter = (index: number) => {
93
+ const updated = filters.filter((_, i) => i !== index);
94
+ setFilters(updated);
95
+ };
96
+
97
+ useEffect(() => {
98
+ if (onChange) onChange(filters);
99
+ }, [filters]);
100
+
101
+
102
+ useEffect(() => {}, [value]);
103
+
104
+
105
+ useEffect(() => {
106
+ setBookmarks(JSON.parse(localStorage.getItem(BOOKMARK_KEY) || "[]"));
107
+ }, []);
108
+
109
+ useEffect(() => {
110
+ localStorage.setItem(BOOKMARK_KEY, JSON.stringify(bookmarks));
111
+ }, [bookmarks]);
112
+
113
+
114
+ return (
115
+ <>
116
+ <div className={cn("p-4 border rounded-sm", pcn<CT>(className, "base"))}>
117
+ <div className="flex justify-between items-center mb-4">
118
+ <p className={cn(pcn<CT>(className, "title"))}>Filter</p>
119
+ <div className="flex gap-4 items-center">
120
+ <div className="flex gap-2 items-center">
121
+ <IconButtonComponent
122
+ icon={faBookmark}
123
+ variant="outline"
124
+ paint="primary"
125
+ className="text-slate-400 icon::text-slate-400"
126
+ size="xs"
127
+ onClick={() => setToggle("MODAL_BOOKMARK", { bookmark_id: "new" })}
128
+ />
129
+
130
+ {!!bookmarks?.length && (
131
+ <ChipComponent
132
+ items={bookmarks.slice(0, 5).map((b) => b.name)}
133
+ onClick={(_, index) => setFilters(bookmarks[index]?.filters)}
134
+ onDelete={(_, index) => setBookmarks(bookmarks.filter(( _, bi: number) => bi != index))}
135
+ />
136
+ )}
137
+
138
+ {bookmarks?.length > 5 && (
139
+ <IconButtonComponent
140
+ icon={faEllipsisH}
141
+ variant="outline"
142
+ paint="primary"
143
+ className="text-slate-400 icon::text-slate-400"
144
+ size="xs"
145
+ onClick={() => setToggle("MODAL_BOOKMARK_LIST")}
146
+ />
147
+ )}
148
+ </div>
149
+
150
+ <ButtonComponent
151
+ icon={faRotate}
152
+ label="Bersihkan"
153
+ variant="outline"
154
+ paint="primary"
155
+ className="text-slate-400 icon::text-slate-400"
156
+ size="xs"
157
+ onClick={() => setFilters([])}
158
+ />
159
+
160
+ {onMinimize && (
161
+ <IconButtonComponent
162
+ icon={faChevronUp}
163
+ variant="outline"
164
+ paint="primary"
165
+ className="text-slate-400 icon::text-slate-400"
166
+ size="xs"
167
+ onClick={onMinimize}
168
+ />
169
+ )}
170
+ </div>
171
+ </div>
172
+
173
+ {filters.map((f, i) => {
174
+ const column = columns.find((c) => c.selector === f.column);
175
+
176
+ return (
177
+ <div key={i} className="flex flex-wrap items-center gap-2 mb-2">
178
+ {i > 0 && (
179
+ <div className="w-[20%] md:w-[10%]">
180
+ <SelectComponent
181
+ name={`filter_logic_${i}`}
182
+ options={LOGIC_OPTIONS}
183
+ placeholder="Dan/Atau"
184
+ value={f.logic}
185
+ onChange={(e) => handleChange(i, "logic", e as "and" | "or")}
186
+ className="text-sm p-2 px-3"
187
+ />
188
+ </div>
189
+ )}
190
+
191
+ <div className={i > 0 ? "w-[30%] md:w-[20%]" : "w-[52.5%] md:w-[30.7%]"}>
192
+ <SelectComponent
193
+ name={`filter_column_${i}`}
194
+ options={columns.map((c) => ({
195
+ label: c.label,
196
+ value: c.selector,
197
+ }))}
198
+ placeholder="Kolom"
199
+ value={f.column}
200
+ onChange={(e) => handleChange(i, "column", e)}
201
+ className="text-sm p-2 px-3"
202
+ />
203
+ </div>
204
+
205
+ <div className="w-[35%] md:w-[18%]">
206
+ <SelectComponent
207
+ name={`filter_operator_${i}`}
208
+ options={FILTER_OPERATORS}
209
+ placeholder="Operator"
210
+ value={f.type}
211
+ onChange={(e) => handleChange(i, "type", e)}
212
+ className="text-sm p-2 px-3"
213
+ />
214
+ </div>
215
+
216
+ {isSm && (
217
+ <IconButtonComponent
218
+ icon={faTimes}
219
+ paint="danger"
220
+ variant="outline"
221
+ onClick={() => removeFilter(i)}
222
+ size="xs"
223
+ />
224
+ )}
225
+
226
+ {column && (
227
+ <div className="w-full md:w-[45%]">
228
+ <InputFilterValueComponent
229
+ type={column.type}
230
+ name={`filter_value_${i}`}
231
+ placeholder="..."
232
+ value={f.value || ""}
233
+ onChange={(e: any) => handleChange(i, "value", e)}
234
+ options={column.type === "select" && column.options ? column.options : []}
235
+ className="text-sm p-2 px-3"
236
+ between={f.type === "bw"}
237
+ multiple={["in", "ni"].includes(f.type || "")}
238
+ />
239
+ </div>
240
+ )}
241
+
242
+ {!isSm && (
243
+ <IconButtonComponent
244
+ icon={faTimes}
245
+ paint="danger"
246
+ variant="outline"
247
+ onClick={() => removeFilter(i)}
248
+ size="xs"
249
+ />
250
+ )}
251
+ </div>
252
+ );
253
+ })}
254
+
255
+ <ButtonComponent
256
+ label="Tambahkan"
257
+ icon={faPlus}
258
+ variant="outline"
259
+ paint="primary"
260
+ size={isSm ? "xs" : "sm"}
261
+ onClick={addFilter}
262
+ className="md:mt-4"
263
+ />
264
+ </div>
265
+
266
+ <ModalComponent
267
+ show={!!toggle["MODAL_BOOKMARK_LIST"]}
268
+ onClose={() => setToggle("MODAL_BOOKMARK_LIST", false)}
269
+ title="Bookmark Filter"
270
+ >
271
+ <div className="p-4 flex flex-col gap-2">
272
+ {bookmarks?.length ? bookmarks?.map((b, key) => (
273
+ <div className="p-2 border rounded-sm flex justify-between" key={key}>
274
+ <p className="pl-1">{b.name}</p>
275
+ <div className="flex gap-2">
276
+ <IconButtonComponent
277
+ icon={faPlus}
278
+ variant="outline"
279
+ paint="primary"
280
+ className=""
281
+ size="xs"
282
+ onClick={() => {
283
+ setFilters(b.filters)
284
+ setToggle("MODAL_BOOKMARK_LIST", false)
285
+ }}
286
+ />
287
+ <IconButtonComponent
288
+ icon={faTimes}
289
+ variant="outline"
290
+ paint="danger"
291
+ className=""
292
+ size="xs"
293
+ onClick={() => setBookmarks(bookmarks.filter(( _, bi: number) => bi != key))}
294
+ />
295
+ </div>
296
+ </div>
297
+ )) : (
298
+ <div className="text-center text-light-foreground py-4"> -- Tidak ada Bookmark --</div>
299
+ )}
300
+ </div>
301
+ </ModalComponent>
302
+
303
+ <ModalComponent
304
+ show={!!toggle["MODAL_BOOKMARK"]}
305
+ onClose={() => setToggle("MODAL_BOOKMARK", false)}
306
+ title="Bookmark Filter"
307
+ footer={
308
+ <div className="flex justify-end">
309
+ <ButtonComponent
310
+ label="Terapkan"
311
+ onClick={() => {
312
+ let updated: FilterBookmark[] = [];
313
+
314
+ if ((toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id == "new") {
315
+ const newBookmark: FilterBookmark = {
316
+ id: crypto.randomUUID(),
317
+ name: (toggle["MODAL_BOOKMARK"] as { bookmark_name: string })?.bookmark_name || "Tanpa Nama",
318
+ filters,
319
+ createdAt: Date.now(),
320
+ };
321
+
322
+ updated = [newBookmark, ...bookmarks];
323
+ } else {
324
+ updated = bookmarks.map(b =>
325
+ b.id === (toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id
326
+ ? { ...b, filters, createdAt: Date.now() }
327
+ : b
328
+ );
329
+ }
330
+
331
+ setBookmarks(updated)
332
+ setToggle("MODAL_BOOKMARK", false)
333
+ }}
334
+ />
335
+ </div>
336
+ }
337
+ >
338
+ <div className="p-4">
339
+ <SelectComponent
340
+ name={`bookmark_id`}
341
+ placeholder="Pilih bookmark filter..."
342
+ value={(toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id ?? ""}
343
+ onChange={e => setToggle("MODAL_BOOKMARK", {...(toggle["MODAL_BOOKMARK"] as object), bookmark_id: e})}
344
+ options={[
345
+ {
346
+ label: "-- BOOKMARK BARU --",
347
+ value: "new",
348
+ },
349
+ ...bookmarks.map((b) => ({
350
+ label: b.name,
351
+ value: b.id,
352
+ }))
353
+ ]}
354
+ />
355
+
356
+ {(toggle["MODAL_BOOKMARK"] as { bookmark_id: string })?.bookmark_id == "new" && (
357
+ <InputComponent
358
+ name="bookmark_name"
359
+ placeholder="Masukkan nama bookmark..."
360
+ value={(toggle["MODAL_BOOKMARK"] as { bookmark_name: string })?.bookmark_name ?? ""}
361
+ onChange={e => setToggle("MODAL_BOOKMARK", {...(toggle["MODAL_BOOKMARK"] as object), bookmark_name: e})}
362
+ className="mt-4"
363
+ />
364
+ )}
365
+ </div>
366
+ </ModalComponent>
367
+ </>
368
+ );
369
+ }
370
+
371
+
372
+
373
+ interface FilterInputProps {
374
+ type ?: string | null;
375
+ name : string;
376
+ value : string | number | number[] | string[] | null;
377
+ onChange : (value: any) => void;
378
+ options ?: { label: string; value: any }[];
379
+ placeholder ?: string;
380
+ className ?: string;
381
+ between ?: boolean;
382
+ multiple ?: boolean;
383
+ }
384
+
385
+ export function InputFilterValueComponent({
386
+ type,
387
+ name,
388
+ value,
389
+ onChange,
390
+ options = [],
391
+ placeholder = "",
392
+ className = "",
393
+ between,
394
+ multiple,
395
+ }: FilterInputProps) {
396
+ const resolvedType = type || "text";
397
+
398
+ if (!between) {
399
+ switch (resolvedType) {
400
+ case "select":
401
+ return (
402
+ <SelectComponent
403
+ name={name}
404
+ options={options}
405
+ placeholder={placeholder}
406
+ value={options.find((o) => o.value === value)?.label}
407
+ onChange={onChange}
408
+ className={className}
409
+ />
410
+ );
411
+
412
+ case "number":
413
+ return (
414
+ <InputNumberComponent
415
+ name={name}
416
+ value={Number(value) || 0}
417
+ onChange={onChange}
418
+ placeholder={placeholder}
419
+ className={className}
420
+ multiple={multiple}
421
+ />
422
+ );
423
+
424
+ case "currency":
425
+ return (
426
+ <InputCurrencyComponent
427
+ name={name}
428
+ value={Number(value) || 0}
429
+ onChange={onChange}
430
+ placeholder={placeholder}
431
+ className={className}
432
+ />
433
+ );
434
+
435
+ case "date":
436
+ return (
437
+ <InputDateComponent
438
+ name={name}
439
+ value={value as string || ""}
440
+ onChange={onChange}
441
+ placeholder={placeholder}
442
+ className={className}
443
+ />
444
+ );
445
+
446
+ default:
447
+ return (
448
+ <InputComponent
449
+ name={name}
450
+ value={value || ""}
451
+ onChange={onChange}
452
+ placeholder={placeholder}
453
+ className={className}
454
+ multiple={multiple}
455
+ />
456
+ );
457
+ }
458
+ }
459
+
460
+ const val = Array.isArray(value) ? value : ["", ""];
461
+ const [from, to] = val;
462
+
463
+ const renderInput = (pos: "from" | "to") => {
464
+ const currentValue = pos === "from" ? from : to;
465
+ const handle = (v: any) => onChange(pos === "from" ? [v, to] : [from, v]);
466
+
467
+ switch (resolvedType) {
468
+ case "number":
469
+ return (
470
+ <InputNumberComponent
471
+ name={`${name}_${pos}`}
472
+ value={Number(currentValue) || 0}
473
+ onChange={handle}
474
+ placeholder={pos === "from" ? "Dari" : "Sampai"}
475
+ className={className}
476
+ />
477
+ );
478
+ case "currency":
479
+ return (
480
+ <InputCurrencyComponent
481
+ name={`${name}_${pos}`}
482
+ value={Number(currentValue) || 0}
483
+ onChange={handle}
484
+ placeholder={pos === "from" ? "Dari" : "Sampai"}
485
+ className={className}
486
+ />
487
+ );
488
+ case "date":
489
+ return (
490
+ <InputDateComponent
491
+ name={`${name}_${pos}`}
492
+ value={currentValue as string || ""}
493
+ onChange={handle}
494
+ placeholder={pos === "from" ? "Dari" : "Sampai"}
495
+ className={className}
496
+ />
497
+ );
498
+ default:
499
+ return (
500
+ <InputComponent
501
+ name={`${name}_${pos}`}
502
+ value={currentValue || ""}
503
+ onChange={(e: any) => handle(e.target.value)}
504
+ placeholder={pos === "from" ? "Dari" : "Sampai"}
505
+ className={className}
506
+ />
507
+ );
508
+ }
509
+ };
510
+
511
+ return (
512
+ <div className="flex items-center gap-2 flex-1">
513
+ {renderInput("from")}
514
+ <span>s/d</span>
515
+ {renderInput("to")}
516
+ </div>
517
+ );
518
+ }