@initsolusidigital/worksuite-shell 0.0.0-stage → 0.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 (75) hide show
  1. package/LICENSE +16 -0
  2. package/README.md +122 -2
  3. package/package.json +44 -4
  4. package/src/components/ai/AppAssistantDraft.vue +120 -0
  5. package/src/components/ai/AppAssistantWidget.vue +245 -0
  6. package/src/components/ai/AppCitedAnswer.vue +86 -0
  7. package/src/components/approvals/AppApprovalInbox.vue +265 -0
  8. package/src/components/approvals/AppApprovalSubjectModal.vue +197 -0
  9. package/src/components/chat/AppChatBubble.vue +324 -0
  10. package/src/components/chat/AppChatList.vue +249 -0
  11. package/src/components/chat/AppChatPanel.vue +315 -0
  12. package/src/components/chat/AppChatWidget.vue +126 -0
  13. package/src/components/communications/AppChannelBadge.vue +47 -0
  14. package/src/components/communications/AppConversationThread.vue +439 -0
  15. package/src/components/customFields/CustomFieldFilterPanel.vue +50 -0
  16. package/src/components/customFields/CustomFieldInput.vue +422 -0
  17. package/src/components/customFields/CustomFieldValue.vue +129 -0
  18. package/src/components/customFields/CustomFieldsSection.vue +65 -0
  19. package/src/components/customFields/fieldTypes.js +23 -0
  20. package/src/components/dashboard/AppCustomWidget.vue +138 -0
  21. package/src/components/dashboard/AppCustomWidgetForm.vue +173 -0
  22. package/src/components/dashboard/AppDashboardGrid.vue +200 -0
  23. package/src/components/dashboard/AppDashboardToolbar.vue +66 -0
  24. package/src/components/dashboard/AppSubAppsCatalog.vue +89 -0
  25. package/src/components/dataTools/AppImportExport.vue +724 -0
  26. package/src/components/dataTools/AppImportSchemaGuide.vue +130 -0
  27. package/src/components/hrMetrics/AppHrMetricsDashboard.vue +231 -0
  28. package/src/components/hrMetrics/AppHrMetricsEmployees.vue +87 -0
  29. package/src/components/hrMetrics/AppHrMetricsStat.vue +61 -0
  30. package/src/components/kpi/AppKpiAppraisalConfig.vue +284 -0
  31. package/src/components/kpi/AppKpiAppraisals.vue +733 -0
  32. package/src/components/kpi/AppKpiDefinitionModal.vue +317 -0
  33. package/src/components/kpi/AppKpiEntryModal.vue +122 -0
  34. package/src/components/kpi/AppKpiLeaderboard.vue +108 -0
  35. package/src/components/kpi/AppKpiMyCard.vue +134 -0
  36. package/src/components/kpi/AppKpiPeriodPicker.vue +115 -0
  37. package/src/components/kpi/AppKpiReportTable.vue +214 -0
  38. package/src/components/kpi/AppKpiScorecard.vue +242 -0
  39. package/src/components/kpi/AppKpiTargetsModal.vue +299 -0
  40. package/src/components/kpi/AppKpiTeam.vue +221 -0
  41. package/src/components/kpi/AppKpiWeightProfiles.vue +244 -0
  42. package/src/components/kpi/AppKpiWorkspace.vue +479 -0
  43. package/src/components/layout/AppGlobalSearch.vue +149 -0
  44. package/src/components/layout/AppLanguagePopup.vue +94 -0
  45. package/src/components/layout/AppLauncherPopup.vue +147 -0
  46. package/src/components/layout/AppLegalConsentModal.vue +484 -0
  47. package/src/components/layout/AppNavbar.vue +402 -0
  48. package/src/components/layout/AppNotificationContent.vue +173 -0
  49. package/src/components/layout/AppNotificationDrawer.vue +98 -0
  50. package/src/components/layout/AppNotificationPopup.vue +67 -0
  51. package/src/components/layout/AppPlatformBanners.vue +192 -0
  52. package/src/components/layout/AppSidebar.vue +226 -0
  53. package/src/components/layout/AppSidebarNav.vue +119 -0
  54. package/src/components/layout/AppUserMenu.vue +89 -0
  55. package/src/components/layout/AppUserMenuContent.vue +59 -0
  56. package/src/composables/useKpi.js +232 -0
  57. package/src/composables/useLgViewport.js +25 -0
  58. package/src/composables/useNavigation.js +177 -0
  59. package/src/layouts/AppLayout.vue +207 -0
  60. package/src/locales/en.json +1362 -0
  61. package/src/locales/id.json +1396 -0
  62. package/src/pages/auth/AccountBlocked.vue +55 -0
  63. package/src/pages/auth/IdentityRedirect.vue +37 -0
  64. package/src/pages/profile/Layout.vue +210 -0
  65. package/src/pages/profile/partials/AccountSection.vue +139 -0
  66. package/src/pages/profile/partials/ApprovalDelegationSection.vue +389 -0
  67. package/src/pages/profile/partials/DevicesCard.vue +222 -0
  68. package/src/pages/profile/partials/PreferencesSection.vue +87 -0
  69. package/src/pages/profile/partials/SecuritySection.vue +93 -0
  70. package/src/pages/profile/partials/SessionsCard.vue +418 -0
  71. package/src/pages/profile/partials/SessionsSection.vue +58 -0
  72. package/src/pages/profile/partials/SupportAccessSection.vue +173 -0
  73. package/src/pages/profile/partials/TrustedDevicesCard.vue +141 -0
  74. package/src/pages/profile/partials/TwoFactorSection.vue +304 -0
  75. package/src/shellSetup.js +46 -0
