@skalfa/skalfa-app 1.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.
- package/.env.example +44 -0
- package/README.md +28 -0
- package/app/auth/edit/page.tsx +65 -0
- package/app/auth/login/page.tsx +63 -0
- package/app/auth/me/page.tsx +58 -0
- package/app/auth/register/page.tsx +69 -0
- package/app/auth/verify/page.tsx +53 -0
- package/app/dashboard/layout.tsx +47 -0
- package/app/dashboard/page.tsx +9 -0
- package/app/dashboard/user/page.tsx +77 -0
- package/app/index.ts +14 -0
- package/app/layout.tsx +38 -0
- package/app/page.tsx +13 -0
- package/barrels.json +6 -0
- package/blueprints/starter.blueprint.json +103 -0
- package/components/base.components/accordion/Accordion.component.tsx +82 -0
- package/components/base.components/breadcrumb/Breadcrumb.component.tsx +80 -0
- package/components/base.components/button/Button.component.tsx +91 -0
- package/components/base.components/button/IconButton.component.tsx +88 -0
- package/components/base.components/button/button.decorate.ts +82 -0
- package/components/base.components/card/AlertCard.component.tsx +69 -0
- package/components/base.components/card/Card.component.tsx +25 -0
- package/components/base.components/card/DashboardCard.component.tsx +44 -0
- package/components/base.components/card/GalleryCard.component.tsx +50 -0
- package/components/base.components/card/ProductCard.component.tsx +65 -0
- package/components/base.components/card/ProfileCard.component.tsx +71 -0
- package/components/base.components/carousel/Carousel.component.tsx +113 -0
- package/components/base.components/chip/Chip.component.tsx +39 -0
- package/components/base.components/document/DocumentViewer.component.tsx +164 -0
- package/components/base.components/document/ExportExcel.component.tsx +340 -0
- package/components/base.components/document/ImportExcel.component.tsx +315 -0
- package/components/base.components/document/PrintTable.component.tsx +204 -0
- package/components/base.components/document/RenderPDF.component.tsx +416 -0
- package/components/base.components/index.ts +85 -0
- package/components/base.components/input/Checkbox.component.tsx +109 -0
- package/components/base.components/input/Input.component.tsx +332 -0
- package/components/base.components/input/InputCheckbox.component.tsx +174 -0
- package/components/base.components/input/InputCurrency.component.tsx +163 -0
- package/components/base.components/input/InputDate.component.tsx +352 -0
- package/components/base.components/input/InputDatetime.component.tsx +260 -0
- package/components/base.components/input/InputDocument.component.tsx +352 -0
- package/components/base.components/input/InputImage.component.tsx +533 -0
- package/components/base.components/input/InputMap.component.tsx +318 -0
- package/components/base.components/input/InputNumber.component.tsx +192 -0
- package/components/base.components/input/InputOtp.component.tsx +169 -0
- package/components/base.components/input/InputPassword.component.tsx +236 -0
- package/components/base.components/input/InputRadio.component.tsx +175 -0
- package/components/base.components/input/InputTime.component.tsx +276 -0
- package/components/base.components/input/InputValues.component.tsx +68 -0
- package/components/base.components/input/Radio.component.tsx +102 -0
- package/components/base.components/input/Select.component.tsx +541 -0
- package/components/base.components/modal/BottomSheet.component.tsx +246 -0
- package/components/base.components/modal/FloatingPage.component.tsx +104 -0
- package/components/base.components/modal/Modal.component.tsx +96 -0
- package/components/base.components/modal/ModalConfirm.component.tsx +218 -0
- package/components/base.components/modal/Toast.component.tsx +126 -0
- package/components/base.components/nav/Bottombar.component.tsx +116 -0
- package/components/base.components/nav/Footer.component.tsx +144 -0
- package/components/base.components/nav/Headbar.component.tsx +104 -0
- package/components/base.components/nav/Navbar.component.tsx +100 -0
- package/components/base.components/nav/Sidebar.component.tsx +301 -0
- package/components/base.components/nav/Tabbar.component.tsx +60 -0
- package/components/base.components/nav/Wizard.component.tsx +73 -0
- package/components/base.components/supervision/FormSupervision.component.tsx +434 -0
- package/components/base.components/supervision/TableSupervision.component.tsx +697 -0
- package/components/base.components/table/ControlBar.component.tsx +497 -0
- package/components/base.components/table/FilterComponent.tsx +518 -0
- package/components/base.components/table/Pagination.component.tsx +159 -0
- package/components/base.components/table/Table.component.tsx +469 -0
- package/components/base.components/typography/TypographyArticle.component.tsx +26 -0
- package/components/base.components/typography/TypographyColumn.component.tsx +20 -0
- package/components/base.components/typography/TypographyContent.component.tsx +20 -0
- package/components/base.components/typography/TypographyTips.component.tsx +20 -0
- package/components/base.components/wrap/Draggable.component.tsx +303 -0
- package/components/base.components/wrap/IDBProvider.tsx +12 -0
- package/components/base.components/wrap/Image.component.tsx +10 -0
- package/components/base.components/wrap/OutsideClick.component.tsx +48 -0
- package/components/base.components/wrap/ScrollContainer.component.tsx +104 -0
- package/components/base.components/wrap/ShortcutProvider.tsx +57 -0
- package/components/base.components/wrap/Swipe.component.tsx +93 -0
- package/components/construct.components/example.tsx +1 -0
- package/components/construct.components/index.ts +5 -0
- package/components/index.ts +3 -0
- package/components/structure.components/example.tsx +1 -0
- package/components/structure.components/index.ts +5 -0
- package/contexts/AppProvider.tsx +12 -0
- package/contexts/Auth.context.tsx +64 -0
- package/contexts/Toggle.context.tsx +44 -0
- package/contexts/index.ts +7 -0
- package/eslint.config.mjs +34 -0
- package/langs/index.ts +1 -0
- package/langs/validation.langs.ts +17 -0
- package/next.config.ts +17 -0
- package/package.json +43 -0
- package/postcss.config.mjs +12 -0
- package/public/204.svg +19 -0
- package/public/500.svg +39 -0
- package/public/images/avatar.jpg +0 -0
- package/public/images/example.png +0 -0
- package/schema/idb/app.schema.ts +9 -0
- package/schema/index.ts +5 -0
- package/styles/globals.css +231 -0
- package/styles/tailwind.safelist +69 -0
- package/tailwind.config.ts +10 -0
- package/tsconfig.json +35 -0
- package/utils/commands/barrels.ts +28 -0
- package/utils/commands/blueprint.ts +421 -0
- package/utils/commands/light.ts +21 -0
- package/utils/commands/logger.ts +42 -0
- package/utils/commands/stubs/table-blueprint.stub +13 -0
- package/utils/commands/use-pdf.ts +29 -0
- package/utils/index.ts +3 -0
|
@@ -0,0 +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
|
+
}
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import { useEffect, useState } from "react";
|
|
4
|
+
import { faChevronLeft, faChevronRight } from "@fortawesome/free-solid-svg-icons";
|
|
5
|
+
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
|
6
|
+
import { cn, pcn } from "@utils";
|
|
7
|
+
import { IconButtonComponent, InputRadioComponent } from "@components";
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
type CT = "item" | "active" | "base";
|
|
12
|
+
|
|
13
|
+
export interface PaginationProps {
|
|
14
|
+
totalRow : number;
|
|
15
|
+
paginate : number;
|
|
16
|
+
page : number;
|
|
17
|
+
onChange ?: (totalRow: number, paginate: number, page: number) => void;
|
|
18
|
+
className ?: string;
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
export function PaginationComponent({
|
|
24
|
+
paginate = 10,
|
|
25
|
+
page = 1,
|
|
26
|
+
totalRow = 0,
|
|
27
|
+
onChange,
|
|
28
|
+
className = "",
|
|
29
|
+
}: PaginationProps) {
|
|
30
|
+
const [pages, setPages] = useState<number[]>([]);
|
|
31
|
+
const lastPage = Math.ceil(totalRow / paginate);
|
|
32
|
+
|
|
33
|
+
useEffect(() => {
|
|
34
|
+
let newPages = [];
|
|
35
|
+
if (totalRow > paginate) {
|
|
36
|
+
const start = Math.max(1, page - 1);
|
|
37
|
+
const end = Math.min(lastPage, page + 1);
|
|
38
|
+
newPages = Array.from({ length: end - start + 1 }, (_, i) => start + i);
|
|
39
|
+
} else {
|
|
40
|
+
newPages = [1];
|
|
41
|
+
}
|
|
42
|
+
setPages(newPages);
|
|
43
|
+
}, [totalRow, page, paginate]);
|
|
44
|
+
|
|
45
|
+
const styles = {
|
|
46
|
+
base : cn("flex items-center justify-end md:justify-between gap-4 md:gap-6", pcn<CT>(className, "base")),
|
|
47
|
+
item : cn("w-8 md:w-12 h-8 text-sm flex justify-center items-center bg-white rounded-[4px] border cursor-pointer",pcn<CT>(className, "item")),
|
|
48
|
+
activeItem : cn("bg-light-primary/50 text-primary",pcn<CT>(className, "active")),
|
|
49
|
+
overflow : "py-1.5 px-2 text-foreground text-sm",
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
if (!totalRow) return;
|
|
53
|
+
|
|
54
|
+
return (
|
|
55
|
+
<div className={styles.base}>
|
|
56
|
+
<div className="hidden md:flex items-center gap-6">
|
|
57
|
+
<InputRadioComponent
|
|
58
|
+
name="paginate"
|
|
59
|
+
options={[10, 20, 50].map((val) => ({
|
|
60
|
+
value: val,
|
|
61
|
+
label: String(val),
|
|
62
|
+
}))}
|
|
63
|
+
value={paginate}
|
|
64
|
+
onChange={(e) => onChange?.(totalRow, Number(e), 1)}
|
|
65
|
+
className="py-1.5 text-sm bg-white rounded-[4px]"
|
|
66
|
+
/>
|
|
67
|
+
|
|
68
|
+
{totalRow > paginate && (
|
|
69
|
+
<div className="flex items-center gap-2 mt-0.5">
|
|
70
|
+
{page > 1 && (
|
|
71
|
+
<button
|
|
72
|
+
className={styles.overflow}
|
|
73
|
+
onClick={() => onChange?.(totalRow, paginate, page - 1)}
|
|
74
|
+
>
|
|
75
|
+
<FontAwesomeIcon icon={faChevronLeft} />
|
|
76
|
+
</button>
|
|
77
|
+
)}
|
|
78
|
+
|
|
79
|
+
{page > 2 && (
|
|
80
|
+
<>
|
|
81
|
+
<button
|
|
82
|
+
className={styles.item}
|
|
83
|
+
onClick={() => onChange?.(totalRow, paginate, 1)}
|
|
84
|
+
>
|
|
85
|
+
1
|
|
86
|
+
</button>
|
|
87
|
+
{page > 3 && <span className={styles.overflow}>...</span>}
|
|
88
|
+
</>
|
|
89
|
+
)}
|
|
90
|
+
|
|
91
|
+
{pages.map((p) => (
|
|
92
|
+
<button
|
|
93
|
+
key={p}
|
|
94
|
+
className={cn(styles.item, p === page && styles.activeItem)}
|
|
95
|
+
onClick={() => onChange?.(totalRow, paginate, p)}
|
|
96
|
+
>
|
|
97
|
+
{p}
|
|
98
|
+
</button>
|
|
99
|
+
))}
|
|
100
|
+
|
|
101
|
+
{page < lastPage - 1 && (
|
|
102
|
+
<>
|
|
103
|
+
{page < lastPage - 2 && (
|
|
104
|
+
<span className={styles.overflow}>...</span>
|
|
105
|
+
)}
|
|
106
|
+
<button
|
|
107
|
+
className={styles.item}
|
|
108
|
+
onClick={() => onChange?.(totalRow, paginate, lastPage)}
|
|
109
|
+
>
|
|
110
|
+
{lastPage}
|
|
111
|
+
</button>
|
|
112
|
+
</>
|
|
113
|
+
)}
|
|
114
|
+
|
|
115
|
+
{page < lastPage && (
|
|
116
|
+
<button
|
|
117
|
+
className={styles.overflow}
|
|
118
|
+
onClick={() => onChange?.(totalRow, paginate, page + 1)}
|
|
119
|
+
>
|
|
120
|
+
<FontAwesomeIcon icon={faChevronRight} />
|
|
121
|
+
</button>
|
|
122
|
+
)}
|
|
123
|
+
</div>
|
|
124
|
+
)}
|
|
125
|
+
</div>
|
|
126
|
+
|
|
127
|
+
<div className="hidden md:block text-sm text-foreground">
|
|
128
|
+
{Math.min(totalRow, paginate * (page - 1) + 1)} - {Math.min(totalRow, paginate * page)} / {totalRow}
|
|
129
|
+
</div>
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
<div className="border rounded-sm flex md:hidden items-center">
|
|
133
|
+
<div className="text-sm text-foreground px-4 py-2">
|
|
134
|
+
{Math.min(totalRow, paginate * (page - 1) + 1)} - {Math.min(totalRow, paginate * page)} / {totalRow}
|
|
135
|
+
</div>
|
|
136
|
+
|
|
137
|
+
{totalRow > paginate && (
|
|
138
|
+
<div className="flex items-center gap-2 bg-light-primary/50 text-primary p-2">
|
|
139
|
+
{page > 1 && (
|
|
140
|
+
<IconButtonComponent
|
|
141
|
+
icon={faChevronLeft}
|
|
142
|
+
onClick={() => onChange?.(totalRow, paginate, page - 1)}
|
|
143
|
+
size="sm"
|
|
144
|
+
/>
|
|
145
|
+
)}
|
|
146
|
+
{/* <div>{page}</div> */}
|
|
147
|
+
{page < lastPage && (
|
|
148
|
+
<IconButtonComponent
|
|
149
|
+
icon={faChevronRight}
|
|
150
|
+
onClick={() => onChange?.(totalRow, paginate, page + 1)}
|
|
151
|
+
size="sm"
|
|
152
|
+
/>
|
|
153
|
+
)}
|
|
154
|
+
</div>
|
|
155
|
+
)}
|
|
156
|
+
</div>
|
|
157
|
+
</div>
|
|
158
|
+
);
|
|
159
|
+
}
|