@skalfa/skalfa-app 1.0.3 → 1.0.5

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 (90) hide show
  1. package/.env.example +8 -16
  2. package/app/auth/edit/page.tsx +1 -1
  3. package/app/auth/login/page.tsx +1 -1
  4. package/app/auth/me/page.tsx +1 -1
  5. package/app/auth/register/page.tsx +1 -1
  6. package/app/auth/verify/page.tsx +1 -1
  7. package/app/dashboard/layout.tsx +2 -2
  8. package/app/dashboard/page.tsx +1 -1
  9. package/app/index.ts +1 -0
  10. package/app/layout.tsx +2 -4
  11. package/app/page.tsx +2 -2
  12. package/bun.lock +7 -2
  13. package/components/index.ts +1 -3
  14. package/package.json +8 -6
  15. package/styles/components.css +1392 -0
  16. package/styles/globals.css +40 -175
  17. package/styles/utilities.css +37 -0
  18. package/tsconfig.json +4 -2
  19. package/utils/commands/skalfa.ts +1 -1
  20. package/components/base.components/accordion/Accordion.component.tsx +0 -82
  21. package/components/base.components/breadcrumb/Breadcrumb.component.tsx +0 -80
  22. package/components/base.components/button/Button.component.tsx +0 -91
  23. package/components/base.components/button/IconButton.component.tsx +0 -88
  24. package/components/base.components/button/button.decorate.ts +0 -82
  25. package/components/base.components/card/AlertCard.component.tsx +0 -69
  26. package/components/base.components/card/Card.component.tsx +0 -25
  27. package/components/base.components/card/DashboardCard.component.tsx +0 -44
  28. package/components/base.components/card/GalleryCard.component.tsx +0 -50
  29. package/components/base.components/card/ProductCard.component.tsx +0 -65
  30. package/components/base.components/card/ProfileCard.component.tsx +0 -71
  31. package/components/base.components/carousel/Carousel.component.tsx +0 -113
  32. package/components/base.components/chip/Chip.component.tsx +0 -39
  33. package/components/base.components/document/DocumentViewer.component.tsx +0 -164
  34. package/components/base.components/document/ExportExcel.component.tsx +0 -340
  35. package/components/base.components/document/ImportExcel.component.tsx +0 -315
  36. package/components/base.components/document/PrintTable.component.tsx +0 -204
  37. package/components/base.components/document/RenderPDF.component.tsx +0 -416
  38. package/components/base.components/index.ts +0 -85
  39. package/components/base.components/input/Checkbox.component.tsx +0 -109
  40. package/components/base.components/input/Input.component.tsx +0 -332
  41. package/components/base.components/input/InputCheckbox.component.tsx +0 -174
  42. package/components/base.components/input/InputCurrency.component.tsx +0 -163
  43. package/components/base.components/input/InputDate.component.tsx +0 -352
  44. package/components/base.components/input/InputDatetime.component.tsx +0 -260
  45. package/components/base.components/input/InputDocument.component.tsx +0 -352
  46. package/components/base.components/input/InputImage.component.tsx +0 -533
  47. package/components/base.components/input/InputMap.component.tsx +0 -318
  48. package/components/base.components/input/InputNumber.component.tsx +0 -192
  49. package/components/base.components/input/InputOtp.component.tsx +0 -169
  50. package/components/base.components/input/InputPassword.component.tsx +0 -236
  51. package/components/base.components/input/InputRadio.component.tsx +0 -175
  52. package/components/base.components/input/InputTime.component.tsx +0 -276
  53. package/components/base.components/input/InputValues.component.tsx +0 -68
  54. package/components/base.components/input/Radio.component.tsx +0 -102
  55. package/components/base.components/input/Select.component.tsx +0 -541
  56. package/components/base.components/modal/BottomSheet.component.tsx +0 -246
  57. package/components/base.components/modal/FloatingPage.component.tsx +0 -104
  58. package/components/base.components/modal/Modal.component.tsx +0 -96
  59. package/components/base.components/modal/ModalConfirm.component.tsx +0 -218
  60. package/components/base.components/modal/Toast.component.tsx +0 -126
  61. package/components/base.components/nav/Bottombar.component.tsx +0 -116
  62. package/components/base.components/nav/Footer.component.tsx +0 -144
  63. package/components/base.components/nav/Headbar.component.tsx +0 -104
  64. package/components/base.components/nav/Navbar.component.tsx +0 -100
  65. package/components/base.components/nav/Sidebar.component.tsx +0 -301
  66. package/components/base.components/nav/Tabbar.component.tsx +0 -60
  67. package/components/base.components/nav/Wizard.component.tsx +0 -73
  68. package/components/base.components/supervision/FormSupervision.component.tsx +0 -434
  69. package/components/base.components/supervision/TableSupervision.component.tsx +0 -697
  70. package/components/base.components/table/ControlBar.component.tsx +0 -497
  71. package/components/base.components/table/FilterComponent.tsx +0 -518
  72. package/components/base.components/table/Pagination.component.tsx +0 -159
  73. package/components/base.components/table/Table.component.tsx +0 -469
  74. package/components/base.components/typography/TypographyArticle.component.tsx +0 -26
  75. package/components/base.components/typography/TypographyColumn.component.tsx +0 -20
  76. package/components/base.components/typography/TypographyContent.component.tsx +0 -20
  77. package/components/base.components/typography/TypographyTips.component.tsx +0 -20
  78. package/components/base.components/wrap/Draggable.component.tsx +0 -303
  79. package/components/base.components/wrap/IDBProvider.tsx +0 -12
  80. package/components/base.components/wrap/Image.component.tsx +0 -10
  81. package/components/base.components/wrap/OutsideClick.component.tsx +0 -48
  82. package/components/base.components/wrap/ScrollContainer.component.tsx +0 -104
  83. package/components/base.components/wrap/ShortcutProvider.tsx +0 -57
  84. package/components/base.components/wrap/Swipe.component.tsx +0 -93
  85. package/components/construct.components/example.tsx +0 -1
  86. package/components/construct.components/index.ts +0 -5
  87. package/components/structure.components/example.tsx +0 -1
  88. package/components/structure.components/index.ts +0 -5
  89. package/schema/idb/app.schema.ts +0 -9
  90. package/schema/index.ts +0 -5