@@ -0,0 +1,389 @@
1
+ <script setup>
2
+ import { ref, computed, onMounted } from 'vue'
3
+ import { useI18n } from 'vue-i18n'
4
+ import { UserRoundCog, Pencil, Trash2 } from '@lucide/vue'
5
+ import { approvalDelegationsApi } from '@initsolusidigital/worksuite-core/api/endpoints/approvalDelegations.js'
6
+ import { usersApi } from '@initsolusidigital/worksuite-core/api/endpoints/users.js'
7
+ import { useAuthStore } from '@initsolusidigital/worksuite-core/stores/auth.js'
8
+ import { useFormSubmit } from '@initsolusidigital/worksuite-core/composables/useFormSubmit.js'
9
+ import { useToast } from '@initsolusidigital/worksuite-core/composables/useToast.js'
10
+ import { normalizeApiError } from '@initsolusidigital/worksuite-core/api/errors.js'
11
+ import { delegationStatus, toDateOnly, DELEGATION_STATUS_COLOR } from '@initsolusidigital/worksuite-core/utils/delegationStatus.js'
12
+ import AppButton from '@initsolusidigital/worksuite-ui/AppButton.vue'
13
+ import AppIconButton from '@initsolusidigital/worksuite-ui/AppIconButton.vue'
14
+ import AppBadge from '@initsolusidigital/worksuite-ui/AppBadge.vue'
15
+ import AppAlert from '@initsolusidigital/worksuite-ui/AppAlert.vue'
16
+ import AppEmptyState from '@initsolusidigital/worksuite-ui/AppEmptyState.vue'
17
+ import AppCombobox from '@initsolusidigital/worksuite-ui/AppCombobox.vue'
18
+ import AppDatePicker from '@initsolusidigital/worksuite-core/components/ui/AppDatePicker.vue'
19
+
20
+ // Seksi "Alihkan Approval Saya" — muka SELF-SERVICE delegasi approval, pasangan muka admin
21
+ // `/approvals/delegations` di hub. Endpoint `GET|POST /approval_delegations/my` +
22
+ // `PUT|DELETE /my/{id}`.
23
+ //
24
+ // Rumahnya di `/profile` karena endpointnya self-scoped platform-wide, persis seperti Sesi &
25
+ // Perangkat dan Akses Dukungan: TANPA gate modul, `delegator_user_id` dipaksa backend dari user
26
+ // login. Konsekuensinya ia ada di setiap app, dan itu memang yang dibutuhkan: delegate (dan delegator) sering justru orang yang tak membuka app tempat
27
+ // dokumennya lahir.
28
+ //
29
+ // Kenapa muka ini ada padahal muka admin sudah jalan: `can_create` pada `approvals` adalah flag
30
+ // ADMIN, jadi tanpa seksi ini seorang manajer yang besok cuti harus menitip ke admin HR dulu.
31
+ // Muka admin tetap dipertahankan untuk kasus orang keburu sakit dan tak sempat mengaturnya.
32
+ const { t, locale } = useI18n()
33
+ const { pushToast } = useToast()
34
+ const authStore = useAuthStore()
35
+
36
+ const rows = ref([])
37
+ const loading = ref(true)
38
+ const pageError = ref('')
39
+
40
+ // ── Daftar wakil ──────────────────────────────────────────────────────────────
41
+ // `GET /get_users` — ungated & sudah ter-scope company (kontrak menunjuknya eksplisit sebagai
42
+ // sumber pilihan delegate, jadi tak ada endpoint baru). Diri sendiri dibuang: backend menolaknya
43
+ // (`Rule::notIn`), dan opsi yang pasti ditolak lebih baik tak pernah ditawarkan.
44
+ const users = ref([])
45
+ const loadingUsers = ref(false)
46
+ const userOptions = computed(() => users.value)
47
+
48
+ async function fetchUsers() {
49
+ if (users.value.length || loadingUsers.value) return
50
+ loadingUsers.value = true
51
+ try {
52
+ const { data } = await usersApi.getList()
53
+ const list = data.data?.data ?? data.data ?? []
54
+ users.value = list
55
+ .filter((u) => u.id !== authStore.user?.id)
56
+ .map((u) => ({ value: u.id, label: [u.first_name, u.last_name].filter(Boolean).join(' ') || u.email || u.id }))
57
+ .sort((a, b) => a.label.localeCompare(b.label, 'id', { sensitivity: 'base' }))
58
+ } catch {
59
+ // Daftar user gagal dimuat bukan alasan mematikan seksi ini — kegagalannya terlihat sendiri
60
+ // (dropdown kosong saat menambah), sementara daftar delegasi yang sudah ada tetap berguna.
61
+ users.value = []
62
+ } finally {
63
+ loadingUsers.value = false
64
+ }
65
+ }
66
+
67
+ // ⚠️ Nama datang sebagai `first_name`/`last_name`, bukan `name`. Relasi `delegate` di-eager-load
68
+ // backend dengan tiga kolom itu saja, jadi tak ada `email` untuk dijadikan cadangan.
69
+ function delegateName(row) {
70
+ const d = row?.delegate
71
+ const n = [d?.first_name, d?.last_name].filter(Boolean).join(' ')
72
+ return n || t('profile.approvalDelegation.unknownUser')
73
+ }
74
+
75
+ // ⚠️ `new Date('2026-08-10')` diurai sebagai UTC — di zona negatif ia mundur satu hari saat
76
+ // dirender lokal. Tanggal kalender WAJIB dibaca sebagai tengah malam LOKAL (`T00:00:00`).
77
+ function fmtDate(value) {
78
+ const d10 = toDateOnly(value)
79
+ if (!d10) return '—'
80
+ const d = new Date(`${d10}T00:00:00`)
81
+ if (Number.isNaN(d.getTime())) return d10
82
+ return d.toLocaleDateString(locale.value === 'id' ? 'id-ID' : 'en-US', {
83
+ year: 'numeric', month: 'short', day: 'numeric',
84
+ })
85
+ }
86
+
87
+ // Yang sedang/akan berlaku ditampilkan lebih dulu — sisanya riwayat. Tanpa pemisahan ini, delegasi
88
+ // yang HIDUP SEKARANG bisa tenggelam di bawah belasan baris yang sudah lewat, padahal justru itu
89
+ // satu-satunya baris yang mengubah siapa menerima pengajuan hari ini.
90
+ const liveRows = computed(() => rows.value.filter((r) => ['active', 'upcoming'].includes(delegationStatus(r))))
91
+ const pastRows = computed(() => rows.value.filter((r) => !['active', 'upcoming'].includes(delegationStatus(r))))
92
+ const activeRow = computed(() => rows.value.find((r) => delegationStatus(r) === 'active') ?? null)
93
+
94
+ async function fetchRows() {
95
+ loading.value = true
96
+ pageError.value = ''
97
+ try {
98
+ const { data } = await approvalDelegationsApi.my.list({ rowsPerPage: 50 })
99
+ rows.value = data.data?.data ?? data.data ?? []
100
+ } catch {
101
+ pageError.value = t('profile.approvalDelegation.loadError')
102
+ rows.value = []
103
+ } finally {
104
+ loading.value = false
105
+ }
106
+ }
107
+
108
+ onMounted(() => { fetchRows(); fetchUsers() })
109
+
110
+ // ── Form (inline, bukan modal) ────────────────────────────────────────────────
111
+ // Inline karena seksi ini sendiri sudah sebuah panel setelan: modal di atas halaman setelan
112
+ // menutupi daftar yang justru perlu dilihat saat memilih rentang tanggal (backend menolak rentang
113
+ // yang beririsan, jadi daftarnya adalah konteks pengisian — bukan latar belakang).
114
+ const showForm = ref(false)
115
+ const editing = ref(null) // null = mode tambah
116
+ const form = ref({ delegate_user_id: null, from_date: '', to_date: '' })
117
+ const { fieldErrors, formError, saving, submit } = useFormSubmit()
118
+
119
+ function openCreate() {
120
+ editing.value = null
121
+ form.value = { delegate_user_id: null, from_date: '', to_date: '' }
122
+ formError.value = ''
123
+ showForm.value = true
124
+ fetchUsers()
125
+ }
126
+ function openEdit(row) {
127
+ editing.value = row
128
+ // ⚠️ Dinormalkan dulu: nilai mentah backend berbentuk datetime UTC, dan `AppDatePicker`
129
+ // (`model-type="yyyy-MM-dd"`) DIAM-DIAM menampilkannya sebagai field kosong.
130
+ form.value = {
131
+ delegate_user_id: row.delegate_user_id,
132
+ from_date: toDateOnly(row.from_date),
133
+ to_date: toDateOnly(row.to_date),
134
+ }
135
+ formError.value = ''
136
+ showForm.value = true
137
+ }
138
+ function closeForm() {
139
+ showForm.value = false
140
+ editing.value = null
141
+ }
142
+
143
+ // Rentang terbalik dipagari di klien supaya kegagalannya muncul sebelum round-trip; backend
144
+ // memagarinya juga (`after_or_equal:from_date`), jadi ini kenyamanan, bukan satu-satunya pagar.
145
+ const invalidRange = computed(() =>
146
+ !!form.value.from_date && !!form.value.to_date && form.value.to_date < form.value.from_date
147
+ )
148
+
149
+ /**
150
+ * Dua sebab bentrok backend (422 + `data.reason`) TIDAK punya field untuk ditandai, sehingga
151
+ * `useFormSubmit` menjatuhkannya ke "Periksa kembali isian" — kalimat yang menyuruh user
152
+ * memperbaiki sesuatu yang tak ditandai di mana pun. Ditimpa di sini dengan sebab sebenarnya.
153
+ * ⚠️ Bercabang dari `reason`, BUKAN dari kalimat message (kanon error-envelope induk).
154
+ */
155
+ function explainConflict(e) {
156
+ if (e.reason === 'delegation_overlap') formError.value = t('profile.approvalDelegation.errorOverlap')
157
+ else if (e.reason === 'delegation_cycle') formError.value = t('profile.approvalDelegation.errorCycle')
158
+ }
159
+
160
+ async function save() {
161
+ if (invalidRange.value) {
162
+ formError.value = t('profile.approvalDelegation.errorRange')
163
+ return
164
+ }
165
+ await submit(
166
+ () => (editing.value
167
+ // Wakilnya sengaja tak ikut: backend hanya menerima tanggal & `is_active` pada PUT, sama
168
+ // seperti pintu admin. Salah orang = hapus lalu buat baru.
169
+ ? approvalDelegationsApi.my.update(editing.value.id, {
170
+ from_date: form.value.from_date,
171
+ to_date: form.value.to_date,
172
+ })
173
+ : approvalDelegationsApi.my.create({
174
+ delegate_user_id: form.value.delegate_user_id,
175
+ from_date: form.value.from_date,
176
+ to_date: form.value.to_date,
177
+ })),
178
+ {
179
+ // ⚠️ `from_date` DAN `to_date` sama-sama WAJIB — bukan asumsi, `required` di controller.
180
+ require: editing.value ? ['from_date', 'to_date'] : ['delegate_user_id', 'from_date', 'to_date'],
181
+ requireIn: form.value,
182
+ successKey: editing.value ? 'common.saveSuccess' : 'profile.approvalDelegation.created',
183
+ errorKey: 'profile.approvalDelegation.saveError',
184
+ onSuccess: () => { closeForm(); fetchRows() },
185
+ onError: explainConflict,
186
+ },
187
+ )
188
+ }
189
+
190
+ // ── Nonaktifkan / aktifkan kembali & hapus ────────────────────────────────────
191
+ const busyId = ref(null)
192
+ const confirmDelete = ref(null)
193
+
194
+ async function toggleActive(row) {
195
+ busyId.value = row.id
196
+ pageError.value = ''
197
+ try {
198
+ await approvalDelegationsApi.my.update(row.id, { is_active: !row.is_active })
199
+ pushToast({ title: t('common.saveSuccess'), variant: 'success' })
200
+ await fetchRows()
201
+ } catch (err) {
202
+ const e = normalizeApiError(err)
203
+ // Mengaktifkan kembali ikut diperiksa guard bentrok backend — dan itu memang saat paling
204
+ // mungkin bentrok terjadi (delegasi lain sudah dibuat selama yang ini nonaktif).
205
+ pageError.value = e.reason === 'delegation_overlap'
206
+ ? t('profile.approvalDelegation.errorOverlap')
207
+ : e.reason === 'delegation_cycle'
208
+ ? t('profile.approvalDelegation.errorCycle')
209
+ : t('profile.approvalDelegation.saveError')
210
+ pushToast({ title: pageError.value, variant: 'alert' })
211
+ } finally {
212
+ busyId.value = null
213
+ }
214
+ }
215
+
216
+ async function doDelete(row) {
217
+ busyId.value = row.id
218
+ try {
219
+ await approvalDelegationsApi.my.remove(row.id)
220
+ pushToast({ title: t('common.deleteSuccess'), variant: 'success' })
221
+ confirmDelete.value = null
222
+ await fetchRows()
223
+ } catch {
224
+ pushToast({ title: t('profile.approvalDelegation.deleteError'), variant: 'alert' })
225
+ } finally {
226
+ busyId.value = null
227
+ }
228
+ }
229
+ </script>
230
+
231
+ <template>
232
+ <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-6">
233
+ <div class="flex flex-col gap-3 sm:flex-row sm:items-start sm:justify-between">
234
+ <div>
235
+ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">{{ t('profile.approvalDelegation.title') }}</h2>
236
+ <p class="text-sm text-gray-500 dark:text-gray-400 mt-0.5">{{ t('profile.approvalDelegation.subtitle') }}</p>
237
+ </div>
238
+ <AppButton v-if="!showForm" variant="primary" class="shrink-0" @click="openCreate">
239
+ {{ t('profile.approvalDelegation.add') }}
240
+ </AppButton>
241
+ </div>
242
+
243
+ <!-- Peringatan pewarisan ROLE — backend memang sengaja berperilaku begini (`actingContext()` menyatukan role delegator ke konteks delegate).
244
+ Orang yang mengisi form membayangkan ia memindahkan "pekerjaan saya"; yang berpindah
245
+ sebenarnya "topi saya" — tanpa kalimat ini, itu baru ketahuan setelah dipakai. -->
246
+ <AppAlert variant="warning" :message="t('profile.approvalDelegation.roleInheritanceWarning')" class="mt-5" />
247
+
248
+ <!-- Siapa yang sedang mewakili SAYA hari ini — pertanyaan pertama yang dibawa user ke sini,
249
+ dan jawabannya tak boleh menuntut membaca tanggal di tabel satu per satu. -->
250
+ <p v-if="activeRow" class="mt-3 text-sm text-gray-700 dark:text-gray-300">
251
+ {{ t('profile.approvalDelegation.activeNow', { name: delegateName(activeRow) }) }}
252
+ </p>
253
+
254
+ <AppAlert v-if="pageError" variant="error" :message="pageError" class="mt-4" />
255
+
256
+ <!-- ── Form tambah / ubah ──────────────────────────────────────────────── -->
257
+ <div v-if="showForm" class="mt-5 rounded-lg border border-gray-200 dark:border-gray-700 p-4 space-y-4">
258
+ <p class="text-sm font-medium text-gray-900 dark:text-white">
259
+ {{ editing ? t('profile.approvalDelegation.editTitle') : t('profile.approvalDelegation.addTitle') }}
260
+ </p>
261
+
262
+ <AppAlert v-if="formError" variant="error" :message="formError" />
263
+
264
+ <!-- Saat ubah, wakilnya jadi teks mati: backend mengabaikan perubahannya, dan field yang
265
+ bisa diisi lalu diam-diam dibuang lebih buruk daripada field yang memang tak ada. -->
266
+ <div v-if="editing" class="rounded-lg bg-gray-50 dark:bg-gray-700/40 px-3 py-2.5">
267
+ <p class="text-sm text-gray-900 dark:text-white">{{ delegateName(editing) }}</p>
268
+ <p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">{{ t('profile.approvalDelegation.delegateLocked') }}</p>
269
+ </div>
270
+ <AppCombobox
271
+ v-else
272
+ v-model="form.delegate_user_id"
273
+ :label="t('profile.approvalDelegation.fieldDelegate')"
274
+ :hint="t('profile.approvalDelegation.fieldDelegateHint')"
275
+ :options="userOptions"
276
+ :loading="loadingUsers"
277
+ :error="fieldErrors.delegate_user_id"
278
+ required
279
+ />
280
+
281
+ <div class="grid grid-cols-1 sm:grid-cols-2 gap-4">
282
+ <AppDatePicker
283
+ v-model="form.from_date"
284
+ :label="t('profile.approvalDelegation.fieldFrom')"
285
+ :error="fieldErrors.from_date"
286
+ required
287
+ />
288
+ <AppDatePicker
289
+ v-model="form.to_date"
290
+ :label="t('profile.approvalDelegation.fieldTo')"
291
+ :hint="t('profile.approvalDelegation.fieldToHint')"
292
+ :error="fieldErrors.to_date"
293
+ required
294
+ />
295
+ </div>
296
+
297
+ <AppAlert v-if="invalidRange" variant="error" :message="t('profile.approvalDelegation.errorRange')" />
298
+ <AppAlert variant="info" :message="t('profile.approvalDelegation.oneAtATime')" />
299
+
300
+ <div class="flex items-center justify-end gap-2">
301
+ <AppButton variant="ghost" size="sm" @click="closeForm">{{ t('common.cancel') }}</AppButton>
302
+ <AppButton variant="primary" size="sm" :loading="saving" :disabled="invalidRange" @click="save">
303
+ {{ t('common.save') }}
304
+ </AppButton>
305
+ </div>
306
+ </div>
307
+
308
+ <!-- ── Daftar ──────────────────────────────────────────────────────────── -->
309
+ <div v-if="loading" class="py-8 flex items-center justify-center text-gray-400">
310
+ <svg class="animate-spin w-6 h-6" fill="none" viewBox="0 0 24 24">
311
+ <circle class="opacity-25" cx="12" cy="12" r="10" stroke="currentColor" stroke-width="4"/>
312
+ <path class="opacity-75" fill="currentColor" d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4z"/>
313
+ </svg>
314
+ </div>
315
+
316
+ <template v-else>
317
+ <AppEmptyState v-if="!rows.length" class="mt-5" :label="t('profile.approvalDelegation.empty')">
318
+ <template #icon><UserRoundCog class="w-6 h-6 text-gray-400 dark:text-gray-500" :stroke-width="1.5" /></template>
319
+ </AppEmptyState>
320
+
321
+ <ul v-if="liveRows.length" class="mt-5 divide-y divide-gray-100 dark:divide-gray-700">
322
+ <li v-for="row in liveRows" :key="row.id" class="flex flex-wrap items-center justify-between gap-3 py-3">
323
+ <div class="min-w-0">
324
+ <p class="text-sm font-medium text-gray-900 dark:text-white">{{ delegateName(row) }}</p>
325
+ <p class="text-xs text-gray-500 dark:text-gray-400 mt-0.5">
326
+ {{ fmtDate(row.from_date) }} – {{ fmtDate(row.to_date) }}
327
+ </p>
328
+ </div>
329
+ <div class="flex items-center gap-2 shrink-0">
330
+ <AppBadge :color="DELEGATION_STATUS_COLOR[delegationStatus(row)]">
331
+ {{ t(`profile.approvalDelegation.status.${delegationStatus(row)}`) }}
332
+ </AppBadge>
333
+ <template v-if="confirmDelete?.id === row.id">
334
+ <span class="text-xs text-gray-500 dark:text-gray-400">{{ t('profile.approvalDelegation.deleteConfirm') }}</span>
335
+ <AppButton variant="danger" size="sm" :loading="busyId === row.id" @click="doDelete(row)">{{ t('common.delete') }}</AppButton>
336
+ <AppButton variant="ghost" size="sm" @click="confirmDelete = null">{{ t('common.cancel') }}</AppButton>
337
+ </template>
338
+ <template v-else>
339
+ <AppIconButton :icon="Pencil" :label="t('common.edit')" :disabled="busyId === row.id" @click="openEdit(row)" />
340
+ <AppButton variant="ghost" size="sm" :loading="busyId === row.id" @click="toggleActive(row)">
341
+ {{ t('profile.approvalDelegation.deactivate') }}
342
+ </AppButton>
343
+ <AppIconButton :icon="Trash2" :label="t('common.delete')" variant="danger" :disabled="busyId === row.id" @click="confirmDelete = row" />
344
+ </template>
345
+ </div>
346
+ </li>
347
+ </ul>
348
+
349
+ <!-- Riwayat: yang sudah lewat atau sengaja dinonaktifkan. Tetap ditampilkan (bukan
350
+ disembunyikan) karena baris nonaktif bisa diaktifkan kembali, dan yang sudah berakhir
351
+ adalah jawaban atas "siapa yang mewakili saya bulan lalu". -->
352
+ <template v-if="pastRows.length">
353
+ <p class="mt-6 mb-1 text-xs font-medium uppercase tracking-wide text-gray-400 dark:text-gray-500">
354
+ {{ t('profile.approvalDelegation.historyTitle') }}
355
+ </p>
356
+ <ul class="divide-y divide-gray-100 dark:divide-gray-700">
357
+ <li v-for="row in pastRows" :key="row.id" class="flex flex-wrap items-center justify-between gap-3 py-3">
358
+ <div class="min-w-0">
359
+ <p class="text-sm text-gray-700 dark:text-gray-300">{{ delegateName(row) }}</p>
360
+ <p class="text-xs text-gray-400 dark:text-gray-500 mt-0.5">
361
+ {{ fmtDate(row.from_date) }} – {{ fmtDate(row.to_date) }}
362
+ </p>
363
+ </div>
364
+ <div class="flex items-center gap-2 shrink-0">
365
+ <AppBadge :color="DELEGATION_STATUS_COLOR[delegationStatus(row)]">
366
+ {{ t(`profile.approvalDelegation.status.${delegationStatus(row)}`) }}
367
+ </AppBadge>
368
+ <template v-if="confirmDelete?.id === row.id">
369
+ <span class="text-xs text-gray-500 dark:text-gray-400">{{ t('profile.approvalDelegation.deleteConfirm') }}</span>
370
+ <AppButton variant="danger" size="sm" :loading="busyId === row.id" @click="doDelete(row)">{{ t('common.delete') }}</AppButton>
371
+ <AppButton variant="ghost" size="sm" @click="confirmDelete = null">{{ t('common.cancel') }}</AppButton>
372
+ </template>
373
+ <template v-else>
374
+ <AppButton
375
+ v-if="!row.is_active"
376
+ variant="ghost"
377
+ size="sm"
378
+ :loading="busyId === row.id"
379
+ @click="toggleActive(row)"
380
+ >{{ t('profile.approvalDelegation.reactivate') }}</AppButton>
381
+ <AppIconButton :icon="Trash2" :label="t('common.delete')" variant="danger" :disabled="busyId === row.id" @click="confirmDelete = row" />
382
+ </template>
383
+ </div>
384
+ </li>
385
+ </ul>
386
+ </template>
387
+ </template>
388
+ </div>
389
+ </template>
@@ -0,0 +1,222 @@
1
+ <script setup>
2
+ import { ref, onMounted, computed } from 'vue'
3
+ import { useI18n } from 'vue-i18n'
4
+ import { Monitor, Smartphone, Tablet, LogOut, ShieldCheck, Pencil, Check, X, HelpCircle } from '@lucide/vue'
5
+ import { Icon } from '@iconify/vue'
6
+ import AppButton from '@initsolusidigital/worksuite-ui/AppButton.vue'
7
+ import AppIconButton from '@initsolusidigital/worksuite-ui/AppIconButton.vue'
8
+ import AppEmptyState from '@initsolusidigital/worksuite-ui/AppEmptyState.vue'
9
+ import AppBadge from '@initsolusidigital/worksuite-ui/AppBadge.vue'
10
+ import { devicesApi } from '@initsolusidigital/worksuite-core/api/endpoints/devices.js'
11
+ import { browserIconData, osIconData } from '@initsolusidigital/worksuite-core/data/deviceIcons.js'
12
+ import { useToast } from '@initsolusidigital/worksuite-core/composables/useToast.js'
13
+ import { tenantTimeZone } from '@initsolusidigital/worksuite-core/utils/datetime.js'
14
+
15
+ // Kartu "Perangkat Aktif" (profil §Sesi & Perangkat). Self-service: daftar device aktif,
16
+ // rename nama kustom persisten (PATCH /devices/{id}), logout jarak jauh per
17
+ // device. Judul = custom_name ?? device_name ?? browser_name; browser/OS ditampilkan pill
18
+ // (logo + nama + versi) konsisten dgn SessionsCard.
19
+ const { t, locale } = useI18n()
20
+ const { pushToast } = useToast()
21
+
22
+ const devices = ref([])
23
+ const loading = ref(true)
24
+ const pageError = ref('')
25
+ const confirmLogout = ref(null)
26
+ const loggingOut = ref(false)
27
+
28
+ // Rename state
29
+ const editingId = ref(null)
30
+ const editName = ref('')
31
+ const savingRename = ref(false)
32
+
33
+ function deviceIcon(d) {
34
+ const os = (d.os_family || d.os_name || '').toLowerCase()
35
+ if (os.includes('android') || os.includes('ios') || d.device_model) return Smartphone
36
+ if (os.includes('ipad') || os.includes('tablet')) return Tablet
37
+ return Monitor
38
+ }
39
+
40
+ // Nama auto (tanpa custom) — dipakai sbg placeholder input rename & fallback judul
41
+ function autoName(d) {
42
+ return d.device_name || d.browser_name || t('devices.unknownDevice')
43
+ }
44
+ function displayName(d) {
45
+ return d.custom_name || autoName(d)
46
+ }
47
+ function browserLabel(d) {
48
+ return [d.browser_name, d.browser_version].filter(Boolean).join(' ')
49
+ }
50
+
51
+ function formatDate(iso) {
52
+ if (!iso) return '—'
53
+ const d = new Date(iso)
54
+ if (isNaN(d)) return iso
55
+ return d.toLocaleString(locale.value === 'id' ? 'id-ID' : 'en-US', {
56
+ year: 'numeric', month: 'short', day: 'numeric', hour: '2-digit', minute: '2-digit', timeZoneName: 'short', timeZone: tenantTimeZone(),
57
+ })
58
+ }
59
+
60
+ async function fetchDevices() {
61
+ loading.value = true
62
+ pageError.value = ''
63
+ try {
64
+ const { data } = await devicesApi.getMy()
65
+ devices.value = data.data ?? []
66
+ } catch {
67
+ pageError.value = t('devices.loadError')
68
+ } finally {
69
+ loading.value = false
70
+ }
71
+ }
72
+
73
+ // ── Rename ──────────────────────────────────────────────────────────────────
74
+ function startRename(d) {
75
+ editingId.value = d.device_id
76
+ editName.value = d.custom_name || '' // kosong = biar user isi baru / placeholder = nama auto
77
+ }
78
+ function cancelRename() {
79
+ editingId.value = null
80
+ editName.value = ''
81
+ }
82
+ async function saveRename(d) {
83
+ savingRename.value = true
84
+ try {
85
+ // name kosong = reset ke auto (sesuai kontrak). Backend balikin daftar ter-update.
86
+ const { data } = await devicesApi.rename(d.device_id, editName.value.trim())
87
+ devices.value = data.data ?? devices.value
88
+ editingId.value = null
89
+ pushToast({ title: t('devices.renameSaved'), variant: 'success' })
90
+ } catch (err) {
91
+ pushToast({ title: err.response?.data?.message || t('devices.renameError'), variant: 'error' })
92
+ } finally {
93
+ savingRename.value = false
94
+ }
95
+ }
96
+
97
+ async function handleLogout(device) {
98
+ loggingOut.value = true
99
+ pageError.value = ''
100
+ try {
101
+ await devicesApi.logout(device.device_id)
102
+ devices.value = devices.value.filter(d => d.device_id !== device.device_id)
103
+ } catch {
104
+ pageError.value = t('devices.logoutError')
105
+ } finally {
106
+ loggingOut.value = false
107
+ confirmLogout.value = null
108
+ }
109
+ }
110
+
111
+ // "Perangkat ini" = flag is_current dari BACKEND (SSO-correct, token-matched), BUKAN
112
+ // getDeviceId() client-side yang di-scope per-origin/port sehingga gagal lintas app.
113
+ // getDeviceId/X-Device-Id tetap dipakai utk batas-device saat login (fungsi beda).
114
+ const isCurrent = (d) => !!d.is_current
115
+
116
+ const sortedDevices = computed(() =>
117
+ [...devices.value].sort((a, b) => {
118
+ if (isCurrent(a)) return -1
119
+ if (isCurrent(b)) return 1
120
+ return new Date(b.last_active_at) - new Date(a.last_active_at)
121
+ })
122
+ )
123
+
124
+ onMounted(fetchDevices)
125
+ </script>
126
+
127
+ <template>
128
+ <div class="bg-white dark:bg-gray-800 rounded-xl border border-gray-200 dark:border-gray-700 shadow-sm p-6">
129
+ <h2 class="text-lg font-semibold text-gray-900 dark:text-white">{{ t('devices.title') }}</h2>
130
+ <p class="text-sm text-gray-500 dark:text-gray-400 mt-0.5 mb-4">{{ t('devices.subtitle') }}</p>
131
+
132
+ <div v-if="pageError" class="mb-4 p-3 bg-red-50 dark:bg-red-900/20 border border-red-200 dark:border-red-800 rounded-lg text-sm text-red-700 dark:text-red-400">
133
+ {{ pageError }}
134
+ </div>
135
+
136
+ <div v-if="loading" class="flex items-center justify-center py-10 text-gray-400 dark:text-gray-500">
137
+ <span class="text-sm">{{ t('common.loading') }}</span>
138
+ </div>
139
+
140
+ <div v-else-if="!devices.length">
141
+ <AppEmptyState :label="t('devices.empty')">
142
+ <template #icon><Monitor class="w-6 h-6 text-gray-400 dark:text-gray-500" :stroke-width="1.5" /></template>
143
+ </AppEmptyState>
144
+ </div>
145
+
146
+ <div v-else class="space-y-3">
147
+ <div
148
+ v-for="d in sortedDevices"
149
+ :key="d.device_id"
150
+ class="rounded-xl border border-gray-100 dark:border-gray-700 p-4 flex items-start gap-4"
151
+ >
152
+ <div class="w-11 h-11 rounded-lg bg-gray-100 dark:bg-gray-700 flex items-center justify-center shrink-0">
153
+ <component :is="deviceIcon(d)" class="w-5 h-5 text-gray-500 dark:text-gray-300" />
154
+ </div>
155
+
156
+ <div class="min-w-0 grow">
157
+ <!-- Judul: editable (nama kustom) -->
158
+ <div v-if="editingId === d.device_id" class="space-y-1">
159
+ <div class="flex items-center gap-2">
160
+ <input
161
+ v-model="editName"
162
+ type="text"
163
+ maxlength="100"
164
+ :placeholder="autoName(d)"
165
+ class="min-w-0 grow px-2.5 py-1.5 text-sm rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-700 text-gray-900 dark:text-white focus:outline-none focus:ring-2 focus:ring-blue-500"
166
+ @keyup.enter="saveRename(d)"
167
+ @keyup.esc="cancelRename"
168
+ />
169
+ <button :aria-label="t('common.save')" type="button" :disabled="savingRename" class="w-7 h-7 shrink-0 flex items-center justify-center rounded-lg text-green-600 hover:bg-green-50 dark:hover:bg-green-900/30 transition-colors disabled:opacity-50" @click="saveRename(d)">
170
+ <Check class="w-4 h-4" />
171
+ </button>
172
+ <button :aria-label="t('common.cancel')" type="button" class="w-7 h-7 shrink-0 flex items-center justify-center rounded-lg text-gray-400 hover:bg-gray-100 dark:hover:bg-gray-700 transition-colors" @click="cancelRename">
173
+ <X class="w-4 h-4" />
174
+ </button>
175
+ </div>
176
+ <p class="text-[11px] text-gray-400 dark:text-gray-500">{{ t('devices.renameHint') }}</p>
177
+ </div>
178
+
179
+ <div v-else class="flex items-center gap-2 flex-wrap">
180
+ <p class="text-sm font-medium text-gray-900 dark:text-white truncate">{{ displayName(d) }}</p>
181
+ <AppBadge v-if="isCurrent(d)" color="green">{{ t('devices.thisDevice') }}</AppBadge>
182
+ <AppIconButton :icon="Pencil" :label="t('devices.rename')" @click="startRename(d)" />
183
+ </div>
184
+
185
+ <!-- Pill browser + OS (logo + nama + versi) -->
186
+ <div class="flex items-center gap-1.5 mt-1.5 flex-wrap">
187
+ <span v-if="d.browser_name" class="inline-flex items-center gap-1 text-[11px] font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 px-2 py-0.5 rounded">
188
+ <Icon v-if="browserIconData(d.browser_name)" :icon="browserIconData(d.browser_name)" class="w-3 h-3" />
189
+ <HelpCircle v-else class="w-3 h-3" />
190
+ {{ browserLabel(d) }}
191
+ </span>
192
+ <span v-if="d.os_name || d.os_family" class="inline-flex items-center gap-1 text-[11px] font-medium bg-gray-100 dark:bg-gray-700 text-gray-600 dark:text-gray-300 px-2 py-0.5 rounded">
193
+ <Icon v-if="osIconData(d.os_family)" :icon="osIconData(d.os_family)" class="w-3 h-3" />
194
+ <HelpCircle v-else class="w-3 h-3" />
195
+ {{ d.os_name || d.os_family }}
196
+ </span>
197
+ </div>
198
+
199
+ <p class="text-xs text-gray-400 dark:text-gray-500 mt-1.5">
200
+ {{ t('devices.lastActive') }}: {{ formatDate(d.last_active_at) }}
201
+ <span v-if="d.session_count > 1"> · {{ t('devices.sessionCount', { count: d.session_count }) }}</span>
202
+ </p>
203
+ </div>
204
+
205
+ <div class="shrink-0">
206
+ <span v-if="isCurrent(d)" class="inline-flex items-center gap-1 text-xs text-gray-400 dark:text-gray-500">
207
+ <ShieldCheck class="w-3.5 h-3.5" />
208
+ </span>
209
+ <template v-else>
210
+ <template v-if="confirmLogout === d.device_id">
211
+ <div class="flex items-center gap-2">
212
+ <AppButton variant="danger" size="sm" :loading="loggingOut" @click="handleLogout(d)">{{ t('devices.logoutConfirm') }}</AppButton>
213
+ <AppButton variant="secondary" size="sm" :disabled="loggingOut" @click="confirmLogout = null">{{ t('common.cancel') }}</AppButton>
214
+ </div>
215
+ </template>
216
+ <AppIconButton v-else :icon="LogOut" :label="t('devices.logout')" variant="danger" @click="confirmLogout = d.device_id" />
217
+ </template>
218
+ </div>
219
+ </div>
220
+ </div>
221
+ </div>
222
+ </template>