Skip to content

Commit faeadca

Browse files
committed
fix(admin-borrow): resolve error in api
1 parent 77055fe commit faeadca

11 files changed

Lines changed: 395 additions & 159 deletions

File tree

components/app/ReceiptAdmin/ReturnTable/column.ts

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,19 @@ const statusMap = {
77
on_time: 'Đúng hạn',
88
};
99

10+
const deviceStatusMap = {
11+
healthy: 'Không hư hỏng',
12+
broken: 'Hư hỏng',
13+
assessing: 'Đang đánh giá',
14+
lost: 'Mất',
15+
};
16+
17+
const deviceStatusColorMap = {
18+
healthy: 'bg-green-100 text-green-800',
19+
broken: 'bg-red-100 text-red-800',
20+
assessing: 'bg-yellow-100 text-yellow-800',
21+
lost: 'bg-gray-100 text-gray-800',
22+
};
1023
export const columns: AugmentedColumnDef<ReturnedReceiptDevice>[] = [
1124
{
1225
id: 'name',
@@ -32,17 +45,6 @@ export const columns: AugmentedColumnDef<ReturnedReceiptDevice>[] = [
3245
),
3346
enableSorting: true,
3447
},
35-
{
36-
id: 'quantity',
37-
title: 'Số lượng',
38-
cell: ({ row }) =>
39-
h(
40-
'span',
41-
{ class: 'text-slate-500 text-sm font-normal leading-tight' },
42-
row.original.quantity,
43-
),
44-
enableSorting: true,
45-
},
4648
{
4749
id: 'borrowedPlace',
4850
title: 'Nơi mượn',
@@ -120,4 +122,29 @@ export const columns: AugmentedColumnDef<ReturnedReceiptDevice>[] = [
120122
),
121123
enableSorting: true,
122124
},
125+
{
126+
id: 'deviceStatus',
127+
title: 'Trạng thái thiết bị',
128+
cell: ({ row }) =>
129+
h(
130+
'span',
131+
{
132+
class: `inline-flex items-center rounded-full px-2.5 py-0.5 text-xs font-medium ${
133+
deviceStatusColorMap[row.original.deviceStatus]
134+
}`,
135+
},
136+
deviceStatusMap[row.original.deviceStatus],
137+
),
138+
enableSorting: true,
139+
},
140+
{
141+
id: 'note',
142+
title: 'Ghi chú',
143+
cell: ({ row }) =>
144+
h(
145+
'span',
146+
{ class: 'text-slate-500 text-sm font-normal leading-tight' },
147+
row.original.note,
148+
),
149+
},
123150
];

components/app/ReceiptAdmin/ReturnTable/schema.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@ export const ReturnedReceiptDeviceSchema = Type.Object({
1212
expectedReturnedAt: Type.Date(),
1313
returnedAt: Type.Date(),
1414
status: Type.Union([Type.Literal('on_time'), Type.Literal('late')]),
15+
deviceStatus: Type.Union([
16+
Type.Literal('healthy'),
17+
Type.Literal('broken'),
18+
Type.Literal('assessing'),
19+
Type.Literal('lost'),
20+
]),
21+
note: Type.Optional(Type.String()),
1522
});
1623

1724
export type ReturnedReceiptDevice = Static<typeof ReturnedReceiptDeviceSchema>;

lib/utils.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,24 @@ export function formatDate (value: string, isRelative: boolean = true): string {
2121
const now = new Date();
2222

2323
if (isRelative) {
24+
if (date > now) {
25+
return date.toLocaleDateString('en-US', {
26+
month: 'short',
27+
day: '2-digit',
28+
year: 'numeric'
29+
});
30+
}
31+
2432
const diffInMinutes = Math.floor(
2533
(now.getTime() - date.getTime()) / (1000 * 60),
2634
);
2735
const diffInHours = Math.floor(diffInMinutes / 60);
2836
const diffInDays = Math.floor(diffInHours / 24);
2937

30-
if (diffInMinutes < 60) {
31-
return 'a minute ago';
38+
if (diffInMinutes < 5) {
39+
return 'just now';
40+
} else if (diffInMinutes < 60) {
41+
return `${diffInMinutes} minutes ago`;
3242
} else if (diffInHours < 24) {
3343
return `${diffInHours} hours ago`;
3444
} else if (diffInDays < 30) {

nuxt.config.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ export default defineNuxtConfig({
1414
'shadcn-nuxt',
1515
'@sidebase/nuxt-auth',
1616
],
17+
build: {
18+
transpile: ['vue-toastification']
19+
},
1720
nitro: {
1821
preset: 'bun',
1922
},
@@ -34,7 +37,7 @@ export default defineNuxtConfig({
3437
},
3538
},
3639
eslint: {},
37-
css: ['~/assets/css/fonts.css', '~/assets/css/main.css'],
40+
css: ['~/assets/css/fonts.css', '~/assets/css/main.css', 'vue-toastification/dist/index.css'],
3841
postcss: {
3942
plugins: {
4043
tailwindcss: {},

0 commit comments

Comments
 (0)