From e9d6785c587a9174807262caa12892b5cf70f8e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miko=20Keskim=C3=A4ki?= Date: Fri, 24 Feb 2023 12:08:22 +0200 Subject: [PATCH] Prefill email with user's primary email if available --- src/client/components/ResultPage/EmailForm.tsx | 10 ++++++++-- src/client/components/ResultPage/ProceedSection.tsx | 6 +++++- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/client/components/ResultPage/EmailForm.tsx b/src/client/components/ResultPage/EmailForm.tsx index 5e69bec5..3cfc66d4 100644 --- a/src/client/components/ResultPage/EmailForm.tsx +++ b/src/client/components/ResultPage/EmailForm.tsx @@ -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) @@ -35,7 +41,7 @@ const EmailForm = ({ resultHTML }: { resultHTML: HTMLElement }) => { mode: 'onBlur', resolver: yupResolver(validationSchema), defaultValues: { - email: '', + email: primaryEmail, }, }) diff --git a/src/client/components/ResultPage/ProceedSection.tsx b/src/client/components/ResultPage/ProceedSection.tsx index 3f380a6d..3917d647 100644 --- a/src/client/components/ResultPage/ProceedSection.tsx +++ b/src/client/components/ResultPage/ProceedSection.tsx @@ -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') @@ -53,7 +57,7 @@ const ProceedSection = () => { ) : ( - + )}