@@ -1,315 +0,0 @@
1
- "use client";
2
-
3
- import { useMemo, useState } from "react";
4
- import ExcelJS from "exceljs";
5
- import { faEdit } from "@fortawesome/free-solid-svg-icons";
6
- import { TableComponent, ButtonComponent, SelectComponent, ModalComponent, IconButtonComponent } from "@components";
7
- import { useToggleContext } from "@contexts";
8
- import { api, FetchControlType } from "@utils";
9
-
10
-
11
-
12
- export type ImportExcelColumnControlType = {
13
- label: string;
14
- selector: string;
15
- };
16
-
17
- type ImportColumn = {
18
- selector: string;
19
- label: string;
20
- source: string | null;
21
- };
22
-
23
- type ImportExcelProps = {
24
- columnControl: ImportExcelColumnControlType[];
25
- onSubmit?: (rows: any[]) => void;
26
- submitControl?: FetchControlType;
27
- fetchControl?: FetchControlType;
28
- };
29
-
30
-
31
-
32
- function numberToExcelColumn(index: number): string
33
- {
34
- let column = "";
35
- let n = index;
36
-
37
- while (n >= 0) {
38
- column = String.fromCharCode((n % 26) + 65) + column;
39
- n = Math.floor(n / 26) - 1;
40
- }
41
-
42
- return column;
43
- }
44
-
45
-
46
-
47
- export function ImportExcel({ columnControl, onSubmit, submitControl, fetchControl }: ImportExcelProps) {
48
- const { toggle, setToggle } = useToggleContext()
49
-
50
- const [columns, setColumns] = useState<ImportColumn[]>([]);
51
- const [rows, setRows] = useState<Record<string, any>[]>([]);
52
- const [loaded, setLoaded] = useState(false);
53
-
54
- const [processing, setProcessing] = useState(false);
55
- const [progress, setProgress] = useState({ success: 0, failed: 0, total: 0 });
56
- const [errors, setErrors] = useState<Record<number, string>>({});
57
-
58
-
59
- const handleImportFile = async (file: File) => {
60
- const workbook = new ExcelJS.Workbook();
61
- const buffer = await file.arrayBuffer();
62
-
63
- await workbook.xlsx.load(buffer);
64
- const sheet = workbook.worksheets[0];
65
-
66
- const excelColumns: ImportColumn[] = [];
67
- sheet.getRow(1).eachCell((_, colIndex) => {
68
- const label = numberToExcelColumn(colIndex - 1);
69
-
70
- excelColumns.push({
71
- selector: label,
72
- label: label,
73
- source: null,
74
- });
75
- });
76
-
77
- const excelRows: Record<string, any>[] = [];
78
- sheet.eachRow((row, rowIndex) => {
79
- if (rowIndex === 1) return;
80
-
81
- const item: Record<string, any> = {};
82
- excelColumns.forEach((col, i) => {
83
- item[col.selector] = row.getCell(i + 1).value;
84
- });
85
-
86
- excelRows.push(item);
87
- });
88
-
89
- setColumns(excelColumns);
90
- setRows(excelRows);
91
- setLoaded(true);
92
- };
93
-
94
- const getColumnLabel = (source: string | null) => {
95
- if (!source) return "";
96
-
97
- const found = columnControl?.find(c => c.selector === source);
98
-
99
- return found?.label ?? source;
100
- };
101
-
102
-
103
- const tableColumns = useMemo(() => {
104
- return columns?.map((c => ({
105
- ...c,
106
- label: <div className="w-full text-center">{c.label}</div>
107
- })));
108
- }, [columns]);
109
-
110
-
111
- const tableData = useMemo(() => {
112
- if (!loaded) return [];
113
-
114
- const mappingRow: Record<string, any> = {};
115
-
116
- columns.forEach(col => {
117
- mappingRow[col.selector] = (
118
- <>
119
- <div className="flex justify-between">
120
- <p className="font-semibold">{getColumnLabel(col.source) || <p className="text-light-foreground">-- PILIH KOLOM --</p>}</p>
121
-
122
- <IconButtonComponent
123
- icon={faEdit}
124
- size="xs"
125
- paint="warning"
126
- variant="outline"
127
- disabled={columns.length <= 1}
128
- onClick={() => setToggle("MODAL_FIELD_IMPORT", { selector: col.selector, value: col.source })}
129
- />
130
- </div>
131
- </>
132
- );
133
- });
134
-
135
- return [mappingRow, ...rows];
136
- }, [columns, rows, loaded, columnControl]);
137
-
138
-
139
- const generatePayload = () => {
140
- return rows.map(row => {
141
- const payload: Record<string, any> = {};
142
-
143
- columns.forEach(col => {
144
- if (col.source) {
145
- payload[col.source] = row[col.selector];
146
- }
147
- });
148
-
149
- return payload;
150
- });
151
- };
152
-
153
- const handleSubmit = async () => {
154
- const payload = generatePayload();
155
-
156
- if (onSubmit) {
157
- onSubmit(payload);
158
- return;
159
- }
160
-
161
- setProcessing(true);
162
- setProgress({ success: 0, failed: 0, total: payload.length });
163
- setErrors({});
164
-
165
- if (submitControl?.path) {
166
- try {
167
- await api({
168
- path : submitControl?.path,
169
- method : "POST",
170
- payload : { data: payload },
171
- });
172
-
173
- setProgress({ success: payload.length, failed: 0, total: payload.length });
174
- setToggle("MODAL_IMPORT_SUCCESS", true);
175
-
176
- setTimeout(() => {
177
- setToggle(Object.keys(toggle).find(k => k.startsWith("MODAL_IMPORT_")) || "", false);
178
- }, 1500);
179
-
180
- } catch (e: any) {
181
- setProgress({ success: 0, failed: payload.length, total: payload.length });
182
- setErrors({ 0: e.message || "Bulk import failed" });
183
- }
184
- } else if (fetchControl) {
185
- let successCount = 0;
186
- let failedCount = 0;
187
-
188
- for (let i = 0; i < payload.length; i++) {
189
- const item = payload[i];
190
-
191
- try {
192
- await api({
193
- ...fetchControl,
194
- method: "POST",
195
- payload: item,
196
- });
197
- successCount++;
198
- } catch (e: any) {
199
- failedCount++;
200
- setErrors(prev => ({ ...prev, [i]: e.message || "Failed" }));
201
- }
202
-
203
- setProgress({ success: successCount, failed: failedCount, total: payload.length });
204
- }
205
- }
206
-
207
- setProcessing(false);
208
- };
209
-
210
- return (
211
- <>
212
-
213
- {!loaded && (
214
- <div className="p-4 relative">
215
- <input
216
- type="file"
217
- accept=".xlsx"
218
- onChange={e =>
219
- {
220
- const file = e.target.files?.[0];
221
- if (file) handleImportFile(file);
222
- }}
223
- className="text-transparent bg-background w-full aspect-video border border-dashed relative file:hidden placeholder:hidden rounded-md cursor-pointer"
224
- />
225
-
226
- <div className="absolute top-1/2 left-1/2 -translate-1/2 text-light-foreground">
227
- Pilih atau tarik file excel di sini
228
- </div>
229
- </div>
230
- )}
231
-
232
- {loaded && (
233
- <TableComponent
234
- controlBar={false}
235
- columns={tableColumns}
236
- data={tableData}
237
- pagination={false}
238
- noIndex
239
- className="p-4 bg-background row::bg-background row::border-0 row::gap-0 row::!hover:bg-background column::p-2 column::border head-column::p-2 head-column::border"
240
- />
241
- )}
242
-
243
- {loaded && !processing && (
244
- <div className="px-4 mt-8">
245
- <ButtonComponent
246
- label="Import Data"
247
- block
248
- onClick={handleSubmit}
249
- />
250
- </div>
251
- )}
252
-
253
- {processing && (
254
- <div className="px-4 mt-8 flex flex-col gap-2">
255
- <div className="flex justify-between text-sm">
256
- <span>Processing: {progress.success + progress.failed} / {progress.total}</span>
257
- {progress.failed > 0 && <span className="text-danger">{progress.failed} Failed</span>}
258
- </div>
259
- <div className="w-full h-2 bg-secondary rounded-full overflow-hidden">
260
- <div
261
- className="h-full bg-primary transition-all duration-300"
262
- style={{ width: `${((progress.success + progress.failed) / progress.total) * 100}%` }}
263
- />
264
- </div>
265
- </div>
266
- )}
267
-
268
- {Object.keys(errors).length > 0 && (
269
- <div className="px-4 mt-4 max-h-40 overflow-y-auto">
270
- <p className="text-danger font-semibold mb-2">Errors Details:</p>
271
- {Object.entries(errors).map(([idx, msg]) => (
272
- <div key={idx} className="text-xs text-danger">
273
- Row {Number(idx) + 1}: {msg}
274
- </div>
275
- ))}
276
- </div>
277
- )}
278
-
279
-
280
- <ModalComponent
281
- show={!!toggle["MODAL_FIELD_IMPORT"]}
282
- onClose={() => setToggle("MODAL_FIELD_IMPORT", false)}
283
- title="Pilih Kolom"
284
- footer={
285
- <div className="flex justify-end">
286
- <ButtonComponent
287
- label="Terapkan"
288
- onClick={() => {
289
- if (!!(toggle["MODAL_FIELD_IMPORT"] as { value: string })?.value) {
290
- setColumns(prev =>
291
- prev.map(c => c.selector === (toggle["MODAL_FIELD_IMPORT"] as { selector: string })?.selector ? { ...c, source: String((toggle["MODAL_FIELD_IMPORT"] as { value: string })?.value) } : c)
292
- )
293
- }
294
- setToggle("MODAL_FIELD_IMPORT", false)
295
- }}
296
- />
297
- </div>
298
- }
299
- >
300
- <div className="p-4">
301
- <SelectComponent
302
- name={`column_${(toggle["MODAL_FIELD_IMPORT"] as { selector: string })?.selector}`}
303
- placeholder="Pilih kolom data..."
304
- value={(toggle["MODAL_FIELD_IMPORT"] as { value: string })?.value ?? ""}
305
- onChange={e => setToggle("MODAL_FIELD_IMPORT", { ...(toggle["MODAL_FIELD_IMPORT"] as object), value: e })}
306
- options={columnControl.map(c => ({
307
- label: c.label,
308
- value: c.selector,
309
- }))}
310
- />
311
- </div>
312
- </ModalComponent>
313
- </>
314
- );
315
- }
@@ -1,204 +0,0 @@
1
- "use client";
2
-
3
- import { useEffect, useMemo, useState } from "react";
4
- import { FetchControlType, useTable } from "@utils";
5
- import { TableComponent, IconButtonComponent, FilterComponent, NodeSchema, PageSchema, RenderPDFPreview, ButtonComponent, RenderPDF } from "@components";
6
- import { faArrowLeft, faArrowRight } from "@fortawesome/free-solid-svg-icons";
7
-
8
-
9
- export type PrintColumn = {
10
- selector : string;
11
- source : string | null;
12
- width : number;
13
- };
14
-
15
- export type ColumnControl = {
16
- selector : string;
17
- label : string;
18
- };
19
-
20
-
21
-
22
- function usePrintColumns(data: any[], columnControl?: ColumnControl[]) {
23
- const fields = useMemo(() => {
24
- if (!data?.[0]) return [];
25
- return Object.keys(data[0]);
26
- }, [data]);
27
-
28
- const [columns, setColumns] = useState<PrintColumn[]>([]);
29
-
30
- useEffect(() => {
31
- if (!data?.[0] || columns.length) return;
32
-
33
- if (columnControl?.length) {
34
- setColumns(
35
- columnControl.map((c) => ({
36
- selector: c.label,
37
- source: c.selector,
38
- width: 120,
39
- }))
40
- );
41
- return;
42
- }
43
-
44
- setColumns(
45
- fields.map((f) => ({
46
- selector: f,
47
- source: f,
48
- width: 120,
49
- }))
50
- );
51
- }, [data, fields, columnControl]);
52
-
53
- const move = (selector: string, dir: "left" | "right") => {
54
- setColumns(prev => {
55
- const idx = prev.findIndex(c => c.selector === selector);
56
- const target = dir === "left" ? idx - 1 : idx + 1;
57
- if (idx < 0 || target < 0 || target >= prev.length) return prev;
58
- const next = [...prev];
59
- [next[idx], next[target]] = [next[target], next[idx]];
60
- return next.map((c) => ({ ...c, selector: c.selector }));
61
- });
62
- };
63
-
64
- return { columns, move };
65
- }
66
-
67
-
68
- function buildPrintSchema({ title, columns, data, columnControl }: {
69
- title ?: string;
70
- columns : PrintColumn[];
71
- data : any[];
72
- columnControl ?: ColumnControl[];
73
- }) : PageSchema[] {
74
- const active = columns.filter(c => c.source);
75
-
76
- const getHeaderLabel = (source: string | null) => {
77
- if (!source) return "";
78
-
79
- const found = columnControl?.find(c => c.selector === source);
80
-
81
- return found?.label ?? source;
82
- };
83
-
84
- const content: NodeSchema[] = [];
85
-
86
- if (title) {
87
- content.push({
88
- type : "text",
89
- content : title,
90
- style : { fontSize: 16, fontWeight: "bold", marginBottom: 12 },
91
- });
92
- }
93
-
94
- content.push({
95
- type : "table",
96
- content : [
97
- {
98
- type : "tr" as const,
99
- content : active.map<NodeSchema>(c => ({
100
- type : "th" as const,
101
- content : getHeaderLabel(c.source),
102
- style : { width: c.width },
103
- })),
104
- },
105
- ...data.map<NodeSchema>(row => ({
106
- type : "tr" as const,
107
- content : active.map<NodeSchema>(c => ({
108
- type : "td" as const,
109
- content : String(row[c.source!] ?? ""),
110
- style : { width: c.width },
111
- })),
112
- })),
113
- ],
114
- });
115
-
116
- return [{ page: { size: "A4", margin: 40, content } }];
117
- }
118
-
119
-
120
-
121
- export function PrintTable({ fetchControl, columnControl, title }: { fetchControl: FetchControlType; columnControl?: ColumnControl[]; title?: string; }) {
122
- const { data } = useTable(fetchControl, undefined, undefined, false);
123
- const rows = data?.data ?? [];
124
-
125
- const { columns, move } = usePrintColumns(rows, columnControl);
126
-
127
- const schema = useMemo(() => buildPrintSchema({
128
- title: title,
129
- columns,
130
- data: rows,
131
- columnControl,
132
- }), [columns, rows, columnControl]);
133
-
134
- return (
135
- <>
136
- <div className="p-4">
137
- <FilterComponent
138
- columns={data?.data[0] && Object.keys(data?.data[0])?.map((c) => ({ label: c, selector: c }))}
139
- onChange={() => {}}
140
- value={[]}
141
- />
142
- </div>
143
-
144
- <div className="p-4">
145
- <TableComponent
146
- controlBar={false}
147
- pagination={false}
148
- noIndex
149
- columns={columns.map(c => ({ selector: c.selector, label: c.selector }))}
150
- data={[
151
- Object.fromEntries(
152
- columns.map((c, key) => [
153
- c.selector,
154
- <div className="flex gap-1" key={key}>
155
- {key > 0 && (
156
- <IconButtonComponent
157
- icon={faArrowLeft}
158
- size="xs"
159
- variant="outline"
160
- className="!text-foreground"
161
- onClick={() => move(c.selector, "left")}
162
- />
163
- )}
164
-
165
- {key < (columns.length - 1) && (
166
- <IconButtonComponent
167
- icon={faArrowRight}
168
- size="xs"
169
- variant="outline"
170
- className="!text-foreground"
171
- onClick={() => move(c.selector, "right")}
172
- />
173
- )}
174
- </div>,
175
- ])
176
- ),
177
- ]}
178
- className="row::bg-transparent row::border-0 row::gap-0 row::!hover:bg-white column::p-2 column::border-l head-column::p-2 head-column::border-l"
179
- />
180
- </div>
181
-
182
- <RenderPDFPreview schema={schema} className="w-full max-h-[400px] overflow-y-auto flex justify-center bg-background mt-4" />
183
-
184
-
185
- <div className="px-4 mt-8">
186
- <ButtonComponent label=" Download PDF" block onClick={async () => {
187
- const bytes = await RenderPDF({ content: schema });
188
-
189
- const arrayBuffer = bytes.buffer instanceof ArrayBuffer ? bytes.buffer : bytes.slice().buffer;
190
-
191
- const blob = new Blob([arrayBuffer], { type: "application/pdf" });
192
- const url = URL.createObjectURL(blob);
193
-
194
- const a = document.createElement("a");
195
- a.href = url;
196
- a.download = title ? `${title}.pdf` : "print.pdf";
197
- a.click();
198
-
199
- URL.revokeObjectURL(url);
200
- }} />
201
- </div>
202
- </>
203
- );
204
- }