Skip to content

Commit

Permalink
Add provinces Autocomplete
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisvasqm committed Apr 30, 2024
1 parent 40fa0b4 commit b92a857
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions src/pages/StudentsPage.tsx
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup, Stack, TextField, Typography } from '@mui/material'
import { Autocomplete, Box, Button, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, FormControl, FormControlLabel, FormLabel, Radio, RadioGroup, Stack, TextField, Typography } from '@mui/material'
import { DatePicker } from '@mui/x-date-pickers'
import dayjs from 'dayjs'
import { matchIsValidTel, MuiTelInput } from 'mui-tel-input'
import { useState } from 'react'
import { Controller, useForm } from 'react-hook-form'
import { z } from 'zod'
import provinces from '../data/provinces'

const schema = z.object({
firstName: z.string().min(1, 'First Name must have at least 1 character'),
lastName: z.string().min(1, 'Last Name must have at least 1 character'),
email: z.string().email('Invalid email'),
phone: z.string().min(15).max(15)
phone: z.string().min(15).max(15),
provinces: z.enum(provinces)
})

type FormData = z.infer<typeof schema>
Expand Down Expand Up @@ -119,6 +121,30 @@ const StudentsPage = () => {
maxDate={maximumDate}
onChange={date => setSelectedBirthDate(date?.toDate().toLocaleDateString()!)} />

<Controller
name="provinces"
control={control}
render={({ field, fieldState }) => {
return (
<Autocomplete
{...field}
options={provinces}
renderInput={(params) => (
<TextField
{...params}
id={field.name}
label="Choose a province"
variant="outlined"
error={!!fieldState.error}
helperText={fieldState.error?.message ? 'Invalid province' : ''}
/>
)}
onChange={(_, data) => field.onChange(data)}
/>
);
}}
/>

<Button
id='register'
type='submit'
Expand Down

0 comments on commit b92a857

Please sign in to comment.