@@ -19,6 +19,7 @@ const { data, suspense } = useQuery<ClassroomData[]>({
1919 queryKey: [' /api/reservation/classroomId' ],
2020})
2121await suspense ()
22+ const sortedClassroomData = ref <ClassroomData []>()
2223
2324if (! data .value ) {
2425 toast ({
@@ -27,7 +28,7 @@ if (!data.value) {
2728 })
2829}
2930else {
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 )
3132}
3233
3334const { data : clubs, suspense : clubsSuspense } = useQuery <AllClubs >({
@@ -78,7 +79,7 @@ async function handleSubmit(e: any) {
7879 }
7980 pending .value = true
8081 try {
81- const { data, error } = await useFetch (' /api/reservation/new' , {
82+ const { data : submitData , error } = await useFetch (' /api/reservation/new' , {
8283 method: ' POST' ,
8384 headers: {
8485 ' Content-Type' : ' application/json' ,
@@ -92,7 +93,7 @@ async function handleSubmit(e: any) {
9293 variant: ' destructive' ,
9394 })
9495 }
95- else if (data .value ?.status === ' SUCCESS' ) {
96+ else if (submitData .value ?.status === ' SUCCESS' ) {
9697 toast ({
9798 title: ' 创建成功' ,
9899 description: ' 已成功创建预约记录,你可以在「管理预约」中查看' ,
@@ -106,7 +107,7 @@ async function handleSubmit(e: any) {
106107 formData .value .applicant = ' '
107108 formData .value .note = ' '
108109 }
109- else if (data .value ?.status === ' PRISMA_ERROR' ) {
110+ else if (submitData .value ?.status === ' PRISMA_ERROR' ) {
110111 toast ({
111112 title: ' 数据错误' ,
112113 description: ' 请稍后再试' ,
@@ -132,15 +133,15 @@ async function handleSubmit(e: any) {
132133 <CardDescription >在此处预约教室</CardDescription >
133134 </CardHeader >
134135 <CardContent >
135- <form class =" space-y-2" @submit =" handleSubmit" >
136+ <Form class =" space-y-2" @submit =" handleSubmit" >
136137 <FormField name =" main" >
137138 <FormItem >
138139 <FormLabel >预约时间</FormLabel >
139140 <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 " >
141142 <!-- 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 " >
144145 每周
145146 </div >
146147 <ToggleGroupItem value =" mon" @click =" day[1] = !day[1]" >
@@ -164,7 +165,7 @@ async function handleSubmit(e: any) {
164165 <SelectValue placeholder =" 选择时段" />
165166 </SelectTrigger >
166167 <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" >
168169 {{ enums.periods.map[period] }}
169170 </SelectItem >
170171 </SelectContent >
@@ -175,7 +176,7 @@ async function handleSubmit(e: any) {
175176 <div class =" py-1" />
176177 <FormItem >
177178 <FormLabel >选择教室</FormLabel >
178- <div v-if =" !clubs || !data " >
179+ <div v-if =" !clubs || !sortedClassroomData " >
179180 <Skeleton class =" h-5 p-3 my-3" />
180181 </div >
181182 <FormControl >
@@ -185,7 +186,7 @@ async function handleSubmit(e: any) {
185186 </SelectTrigger >
186187 <!-- Only available classrooms should be filled in the following <SelectContent/> -->
187188 <SelectContent >
188- <SelectGroup v-for =" classroom in data " :key =" classroom.id" >
189+ <SelectGroup v-for =" classroom in sortedClassroomData " :key =" ` classroom-${classroom .id}` " >
189190 <SelectItem :value =" classroom.id.toString()" >
190191 <span class =" inline-block min-w-32 text-left" >
191192 <span class =" inline-block min-w-14" >
@@ -214,23 +215,23 @@ async function handleSubmit(e: any) {
214215 </SelectTrigger >
215216 <SelectContent >
216217 <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) " >
218219 {{ club.name.zh }}
219220 <span class =" inline-block text-gray-500" >
220221 社长
221222 </span >
222223 </SelectItem >
223224 </SelectGroup >
224225 <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) " >
226227 {{ club.name.zh }}
227228 <span class =" inline-block text-gray-500" >
228229 副社
229230 </span >
230231 </SelectItem >
231232 </SelectGroup >
232233 <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) " >
234235 {{ club.name.zh }}
235236 <span class =" inline-block text-gray-500" >
236237 成员
@@ -260,7 +261,7 @@ async function handleSubmit(e: any) {
260261 <span v-if =" !pending" >提交预约</span >
261262 <span v-if =" pending" >处理中...</span >
262263 </Button >
263- </form >
264+ </Form >
264265 </CardContent >
265266 </Card >
266267</template >
0 commit comments