mirror of
				https://github.com/steveiliop56/tinyauth.git
				synced 2025-10-30 21:55:43 +00:00 
			
		
		
		
	
		
			
				
	
	
		
			41 lines
		
	
	
		
			854 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			41 lines
		
	
	
		
			854 B
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
| import { Button, PinInput } from "@mantine/core";
 | |
| import { useForm, zodResolver } from "@mantine/form";
 | |
| import { z } from "zod";
 | |
| 
 | |
| const schema = z.object({
 | |
|   code: z.string(),
 | |
| });
 | |
| 
 | |
| type FormValues = z.infer<typeof schema>;
 | |
| 
 | |
| interface TotpFormProps {
 | |
|   onSubmit: (values: FormValues) => void;
 | |
|   isPending: boolean;
 | |
| }
 | |
| 
 | |
| export const TotpForm = (props: TotpFormProps) => {
 | |
|   const { onSubmit, isPending } = props;
 | |
| 
 | |
|   const form = useForm({
 | |
|     mode: "uncontrolled",
 | |
|     initialValues: {
 | |
|       code: "",
 | |
|     },
 | |
|     validate: zodResolver(schema),
 | |
|   });
 | |
| 
 | |
|   return (
 | |
|     <form onSubmit={form.onSubmit(onSubmit)}>
 | |
|       <PinInput
 | |
|         length={6}
 | |
|         type={"number"}
 | |
|         placeholder=""
 | |
|         {...form.getInputProps("code")}
 | |
|       />
 | |
|       <Button type="submit" mt="xl" loading={isPending} fullWidth>
 | |
|         Verify
 | |
|       </Button>
 | |
|     </form>
 | |
|   );
 | |
| };
 | 
