Skip to content
Snippets Groups Projects
Verified Commit 50275205 authored by Andreas Ellewsen's avatar Andreas Ellewsen
Browse files

Add label to email field

parent 44f7d800
No related branches found
No related tags found
1 merge request!181Add label to email field
Pipeline #101640 passed
...@@ -22,7 +22,7 @@ import { ...@@ -22,7 +22,7 @@ import {
import { Guest } from 'interfaces' import { Guest } from 'interfaces'
import SponsorInfoButtons from 'routes/components/sponsorInfoButtons' import SponsorInfoButtons from 'routes/components/sponsorInfoButtons'
import { useEffect, useState } from 'react' import { useEffect, useState } from 'react'
import { SubmitHandler, useForm } from 'react-hook-form' import { SubmitHandler, useForm, Controller } from 'react-hook-form'
import IdentityLine from 'components/identityLine' import IdentityLine from 'components/identityLine'
import { isValidEmail, submitJsonOpts } from 'utils' import { isValidEmail, submitJsonOpts } from 'utils'
...@@ -93,13 +93,19 @@ export default function GuestInfo({ ...@@ -93,13 +93,19 @@ export default function GuestInfo({
const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false) const [confirmationDialogOpen, setConfirmationDialogOpen] = useState(false)
const [emailDirty, setEmailDirty] = useState(false) const [emailDirty, setEmailDirty] = useState(false)
const defaultValues = {
email: guest.email,
}
// Using useForm even though only the e-mail is allow to change at present, since useForm makes setup and validation easier // Using useForm even though only the e-mail is allow to change at present, since useForm makes setup and validation easier
const { const {
register,
handleSubmit, handleSubmit,
setValue, setValue,
control,
formState: { errors }, formState: { errors },
} = useForm<Email>({ mode: 'onChange' }) } = useForm({
mode: 'onChange',
defaultValues,
})
useEffect(() => { useEffect(() => {
setValue('email', guest.email) setValue('email', guest.email)
...@@ -150,6 +156,7 @@ export default function GuestInfo({ ...@@ -150,6 +156,7 @@ export default function GuestInfo({
} }
const emailFieldChange = (event: any) => { const emailFieldChange = (event: any) => {
setValue('email', event.target.value)
if (event.target.value !== guest.email) { if (event.target.value !== guest.email) {
setEmailDirty(true) setEmailDirty(true)
} else { } else {
...@@ -188,14 +195,23 @@ export default function GuestInfo({ ...@@ -188,14 +195,23 @@ export default function GuestInfo({
justifyContent: 'flex-start', justifyContent: 'flex-start',
}} }}
> >
<TextField <Controller
id="email" name="email"
error={!!errors.email} control={control}
helperText={errors.email && errors.email.message} rules={{
{...register(`email`, {
validate: isValidEmail, validate: isValidEmail,
})} }}
onChange={emailFieldChange} render={({ field: { value }, ...rest }) => (
<TextField
id="email"
label={t('input.email')}
error={!!errors.email}
helperText={errors.email && errors.email.message}
value={value}
{...rest}
onChange={emailFieldChange}
/>
)}
/> />
{/* If the guest has not completed the registration process, he should have an invitation he has not responded to */} {/* If the guest has not completed the registration process, he should have an invitation he has not responded to */}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment