Skip to content

Commit

Permalink
Prefill email with user's primary email if available
Browse files Browse the repository at this point in the history
  • Loading branch information
Keskimaki committed Feb 24, 2023
1 parent 4b44075 commit e9d6785
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
10 changes: 8 additions & 2 deletions src/client/components/ResultPage/EmailForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@ import apiClient from '../../util/apiClient'

import styles from './styles'

const EmailForm = ({ resultHTML }: { resultHTML: HTMLElement }) => {
const EmailForm = ({
resultHTML,
primaryEmail = '',
}: {
resultHTML: HTMLElement
primaryEmail: string
}) => {
const { t } = useTranslation()
const [isSent, setIsSent] = useState(false)

Expand All @@ -35,7 +41,7 @@ const EmailForm = ({ resultHTML }: { resultHTML: HTMLElement }) => {
mode: 'onBlur',
resolver: yupResolver(validationSchema),
defaultValues: {
email: '',
email: primaryEmail,
},
})

Expand Down
6 changes: 5 additions & 1 deletion src/client/components/ResultPage/ProceedSection.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,14 @@ import { Box, Button, Container, Stack, Typography } from '@mui/material'

import styles from './styles'
import EmailForm from './EmailForm'
import useLoggedInUser from '../../hooks/useLoggedInUser'

const ProceedSection = () => {
const { t } = useTranslation()
const [openMailPrompt, setOpenMailPrompt] = useState(false)
const { user, isLoading } = useLoggedInUser()

if (isLoading) return null

const resultHTML = document.getElementById('result-component')

Expand Down Expand Up @@ -53,7 +57,7 @@ const ProceedSection = () => {
</Button>
</>
) : (
<EmailForm resultHTML={resultHTML} />
<EmailForm resultHTML={resultHTML} primaryEmail={user?.email} />
)}
</Stack>
</Box>
Expand Down

0 comments on commit e9d6785

Please sign in to comment.