@@ -19,6 +19,7 @@ const { data, suspense } = useQuery<ClassroomData[]>({
19
19
queryKey: [' /api/reservation/classroomId' ],
20
20
})
21
21
await suspense ()
22
+ const sortedClassroomData = ref <ClassroomData []>()
22
23
23
24
if (! data .value ) {
24
25
toast ({
@@ -27,7 +28,7 @@ if (!data.value) {
27
28
})
28
29
}
29
30
else {
30
- data .value = data .value .sort ((a : any , b : any ) => a .name < b .name ? - 1 : 1 )
31
+ sortedClassroomData .value = [ ... data .value ] .sort ((a : any , b : any ) => a .name < b .name ? - 1 : 1 )
31
32
}
32
33
33
34
const { data : clubs, suspense : clubsSuspense } = useQuery <AllClubs >({
@@ -78,7 +79,7 @@ async function handleSubmit(e: any) {
78
79
}
79
80
pending .value = true
80
81
try {
81
- const { data, error } = await useFetch (' /api/reservation/new' , {
82
+ const { data : submitData , error } = await useFetch (' /api/reservation/new' , {
82
83
method: ' POST' ,
83
84
headers: {
84
85
' Content-Type' : ' application/json' ,
@@ -92,7 +93,7 @@ async function handleSubmit(e: any) {
92
93
variant: ' destructive' ,
93
94
})
94
95
}
95
- else if (data .value ?.status === ' SUCCESS' ) {
96
+ else if (submitData .value ?.status === ' SUCCESS' ) {
96
97
toast ({
97
98
title: ' 创建成功' ,
98
99
description: ' 已成功创建预约记录,你可以在「管理预约」中查看' ,
@@ -106,7 +107,7 @@ async function handleSubmit(e: any) {
106
107
formData .value .applicant = ' '
107
108
formData .value .note = ' '
108
109
}
109
- else if (data .value ?.status === ' PRISMA_ERROR' ) {
110
+ else if (submitData .value ?.status === ' PRISMA_ERROR' ) {
110
111
toast ({
111
112
title: ' 数据错误' ,
112
113
description: ' 请稍后再试' ,
@@ -132,15 +133,15 @@ async function handleSubmit(e: any) {
132
133
<CardDescription >在此处预约教室</CardDescription >
133
134
</CardHeader >
134
135
<CardContent >
135
- <form class =" space-y-2" @submit =" handleSubmit" >
136
+ <Form class =" space-y-2" @submit =" handleSubmit" >
136
137
<FormField name =" main" >
137
138
<FormItem >
138
139
<FormLabel >预约时间</FormLabel >
139
140
<FormControl >
140
- <div class =" flex flex-col sm:flex-row space-y-2 sm:space-y-0 sm:space-x-1 justify-start " >
141
+ <div class =" flex flex-col justify-start sm:flex-row space-y-2 sm:space-x-1 sm:space-y-0 " >
141
142
<!-- This ToggleGroup should be implemented in a better way but anyway it works -->
142
- <ToggleGroup :key =" reloadKey" type =" multiple" variant =" outline" >
143
- <div class =" text-muted-foreground text-sm text-center w-7 " >
143
+ <ToggleGroup :key =" ` reloadKey-${reloadKey}` " type =" multiple" variant =" outline" >
144
+ <div class =" w-7 text-center text-sm text-muted-foreground " >
144
145
每周
145
146
</div >
146
147
<ToggleGroupItem value =" mon" @click =" day[1] = !day[1]" >
@@ -164,7 +165,7 @@ async function handleSubmit(e: any) {
164
165
<SelectValue placeholder =" 选择时段" />
165
166
</SelectTrigger >
166
167
<SelectContent >
167
- <SelectItem v-for =" period in enums.periods.values" :key =" period" :value =" period" >
168
+ <SelectItem v-for =" period in enums.periods.values" :key =" ` period-${period}` " :value =" period" >
168
169
{{ enums.periods.map[period] }}
169
170
</SelectItem >
170
171
</SelectContent >
@@ -175,7 +176,7 @@ async function handleSubmit(e: any) {
175
176
<div class =" py-1" />
176
177
<FormItem >
177
178
<FormLabel >选择教室</FormLabel >
178
- <div v-if =" !clubs || !data " >
179
+ <div v-if =" !clubs || !sortedClassroomData " >
179
180
<Skeleton class =" h-5 p-3 my-3" />
180
181
</div >
181
182
<FormControl >
@@ -185,7 +186,7 @@ async function handleSubmit(e: any) {
185
186
</SelectTrigger >
186
187
<!-- Only available classrooms should be filled in the following <SelectContent/> -->
187
188
<SelectContent >
188
- <SelectGroup v-for =" classroom in data " :key =" classroom.id" >
189
+ <SelectGroup v-for =" classroom in sortedClassroomData " :key =" ` classroom-${classroom .id}` " >
189
190
<SelectItem :value =" classroom.id.toString()" >
190
191
<span class =" inline-block min-w-32 text-left" >
191
192
<span class =" inline-block min-w-14" >
@@ -214,23 +215,23 @@ async function handleSubmit(e: any) {
214
215
</SelectTrigger >
215
216
<SelectContent >
216
217
<SelectGroup v-if =" clubs?.president && clubs?.president.length" >
217
- <SelectItem v-for =" club in clubs?.president" :key =" club.id" :value =" club.id" >
218
+ <SelectItem v-for =" club in clubs?.president" :key =" ` club-${club .id}` " :value =" String( club.id) " >
218
219
{{ club.name.zh }}
219
220
<span class =" inline-block text-gray-500" >
220
221
社长
221
222
</span >
222
223
</SelectItem >
223
224
</SelectGroup >
224
225
<SelectGroup v-if =" clubs?.vice && clubs?.vice.length" >
225
- <SelectItem v-for =" club in clubs?.vice" :key =" club.id" :value =" club.id" >
226
+ <SelectItem v-for =" club in clubs?.vice" :key =" ` club-${club .id}` " :value =" String( club.id) " >
226
227
{{ club.name.zh }}
227
228
<span class =" inline-block text-gray-500" >
228
229
副社
229
230
</span >
230
231
</SelectItem >
231
232
</SelectGroup >
232
233
<SelectGroup v-if =" clubs?.member && clubs?.member.length" >
233
- <SelectItem v-for =" club in clubs?.member" :key =" club.id" :value =" club.id" >
234
+ <SelectItem v-for =" club in clubs?.member" :key =" ` club-${club .id}` " :value =" String( club.id) " >
234
235
{{ club.name.zh }}
235
236
<span class =" inline-block text-gray-500" >
236
237
成员
@@ -260,7 +261,7 @@ async function handleSubmit(e: any) {
260
261
<span v-if =" !pending" >提交预约</span >
261
262
<span v-if =" pending" >处理中...</span >
262
263
</Button >
263
- </form >
264
+ </Form >
264
265
</CardContent >
265
266
</Card >
266
267
</template >
0 commit comments