feat: code om klas te joinen klaar
This commit is contained in:
		
							parent
							
								
									65256d1691
								
							
						
					
					
						commit
						bc2ce7fee3
					
				
					 1 changed files with 40 additions and 7 deletions
				
			
		|  | @ -83,23 +83,49 @@ | ||||||
|     // These rules are used to display a message to the user if they use a code that has an invalid format |     // These rules are used to display a message to the user if they use a code that has an invalid format | ||||||
|     const codeRules = [ |     const codeRules = [ | ||||||
|         (value: string | undefined): string | boolean => { |         (value: string | undefined): string | boolean => { | ||||||
|             if (value !== undefined && validate(value) && version(value) === 4) return true; |             if (value === undefined || value === "") { | ||||||
|  |                 return true; | ||||||
|  |             } else if (value !== undefined && validate(value) && version(value) === 4) { | ||||||
|  |                 return true; | ||||||
|  |             } else { | ||||||
|                 return t("invalidFormat"); |                 return t("invalidFormat"); | ||||||
|  |             } | ||||||
|         }, |         }, | ||||||
|     ]; |     ]; | ||||||
| 
 | 
 | ||||||
|     // Used to send the actual class join request |     // Used to send the actual class join request | ||||||
|     const { mutate, isError } = useCreateJoinRequestMutation(); |     const { mutate } = useCreateJoinRequestMutation(); | ||||||
| 
 | 
 | ||||||
|     // Function called when a student submits a code to join a class |     // Function called when a student submits a code to join a class | ||||||
|     function submitCode() { |     function submitCode() { | ||||||
|         // Check if the code is valid |         // Check if the code is valid | ||||||
|         if (code.value !== undefined && validate(code.value) && version(code.value) === 4) { |         if (code.value !== undefined && validate(code.value) && version(code.value) === 4) { | ||||||
|             mutate( { username : username.value! , classId : code.value }); |             mutate( | ||||||
|  |                 { username: username.value!, classId: code.value }, | ||||||
|  |                 { | ||||||
|  |                     onSuccess: () => { | ||||||
|  |                         showSnackbar(t("sent"), "success"); | ||||||
|  |                     }, | ||||||
|  |                     onError: (e) => { | ||||||
|  |                         showSnackbar(t("failed") + ": " + e.message, "error"); | ||||||
|  |                     }, | ||||||
|  |                 }, | ||||||
|  |             ); | ||||||
|  |             code.value = ""; | ||||||
|  |         } | ||||||
|  |     } | ||||||
| 
 | 
 | ||||||
|             console.log("Code submitted:", code.value); |     const snackbar = ref({ | ||||||
|         } |         visible: false, | ||||||
|     } |         message: "", | ||||||
|  |         color: "success", | ||||||
|  |     }); | ||||||
|  | 
 | ||||||
|  |     const showSnackbar = (message: string, color: string) => { | ||||||
|  |         snackbar.value.message = message; | ||||||
|  |         snackbar.value.color = color; | ||||||
|  |         snackbar.value.visible = true; | ||||||
|  |     }; | ||||||
| </script> | </script> | ||||||
| <template> | <template> | ||||||
|     <main> |     <main> | ||||||
|  | @ -217,6 +243,13 @@ | ||||||
|                 </div> |                 </div> | ||||||
|             </div> |             </div> | ||||||
|         </div> |         </div> | ||||||
|  |         <v-snackbar | ||||||
|  |             v-model="snackbar.visible" | ||||||
|  |             :color="snackbar.color" | ||||||
|  |             timeout="3000" | ||||||
|  |         > | ||||||
|  |             {{ snackbar.message }} | ||||||
|  |         </v-snackbar> | ||||||
|     </main> |     </main> | ||||||
| </template> | </template> | ||||||
| <style scoped> | <style scoped> | ||||||
|  |  | ||||||
		Reference in a new issue