Skip to content

Commit 4134a5e

Browse files
committed
fix: handle virtual device
1 parent de27103 commit 4134a5e

10 files changed

Lines changed: 157 additions & 75 deletions

File tree

components/app/Checkout/DeviceKindTable/column.ts

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,51 @@ import type { AugmentedColumnDef } from '~/components/common/DataTable/column';
55
export function createColumns ({
66
onDeviceKindLinkClick,
77
}: {
8-
onDeviceKindLinkClick: (id: string) => void,
8+
onDeviceKindLinkClick: (id: string) => void;
99
}): AugmentedColumnDef<DeviceKindInCartList>[] {
1010
return [
1111
{
1212
id: 'id',
1313
title: 'Mã loại thiết bị',
1414
cell: ({ row }) =>
15-
h(
16-
'p',
17-
{ class: 'text-normal pl-3' },
18-
[row.original.id.toUpperCase()],
19-
),
15+
h('p', { class: 'text-normal pl-3' }, [row.original.id.toUpperCase()]),
2016
},
2117
{
2218
id: 'name',
2319
title: 'Tên loại thiết bị',
2420
cell: ({ row }) =>
2521
h(
2622
'p',
27-
{ class: 'line-clamp-2 text-slate-500 text-normal leading-6 font-normal' },
23+
{
24+
class:
25+
'line-clamp-2 text-slate-500 text-normal leading-6 font-normal',
26+
},
2827
row.original.name,
2928
),
3029
},
30+
{
31+
id: 'category',
32+
title: 'Phân nhóm',
33+
cell: ({ row }) =>
34+
h(
35+
'p',
36+
{
37+
class:
38+
'line-clamp-2 text-slate-500 text-normal leading-6 font-normal',
39+
},
40+
row.original.category,
41+
),
42+
},
3143
{
3244
id: 'quantity',
3345
title: 'SL',
3446
cell: ({ row }) =>
3547
h(
3648
'p',
37-
{ class: 'line-clamp-2 text-slate-500 text-right text-normal leading-6 font-normal' },
49+
{
50+
class:
51+
'line-clamp-2 text-slate-500 text-center text-normal leading-6 font-normal',
52+
},
3853
row.original.quantity,
3954
),
4055
},
@@ -44,7 +59,10 @@ export function createColumns ({
4459
cell: ({ row }) =>
4560
h(
4661
'div',
47-
{ class: 'flex justify-end items-center text-lg hover:cursor-pointer', onClick: () => onDeviceKindLinkClick(row.original.id) },
62+
{
63+
class: 'flex justify-end items-center text-lg hover:cursor-pointer',
64+
onClick: () => onDeviceKindLinkClick(row.original.id),
65+
},
4866
h(Icon, { name: 'i-heroicons-arrow-top-right-on-square' }),
4967
),
5068
},

components/app/Checkout/DeviceKindTable/index.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ const props = defineProps<{
77
cart: {
88
id: string;
99
name: string;
10+
category: string;
1011
deviceIds: string[];
1112
}[],
1213
}>();
@@ -28,6 +29,7 @@ async function fetchData (offset: number, length: number, options: { desc?: bool
2829
let deviceKinds = props.cart.map((deviceKind) => ({
2930
id: deviceKind.id,
3031
name: deviceKind.name,
32+
category: deviceKind.category,
3133
quantity: deviceKind.deviceIds.length,
3234
}));
3335
if (options.sortField) {
@@ -45,5 +47,8 @@ async function fetchData (offset: number, length: number, options: { desc?: bool
4547
</script>
4648

4749
<template>
48-
<DataTable :key="cart.flatMap(({ deviceIds }) => deviceIds).join('-')" :selectable="false" :searchable="false" :qrable="false" :fetch-fn="fetchData" :delete-fn="deleteData" :columns="createColumns({ onDeviceKindLinkClick }) as AugmentedColumnDef<unknown>[]" />
50+
<DataTable
51+
:key="cart.flatMap(({ deviceIds }) => deviceIds).join('-')" :selectable="false" :searchable="false"
52+
:qrable="false" :fetch-fn="fetchData" :delete-fn="deleteData"
53+
:columns="createColumns({ onDeviceKindLinkClick }) as AugmentedColumnDef<unknown>[]" />
4954
</template>

components/app/Checkout/DeviceKindTable/schema.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import type { Static } from '@sinclair/typebox';
44
export const DeviceKindInCartList = Type.Object({
55
id: Type.String(),
66
name: Type.String(),
7+
category: Type.String(),
78
quantity: Type.Number(),
89
});
910

components/app/NavBar.vue

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
<template>
22
<nav
33
class="bg-tertiary-darker flex justify-center md:justify-start md:pl-28 text-white items-stretch text-normal md:text-lg">
4-
<NuxtLink class="flex items-center cursor-pointer h-16 px-2 sm:px-5 hover:bg-primary-darker" href="/devices"> Thiết bị </NuxtLink>
5-
<button class="cursor-pointer h-16 px-2 sm:px-5 hover:bg-primary-darker"> Phòng thí nghiệm </button>
4+
<NuxtLink class="flex items-center cursor-pointer h-16 px-2 sm:px-5 hover:bg-primary-darker" href="/devices"> Thiết
5+
bị </NuxtLink>
6+
<NuxtLink class="flex items-center cursor-pointer h-16 px-2 sm:px-5 hover:bg-primary-darker" href="/admin/labs">
7+
Phòng thí nghiệm
8+
</NuxtLink>
69
<button class="cursor-pointer h-16 px-2.5 sm:px-5 hover:bg-primary-darker"> Bài viết </button>
710
<button class="cursor-pointer h-16 px-2.5 sm:px-5 hover:bg-primary-darker"> Quy định </button>
811
<button class="cursor-pointer h-16 px-2.5 sm:px-5 hover:bg-primary-darker"> Liên hệ </button>

composables/states.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
export const useLab = () => {
22
const lab = useState<{ id: string }>('lab', () => ({
3-
id: '015bd698-f8fb-4672-a43e-4e6fa64305ea',
3+
id: '16824ad6-5ffd-4c90-80d2-a1d70f068cf1',
44
}));
55

66
return {

nuxt.config.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ export default defineNuxtConfig({
1717
auth: {
1818
isEnabled: true,
1919
disableServerSideAuth: false,
20-
baseURL: 'http://localhost:3000/api/auth',
20+
baseURL:
21+
'https://scoring-sponsored-newark-driven.trycloudflare.com/api/auth',
2122
provider: {
2223
type: 'authjs',
2324
},
@@ -73,4 +74,7 @@ export default defineNuxtConfig({
7374
title: 'Labsyncro',
7475
},
7576
},
77+
devServer: {
78+
host: '0.0.0.0',
79+
},
7680
});

pages/admin/borrows/form.vue

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,17 @@
11
<script setup lang="ts">
22
import moment from 'moment';
3-
import { deviceKindService, receiptService, userService } from '~/services';
3+
import { deviceKindService, receiptService, userService, deviceService } from '~/services';
44
55
const route = useRoute();
66
7+
const { lab } = useLab();
8+
79
const currentDeviceKindId = ref<string | null>(null);
810
911
const devicesInCart = ref<{
1012
id: string;
1113
name: string;
14+
category: string;
1215
deviceIds: string[];
1316
}[]>([]);
1417
@@ -40,6 +43,7 @@ async function addDevice ({ kind, id }: { kind: string, id: string }) {
4043
devicesInCart.value.push({
4144
id: kind,
4245
name: deviceKindMeta.name,
46+
category: deviceKindMeta.categoryName,
4347
deviceIds: [id],
4448
});
4549
}
@@ -126,9 +130,11 @@ const handleVirtualKeyboardDetection = async (input: string, type?: 'userId' | '
126130
} else if (type === 'device') {
127131
const deviceKindId = input.match(/\/devices\/([a-fA-F0-9]+)/)?.[1];
128132
const deviceId = input.match(/[?&]id=([a-fA-F0-9]+)/)![1];
133+
console.log(deviceKindId, deviceId);
129134
const { id, status } = await deviceService.checkDevice(deviceId, lab.value.id);
130135
if (status === 'borrowing') {
131136
} else if (status === 'healthy') {
137+
await addDevice({ kind: deviceKindId!, id: deviceId });
132138
}
133139
}
134140
};

0 commit comments

Comments
 (0)