unipo-ui 1.2.0 → 1.3.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.
Files changed (173) hide show
  1. package/cli/index.mjs +53 -4
  2. package/dist/admisi-YCOE3DMH.cjs +20 -0
  3. package/dist/admisi-YXCTBECZ.js +11 -0
  4. package/dist/akademik-PJGL6MSP.cjs +20 -0
  5. package/dist/akademik-TPDFEZGF.js +11 -0
  6. package/dist/akses-AUPQD6YN.cjs +20 -0
  7. package/dist/akses-V5XIMBWT.js +11 -0
  8. package/dist/arsip-2T7IEION.cjs +20 -0
  9. package/dist/arsip-LDRV7FYX.js +11 -0
  10. package/dist/cbt-4N6COVIN.js +11 -0
  11. package/dist/cbt-GMQSR7TP.cjs +20 -0
  12. package/dist/chunk-34OKV63Q.js +122 -0
  13. package/dist/chunk-34OKV63Q.js.map +1 -0
  14. package/dist/chunk-3O5ELKBH.cjs +18 -0
  15. package/dist/chunk-3O5ELKBH.cjs.map +1 -0
  16. package/dist/chunk-4BQOABRV.js +462 -0
  17. package/dist/chunk-4BQOABRV.js.map +1 -0
  18. package/dist/{chunk-DEF5CA7C.cjs → chunk-5VNCBW4R.cjs} +282 -1165
  19. package/dist/chunk-5VNCBW4R.cjs.map +1 -0
  20. package/dist/{chunk-SJ4DJOMZ.js → chunk-7AJ4LW5H.js} +163 -1019
  21. package/dist/chunk-7AJ4LW5H.js.map +1 -0
  22. package/dist/chunk-JASW45YF.cjs +510 -0
  23. package/dist/chunk-JASW45YF.cjs.map +1 -0
  24. package/dist/chunk-JSUHAYQ4.js +15 -0
  25. package/dist/chunk-JSUHAYQ4.js.map +1 -0
  26. package/dist/chunk-LN6HZMPI.js +1006 -0
  27. package/dist/chunk-LN6HZMPI.js.map +1 -0
  28. package/dist/chunk-LNJTDEQR.cjs +1937 -0
  29. package/dist/chunk-LNJTDEQR.cjs.map +1 -0
  30. package/dist/chunk-MKQEH7QS.cjs +1058 -0
  31. package/dist/chunk-MKQEH7QS.cjs.map +1 -0
  32. package/dist/chunk-TAKLMRU7.cjs +150 -0
  33. package/dist/chunk-TAKLMRU7.cjs.map +1 -0
  34. package/dist/chunk-TYCRRYCQ.js +1843 -0
  35. package/dist/chunk-TYCRRYCQ.js.map +1 -0
  36. package/dist/crm-C4XGSG6O.js +11 -0
  37. package/dist/crm-LTVCDNMK.cjs +20 -0
  38. package/dist/dasbor-OJLMSFTF.cjs +20 -0
  39. package/dist/dasbor-Y3UPFYFE.js +11 -0
  40. package/dist/edom-3GZUUB7H.cjs +20 -0
  41. package/dist/edom-K4Y2NV4K.js +11 -0
  42. package/dist/fakultas-DJRUVJBV.js +11 -0
  43. package/dist/fakultas-VVAQOPUX.cjs +20 -0
  44. package/dist/filter-D54KALbB.d.cts +436 -0
  45. package/dist/filter-D54KALbB.d.ts +436 -0
  46. package/dist/helpdesk-AWVC7BPE.cjs +20 -0
  47. package/dist/helpdesk-BAOXAU6G.js +11 -0
  48. package/dist/humas-7BMMJ3WF.js +11 -0
  49. package/dist/humas-H56JFUW6.cjs +20 -0
  50. package/dist/ikon.cjs +125 -0
  51. package/dist/ikon.cjs.map +1 -0
  52. package/dist/ikon.d.cts +140 -0
  53. package/dist/ikon.d.ts +140 -0
  54. package/dist/ikon.js +6 -0
  55. package/dist/ikon.js.map +1 -0
  56. package/dist/iku-7JLF2NIH.js +11 -0
  57. package/dist/iku-F47ZLMYJ.cjs +20 -0
  58. package/dist/index.cjs +544 -257
  59. package/dist/index.cjs.map +1 -1
  60. package/dist/index.d.cts +192 -2
  61. package/dist/index.d.ts +192 -2
  62. package/dist/index.js +126 -4
  63. package/dist/index.js.map +1 -1
  64. package/dist/induk-BGTGKRLL.js +11 -0
  65. package/dist/induk-DLYDMZAM.cjs +20 -0
  66. package/dist/integrasi-4VXNGA3V.cjs +20 -0
  67. package/dist/integrasi-IP3WWDO7.js +11 -0
  68. package/dist/kalender-DGQDGJCL.cjs +20 -0
  69. package/dist/kalender-FGGUBYKZ.js +11 -0
  70. package/dist/karier-H3HBFCQQ.js +11 -0
  71. package/dist/karier-QTU2P5YD.cjs +20 -0
  72. package/dist/katalog.cjs +1709 -0
  73. package/dist/katalog.cjs.map +1 -0
  74. package/dist/katalog.d.cts +645 -0
  75. package/dist/katalog.d.ts +645 -0
  76. package/dist/katalog.js +1626 -0
  77. package/dist/katalog.js.map +1 -0
  78. package/dist/kelulusan-BHFQM5N4.cjs +20 -0
  79. package/dist/kelulusan-ZR7CM6I5.js +11 -0
  80. package/dist/kemahasiswaan-EINWXAY7.cjs +20 -0
  81. package/dist/kemahasiswaan-NH2LEDH7.js +11 -0
  82. package/dist/kerjasama-FAOHZCML.js +11 -0
  83. package/dist/kerjasama-TXWJOU4Y.cjs +20 -0
  84. package/dist/keu-4TXF4FEP.cjs +20 -0
  85. package/dist/keu-SD7UOCDB.js +11 -0
  86. package/dist/kurikulum-SRO7TJYI.cjs +20 -0
  87. package/dist/kurikulum-XT7PZJOK.js +11 -0
  88. package/dist/layanan-RQ2AWCQ5.cjs +20 -0
  89. package/dist/layanan-Y6WUCSD2.js +11 -0
  90. package/dist/lms-5JYOSLBI.cjs +20 -0
  91. package/dist/lms-NTXMSHG2.js +11 -0
  92. package/dist/lppm-7DH7PRF3.cjs +20 -0
  93. package/dist/lppm-UXYGIOIF.js +11 -0
  94. package/dist/master-GKTTAKLF.cjs +20 -0
  95. package/dist/master-ZG4SPPDU.js +11 -0
  96. package/dist/mbkm-OGR72BTB.js +11 -0
  97. package/dist/mbkm-URKJHUIQ.cjs +20 -0
  98. package/dist/notifikasi-FMA26M4I.js +11 -0
  99. package/dist/notifikasi-QDCYIX7G.cjs +20 -0
  100. package/dist/pddikti-RJVYY2J4.cjs +20 -0
  101. package/dist/pddikti-VF2PXDKA.js +11 -0
  102. package/dist/{content-DaJPx5LX.d.cts → pemeliharaan-D5S-1lqW.d.ts} +38 -434
  103. package/dist/{content-DaJPx5LX.d.ts → pemeliharaan-Dr0HSxvZ.d.cts} +38 -434
  104. package/dist/perpustakaan-5RL33XG2.js +11 -0
  105. package/dist/perpustakaan-JXZW43MJ.cjs +20 -0
  106. package/dist/pilih-BEes_D3n.d.cts +205 -0
  107. package/dist/pilih-CEKqXMUS.d.ts +205 -0
  108. package/dist/pmb-EGTWW2ZH.cjs +20 -0
  109. package/dist/pmb-G7EAFJ3R.js +11 -0
  110. package/dist/portal-EI7TXN7H.cjs +20 -0
  111. package/dist/portal-MMUYX3RA.js +11 -0
  112. package/dist/portal-api-BJLO6AGI.js +11 -0
  113. package/dist/portal-api-Q6B3X6ZV.cjs +20 -0
  114. package/dist/profil-46FV46VH.cjs +20 -0
  115. package/dist/profil-4BIXIM6D.js +11 -0
  116. package/dist/referensi-HNYOJGNX.js +11 -0
  117. package/dist/referensi-VOT5BRCL.cjs +20 -0
  118. package/dist/registry.json +606 -4
  119. package/dist/repositori-2MJ43NXM.js +11 -0
  120. package/dist/repositori-KFXVJB7B.cjs +20 -0
  121. package/dist/rpl-2ZXHNSPF.js +11 -0
  122. package/dist/rpl-YF5MV2YA.cjs +20 -0
  123. package/dist/sarpras-CQ7QKVUN.js +11 -0
  124. package/dist/sarpras-XGPHHFCG.cjs +20 -0
  125. package/dist/scss/components/_animasi.scss +280 -0
  126. package/dist/scss/components/_ikon.scss +249 -0
  127. package/dist/scss/components/_katalog.scss +662 -0
  128. package/dist/scss/components/_platform.scss +364 -0
  129. package/dist/scss/index.scss +4 -0
  130. package/dist/sdm-N6LE66PP.cjs +20 -0
  131. package/dist/sdm-QKBXH3JF.js +11 -0
  132. package/dist/siakad.cjs +1389 -2915
  133. package/dist/siakad.cjs.map +1 -1
  134. package/dist/siakad.d.cts +31 -196
  135. package/dist/siakad.d.ts +31 -196
  136. package/dist/siakad.js +446 -2194
  137. package/dist/siakad.js.map +1 -1
  138. package/dist/spmi-J37NEYIU.js +11 -0
  139. package/dist/spmi-N6EU7KNC.cjs +20 -0
  140. package/dist/tracer-G6DDXVXC.cjs +20 -0
  141. package/dist/tracer-M3FTNWBG.js +11 -0
  142. package/dist/ui-unipo.css +1650 -0
  143. package/dist/ui-unipo.min.css +1 -1
  144. package/package.json +25 -3
  145. package/src/components/animasi.tsx +186 -0
  146. package/src/components/modal.tsx +113 -0
  147. package/src/components/overlays.tsx +6 -1
  148. package/src/components/pemeliharaan.tsx +152 -0
  149. package/src/components/platform.tsx +94 -0
  150. package/src/ikon/ilustrasi.tsx +283 -0
  151. package/src/ikon/index.ts +7 -0
  152. package/src/ikon/kotak.tsx +30 -0
  153. package/src/ikon/unipo.tsx +326 -0
  154. package/src/index.ts +8 -0
  155. package/src/katalog/aturan.ts +488 -0
  156. package/src/katalog/data/id.ts +749 -0
  157. package/src/katalog/data/indeks.json +1 -0
  158. package/src/katalog/data/muat.ts +47 -0
  159. package/src/katalog/ikon.tsx +11 -0
  160. package/src/katalog/index.ts +13 -0
  161. package/src/katalog/isian.tsx +372 -0
  162. package/src/katalog/katalog.tsx +138 -0
  163. package/src/katalog/kelola.tsx +620 -0
  164. package/src/katalog/modul.tsx +336 -0
  165. package/src/katalog/tampil.tsx +147 -0
  166. package/src/katalog/tipe.ts +141 -0
  167. package/src/katalog/wizard.tsx +155 -0
  168. package/src/lib/platform.ts +91 -0
  169. package/src/siakad/index.ts +1 -0
  170. package/src/siakad/pemeliharaan.tsx +118 -0
  171. package/src/siakad/provider.tsx +2 -0
  172. package/dist/chunk-DEF5CA7C.cjs.map +0 -1
  173. package/dist/chunk-SJ4DJOMZ.js.map +0 -1
