feat: validatie voor de code die een student stuurt in de frontend
This commit is contained in:
		
							parent
							
								
									f8cdde7d30
								
							
						
					
					
						commit
						729c3f6972
					
				
					 1 changed files with 50 additions and 51 deletions
				
			
		|  | @ -2,6 +2,8 @@ | ||||||
|     import { useI18n } from "vue-i18n"; |     import { useI18n } from "vue-i18n"; | ||||||
|     import authState from "@/services/auth/auth-service.ts"; |     import authState from "@/services/auth/auth-service.ts"; | ||||||
|     import { ref, watch } from "vue"; |     import { ref, watch } from "vue"; | ||||||
|  |     import { validate, version } from "uuid"; | ||||||
|  | 
 | ||||||
|     const { t } = useI18n(); |     const { t } = useI18n(); | ||||||
| 
 | 
 | ||||||
|     const role: String = authState.authState.activeRole!; |     const role: String = authState.authState.activeRole!; | ||||||
|  | @ -42,10 +44,18 @@ | ||||||
| 
 | 
 | ||||||
|     const classes: Array<Class> = [class01, class02, class03]; |     const classes: Array<Class> = [class01, class02, class03]; | ||||||
| 
 | 
 | ||||||
|     const code = ref(""); |     const valid = ref(false); | ||||||
|     console.log(code); |     const code = ref<string>(""); | ||||||
|  |     const codeRules = [ | ||||||
|  |         (value: string | undefined) => { | ||||||
|  |             if (value !== undefined && validate(value) && version(value) === 4) return true; | ||||||
|  |             return "Invalid format."; | ||||||
|  |         }, | ||||||
|  |     ]; | ||||||
|     watch(code, (newValue) => { |     watch(code, (newValue) => { | ||||||
|  |         if (code.value !== undefined && validate(code.value) && version(code.value) == 4) { | ||||||
|             console.log("Code changed:", newValue); |             console.log("Code changed:", newValue); | ||||||
|  |         } | ||||||
|     }); |     }); | ||||||
| 
 | 
 | ||||||
|     // handle dialog for showing members of a class |     // handle dialog for showing members of a class | ||||||
|  | @ -64,7 +74,7 @@ | ||||||
| <template> | <template> | ||||||
|     <main> |     <main> | ||||||
|         <h class="title">{{ t("classes") }}</h> |         <h class="title">{{ t("classes") }}</h> | ||||||
|         <div v-if="role === 'student'"> | 
 | ||||||
|         <v-table class="table"> |         <v-table class="table"> | ||||||
|             <thead> |             <thead> | ||||||
|                 <tr> |                 <tr> | ||||||
|  | @ -78,30 +88,15 @@ | ||||||
|                     :key="c.id" |                     :key="c.id" | ||||||
|                 > |                 > | ||||||
|                     <td>{{ c.displayName }}</td> |                     <td>{{ c.displayName }}</td> | ||||||
|                         <td class="link" @click="openDialog(c)">{{ c.students.length }}</td> |                     <td | ||||||
|                     </tr> |                         class="link" | ||||||
|                 </tbody> |                         @click="openDialog(c)" | ||||||
|             </v-table> |  | ||||||
|         </div> |  | ||||||
|         <div v-else> |  | ||||||
|             <v-table class="table"> |  | ||||||
|                 <thead> |  | ||||||
|                     <tr> |  | ||||||
|                         <th class="header">{{ t("classes") }}</th> |  | ||||||
|                         <th class="header">{{ t("members") }}</th> |  | ||||||
|                     </tr> |  | ||||||
|                 </thead> |  | ||||||
|                 <tbody> |  | ||||||
|                     <tr |  | ||||||
|                         v-for="c in classes" |  | ||||||
|                         :key="c.id" |  | ||||||
|                     > |                     > | ||||||
|                         <td>{{ c.displayName }}</td> |                         {{ c.students.length }} | ||||||
|                         <td>{{ c.students.length }}</td> |                     </td> | ||||||
|                 </tr> |                 </tr> | ||||||
|             </tbody> |             </tbody> | ||||||
|         </v-table> |         </v-table> | ||||||
|         </div> |  | ||||||
|         <v-dialog |         <v-dialog | ||||||
|             v-model="dialog" |             v-model="dialog" | ||||||
|             width="400" |             width="400" | ||||||
|  | @ -127,16 +122,20 @@ | ||||||
|                 </v-card-actions> |                 </v-card-actions> | ||||||
|             </v-card> |             </v-card> | ||||||
|         </v-dialog> |         </v-dialog> | ||||||
|  |         <div v-if="role === 'student'"> | ||||||
|             <div class="join"> |             <div class="join"> | ||||||
|                 <h1>{{ t("joinClass") }}</h1> |                 <h1>{{ t("joinClass") }}</h1> | ||||||
|                 <p>{{ t("JoinClassExplanation") }}</p> |                 <p>{{ t("JoinClassExplanation") }}</p> | ||||||
| 
 |                 <v-form v-model="valid"> | ||||||
|                     <v-text-field |                     <v-text-field | ||||||
|                         label="CODE" |                         label="CODE" | ||||||
|                         v-model="code" |                         v-model="code" | ||||||
|  |                         :rules="codeRules" | ||||||
|                         variant="outlined" |                         variant="outlined" | ||||||
|                 max-width="300px" |                         max-width="400px" | ||||||
|                     ></v-text-field> |                     ></v-text-field> | ||||||
|  |                 </v-form> | ||||||
|  |             </div> | ||||||
|         </div> |         </div> | ||||||
|     </main> |     </main> | ||||||
| </template> | </template> | ||||||
|  |  | ||||||
		Reference in a new issue
	
	 laurejablonski
						laurejablonski