11<script setup lang="ts">
22 import type { TableColumn } from ' @nuxt/ui'
33 import { refDebounced } from ' @vueuse/core'
4+ import { h , resolveComponent } from ' vue'
5+ import { authClient } from ' ~/utils/auth-client'
46
57 const route = useRoute ()
68 const userId = route .params .id as string
9+ const UCheckbox = resolveComponent (' UCheckbox' )
10+
11+ // Fetch Current Session
12+ const { data : session } = await authClient .useSession (useFetch )
13+ const isOnboardingUser = computed (() => session .value ?.user ?.role === ' ONBOARDING' )
714
815 // Fetch User Info
916 const { data : user } = await useFetch (` /api/get/users/byId/${userId } ` )
6774 return filteredData .value .slice (start , start + limit .value )
6875 })
6976
70- const columns: TableColumn <any >[] = [
71- {
72- accessorKey: ' task.desc' ,
73- header: ' Task' ,
74- },
75- {
76- accessorKey: ' task.supervisor.name' ,
77- header: ' Supervisor' ,
78- cell : ({ row }) => row .original .task .supervisor ?.name || ' Unassigned' ,
79- },
80- {
81- accessorKey: ' completed' ,
82- header: ' Status' ,
83- cell : ({ row }) => {
84- const completed = row .original .completed
85- return h (
86- ' div' ,
87- { class: ' flex items-center' },
88- h (
89- ' span' ,
90- {
91- class: [
92- ' inline-flex items-center px-2 py-0.5 rounded text-xs font-medium' ,
93- completed
94- ? ' bg-green-100 text-green-800 dark:bg-green-900 dark:text-green-200'
95- : ' bg-yellow-100 text-yellow-800 dark:bg-yellow-900 dark:text-yellow-200' ,
96- ],
97- },
98- completed ? ' Completed' : ' Pending'
99- )
100- )
77+ const columns: TableColumn <any >[] = [
78+ {
79+ accessorKey: ' completed' ,
80+ header: ' Status' ,
81+ cell : ({ row }) => {
82+ return h (' div' , { class: ' flex items-center gap-2' }, [
83+ h (UCheckbox , {
84+ modelValue: row .original .completed ,
85+ disabled: isOnboardingUser .value ,
86+ ' onUpdate:modelValue' : (val : boolean ) => toggleStatus (row .original , val ),
87+ }),
88+ h (' span' , {
89+ class: [' text-xs font-medium' , row .original .completed ? ' text-green-600' : ' text-gray-500' ]
90+ }, row .original .completed ? ' Completed' : ' Pending' )
91+ ])
92+ }
10193 },
102- },
103- ]
104- </script >
105-
94+ {
95+ accessorKey: ' task.desc' ,
96+ header: ' Task' ,
97+ },
98+ {
99+ accessorKey: ' task.supervisor.name' ,
100+ header: ' Supervisor' ,
101+ cell : ({ row }) => row .original .task .supervisor ?.name || ' Unassigned' ,
102+ },
103+ ]
104+
105+ async function toggleStatus(row : any , checked : boolean ) {
106+ try {
107+ await $fetch (` /api/put/onboarding-tasks/${row .id } ` , {
108+ method: ' PUT' ,
109+ body: { completed: checked },
110+ })
111+ await refresh ()
112+ } catch (e ) {
113+ console .error (e )
114+ }
115+ }
116+ </script >
106117<template >
107118 <div class =" flex flex-col gap-6 p-6" >
108119 <div class =" flex items-center gap-4" >
109120 <UButton
121+ v-if =" !isOnboardingUser"
110122 icon =" i-heroicons-arrow-left"
111123 color =" neutral"
112124 variant =" ghost"
113125 to =" /"
114126 />
115127 <div >
116- <h1 class =" text-2xl font-bold text-gray-900 dark:text-white" >
128+ <h1 v-if = " !isOnboardingUser " class =" text-2xl font-bold text-gray-900 dark:text-white" >
117129 {{ user?.name }}
118130 </h1 >
119- <p class =" text-sm text-gray-500 dark:text-gray-400" >
120- {{ user?.role }} • {{ user?.department?.name || 'No Department' }}
121- </p >
122131 </div >
123132 </div >
124133
140149 </p >
141150 </div >
142151 </div >
143- </template >
152+ </template >
0 commit comments