@finema/finework-layer 0.0.12 → 0.0.13
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.
- package/.husky/pre-commit +1 -0
- package/.playground/app/assets/css/main.css +6 -0
- package/.playground/app/pages/layout-admin.vue +104 -0
- package/.playground/app.config.ts +2 -2
- package/.playground/nuxt.config.ts +1 -9
- package/CHANGELOG.md +34 -28
- package/app/app.config.ts +297 -298
- package/app/app.vue +10 -10
- package/app/assets/css/main.css +2 -3
- package/app/components/Button/ActionIcon.vue +29 -29
- package/app/components/Button/Back.vue +22 -22
- package/app/components/InfoItemList.vue +202 -202
- package/app/components/Layout/Admin/Apps.vue +45 -0
- package/app/components/Layout/Admin/Sidebar.vue +233 -0
- package/app/components/Layout/Admin/index.vue +220 -0
- package/app/components/StatusBox.vue +56 -56
- package/app/composables/useAuth.ts +189 -0
- package/app/composables/useRequestOptions.ts +50 -0
- package/app/constants/routes.ts +86 -0
- package/app/error.vue +218 -218
- package/app.config.ts +2 -2
- package/bun.lock +151 -111
- package/eslint.config.js +3 -1
- package/index.d.ts +16 -16
- package/nuxt.config.ts +6 -10
- package/package.json +15 -8
- package/tsconfig.json +20 -2
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
export enum Permission {
|
|
2
|
+
USER = 'USER',
|
|
3
|
+
ADMIN = 'ADMIN',
|
|
4
|
+
SUPER = 'SUPER',
|
|
5
|
+
NONE = 'NONE',
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export const PERMISSION_LABEL = {
|
|
9
|
+
[Permission.ADMIN]: 'Admin',
|
|
10
|
+
[Permission.USER]: 'User',
|
|
11
|
+
[Permission.SUPER]: 'Super Admin',
|
|
12
|
+
[Permission.NONE]: 'No Access',
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
export interface ITeam {
|
|
16
|
+
id: string
|
|
17
|
+
name: string
|
|
18
|
+
code: string
|
|
19
|
+
color: string
|
|
20
|
+
description?: string
|
|
21
|
+
working_start_at: string
|
|
22
|
+
working_end_at: string
|
|
23
|
+
users: IUser[] | null
|
|
24
|
+
created_at: string
|
|
25
|
+
updated_at: string
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface IUser {
|
|
29
|
+
id: string
|
|
30
|
+
email: string
|
|
31
|
+
full_name: string
|
|
32
|
+
display_name: string
|
|
33
|
+
position: string
|
|
34
|
+
team: ITeam
|
|
35
|
+
team_code: string
|
|
36
|
+
avatar_url: string
|
|
37
|
+
company: string
|
|
38
|
+
access_level: IUserAccessLevel
|
|
39
|
+
is_active: boolean
|
|
40
|
+
joined_date: string
|
|
41
|
+
slack_id: string
|
|
42
|
+
created_at: string
|
|
43
|
+
updated_at: string
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export enum UserModule {
|
|
47
|
+
CHECKIN = 'clockin',
|
|
48
|
+
PMO = 'pmo',
|
|
49
|
+
TIMESHEET = 'timesheet',
|
|
50
|
+
SETTING = 'setting',
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export interface IUserAccessLevel {
|
|
54
|
+
used_id: string
|
|
55
|
+
pmo: Permission.USER | Permission.ADMIN | Permission.SUPER
|
|
56
|
+
clockin: Permission.USER | Permission.ADMIN
|
|
57
|
+
timesheet: Permission.USER | Permission.ADMIN
|
|
58
|
+
setting: Permission.USER | Permission.SUPER
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export const useAuth = () => {
|
|
62
|
+
const {
|
|
63
|
+
auth,
|
|
64
|
+
} = useRequestOptions()
|
|
65
|
+
|
|
66
|
+
const token = useCookie('token', {
|
|
67
|
+
path: '/',
|
|
68
|
+
maxAge: 60 * 60 * 24 * 365,
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
const isAuthenticated = computed(() => !!token.value)
|
|
72
|
+
const me = defineStore('auth.me', () => {
|
|
73
|
+
const value = ref<IUser | null>(null)
|
|
74
|
+
|
|
75
|
+
const set = (user: IUser | null) => {
|
|
76
|
+
value.value = user
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return {
|
|
80
|
+
value,
|
|
81
|
+
set,
|
|
82
|
+
}
|
|
83
|
+
})()
|
|
84
|
+
|
|
85
|
+
const fetchMe = (() => {
|
|
86
|
+
return useObjectLoader<IUser>({
|
|
87
|
+
method: 'GET',
|
|
88
|
+
url: '/me',
|
|
89
|
+
getRequestOptions: auth,
|
|
90
|
+
})
|
|
91
|
+
})()
|
|
92
|
+
|
|
93
|
+
const updateMe = (() => {
|
|
94
|
+
return useObjectLoader<IUser>({
|
|
95
|
+
method: 'PUT',
|
|
96
|
+
url: '/me',
|
|
97
|
+
getRequestOptions: auth,
|
|
98
|
+
})
|
|
99
|
+
})()
|
|
100
|
+
|
|
101
|
+
const loginSlack = async () => {
|
|
102
|
+
const config = useRuntimeConfig()
|
|
103
|
+
|
|
104
|
+
window.location.href = config.public.baseAPI + '/auth/slack-login'
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
const loginMs = async () => {
|
|
108
|
+
const config = useRuntimeConfig()
|
|
109
|
+
|
|
110
|
+
window.location.href = config.public.baseAPI + '/auth/ms-login'
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
useWatchTrue(() => fetchMe.status.value.isSuccess, () => {
|
|
114
|
+
me.set(fetchMe.data.value)
|
|
115
|
+
})
|
|
116
|
+
|
|
117
|
+
useWatchTrue(() => fetchMe.status.value.isError, () => {
|
|
118
|
+
token.value = undefined
|
|
119
|
+
me.set(null)
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
const hasPermission = (module: UserModule, ...permission: Permission[]) => {
|
|
123
|
+
if (!me.value?.access_level) {
|
|
124
|
+
return false
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
return permission.includes(me.value.access_level[module])
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
const isSuperAdmin = computed(() => {
|
|
131
|
+
return me.value?.access_level?.setting === Permission.SUPER
|
|
132
|
+
})
|
|
133
|
+
|
|
134
|
+
const menusNavbar = computed(() => [
|
|
135
|
+
{
|
|
136
|
+
label: 'Clock-In',
|
|
137
|
+
icon: '/admin/clock-in-logo.png',
|
|
138
|
+
to: routes.clockin.home.to,
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
label: 'Timesheet',
|
|
142
|
+
icon: '/admin/timesheet-logo.png',
|
|
143
|
+
to: routes.timesheet.home.to,
|
|
144
|
+
},
|
|
145
|
+
...(hasPermission(UserModule.PMO, Permission.ADMIN, Permission.USER, Permission.SUPER)
|
|
146
|
+
? [{
|
|
147
|
+
label: 'PMO',
|
|
148
|
+
icon: '/admin/pmo-logo.png',
|
|
149
|
+
to: routes.pmo.project.projects.to,
|
|
150
|
+
}]
|
|
151
|
+
: []),
|
|
152
|
+
...(hasPermission(UserModule.CHECKIN, Permission.ADMIN)
|
|
153
|
+
? [{
|
|
154
|
+
label: 'Clock-In Admin',
|
|
155
|
+
icon: '/admin/clock-in-admin-logo.png',
|
|
156
|
+
to: routes.adminClockin.checkinDashboard.to,
|
|
157
|
+
}]
|
|
158
|
+
: []),
|
|
159
|
+
...(hasPermission(UserModule.TIMESHEET, Permission.ADMIN)
|
|
160
|
+
? [{
|
|
161
|
+
label: 'Timesheet Admin',
|
|
162
|
+
icon: '/admin/timesheet-admin-logo.png',
|
|
163
|
+
to: routes.adminTimesheet.summaryReport.to,
|
|
164
|
+
}]
|
|
165
|
+
: []),
|
|
166
|
+
|
|
167
|
+
...(hasPermission(UserModule.SETTING, Permission.SUPER)
|
|
168
|
+
? [{
|
|
169
|
+
label: 'Super Admin',
|
|
170
|
+
icon: '/admin/super-admin-logo.png',
|
|
171
|
+
to: routes.admin.users.to,
|
|
172
|
+
}]
|
|
173
|
+
: []),
|
|
174
|
+
])
|
|
175
|
+
|
|
176
|
+
return {
|
|
177
|
+
token,
|
|
178
|
+
loginSlack,
|
|
179
|
+
loginMs,
|
|
180
|
+
isAuthenticated,
|
|
181
|
+
me,
|
|
182
|
+
fetchMe,
|
|
183
|
+
updateMe,
|
|
184
|
+
hasPermission,
|
|
185
|
+
isSuperAdmin,
|
|
186
|
+
menusNavbar,
|
|
187
|
+
|
|
188
|
+
}
|
|
189
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios'
|
|
2
|
+
|
|
3
|
+
export const useRequestOptions = () => {
|
|
4
|
+
const config = useRuntimeConfig()
|
|
5
|
+
|
|
6
|
+
const mock = (): Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
7
|
+
baseURL: string
|
|
8
|
+
} => {
|
|
9
|
+
return {
|
|
10
|
+
baseURL: config.public.baseAPIMock || 'http://localhost:3000/api/mock',
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
const base = (): Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
15
|
+
baseURL: string
|
|
16
|
+
} => {
|
|
17
|
+
return {
|
|
18
|
+
baseURL: config.public.baseAPI,
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const auth = (): Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
23
|
+
baseURL: string
|
|
24
|
+
} => {
|
|
25
|
+
return {
|
|
26
|
+
baseURL: config.public.baseAPI,
|
|
27
|
+
headers: {
|
|
28
|
+
Authorization: `Bearer ${useAuth().token.value}`,
|
|
29
|
+
},
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const file = (): Omit<AxiosRequestConfig, 'baseURL'> & {
|
|
34
|
+
baseURL: string
|
|
35
|
+
} => {
|
|
36
|
+
return {
|
|
37
|
+
baseURL: config.public.baseAPI + '/uploads',
|
|
38
|
+
headers: {
|
|
39
|
+
Authorization: `Bearer ${useAuth().token.value}`,
|
|
40
|
+
},
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
return {
|
|
45
|
+
base,
|
|
46
|
+
mock,
|
|
47
|
+
auth,
|
|
48
|
+
file,
|
|
49
|
+
}
|
|
50
|
+
}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
export const routes = {
|
|
2
|
+
home: {
|
|
3
|
+
label: 'หน้าแรก',
|
|
4
|
+
to: '/',
|
|
5
|
+
},
|
|
6
|
+
chooseTeam: {
|
|
7
|
+
label: 'เลือกทีม',
|
|
8
|
+
to: '/choose-team',
|
|
9
|
+
},
|
|
10
|
+
login: {
|
|
11
|
+
label: 'เลือก',
|
|
12
|
+
to: '/login',
|
|
13
|
+
},
|
|
14
|
+
logout: {
|
|
15
|
+
label: 'Log out',
|
|
16
|
+
to: '/api/auth/logout',
|
|
17
|
+
},
|
|
18
|
+
releaseHistory: {
|
|
19
|
+
label: 'Release History',
|
|
20
|
+
to: '/releases',
|
|
21
|
+
icon: 'heroicons:tag',
|
|
22
|
+
},
|
|
23
|
+
account: {
|
|
24
|
+
profile: {
|
|
25
|
+
label: 'โปรไฟล์',
|
|
26
|
+
to: '/account/profile',
|
|
27
|
+
icon: 'mage:user',
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
|
|
31
|
+
announcements: {
|
|
32
|
+
label: 'Finema Newsletter',
|
|
33
|
+
to: '/announcements',
|
|
34
|
+
icon: 'mage:announcement',
|
|
35
|
+
},
|
|
36
|
+
|
|
37
|
+
adminClockin: {
|
|
38
|
+
checkinDashboard: {
|
|
39
|
+
label: 'ภาพรวมเช็คอิน',
|
|
40
|
+
icon: 'mage:dashboard',
|
|
41
|
+
to: '/clockin-admin',
|
|
42
|
+
permissions: ['clockin:ADMIN'],
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
adminTimesheet: {
|
|
46
|
+
summaryReport: {
|
|
47
|
+
label: 'ภาพรวม',
|
|
48
|
+
icon: 'heroicons-outline:user-group',
|
|
49
|
+
to: '/timesheet-admin/reports/summary',
|
|
50
|
+
permissions: ['timesheet:ADMIN'],
|
|
51
|
+
},
|
|
52
|
+
},
|
|
53
|
+
admin: {
|
|
54
|
+
users: {
|
|
55
|
+
label: 'จัดการผู้ใช้งาน',
|
|
56
|
+
icon: 'hugeicons:user-circle-02',
|
|
57
|
+
to: '/admin/users',
|
|
58
|
+
permissions: ['setting:SUPER'],
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
clockin: {
|
|
62
|
+
home: {
|
|
63
|
+
label: 'Clock-In',
|
|
64
|
+
icon: 'i-heroicons-outline:location-marker',
|
|
65
|
+
to: '/clockin',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
timesheet: {
|
|
69
|
+
home: {
|
|
70
|
+
label: 'Timesheet',
|
|
71
|
+
icon: 'mage:dashboard',
|
|
72
|
+
to: '/timesheet',
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
pmo: {
|
|
76
|
+
project: {
|
|
77
|
+
projects: {
|
|
78
|
+
label: 'โครงการของฉัน',
|
|
79
|
+
to: '/pmo/projects',
|
|
80
|
+
icon: 'lucide:layers',
|
|
81
|
+
permissions: ['pmo:USER', 'pmo:ADMIN', 'pmo:SUPER'],
|
|
82
|
+
},
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
|
|
86
|
+
} as const
|