@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,733 @@
1
+ <script setup>
2
+ // Siklus appraisal: daftar + detail satu siklus (`draft → submitted → acknowledged → closed`).
3
+ //
4
+ // **Daftar TIDAK disaring di klien.** Server sudah menyaringnya untuk non-pengelola (milik
5
+ // sendiri + semua yang ia pimpin), dan layar ini tak tahu siapa memimpin siapa — menyaring ulang di
6
+ // sini hanya bisa menghasilkan dua hal: menyembunyikan baris yang sah, atau memberi rasa aman palsu.
7
+ //
8
+ // **Tombol digambar dari STATUS + PERAN, bukan dari coba-lalu-403.** Acknowledge misalnya hanya
9
+ // boleh oleh karyawan ybs (403 `not_the_subject`); menawarkannya kepada atasan berarti menawarkan
10
+ // tombol yang pasti ditolak, dan pengguna akan menyimpulkan aplikasinya rusak. Siapa penilai dibaca
11
+ // dari `can_assess` per siklus (server) — layar tak tahu siapa memimpin siapa, dan pemegang
12
+ // `kpis,can_read` saja bisa membuka siklus orang lain tanpa berhak menilainya.
13
+ //
14
+ // **Penilaian aspek** (kontrak `kp1-kpi-tracking.md`): tiap aspek dinilai 1–5 dengan
15
+ // rubriknya terlihat di samping tiap angka; nilai 1 atau 5 WAJIB bercatatan (server menolak saat
16
+ // submit `aspect_note_required`, layar menahannya lebih dulu). Nilai aspek hanya bisa diubah selama
17
+ // draft; catatan umum tetap bisa sampai closed. Submit membekukan nilai akhir DAN seluruh baris KPI
18
+ // subjek di periode itu — sesudahnya isian/target periode itu ditolak `period_frozen`.
19
+ import { ref, computed, watch } from 'vue'
20
+ import { useI18n } from 'vue-i18n'
21
+ import { Plus, FileText, Trash2, RefreshCw, Users } from '@lucide/vue'
22
+ import { kpiAppraisalsApi } from '@initsolusidigital/worksuite-core/api/endpoints/kpi.js'
23
+ import { useFormSubmit } from '@initsolusidigital/worksuite-core/composables/useFormSubmit.js'
24
+ import { useToast } from '@initsolusidigital/worksuite-core/composables/useToast.js'
25
+ import { useKpi } from '../../composables/useKpi.js'
26
+ import { normalizeApiError } from '@initsolusidigital/worksuite-core/api/errors.js'
27
+ import { toDateOnly } from '@initsolusidigital/worksuite-core/utils/dateOnly.js'
28
+ import AppCard from '@initsolusidigital/worksuite-ui/AppCard.vue'
29
+ import AppBadge from '@initsolusidigital/worksuite-ui/AppBadge.vue'
30
+ import AppButton from '@initsolusidigital/worksuite-ui/AppButton.vue'
31
+ import AppAlert from '@initsolusidigital/worksuite-ui/AppAlert.vue'
32
+ import AppInput from '@initsolusidigital/worksuite-ui/AppInput.vue'
33
+ import AppTextarea from '@initsolusidigital/worksuite-ui/AppTextarea.vue'
34
+ import AppModal from '@initsolusidigital/worksuite-ui/AppModal.vue'
35
+ import AppCombobox from '@initsolusidigital/worksuite-ui/AppCombobox.vue'
36
+ import AppSpinner from '@initsolusidigital/worksuite-ui/AppSpinner.vue'
37
+ import AppEmptyState from '@initsolusidigital/worksuite-ui/AppEmptyState.vue'
38
+ import AppDatePicker from '@initsolusidigital/worksuite-core/components/ui/AppDatePicker.vue'
39
+ import AppKpiPeriodPicker from './AppKpiPeriodPicker.vue'
40
+ import AppKpiScorecard from './AppKpiScorecard.vue'
41
+
42
+ const props = defineProps({
43
+ companyId: { type: String, required: true },
44
+ /** Karyawan `{value,label}` untuk pemilih subjek — hanya app ber-master karyawan. */
45
+ employees: { type: Array, default: () => [] },
46
+ /** Pemegang `kpis,can_update` / super admin: boleh membuat & menutup siklus siapa pun. */
47
+ canManage: { type: Boolean, default: false },
48
+ /** `employees.id` milik user yang login — penentu Acknowledge & siapa yang boleh menilai. */
49
+ myEmployeeId: { type: String, default: '' },
50
+ /** Template berita acara jenis `appraisal` `{value,label}`; kosong = tombolnya tak dirender. */
51
+ documentTemplates: { type: Array, default: () => [] },
52
+ formatMetric: { type: Function, required: true },
53
+ formatAchievement: { type: Function, required: true },
54
+ /** Boleh mengisi realisasi — tombol "Isi" pada KPI yang belum diisi. */
55
+ canFill: { type: Boolean, default: false },
56
+ /** Dinaikkan pemanggil sesudah isian tersimpan, supaya scorecard draft dimuat ulang. */
57
+ refreshToken: { type: Number, default: 0 },
58
+ /** Pemanggil memimpin orang (atau pengelola) → tombol buat penilaian massal untuk tim. */
59
+ canBulk: { type: Boolean, default: false },
60
+ /** Periode Workspace — bawaan penilaian massal bila berbentuk bulan. */
61
+ period: { type: String, default: '' },
62
+ /** Buka siklus ini (dari layar Tim). */
63
+ openId: { type: String, default: '' },
64
+ })
65
+ const emit = defineEmits(['open-document', 'fill'])
66
+
67
+ const { t } = useI18n()
68
+ const { pushToast } = useToast()
69
+ // Di-destructure: template tak meng-unwrap ref yang bersarang di objek biasa, jadi
70
+ // `aksi.fieldErrors.x` akan selalu undefined dan galat per kotak tak pernah tampil.
71
+ const { fieldErrors, formError, saving, submit } = useFormSubmit()
72
+ const { formatScore, statusTone } = useKpi(() => props.companyId)
73
+
74
+ const rows = ref([])
75
+ const loading = ref(false)
76
+ const listError = ref('')
77
+ const statusFilter = ref('')
78
+
79
+ const detail = ref(null)
80
+ const detailLoading = ref(false)
81
+
82
+ const showCreate = ref(false)
83
+ const form = ref({ employee_id: '', period: '' })
84
+ const createError = ref('')
85
+
86
+ const kualitatif = ref({ manager_rating: '', manager_notes: '', one_on_one_at: '' })
87
+ const tanggapan = ref('')
88
+ const showDoc = ref(false)
89
+ const docTemplate = ref('')
90
+ const konfirmasiHapus = ref(null)
91
+ /** `data.missing[]` dari 422 `scorecard_incomplete` — dirender sebagai daftar yang bisa diisi. */
92
+ const belumDiisi = ref([])
93
+
94
+ /** Salinan kerja nilai aspek `{aspect_id, aspect_name, rubric, score, note}`. */
95
+ const aspek = ref([])
96
+ const aspekAsli = ref('')
97
+ const aspekErr = ref({})
98
+
99
+ const showBulk = ref(false)
100
+ const bulkPeriod = ref('')
101
+ const bulkResult = ref(null)
102
+
103
+ const STATUS_TONE = { draft: 'gray', submitted: 'blue', acknowledged: 'amber', closed: 'green' }
104
+ const STATUSES = ['draft', 'submitted', 'acknowledged', 'closed']
105
+ const SKALA = ['1', '2', '3', '4', '5']
106
+
107
+ const statusOptions = computed(() => [
108
+ { value: '', label: t('kpi.appraisal.filterAll') },
109
+ ...STATUSES.map(s => ({ value: s, label: t(`kpi.appraisal.status.${s}`) })),
110
+ ])
111
+
112
+ /**
113
+ * Nama karyawan siklus. ⚠️ Backend mengirimnya di `employee.display_name` (relasi + append), BUKAN
114
+ * `employee_name` datar — membaca kunci datar membuat daftar, judul, & konfirmasi hapus selalu jatuh
115
+ * ke UUID tanpa satu pun galat.
116
+ */
117
+ const namaKaryawan = (r) => r?.employee?.display_name || r?.employee_name || r?.employee_id || ''
118
+
119
+ const milikSaya = computed(() => !!detail.value && !!props.myEmployeeId && detail.value.employee_id === props.myEmployeeId)
120
+ // `can_assess` dari server = gerbang PUT …/aspects & submit (super admin · `kpis,can_update` · atasan
121
+ // berantai / PIC departemen; diri sendiri false). Turunan lokal "pengelola ATAU bukan milik sendiri"
122
+ // memberi tombol nilai kepada PEMBACA (`kpis,can_read` saja) yang membuka siklus orang lain — tombol
123
+ // yang lalu ditolak 403. Turunan itu hanya cadangan bila backend belum mengirim flag-nya.
124
+ const bolehMenilai = computed(() => {
125
+ if (!detail.value) return false
126
+ if (typeof detail.value.can_assess === 'boolean') return detail.value.can_assess
127
+ return props.canManage || !milikSaya.value
128
+ })
129
+
130
+ const bolehAcknowledge = computed(() => !!detail.value && detail.value.status === 'submitted' && milikSaya.value)
131
+
132
+ // Isian kualitatif terbuka sampai SEBELUM closed — catatan 1-on-1 lazim ditulis sesudah submit,
133
+ // justru karena pertemuannya baru terjadi setelah angkanya beku.
134
+ const bolehSuntingKualitatif = computed(() => !!detail.value && detail.value.status !== 'closed' && bolehMenilai.value)
135
+ const punyaAspek = computed(() => aspek.value.length > 0)
136
+ const bolehNilaiAspek = computed(() => punyaAspek.value && detail.value?.status === 'draft' && bolehMenilai.value)
137
+
138
+ const bolehSubmit = computed(() => !!detail.value && detail.value.status === 'draft' && bolehMenilai.value)
139
+ const bolehTutup = computed(() =>
140
+ !!detail.value && ['submitted', 'acknowledged'].includes(detail.value.status) && bolehMenilai.value)
141
+ const bolehBeritaAcara = computed(() =>
142
+ !!detail.value && detail.value.status !== 'draft' && props.documentTemplates.length > 0)
143
+ const aspekBerubah = computed(() => JSON.stringify(muatanAspek()) !== aspekAsli.value)
144
+
145
+ async function muatDaftar() {
146
+ loading.value = true
147
+ listError.value = ''
148
+ try {
149
+ const { data } = await kpiAppraisalsApi.getList(props.companyId,
150
+ statusFilter.value ? { status: statusFilter.value } : undefined)
151
+ rows.value = data.data?.data ?? data.data ?? []
152
+ } catch (err) {
153
+ const e = normalizeApiError(err)
154
+ listError.value = e.isForbidden ? t('kpi.noPermission') : (e.backendMessage || t('common.serverError'))
155
+ rows.value = []
156
+ } finally {
157
+ loading.value = false
158
+ }
159
+ }
160
+
161
+ function pakaiDetail(d) {
162
+ detail.value = d
163
+ kualitatif.value = {
164
+ manager_rating: d?.manager_rating ?? '',
165
+ manager_notes: d?.manager_notes ?? '',
166
+ // `one_on_one_at` tiba sebagai `Y-m-d`; `toDateOnly` tetap dipasang sebagai pagar kanon
167
+ // tanggal: bila kolom ini kembali terserial datetime UTC, `AppDatePicker` menampilkannya
168
+ // KOSONG lalu Simpan mengirim balik tanggal yang tak pernah dilihat siapa pun — nol galat.
169
+ one_on_one_at: toDateOnly(d?.one_on_one_at) ?? '',
170
+ }
171
+ tanggapan.value = d?.employee_response ?? ''
172
+ aspek.value = [...(d?.aspect_scores ?? [])]
173
+ .sort((a, b) => (a.order ?? 0) - (b.order ?? 0))
174
+ .map(a => ({ aspect_id: a.aspect_id, aspect_name: a.aspect_name, rubric: a.rubric ?? {},
175
+ score: a.score == null ? '' : String(a.score), note: a.note ?? '' }))
176
+ aspekAsli.value = JSON.stringify(muatanAspek())
177
+ aspekErr.value = {}
178
+ }
179
+
180
+ async function buka(id) {
181
+ detailLoading.value = true
182
+ try {
183
+ const { data } = await kpiAppraisalsApi.get(props.companyId, id)
184
+ pakaiDetail(data.data ?? null)
185
+ } catch {
186
+ pushToast({ title: t('kpi.appraisal.loadError'), variant: 'alert' })
187
+ } finally {
188
+ detailLoading.value = false
189
+ }
190
+ }
191
+
192
+ async function buat() {
193
+ createError.value = ''
194
+ const ok = await submit(
195
+ () => kpiAppraisalsApi.create(props.companyId, { ...form.value }),
196
+ {
197
+ require: ['employee_id', 'period'],
198
+ requireIn: form.value,
199
+ successKey: 'kpi.appraisal.created',
200
+ onError: (e) => {
201
+ // Siklus untuk periode yang sama sudah ada — jalan keluarnya membuka yang itu, bukan
202
+ // memperbaiki isian; kalimatnya karena itu mengatakan begitu.
203
+ if (e.reason === 'appraisal_exists') createError.value = t('kpi.appraisal.errExists')
204
+ },
205
+ },
206
+ )
207
+ if (ok) { showCreate.value = false; form.value = { employee_id: '', period: '' }; await muatDaftar() }
208
+ }
209
+
210
+ function bukaBulk() {
211
+ bulkResult.value = null
212
+ bulkPeriod.value = /^\d{4}-\d{2}$/.test(props.period) ? props.period : ''
213
+ showBulk.value = true
214
+ }
215
+
216
+ async function buatMassal() {
217
+ const ok = await submit(
218
+ () => kpiAppraisalsApi.bulk(props.companyId, { period: bulkPeriod.value }),
219
+ {
220
+ require: ['period'],
221
+ requireIn: { period: bulkPeriod.value },
222
+ onSuccess: (res) => {
223
+ const body = res?.data?.data ?? {}
224
+ bulkResult.value = { created: body.created ?? [], skipped: body.skipped ?? [] }
225
+ },
226
+ },
227
+ )
228
+ if (ok) {
229
+ pushToast({ title: t('kpi.appraisal.bulkDone', { n: bulkResult.value?.created.length ?? 0 }), variant: 'success' })
230
+ await muatDaftar()
231
+ }
232
+ }
233
+
234
+ const namaDariId = (id) => props.employees.find(e => e.value === id)?.label ?? id
235
+
236
+ async function simpanKualitatif() {
237
+ const isi = { ...kualitatif.value }
238
+ if (isi.manager_rating === '' || punyaAspek.value) delete isi.manager_rating
239
+ if (!isi.one_on_one_at) delete isi.one_on_one_at
240
+ const ok = await submit(
241
+ () => kpiAppraisalsApi.update(props.companyId, detail.value.id, isi),
242
+ { successKey: 'common.saveSuccess', errorKey: 'kpi.appraisal.saveError' },
243
+ )
244
+ if (ok) await buka(detail.value.id)
245
+ }
246
+
247
+ function muatanAspek() {
248
+ return aspek.value.map(a => ({
249
+ aspect_id: a.aspect_id,
250
+ score: a.score === '' ? null : Number(a.score),
251
+ ...(a.note?.trim() ? { note: a.note.trim() } : {}),
252
+ }))
253
+ }
254
+
255
+ /** Nilai 1/5 tanpa catatan ditahan di layar; `wajibLengkap` = cek dari tombol Submit. */
256
+ function periksaAspek(wajibLengkap) {
257
+ const err = {}
258
+ for (const a of aspek.value) {
259
+ if (wajibLengkap && a.score === '') err[a.aspect_id] = t('kpi.appraisal.aspectRequired')
260
+ else if ((a.score === '1' || a.score === '5') && !a.note?.trim()) err[a.aspect_id] = t('kpi.appraisal.aspectNoteRequired')
261
+ }
262
+ aspekErr.value = err
263
+ return !Object.keys(err).length
264
+ }
265
+
266
+ async function simpanAspek({ diam = false } = {}) {
267
+ if (!periksaAspek(false)) { formError.value = t('common.checkRequired'); return false }
268
+ return submit(
269
+ () => kpiAppraisalsApi.updateAspects(props.companyId, detail.value.id, { scores: muatanAspek() }),
270
+ {
271
+ ...(diam ? {} : { successKey: 'common.saveSuccess' }),
272
+ onError: (e) => { if (e.reason === 'appraisal_not_draft') formError.value = t('kpi.appraisal.errNotDraft') },
273
+ onSuccess: (res) => { const d = res?.data?.data; if (d?.id) pakaiDetail(d) },
274
+ },
275
+ )
276
+ }
277
+
278
+ async function segarkanAspek() {
279
+ const ok = await submit(
280
+ () => kpiAppraisalsApi.refreshAspects(props.companyId, detail.value.id),
281
+ { successKey: 'kpi.appraisal.aspectsRefreshed' },
282
+ )
283
+ // Dimuat ulang dari server, bukan dari respons: bentuk respons refresh tak dikunci kontrak.
284
+ if (ok) await buka(detail.value.id)
285
+ }
286
+
287
+ /** Isi KPI yang belum diisi: form isiannya milik pemanggil (Workspace), subjeknya karyawan siklus ini. */
288
+ function isi(mi) {
289
+ emit('fill', { ...mi, employee_id: detail.value.employee_id, employee_name: namaKaryawan(detail.value) })
290
+ }
291
+
292
+ /** Sorot aspek yang disebut `data.aspects[]` (berisi NAMA aspek) dengan kalimat sebabnya. */
293
+ function sorotAspek(nama, kalimat) {
294
+ const set = new Set(nama ?? [])
295
+ aspekErr.value = Object.fromEntries(aspek.value.filter(a => set.has(a.aspect_name)).map(a => [a.aspect_id, kalimat]))
296
+ }
297
+
298
+ async function submitSiklus() {
299
+ belumDiisi.value = []
300
+ if (punyaAspek.value) {
301
+ if (!periksaAspek(true)) { formError.value = t('kpi.appraisal.errAspectsIncomplete'); return }
302
+ // Nilai yang dipilih tapi belum disimpan ikut terkirim dulu — submit membekukan apa yang
303
+ // tersimpan di server, bukan yang terlihat di layar.
304
+ if (aspekBerubah.value && !(await simpanAspek({ diam: true }))) return
305
+ }
306
+ const ok = await submit(
307
+ () => kpiAppraisalsApi.submit(props.companyId, detail.value.id),
308
+ {
309
+ successKey: 'kpi.appraisal.submitted',
310
+ onError: (e) => {
311
+ // ⚠️ **`e.raw` adalah objek galat AXIOS, bukan body respons** — jalannya
312
+ // `raw.response.data.data`. Salah satu tingkat saja membuat daftar di bawah selalu kosong
313
+ // dan pesannya diam-diam jatuh ke kalimat generik.
314
+ const data = e.raw?.response?.data?.data ?? {}
315
+ // Menyebut BULAN mana yang belum beku, bukan sekadar "belum bisa disubmit": tanpa
316
+ // daftarnya, tak seorang pun tahu apa yang harus dikerjakan berikutnya.
317
+ if (e.reason === 'span_not_frozen') {
318
+ const bulan = (data.open_months ?? []).join(', ')
319
+ formError.value = bulan ? t('kpi.appraisal.errNotFrozenList', { months: bulan }) : t('kpi.appraisal.errNotFrozen')
320
+ }
321
+ // Komposit dari data separuh tak bisa diperbaiki sesudah dibekukan, jadi server menolak
322
+ // submit dan menyebut barisnya; daftarnya dirender di bawah banner dengan tombol isi.
323
+ if (e.reason === 'scorecard_incomplete') {
324
+ belumDiisi.value = data.missing ?? []
325
+ formError.value = t('kpi.appraisal.errIncomplete')
326
+ }
327
+ if (e.reason === 'aspects_incomplete') {
328
+ sorotAspek(data.aspects, t('kpi.appraisal.aspectRequired'))
329
+ formError.value = t('kpi.appraisal.errAspectsIncomplete')
330
+ }
331
+ if (e.reason === 'aspect_note_required') {
332
+ sorotAspek(data.aspects, t('kpi.appraisal.aspectNoteRequired'))
333
+ formError.value = t('kpi.appraisal.errAspectNote')
334
+ }
335
+ if (e.reason === 'appraisal_not_draft') formError.value = t('kpi.appraisal.errNotDraft')
336
+ },
337
+ },
338
+ )
339
+ if (ok) { await buka(detail.value.id); await muatDaftar() }
340
+ }
341
+
342
+ async function acknowledge() {
343
+ const ok = await submit(
344
+ () => kpiAppraisalsApi.acknowledge(props.companyId, detail.value.id,
345
+ tanggapan.value.trim() ? { employee_response: tanggapan.value.trim() } : {}),
346
+ { successKey: 'kpi.appraisal.acknowledged', errorKey: 'kpi.appraisal.saveError' },
347
+ )
348
+ if (ok) { await buka(detail.value.id); await muatDaftar() }
349
+ }
350
+
351
+ async function tutup() {
352
+ const ok = await submit(
353
+ () => kpiAppraisalsApi.close(props.companyId, detail.value.id),
354
+ { successKey: 'kpi.appraisal.closed', errorKey: 'kpi.appraisal.saveError' },
355
+ )
356
+ if (ok) { await buka(detail.value.id); await muatDaftar() }
357
+ }
358
+
359
+ async function hapus() {
360
+ const ok = await submit(
361
+ () => kpiAppraisalsApi.remove(props.companyId, konfirmasiHapus.value.id),
362
+ { successKey: 'common.deleteSuccess', errorKey: 'kpi.appraisal.saveError' },
363
+ )
364
+ if (ok) {
365
+ if (detail.value?.id === konfirmasiHapus.value.id) detail.value = null
366
+ konfirmasiHapus.value = null
367
+ await muatDaftar()
368
+ }
369
+ }
370
+
371
+ async function terbitkanBeritaAcara() {
372
+ const ok = await submit(
373
+ () => kpiAppraisalsApi.createDocument(props.companyId, detail.value.id, { template_id: docTemplate.value }),
374
+ {
375
+ require: ['docTemplate'],
376
+ requireIn: { docTemplate: docTemplate.value },
377
+ successKey: 'kpi.appraisal.docCreated',
378
+ onError: (e) => {
379
+ if (e.reason === 'template_type_mismatch') formError.value = t('kpi.appraisal.errTemplateType')
380
+ },
381
+ onSuccess: (res) => {
382
+ showDoc.value = false
383
+ // Dokumennya dibuka lewat alur dokumen milik APP pemanggil — paket tak mengenal rutenya, dan
384
+ // TTD dua pihak memakai e-sign DMS existing di layar itu, bukan mesin baru di sini.
385
+ const doc = res?.data?.data ?? res?.data
386
+ if (doc?.id) emit('open-document', doc)
387
+ },
388
+ },
389
+ )
390
+ if (ok) await buka(detail.value.id)
391
+ }
392
+
393
+ const angka = (v) => (v === null || v === undefined ? '—' : formatScore(v))
394
+
395
+ watch(() => props.refreshToken, () => {
396
+ belumDiisi.value = []
397
+ if (formError.value === t('kpi.appraisal.errIncomplete')) formError.value = ''
398
+ })
399
+ watch(() => detail.value?.id, () => { belumDiisi.value = [] })
400
+ watch(statusFilter, muatDaftar)
401
+ watch(() => props.companyId, muatDaftar, { immediate: true })
402
+ watch(() => props.openId, (id) => { if (id) buka(id) }, { immediate: true })
403
+ </script>
404
+
405
+ <template>
406
+ <div class="grid gap-4 lg:grid-cols-[minmax(0,20rem)_minmax(0,1fr)]">
407
+ <!-- ── Daftar siklus ─────────────────────────────────────────────────── -->
408
+ <AppCard :title="t('kpi.appraisal.listTitle')" padding="tight">
409
+ <template #actions>
410
+ <div class="flex flex-wrap items-center gap-1.5">
411
+ <AppButton v-if="canBulk" variant="secondary" size="sm" @click="bukaBulk">
412
+ <Users class="w-4 h-4" />{{ t('kpi.appraisal.bulk') }}
413
+ </AppButton>
414
+ <AppButton v-if="canManage" size="sm" @click="showCreate = true">
415
+ <Plus class="w-4 h-4" />{{ t('kpi.appraisal.add') }}
416
+ </AppButton>
417
+ </div>
418
+ </template>
419
+
420
+ <div class="space-y-3">
421
+ <AppCombobox
422
+ v-model="statusFilter"
423
+ :aria-label="t('kpi.appraisal.filterStatus')"
424
+ :options="statusOptions"
425
+ hide-clear
426
+ dense
427
+ />
428
+
429
+ <AppAlert v-if="listError" variant="error">{{ listError }}</AppAlert>
430
+ <AppSpinner v-else-if="loading" />
431
+
432
+ <ul v-else-if="rows.length" class="space-y-1.5">
433
+ <li v-for="r in rows" :key="r.id">
434
+ <button
435
+ type="button"
436
+ class="w-full text-left rounded-lg border px-3 py-2 transition-colors"
437
+ :class="detail?.id === r.id
438
+ ? 'border-blue-500 bg-blue-50 dark:bg-blue-900/20'
439
+ : 'border-gray-200 dark:border-gray-700 hover:bg-gray-50 dark:hover:bg-gray-900/40'"
440
+ @click="buka(r.id)"
441
+ >
442
+ <div class="flex items-center justify-between gap-2">
443
+ <span class="text-sm text-gray-900 dark:text-white truncate">{{ namaKaryawan(r) }}</span>
444
+ <AppBadge :color="STATUS_TONE[r.status] ?? 'gray'">{{ t(`kpi.appraisal.status.${r.status}`) }}</AppBadge>
445
+ </div>
446
+ <p class="text-xs text-gray-500 dark:text-gray-400">
447
+ {{ r.period }}
448
+ <template v-if="r.final_score != null"> · {{ t('kpi.appraisal.finalShort') }} {{ angka(r.final_score) }}</template>
449
+ </p>
450
+ </button>
451
+ </li>
452
+ </ul>
453
+
454
+ <AppEmptyState
455
+ v-else
456
+ :title="t('kpi.appraisal.emptyTitle')"
457
+ :description="t('kpi.appraisal.emptyBody')"
458
+ />
459
+ </div>
460
+ </AppCard>
461
+
462
+ <!-- ── Detail siklus ─────────────────────────────────────────────────── -->
463
+ <AppCard v-if="detail" :title="namaKaryawan(detail) || t('kpi.appraisal.detailTitle')" :description="detail.period">
464
+ <template #actions>
465
+ <AppBadge :color="STATUS_TONE[detail.status] ?? 'gray'">{{ t(`kpi.appraisal.status.${detail.status}`) }}</AppBadge>
466
+ </template>
467
+
468
+ <div class="space-y-5">
469
+ <AppAlert v-if="formError" variant="error">
470
+ {{ formError }}
471
+ <ul v-if="belumDiisi.length" class="mt-2 space-y-1">
472
+ <li v-for="mi in belumDiisi" :key="`${mi.kpi_definition_id}|${mi.period}`" class="flex flex-wrap items-center gap-x-2">
473
+ <span>{{ mi.code ? `${mi.code} — ${mi.name}` : mi.name }} — {{ mi.period }}</span>
474
+ <button
475
+ v-if="canFill"
476
+ type="button"
477
+ class="text-xs font-medium underline hover:no-underline"
478
+ @click="isi(mi)"
479
+ >{{ t('kpi.scorecard.fillMissing') }}</button>
480
+ </li>
481
+ </ul>
482
+ </AppAlert>
483
+ <AppSpinner v-if="detailLoading" />
484
+
485
+ <template v-else>
486
+ <!-- Angka: sesudah submit yang tampil adalah SNAPSHOT BEKU milik siklus ini, bukan
487
+ hitungan hidup — itu sebabnya keduanya tak boleh dirender dari sumber yang sama. -->
488
+ <div v-if="detail.status !== 'draft'" class="rounded-xl border border-gray-200 dark:border-gray-700 bg-gray-50 dark:bg-gray-900/40 px-4 py-3 space-y-2" data-kpi-final>
489
+ <div v-if="detail.final_score != null" class="flex flex-wrap items-baseline gap-3">
490
+ <span class="text-sm text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.finalScore') }}</span>
491
+ <AppBadge :color="statusTone(detail.final_status)" class="text-base">{{ angka(detail.final_score) }}</AppBadge>
492
+ <span class="text-xs text-gray-500 dark:text-gray-400">
493
+ {{ t('kpi.appraisal.finalBreakdown', {
494
+ kw: angka(detail.kpi_weight), kpi: angka(detail.composite_score),
495
+ aw: angka(detail.aspect_weight), asp: angka(detail.aspect_pct),
496
+ }) }}
497
+ </span>
498
+ </div>
499
+ <div class="flex flex-wrap items-baseline gap-3">
500
+ <span class="text-sm text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.frozenComposite') }}</span>
501
+ <span class="text-lg font-semibold tabular-nums text-gray-900 dark:text-white">{{ angka(detail.composite_score) }}</span>
502
+ </div>
503
+ <p class="text-xs text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.frozenHint') }}</p>
504
+ <p class="text-xs text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.kpiLocked', { period: detail.period }) }}</p>
505
+ </div>
506
+
507
+ <AppKpiScorecard
508
+ v-else
509
+ :key="`${detail.id}-${refreshToken}`"
510
+ :can-fill="canFill"
511
+ :company-id="companyId"
512
+ :employee-id="detail.employee_id"
513
+ :period="detail.period"
514
+ :format-metric="formatMetric"
515
+ :format-achievement="formatAchievement"
516
+ @fill="isi"
517
+ />
518
+
519
+ <!-- Penilaian aspek -->
520
+ <div v-if="punyaAspek" class="space-y-3" data-kpi-aspects>
521
+ <div class="flex flex-wrap items-center justify-between gap-2">
522
+ <h4 class="text-sm font-semibold text-gray-900 dark:text-white">{{ t('kpi.appraisal.aspectsTitle') }}</h4>
523
+ <AppButton v-if="bolehNilaiAspek" variant="ghost" size="sm" :loading="saving" @click="segarkanAspek">
524
+ <RefreshCw class="w-4 h-4" />{{ t('kpi.appraisal.refreshAspects') }}
525
+ </AppButton>
526
+ </div>
527
+ <p v-if="detail.status === 'draft' && detail.aspect_average != null" class="text-xs text-gray-500 dark:text-gray-400">
528
+ {{ t('kpi.appraisal.aspectPreview', { avg: angka(detail.aspect_average), pct: angka(detail.aspect_pct) }) }}
529
+ </p>
530
+
531
+ <fieldset
532
+ v-for="a in aspek"
533
+ :key="a.aspect_id"
534
+ class="rounded-lg border p-3"
535
+ :class="aspekErr[a.aspect_id] ? 'border-red-400 dark:border-red-500' : 'border-gray-200 dark:border-gray-700'"
536
+ :data-kpi-aspect-score="a.aspect_name"
537
+ >
538
+ <legend class="px-1 text-sm font-medium text-gray-900 dark:text-white">{{ a.aspect_name }}</legend>
539
+ <div class="grid gap-1">
540
+ <label
541
+ v-for="n in SKALA"
542
+ :key="n"
543
+ class="flex items-start gap-2 rounded px-2 py-1 text-sm"
544
+ :class="[a.score === n ? 'bg-blue-50 dark:bg-blue-900/20' : '', bolehNilaiAspek ? 'cursor-pointer hover:bg-gray-50 dark:hover:bg-gray-900/40' : '']"
545
+ >
546
+ <input
547
+ v-model="a.score"
548
+ type="radio"
549
+ :name="`aspek-${a.aspect_id}`"
550
+ :value="n"
551
+ :disabled="!bolehNilaiAspek"
552
+ class="mt-0.5"
553
+ />
554
+ <span class="font-semibold tabular-nums w-3">{{ n }}</span>
555
+ <span class="text-gray-600 dark:text-gray-300">{{ a.rubric?.[n] || '—' }}</span>
556
+ </label>
557
+ </div>
558
+ <AppTextarea
559
+ v-model="a.note"
560
+ class="mt-2"
561
+ :label="t('kpi.appraisal.aspectNote')"
562
+ :hint="a.score === '1' || a.score === '5' ? t('kpi.appraisal.aspectNoteHint') : ''"
563
+ :rows="2"
564
+ :disabled="!bolehNilaiAspek"
565
+ :required="a.score === '1' || a.score === '5'"
566
+ :error="aspekErr[a.aspect_id]"
567
+ />
568
+ </fieldset>
569
+
570
+ <AppButton v-if="bolehNilaiAspek" size="sm" :loading="saving" :disabled="!aspekBerubah" @click="simpanAspek()">
571
+ {{ t('kpi.appraisal.saveAspects') }}
572
+ </AppButton>
573
+ </div>
574
+
575
+ <!-- Isian kualitatif -->
576
+ <div class="space-y-3">
577
+ <h4 class="text-sm font-semibold text-gray-900 dark:text-white">{{ t('kpi.appraisal.qualitative') }}</h4>
578
+ <div class="grid gap-3 sm:grid-cols-2">
579
+ <!-- Nilai tunggal lama hanya untuk siklus TANPA aspek (siklus lama / tenant tanpa master
580
+ aspek); bila ada aspek, rata-rata aspek yang menggantikannya. -->
581
+ <AppInput
582
+ v-if="!punyaAspek"
583
+ v-model="kualitatif.manager_rating"
584
+ type="number"
585
+ min="1"
586
+ max="5"
587
+ :label="t('kpi.appraisal.fieldRating')"
588
+ :hint="t('kpi.appraisal.hintRating')"
589
+ :disabled="!bolehSuntingKualitatif"
590
+ />
591
+ <AppDatePicker
592
+ v-model="kualitatif.one_on_one_at"
593
+ :label="t('kpi.appraisal.fieldOneOnOne')"
594
+ :disabled="!bolehSuntingKualitatif"
595
+ />
596
+ </div>
597
+ <AppTextarea
598
+ v-model="kualitatif.manager_notes"
599
+ :label="t('kpi.appraisal.fieldNotes')"
600
+ :rows="3"
601
+ :disabled="!bolehSuntingKualitatif"
602
+ />
603
+ <AppButton v-if="bolehSuntingKualitatif" size="sm" :loading="saving" @click="simpanKualitatif">
604
+ {{ t('common.save') }}
605
+ </AppButton>
606
+ </div>
607
+
608
+ <!-- Tanggapan karyawan: kotaknya HANYA untuk yang bersangkutan; bagi orang lain ia
609
+ dirender sebagai teks, sebab isinya memang bagian dari berita acara. -->
610
+ <div v-if="bolehAcknowledge || detail.employee_response" class="space-y-2">
611
+ <h4 class="text-sm font-semibold text-gray-900 dark:text-white">{{ t('kpi.appraisal.response') }}</h4>
612
+ <AppTextarea
613
+ v-if="bolehAcknowledge"
614
+ v-model="tanggapan"
615
+ :label="t('kpi.appraisal.fieldResponse')"
616
+ :hint="t('kpi.appraisal.hintResponse')"
617
+ :rows="3"
618
+ />
619
+ <p v-else class="text-sm text-gray-700 dark:text-gray-300 whitespace-pre-line">{{ detail.employee_response }}</p>
620
+ </div>
621
+
622
+ <div class="flex flex-wrap items-center gap-2 pt-1">
623
+ <AppButton v-if="bolehSubmit" :loading="saving" @click="submitSiklus">
624
+ {{ t('kpi.appraisal.submit') }}
625
+ </AppButton>
626
+ <AppButton v-if="bolehAcknowledge" :loading="saving" @click="acknowledge">
627
+ {{ t('kpi.appraisal.acknowledge') }}
628
+ </AppButton>
629
+ <AppButton v-if="bolehTutup" variant="secondary" :loading="saving" @click="tutup">
630
+ {{ t('kpi.appraisal.close') }}
631
+ </AppButton>
632
+ <AppButton v-if="bolehBeritaAcara" variant="secondary" @click="showDoc = true">
633
+ <FileText class="w-4 h-4" />{{ t('kpi.appraisal.issueDoc') }}
634
+ </AppButton>
635
+ <AppButton
636
+ v-if="detail.status === 'draft' && canManage"
637
+ variant="ghost"
638
+ size="sm"
639
+ :aria-label="t('common.delete')"
640
+ @click="konfirmasiHapus = detail"
641
+ >
642
+ <Trash2 class="w-4 h-4 text-red-600 dark:text-red-400" />
643
+ </AppButton>
644
+ </div>
645
+ <p v-if="bolehSubmit" class="text-xs text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.submitHint') }}</p>
646
+ </template>
647
+ </div>
648
+ </AppCard>
649
+
650
+ <AppCard v-else>
651
+ <AppEmptyState :title="t('kpi.appraisal.pickTitle')" :description="t('kpi.appraisal.pickBody')" />
652
+ </AppCard>
653
+
654
+ <!-- ── Dialog buat siklus ────────────────────────────────────────────── -->
655
+ <AppModal v-if="showCreate" :title="t('kpi.appraisal.add')" @close="showCreate = false">
656
+ <div class="space-y-4">
657
+ <AppAlert v-if="createError" variant="error">{{ createError }}</AppAlert>
658
+ <AppCombobox
659
+ v-model="form.employee_id"
660
+ :error="fieldErrors.employee_id"
661
+ :label="t('kpi.appraisal.fieldEmployee')"
662
+ :options="employees"
663
+ :placeholder="t('kpi.appraisal.selectEmployee')"
664
+ required
665
+ />
666
+ <div>
667
+ <p class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{{ t('kpi.appraisal.fieldPeriod') }}</p>
668
+ <AppKpiPeriodPicker v-model="form.period" />
669
+ <p class="mt-1 text-xs text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.hintPeriod') }}</p>
670
+ </div>
671
+ </div>
672
+ <template #footer>
673
+ <AppButton variant="secondary" @click="showCreate = false">{{ t('common.cancel') }}</AppButton>
674
+ <AppButton :loading="saving" @click="buat">{{ t('kpi.appraisal.createSubmit') }}</AppButton>
675
+ </template>
676
+ </AppModal>
677
+
678
+ <!-- ── Dialog penilaian massal ───────────────────────────────────────── -->
679
+ <AppModal v-if="showBulk" :title="t('kpi.appraisal.bulk')" @close="showBulk = false">
680
+ <div class="space-y-4">
681
+ <p class="text-sm text-gray-600 dark:text-gray-300">{{ t('kpi.appraisal.bulkHint') }}</p>
682
+ <div v-if="!bulkResult">
683
+ <p class="text-sm font-medium text-gray-700 dark:text-gray-300 mb-1">{{ t('kpi.appraisal.fieldPeriod') }}</p>
684
+ <AppKpiPeriodPicker v-model="bulkPeriod" />
685
+ </div>
686
+ <div v-else class="space-y-2 text-sm" data-kpi-bulk-result>
687
+ <p class="text-gray-900 dark:text-white">{{ t('kpi.appraisal.bulkCreated', { n: bulkResult.created.length }) }}</p>
688
+ <div v-if="bulkResult.skipped.length">
689
+ <p class="text-gray-700 dark:text-gray-300">{{ t('kpi.appraisal.bulkSkipped', { n: bulkResult.skipped.length }) }}</p>
690
+ <ul class="mt-1 space-y-0.5 text-xs text-gray-600 dark:text-gray-400">
691
+ <li v-for="s in bulkResult.skipped" :key="s.employee_id">
692
+ {{ namaDariId(s.employee_id) }} — {{ t(`kpi.appraisal.bulkReason.${s.reason}`, s.reason) }}
693
+ </li>
694
+ </ul>
695
+ </div>
696
+ </div>
697
+ </div>
698
+ <template #footer>
699
+ <AppButton variant="secondary" @click="showBulk = false">{{ bulkResult ? t('common.close') : t('common.cancel') }}</AppButton>
700
+ <AppButton v-if="!bulkResult" :loading="saving" @click="buatMassal">{{ t('kpi.appraisal.bulkSubmit') }}</AppButton>
701
+ </template>
702
+ </AppModal>
703
+
704
+ <!-- ── Dialog berita acara ───────────────────────────────────────────── -->
705
+ <AppModal v-if="showDoc" :title="t('kpi.appraisal.issueDoc')" @close="showDoc = false">
706
+ <div class="space-y-4">
707
+ <AppAlert v-if="formError" variant="error">{{ formError }}</AppAlert>
708
+ <AppCombobox
709
+ v-model="docTemplate"
710
+ :label="t('kpi.appraisal.fieldTemplate')"
711
+ :options="documentTemplates"
712
+ :placeholder="t('kpi.appraisal.selectTemplate')"
713
+ required
714
+ />
715
+ <p class="text-xs text-gray-500 dark:text-gray-400">{{ t('kpi.appraisal.docHint') }}</p>
716
+ </div>
717
+ <template #footer>
718
+ <AppButton variant="secondary" @click="showDoc = false">{{ t('common.cancel') }}</AppButton>
719
+ <AppButton :loading="saving" @click="terbitkanBeritaAcara">{{ t('kpi.appraisal.issueDoc') }}</AppButton>
720
+ </template>
721
+ </AppModal>
722
+
723
+ <AppModal v-if="konfirmasiHapus" :title="t('common.delete')" @close="konfirmasiHapus = null">
724
+ <p class="text-sm text-gray-700 dark:text-gray-300">
725
+ {{ t('kpi.appraisal.deleteConfirm', { name: namaKaryawan(konfirmasiHapus) || konfirmasiHapus.period }) }}
726
+ </p>
727
+ <template #footer>
728
+ <AppButton variant="secondary" @click="konfirmasiHapus = null">{{ t('common.cancel') }}</AppButton>
729
+ <AppButton variant="danger" :loading="saving" @click="hapus">{{ t('common.delete') }}</AppButton>
730
+ </template>
731
+ </AppModal>
732
+ </div>
733
+ </template>