@@ -0,0 +1,620 @@
1
+ 'use client';
2
+ import * as React from 'react';
3
+ import { Download, FileText, Paperclip, Pencil, Plus, RefreshCw, Trash2 } from 'lucide-react';
4
+ import type { Siakad } from 'unipo-siakad-sdk';
5
+ import { Badge, Button, Skeleton } from '../components/actions';
6
+ import { Dropzone } from '../components/calendar';
7
+ import { Empty, Tabs } from '../components/display';
8
+ import { DataTable, type DataColumn, type SortState } from '../components/data-table';
9
+ import { FilterBar, type FilterField } from '../components/filter';
10
+ import { ConfirmDialog, Dialog, DialogClose, Sheet, Tooltip, useToast, type MenuEntry } from '../components/overlays';
11
+ import { formatBytes, formatDate } from '../lib/format';
12
+ import { GalatApi } from '../siakad/galat';
13
+ import { PilihEntitas } from '../siakad/pilih';
14
+ import { invalidateSiakad, pesanGalat, useOptionalSiakad, useSiakad, useSiakadQuery } from '../siakad/provider';
15
+ import { useSiakadTable } from '../siakad/tabel';
16
+ import {
17
+ isiPath,
18
+ judulBaris,
19
+ judulOperasi,
20
+ keabsahanAksi,
21
+ labelKolom,
22
+ labelNilai,
23
+ nilaiKunci,
24
+ paramPath,
25
+ pilihKolom,
26
+ punyaScope,
27
+ } from './aturan';
28
+ import { FormulirSkema, sumberDariAcuan, useFormulirSkema } from './isian';
29
+ import { useKatalog, useSumber, type SumberState } from './katalog';
30
+ import { AlurStatus, DetailBaris, NilaiSel } from './tampil';
31
+ import type { Baris, Operasi, Skema } from './tipe';
32
+
33
+ const SISTEM = new Set(['page', 'per_page', 'q', 'urut', 'dari', 'sampai', 'limit', 'offset', 'sort']);
34
+
35
+ /** Field saringan dari parameter query endpoint daftar: enum → pilihan, boolean → saklar, kunci tabel → pilih-cari, dari/sampai → rentang tanggal. */
36
+ export function saringanDariOperasi(op: Operasi | undefined, sembunyi: string[] = []): FilterField[] {
37
+ if (!op?.pa) return [];
38
+ const out: FilterField[] = [];
39
+ for (const p of op.pa) {
40
+ if (p.in !== 'query' || SISTEM.has(p.nm) || sembunyi.includes(p.nm)) continue;
41
+ const s = p.s;
42
+ if (s.e?.length) out.push({ key: p.nm, label: labelKolom(p.nm), type: 'select', options: s.e.filter((x) => x !== null).map((x) => ({ value: String(x), label: labelNilai(x) })) });
43
+ else if (s.t === 'boolean') out.push({ key: p.nm, label: labelKolom(p.nm), type: 'boolean' });
44
+ else if (s.rf) {
45
+ const src = sumberDariAcuan(s.rf, p.nm);
46
+ out.push({
47
+ key: p.nm,
48
+ label: labelKolom(p.nm),
49
+ type: 'custom',
50
+ render: (v, set) => <PilihEntitas jenis={src} value={(v as string) ?? null} onValueChange={(x) => set(x ?? undefined)} size="sm" />,
51
+ });
52
+ }
53
+ }
54
+ if (op.pa.some((p) => p.nm === 'dari') && op.pa.some((p) => p.nm === 'sampai')) out.push({ key: 'rentang', label: 'Tanggal', type: 'date-range', params: ['dari', 'sampai'] });
55
+ return out;
56
+ }
57
+
58
+ async function jalankan(siakad: Siakad, op: Operasi, nilaiPath: Record<string, unknown>, body?: unknown, query?: Record<string, unknown>) {
59
+ const multipart = typeof FormData !== 'undefined' && body instanceof FormData;
60
+ return siakad.request({ method: op.m, path: op.path, query: { ...(query as object), ...nilaiPath } as never, body, multipart, public: Boolean(op.pub) });
61
+ }
62
+
63
+ /** Nilai path item untuk satu baris: kunci item + parameter induk yang sudah diketahui. */
64
+ function nilaiPathBaris(sumber: SumberState['sumber'], baris: Baris, induk?: Record<string, unknown>): Record<string, unknown> {
65
+ const out: Record<string, unknown> = { ...induk };
66
+ if (sumber?.key) out[sumber.key] = nilaiKunci(baris, sumber.key);
67
+ return out;
68
+ }
69
+
70
+ // ================================================================ Tabel
71
+ export interface TabelSumberProps {
72
+ /** Path sumber data, mis. '/v1/kemahasiswaan/beasiswa'. */
73
+ sumber: string;
74
+ /** Nilai parameter path induk untuk sumber anak, mis. { id: 12 } untuk /v1/x/{id}/anak. */
75
+ induk?: Record<string, unknown>;
76
+ /** Saringan tetap (tidak tampil di bilah saringan). */
77
+ query?: Record<string, string | number | boolean | undefined>;
78
+ /** Kolom yang ditampilkan (bawaan dipilih otomatis). */
79
+ kolom?: string[];
80
+ /** Ganti isi sel kolom tertentu. */
81
+ sel?: Record<string, (b: Baris) => React.ReactNode>;
82
+ onRowClick?: (b: Baris) => void;
83
+ rowActions?: (b: Baris) => MenuEntry[];
84
+ actions?: React.ReactNode;
85
+ perPage?: number;
86
+ /** Simpan saringan di URL. */
87
+ syncUrl?: boolean;
88
+ /** Muat ulang dari luar (naikkan angka). */
89
+ muatUlang?: number;
90
+ className?: string;
91
+ }
92
+
93
+ /** Tabel data dari endpoint daftar katalog: saringan dari parameter API, urut server, halaman, ekspor CSV. */
94
+ export function TabelSumber({ sumber: id, induk, query, kolom, sel, onRowClick, rowActions, actions, perPage = 20, syncUrl, className }: TabelSumberProps) {
95
+ const st = useSumber(id);
96
+ const list = st.op(st.sumber?.list);
97
+ if (st.loading) return <Skeleton height={240} />;
98
+ if (st.error) return <GalatApi error={st.error} title="Katalog tidak dapat dimuat" />;
99
+ if (!list) return <Empty title="Sumber ini tidak punya daftar" description="Gunakan operasi detail atau aksi yang tersedia." bordered />;
100
+ return <TabelSumberDalam st={st} list={list} induk={induk} query={query} kolom={kolom} sel={sel} onRowClick={onRowClick} rowActions={rowActions} actions={actions} perPage={perPage} syncUrl={syncUrl} className={className} />;
101
+ }
102
+
103
+ function TabelSumberDalam({ st, list, induk, query, kolom, sel, onRowClick, rowActions, actions, perPage, syncUrl, className }: Omit<TabelSumberProps, 'sumber'> & { st: SumberState; list: Operasi }) {
104
+ const tetap = Object.keys(query ?? {});
105
+ const fields = React.useMemo(() => saringanDariOperasi(list, [...tetap, ...paramPath(list.path)]), [list, tetap.join()]); // eslint-disable-line react-hooks/exhaustive-deps
106
+ const bisaUrut = Boolean(list.pa?.some((p) => p.nm === 'urut'));
107
+ const bisaCari = Boolean(list.pa?.some((p) => p.nm === 'q'));
108
+ const [sort, setSort] = React.useState<SortState>(null);
109
+ const path = isiPath(list.path, induk ?? {});
110
+ const t = useSiakadTable<Baris>({
111
+ key: `katalog:${path}:${JSON.stringify(query ?? {})}:${sort ? (sort.dir === 'desc' ? '-' : '') + sort.key : ''}`,
112
+ fetch: (s, q, signal) => s.request<Baris[]>({ method: 'GET', path, query: { ...query, ...q, ...(sort ? { urut: (sort.dir === 'desc' ? '-' : '') + sort.key } : {}) } as never, public: Boolean(list.pub) }, { signal }),
113
+ fields,
114
+ perPage,
115
+ syncUrl,
116
+ });
117
+ const rows = Array.isArray(t.data) ? t.data : undefined;
118
+ const { semua, awal } = pilihKolom(st.skemaBaris, rows ?? [], 6);
119
+ const tampil = kolom ?? awal;
120
+ const columns: DataColumn<Baris>[] = semua
121
+ .filter((k) => tampil.includes(k) || !kolom)
122
+ .map((k) => ({
123
+ key: k,
124
+ header: labelKolom(k),
125
+ label: labelKolom(k),
126
+ sortable: bisaUrut,
127
+ defaultHidden: !tampil.includes(k),
128
+ cell: sel?.[k] ?? ((b: Baris) => <NilaiSel nama={k} value={b[k]} skema={st.skemaBaris?.pr?.[k]} />),
129
+ value: (b: Baris) => (b[k] == null || typeof b[k] === 'object' ? '' : b[k]),
130
+ mobile: k === tampil[0] ? 'title' : /status/.test(k) ? 'badge' : undefined,
131
+ }));
132
+ return (
133
+ <DataTable<Baris>
134
+ className={className}
135
+ {...t.tableProps}
136
+ rows={rows}
137
+ columns={columns}
138
+ rowKey={(b) => String(nilaiKunci(b, st.sumber?.key) ?? JSON.stringify(b))}
139
+ onRowClick={onRowClick}
140
+ rowActions={rowActions}
141
+ sort={bisaUrut ? sort : undefined}
142
+ onSortChange={bisaUrut ? setSort : undefined}
143
+ exportCsv={st.sumber?.title}
144
+ toolbar={fields.length || bisaCari ? <FilterBar fields={fields} {...t.filterProps} search={bisaCari ? { placeholder: `Cari ${st.sumber?.title.toLowerCase() ?? ''}` } : false} resultLabel={st.sumber?.title.toLowerCase()} /> : undefined}
145
+ actions={actions}
146
+ empty={{ icon: <FileText />, title: `Belum ada ${st.sumber?.title.toLowerCase() ?? 'data'}` }}
147
+ />
148
+ );
149
+ }
150
+
151
+ // ================================================================ Aksi baris
152
+ export interface TombolAksiProps {
153
+ op: Operasi;
154
+ /** Baris sasaran (aksi item) atau kosong (aksi koleksi). */
155
+ baris?: Baris | null;
156
+ /** Nilai parameter path, mis. { id: 12 }. */
157
+ nilaiPath: Record<string, unknown>;
158
+ skemaBaris?: Skema;
159
+ onSelesai?: (hasil: unknown) => void;
160
+ /** Tampilan tombol. */
161
+ variant?: 'primary' | 'outline' | 'ghost' | 'destructive' | 'secondary';
162
+ size?: 'sm' | 'md';
163
+ /** Tetap tampil (nonaktif dengan alasan) bila status tidak memenuhi. Bawaan disembunyikan. */
164
+ tampilkanTakSah?: boolean;
165
+ }
166
+
167
+ const BAHAYA = /(hapus|tolak|batal|cabut|blokir|musnah|nonaktif|tutup|kembalikan|reset)/i;
168
+
169
+ /**
170
+ * Satu aksi alur kerja (POST /{id}/aksi): disembunyikan bila status baris tidak sesuai aturan backend, membuka
171
+ * formulir bila aksi punya isian (catatan, alasan, nilai), atau konfirmasi bila tidak.
172
+ */
173
+ export function TombolAksi({ op, baris, nilaiPath, skemaBaris, onSelesai, variant, size = 'sm', tampilkanTakSah }: TombolAksiProps) {
174
+ const siakad = useSiakad();
175
+ const { scopes } = useKatalog();
176
+ const toast = useToast();
177
+ const [buka, setBuka] = React.useState(false);
178
+ const sah = keabsahanAksi(op, baris, skemaBaris, scopes);
179
+ const judul = judulOperasi(op);
180
+ const punyaIsian = Boolean(op.b && Object.keys(op.b.s.pr ?? {}).length);
181
+ const form = useFormulirSkema(op.b?.s);
182
+ const [galat, setGalat] = React.useState<unknown>(null);
183
+ const [sibuk, setSibuk] = React.useState(false);
184
+ const v = variant ?? (BAHAYA.test(judul) ? 'outline' : 'primary');
185
+ if (!sah.boleh && !tampilkanTakSah) return null;
186
+ const selesai = (hasil: unknown) => {
187
+ toast.add({ title: `${judul} berhasil`, description: op.tr?.ke ? `Status menjadi ${labelNilai(op.tr.ke)}.` : undefined, type: 'success' });
188
+ invalidateSiakad('katalog:');
189
+ onSelesai?.(hasil);
190
+ };
191
+ const tombol = (
192
+ <Button variant={v} size={size} disabled={!sah.boleh}>
193
+ {judul}
194
+ </Button>
195
+ );
196
+ if (!sah.boleh) return <Tooltip content={sah.alasan}>{<span tabIndex={0}>{tombol}</span>}</Tooltip>;
197
+ if (!punyaIsian) {
198
+ return (
199
+ <ConfirmDialog
200
+ trigger={tombol}
201
+ title={`${judul}?`}
202
+ description={[baris ? judulBaris(baris) : null, op.tr?.ke ? `Status akan menjadi ${labelNilai(op.tr.ke)}.` : null, op.ds?.replace(/(Pengelola modul|Pemilik data( atau pengelola)?|Admin modul)\.\s*/, '').replace(/Status harus[^.]*\.\s*/, '')].filter(Boolean).join(' ') || undefined}
203
+ confirmLabel={judul}
204
+ tone={BAHAYA.test(judul) ? 'danger' : 'primary'}
205
+ onConfirm={async () => {
206
+ try {
207
+ const r = await jalankan(siakad, op, nilaiPath, op.m === 'POST' ? {} : undefined);
208
+ selesai(r.data);
209
+ } catch (e) {
210
+ toast.add({ title: `${judul} gagal`, description: pesanGalat(e), type: 'error' });
211
+ throw e;
212
+ }
213
+ }}
214
+ />
215
+ );
216
+ }
217
+ return (
218
+ <Dialog
219
+ open={buka}
220
+ onOpenChange={(o) => {
221
+ setBuka(o);
222
+ if (!o) {
223
+ form.reset();
224
+ setGalat(null);
225
+ }
226
+ }}
227
+ trigger={tombol}
228
+ title={judul}
229
+ description={baris ? judulBaris(baris) : op.ds}
230
+ size="md"
231
+ footer={
232
+ <>
233
+ <DialogClose render={<Button variant="ghost" />}>Batal</DialogClose>
234
+ <Button
235
+ variant={BAHAYA.test(judul) ? 'destructive' : 'primary'}
236
+ loading={sibuk}
237
+ onClick={async () => {
238
+ const body = form.kirim();
239
+ if (!body) return;
240
+ setSibuk(true);
241
+ setGalat(null);
242
+ try {
243
+ const r = await jalankan(siakad, op, nilaiPath, body);
244
+ setBuka(false);
245
+ selesai(r.data);
246
+ } catch (e) {
247
+ if (!form.galatServer(e)) setGalat(e);
248
+ } finally {
249
+ setSibuk(false);
250
+ }
251
+ }}
252
+ >
253
+ {judul}
254
+ </Button>
255
+ </>
256
+ }
257
+ >
258
+ {galat ? <GalatApi error={galat} title={`${judul} gagal`} /> : null}
259
+ <FormulirSkema skema={op.b?.s} form={form} columns={1} />
260
+ </Dialog>
261
+ );
262
+ }
263
+
264
+ /** Semua aksi alur kerja yang sah untuk satu baris, berderet. */
265
+ export function AksiSumber({ sumber: id, baris, induk, onSelesai, tampilkanTakSah }: { sumber: string; baris: Baris; induk?: Record<string, unknown>; onSelesai?: (hasil: unknown) => void; tampilkanTakSah?: boolean }) {
266
+ const st = useSumber(id);
267
+ if (!st.sumber) return null;
268
+ const ops = st.sumber.actions.map((a) => st.op(a)).filter((o): o is Operasi => Boolean(o) && o!.m !== 'GET');
269
+ if (!ops.length) return null;
270
+ return (
271
+ <div className="u-aksi-sumber">
272
+ {ops.map((o) => (
273
+ <TombolAksi key={o.id} op={o} baris={baris} nilaiPath={nilaiPathBaris(st.sumber, baris, induk)} skemaBaris={st.skemaBaris} onSelesai={onSelesai} tampilkanTakSah={tampilkanTakSah} />
274
+ ))}
275
+ </div>
276
+ );
277
+ }
278
+
279
+ // ================================================================ Formulir tambah/ubah
280
+ export interface FormulirSumberProps {
281
+ sumber: string;
282
+ /** Baris yang diubah; kosong = tambah. */
283
+ baris?: Baris | null;
284
+ induk?: Record<string, unknown>;
285
+ /** Nilai awal tambahan untuk mode tambah. */
286
+ nilai?: Record<string, unknown>;
287
+ open?: boolean;
288
+ onOpenChange?: (o: boolean) => void;
289
+ trigger?: React.ReactElement;
290
+ onTersimpan?: (b: Baris) => void;
291
+ /** Tampil sebagai panel samping (bawaan) atau dialog. */
292
+ tampilan?: 'sheet' | 'dialog';
293
+ }
294
+
295
+ /** Panel tambah/ubah satu sumber data dengan validasi backend dan galat 422 per isian. */
296
+ export function FormulirSumber({ sumber: id, baris, induk, nilai, open, onOpenChange, trigger, onTersimpan, tampilan = 'sheet' }: FormulirSumberProps) {
297
+ const st = useSumber(id);
298
+ const siakad = useSiakad();
299
+ const toast = useToast();
300
+ const ubah = Boolean(baris);
301
+ const op = st.op(ubah ? st.sumber?.update : st.sumber?.create);
302
+ const skema = op?.b?.s;
303
+ const form = useFormulirSkema(skema, { data: baris ?? undefined, nilai });
304
+ const [galat, setGalat] = React.useState<unknown>(null);
305
+ const [sibuk, setSibuk] = React.useState(false);
306
+ const [inner, setInner] = React.useState(false);
307
+ const isOpen = open ?? inner;
308
+ const setOpen = (o: boolean) => {
309
+ setInner(o);
310
+ onOpenChange?.(o);
311
+ if (!o) setGalat(null);
312
+ };
313
+ if (!op) return null;
314
+ const nama = st.sumber?.title.toLowerCase() ?? 'data';
315
+ const W = tampilan === 'sheet' ? Sheet : Dialog;
316
+ return (
317
+ <W
318
+ open={isOpen}
319
+ onOpenChange={setOpen}
320
+ trigger={trigger}
321
+ size="lg"
322
+ title={ubah ? `Ubah ${nama}` : `Tambah ${nama}`}
323
+ description={ubah ? judulBaris(baris, st.sumber?.key) : op.ds?.replace(/(Pengelola modul|Pemilik data( atau pengelola)?|Admin modul)\.\s*/, '') || undefined}
324
+ footer={
325
+ <>
326
+ <DialogClose render={<Button variant="ghost" />}>Batal</DialogClose>
327
+ <Button
328
+ loading={sibuk}
329
+ onClick={async () => {
330
+ const body = form.kirim();
331
+ if (!body) return;
332
+ if (ubah && body && !(body instanceof FormData) && !Object.keys(body).length) {
333
+ setOpen(false);
334
+ return;
335
+ }
336
+ setSibuk(true);
337
+ setGalat(null);
338
+ try {
339
+ const nilaiPath = ubah ? nilaiPathBaris(st.sumber, baris!, induk) : { ...induk };
340
+ const r = await jalankan(siakad, op, nilaiPath, body);
341
+ toast.add({ title: ubah ? 'Perubahan tersimpan' : `${st.sumber?.title} ditambahkan`, type: 'success' });
342
+ invalidateSiakad('katalog:');
343
+ setOpen(false);
344
+ if (!ubah) form.reset();
345
+ onTersimpan?.((r.data as Baris) ?? {});
346
+ } catch (e) {
347
+ if (!form.galatServer(e)) setGalat(e);
348
+ } finally {
349
+ setSibuk(false);
350
+ }
351
+ }}
352
+ >
353
+ {ubah ? 'Simpan perubahan' : `Tambah ${nama}`}
354
+ </Button>
355
+ </>
356
+ }
357
+ >
358
+ {galat ? <GalatApi error={galat} title="Gagal menyimpan" /> : null}
359
+ <FormulirSkema skema={skema} form={form} sembunyi={Object.keys(induk ?? {})} />
360
+ </W>
361
+ );
362
+ }
363
+
364
+ // ================================================================ Lampiran (sumber /berkas)
365
+ /** Lampiran baris (PusatData berkas): daftar, unggah (seret berkas), unduh, dan hapus. */
366
+ export function LampiranSumber({ path, bisaUbah = true }: { path: string; bisaUbah?: boolean }) {
367
+ const siakad = useSiakad();
368
+ const toast = useToast();
369
+ const q = useSiakadQuery<Baris[]>(['katalog:berkas', path], (s, signal) => s.request({ method: 'GET', path }, { signal }));
370
+ const [sibuk, setSibuk] = React.useState(false);
371
+ const unggah = async (files: File[]) => {
372
+ setSibuk(true);
373
+ try {
374
+ for (const f of files) {
375
+ const fd = new FormData();
376
+ fd.append('berkas', f);
377
+ await siakad.request({ method: 'POST', path, body: fd, multipart: true });
378
+ }
379
+ toast.add({ title: `${files.length} berkas diunggah`, type: 'success' });
380
+ q.refetch();
381
+ } catch (e) {
382
+ toast.add({ title: 'Gagal mengunggah', description: pesanGalat(e), type: 'error' });
383
+ } finally {
384
+ setSibuk(false);
385
+ }
386
+ };
387
+ const unduh = async (b: Baris) => {
388
+ try {
389
+ const r = await siakad.request<unknown>({ method: 'GET', path: `${path}/${b.uuid}` });
390
+ const url = (r.data as Baris | undefined)?.url;
391
+ if (typeof url === 'string') window.open(url, '_blank', 'noopener');
392
+ } catch (e) {
393
+ toast.add({ title: 'Gagal mengunduh', description: pesanGalat(e), type: 'error' });
394
+ }
395
+ };
396
+ return (
397
+ <div className="u-lampiran">
398
+ {q.error ? <GalatApi error={q.error} onRetry={q.refetch} /> : null}
399
+ {q.loading && !q.data ? <Skeleton height={64} /> : null}
400
+ {Array.isArray(q.data) && q.data.length > 0 && (
401
+ <ul className="u-lampiran-daftar">
402
+ {q.data.map((b) => (
403
+ <li key={String(b.uuid)}>
404
+ <Paperclip aria-hidden />
405
+ <span>
406
+ <b>{String(b.nama ?? b.uuid)}</b>
407
+ <small>{[b.jenis, typeof b.ukuran === 'number' ? formatBytes(b.ukuran) : null, b.created_at ? formatDate(String(b.created_at), 'medium') : null].filter(Boolean).join(' · ')}</small>
408
+ </span>
409
+ <Button variant="ghost" size="sm" iconOnly aria-label="Unduh" onClick={() => unduh(b)}>
410
+ <Download />
411
+ </Button>
412
+ {bisaUbah && (
413
+ <ConfirmDialog
414
+ trigger={
415
+ <Button variant="ghost" size="sm" iconOnly aria-label="Hapus lampiran">
416
+ <Trash2 />
417
+ </Button>
418
+ }
419
+ title="Hapus lampiran?"
420
+ description={String(b.nama ?? '')}
421
+ confirmLabel="Hapus lampiran"
422
+ onConfirm={async () => {
423
+ await siakad.request({ method: 'DELETE', path: `${path}/${b.uuid}` });
424
+ q.refetch();
425
+ }}
426
+ />
427
+ )}
428
+ </li>
429
+ ))}
430
+ </ul>
431
+ )}
432
+ {Array.isArray(q.data) && q.data.length === 0 && !bisaUbah && <p className="u-field-description">Belum ada lampiran.</p>}
433
+ {bisaUbah && <Dropzone onFiles={unggah} multiple disabled={sibuk} title={sibuk ? 'Mengunggah…' : 'Seret berkas ke sini atau pilih'} hint="PDF, gambar, dokumen Office/ODF, CSV, TXT, ZIP" maxSize={20 * 1024 * 1024} />}
434
+ </div>
435
+ );
436
+ }
437
+
438
+ // ================================================================ Detail baris
439
+ export interface DetailSumberProps {
440
+ sumber: string;
441
+ baris: Baris;
442
+ induk?: Record<string, unknown>;
443
+ onUbah?: () => void;
444
+ onHapus?: () => void;
445
+ onBerubah?: (b: Baris) => void;
446
+ }
447
+
448
+ /** Isi panel detail: alur status, aksi yang sah, data lengkap (dimuat ulang dari endpoint detail), lampiran, dan data anak. */
449
+ export function DetailSumber({ sumber: id, baris, induk, onBerubah }: DetailSumberProps) {
450
+ const st = useSumber(id);
451
+ const get = st.op(st.sumber?.get);
452
+ const nilaiPath = nilaiPathBaris(st.sumber, baris, induk);
453
+ const kunci = st.sumber?.key ? nilaiKunci(baris, st.sumber.key) : undefined;
454
+ const q = useSiakadQuery<Baris>(['katalog:detail', get?.path, nilaiPath], (s, signal) => s.request({ method: 'GET', path: get!.path, query: nilaiPath as never, public: Boolean(get?.pub) }, { signal }), { enabled: Boolean(get && kunci) });
455
+ const b = (q.data && typeof q.data === 'object' && !Array.isArray(q.data) ? q.data : null) ?? baris;
456
+ const aksi = (st.sumber?.actions ?? []).map((a) => st.op(a)).filter((o): o is Operasi => Boolean(o));
457
+ const kolomStatus = st.skemaBaris?.pr?.status?.e ? 'status' : undefined;
458
+ const anak = (st.sumber?.children ?? []).filter((c) => !/\/berkas$/.test(c));
459
+ const berkas = (st.sumber?.children ?? []).find((c) => /\/berkas$/.test(c));
460
+ const tabs = [
461
+ {
462
+ value: 'data',
463
+ label: 'Data',
464
+ content: (
465
+ <div className="u-detail-sumber">
466
+ {kolomStatus && aksi.some((o) => o.tr) && <AlurStatus status={st.skemaBaris!.pr!.status.e!.map(String)} sekarang={b.status == null ? null : String(b.status)} aksi={aksi} baris={b} skemaBaris={st.skemaBaris} />}
467
+ {q.error ? <GalatApi error={q.error} onRetry={q.refetch} variant="warning" title="Data terbaru tidak dapat dimuat" /> : null}
468
+ <DetailBaris baris={b} skema={st.skemaBaris} />
469
+ </div>
470
+ ),
471
+ },
472
+ ...(berkas && st.sumber?.key
473
+ ? [{ value: 'berkas', label: 'Lampiran', icon: <Paperclip />, content: <LampiranSumber path={isiPath(berkas, { ...induk, [paramPath(berkas)[0] ?? 'id']: kunci })} bisaUbah={Boolean(st.sumber.update)} /> }]
474
+ : []),
475
+ ...anak.map((c) => ({
476
+ value: c,
477
+ label: st.modul?.resources.find((r) => r.id === c)?.title ?? labelKolom(c.split('/').pop() ?? c),
478
+ content: <KelolaSumber sumber={c} induk={{ ...induk, [paramPath(c).at(-1) ?? 'id']: kunci }} ringkas />,
479
+ })),
480
+ ];
481
+ return (
482
+ <div className="u-detail-sumber-wrap">
483
+ {aksi.length > 0 && <AksiSumber sumber={id} baris={b} induk={induk} onSelesai={(h) => (q.refetch(), h && typeof h === 'object' && onBerubah?.(h as Baris))} />}
484
+ {tabs.length > 1 ? <Tabs items={tabs} defaultValue="data" /> : tabs[0].content}
485
+ </div>
486
+ );
487
+ }
488
+
489
+ // ================================================================ Kelola: tabel + tambah + detail + ubah + hapus + aksi
490
+ export interface KelolaSumberProps extends Omit<TabelSumberProps, 'onRowClick' | 'rowActions' | 'actions'> {
491
+ /** Judul di atas tabel (bawaan judul sumber). Isi false untuk tanpa judul. */
492
+ judul?: React.ReactNode | false;
493
+ deskripsi?: React.ReactNode;
494
+ /** Sembunyikan tombol tambah/ubah/hapus (tampilan baca saja). */
495
+ bacaSaja?: boolean;
496
+ /** Tampilan ringkas untuk tab di dalam detail (tanpa judul). */
497
+ ringkas?: boolean;
498
+ /** Tombol tambahan di bilah alat. */
499
+ actions?: React.ReactNode;
500
+ }
501
+
502
+ /**
503
+ * Halaman kelola lengkap satu sumber data API SIAKAD: daftar dengan saringan, tambah, detail (alur status, aksi
504
+ * yang sah menurut backend, lampiran, data anak), ubah, dan hapus. Tombol disembunyikan bila scope token kurang.
505
+ *
506
+ * <KelolaSumber sumber="/v1/kemahasiswaan/beasiswa" />
507
+ */
508
+ export function KelolaSumber({ sumber: id, judul, deskripsi, bacaSaja, ringkas, induk, actions, ...tabel }: KelolaSumberProps) {
509
+ const st = useSumber(id);
510
+ const { scopes } = useKatalog();
511
+ const siakad = useOptionalSiakad();
512
+ const toast = useToast();
513
+ const [detail, setDetail] = React.useState<Baris | null>(null);
514
+ const [ubah, setUbah] = React.useState<Baris | null>(null);
515
+ const [tambah, setTambah] = React.useState(false);
516
+ const [hapus, setHapus] = React.useState<Baris | null>(null);
517
+ if (st.loading) return <Skeleton height={280} />;
518
+ if (st.error || !st.sumber) return <GalatApi error={st.error ?? new Error('Sumber tidak ditemukan.')} title="Katalog tidak dapat dimuat" />;
519
+ const s = st.sumber;
520
+ const opCreate = st.op(s.create);
521
+ const opUpdate = st.op(s.update);
522
+ const opDel = st.op(s.del);
523
+ const boleh = (o: Operasi | undefined) => Boolean(o) && !bacaSaja && punyaScope(o!, scopes);
524
+ const nama = s.title.toLowerCase();
525
+ const rowActions = (b: Baris): MenuEntry[] => [
526
+ { label: 'Lihat detail', onSelect: () => setDetail(b) },
527
+ ...(boleh(opUpdate) ? [{ label: 'Ubah', icon: <Pencil />, onSelect: () => setUbah(b) }] : []),
528
+ ...(boleh(opDel) ? [{ type: 'separator' as const }, { label: 'Hapus', icon: <Trash2 />, destructive: true, onSelect: () => setHapus(b) }] : []),
529
+ ];
530
+ return (
531
+ <section className="u-kelola-sumber" data-ringkas={ringkas || undefined}>
532
+ {judul !== false && !ringkas && (
533
+ <header className="u-kelola-head">
534
+ <div>
535
+ <h2>{judul ?? s.title}</h2>
536
+ {deskripsi !== undefined ? deskripsi && <p>{deskripsi}</p> : <p className="u-mono">{s.base}</p>}
537
+ </div>
538
+ <div className="u-kelola-head-aksi">
539
+ {(st.op(s.list)?.sc ?? []).map((sc) => (
540
+ <Badge key={sc} variant="neutral">
541
+ {sc}
542
+ </Badge>
543
+ ))}
544
+ </div>
545
+ </header>
546
+ )}
547
+ <TabelSumber
548
+ {...tabel}
549
+ sumber={id}
550
+ induk={induk}
551
+ onRowClick={st.sumber.get || st.sumber.item ? setDetail : undefined}
552
+ rowActions={rowActions}
553
+ actions={
554
+ <>
555
+ {actions}
556
+ <Tooltip content="Muat ulang">
557
+ <Button variant="ghost" size="sm" iconOnly aria-label="Muat ulang" onClick={() => invalidateSiakad('katalog:')}>
558
+ <RefreshCw />
559
+ </Button>
560
+ </Tooltip>
561
+ {boleh(opCreate) && (
562
+ <Button size="sm" onClick={() => setTambah(true)}>
563
+ <Plus /> Tambah {ringkas ? '' : nama}
564
+ </Button>
565
+ )}
566
+ </>
567
+ }
568
+ />
569
+ {boleh(opCreate) && <FormulirSumber sumber={id} induk={induk} open={tambah} onOpenChange={setTambah} onTersimpan={(b) => b && Object.keys(b).length && setDetail(b)} />}
570
+ {ubah && <FormulirSumber sumber={id} induk={induk} baris={ubah} open onOpenChange={(o) => !o && setUbah(null)} onTersimpan={(b) => detail && setDetail({ ...detail, ...b })} />}
571
+ <Sheet
572
+ open={Boolean(detail)}
573
+ onOpenChange={(o) => !o && setDetail(null)}
574
+ size="lg"
575
+ title={detail ? judulBaris(detail, s.key) || s.title : s.title}
576
+ description={s.title}
577
+ footer={
578
+ detail && (boleh(opUpdate) || boleh(opDel)) ? (
579
+ <>
580
+ {boleh(opDel) && (
581
+ <Button variant="ghost" onClick={() => setHapus(detail)}>
582
+ <Trash2 /> Hapus
583
+ </Button>
584
+ )}
585
+ {boleh(opUpdate) && (
586
+ <Button variant="outline" onClick={() => setUbah(detail)}>
587
+ <Pencil /> Ubah
588
+ </Button>
589
+ )}
590
+ </>
591
+ ) : undefined
592
+ }
593
+ >
594
+ {detail && <DetailSumber sumber={id} baris={detail} induk={induk} onBerubah={(b) => setDetail({ ...detail, ...b })} />}
595
+ </Sheet>
596
+ <ConfirmDialog
597
+ open={Boolean(hapus)}
598
+ onOpenChange={(o) => !o && setHapus(null)}
599
+ title={`Hapus ${nama}?`}
600
+ description={hapus ? `${judulBaris(hapus, s.key)} akan dihapus. Data yang sudah dipakai di tempat lain bisa ditolak server.` : undefined}
601
+ confirmLabel={`Hapus ${nama}`}
602
+ onConfirm={async () => {
603
+ if (!hapus || !siakad || !opDel) return;
604
+ try {
605
+ await jalankan(siakad, opDel, nilaiPathBaris(s, hapus, induk));
606
+ toast.add({ title: `${s.title} dihapus`, type: 'success' });
607
+ invalidateSiakad('katalog:');
608
+ if (detail && nilaiKunci(detail, s.key) === nilaiKunci(hapus, s.key)) setDetail(null);
609
+ } catch (e) {
610
+ toast.add({ title: 'Gagal menghapus', description: pesanGalat(e), type: 'error' });
611
+ throw e;
612
+ }
613
+ }}
614
+ />
615
+ </section>
616
+ );
617
+ }
618
+
619
+ /** Alias pendek: `<Fitur sumber="/v1/sarpras/peminjaman" />`. */
620
+ export const Fitur = KelolaSumber;