diff --git a/editor.planx.uk/src/pages/VerifyEmail/VerifyEmail.tsx b/editor.planx.uk/src/pages/VerifyEmail/VerifyEmail.tsx index d80d901a41..5bb972129a 100644 --- a/editor.planx.uk/src/pages/VerifyEmail/VerifyEmail.tsx +++ b/editor.planx.uk/src/pages/VerifyEmail/VerifyEmail.tsx @@ -5,6 +5,7 @@ import Typography from "@mui/material/Typography"; import Card from "@planx/components/shared/Preview/Card"; import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader"; import { useFormik } from "formik"; +import { publicClient } from "lib/graphql"; import React, { useMemo } from "react"; import InputLabel from "ui/public/InputLabel"; import Input from "ui/shared/Input/Input"; @@ -24,25 +25,30 @@ interface VerifyEmailProps { export const VerifyEmail = ({ params }: VerifyEmailProps): JSX.Element => { const { sessionId, team } = params; - // const { data, loading, error } = useQuery( - const { data } = useQuery( + const { data, error, loading } = useQuery( gql` ${TEAM_EMAIL_SETTINGS_QUERY} `, { variables: { slug: team }, - }, + client: publicClient, + skip: !team, + } ); const teamEmail = useMemo( () => data?.teamSettings.submissionEmail || null, - [data], + [data] ); const handleSubmit = (email: string) => { - console.log("need to validate this email!", email); - const url = `${process.env.API_URL_EXT}/download-application-files/${sessionId}?email=${teamEmail}&localAuthority=${team}`; - window.open(url, "_blank"); + if (email === teamEmail) { + const url = `${process.env.API_URL_EXT}/download-application-files/${sessionId}?email=${teamEmail}&localAuthority=${team}`; + window.open(url, "_blank"); + } else { + // handle error + console.error("wrong email!"); + } }; const formik = useFormik({ @@ -60,33 +66,36 @@ export const VerifyEmail = ({ params }: VerifyEmailProps): JSX.Element => { Download your application + {loading && Loading!} - - - - - - - - - - + {!loading && ( + + + + + + + + + + + )} ); }; diff --git a/editor.planx.uk/src/pages/VerifyEmail/queries/TEAM_EMAIL_SETTINGS_QUERY.ts b/editor.planx.uk/src/pages/VerifyEmail/queries/TEAM_EMAIL_SETTINGS_QUERY.ts index a783120146..ddcef5030d 100644 --- a/editor.planx.uk/src/pages/VerifyEmail/queries/TEAM_EMAIL_SETTINGS_QUERY.ts +++ b/editor.planx.uk/src/pages/VerifyEmail/queries/TEAM_EMAIL_SETTINGS_QUERY.ts @@ -1,5 +1,4 @@ -// duplicated from api.planx.uk/modules/send/email/service.ts as it doesn't seem possible to import from there -// it causes "Uncaught ReferenceError: global is not defined" errors +// NOTE this is duplicated from api.planx.uk/modules/send/email/service.ts as it doesn't seem possible to import from there export const TEAM_EMAIL_SETTINGS_QUERY = ` query GetTeamEmailSettings($slug: String) { teams(where: { slug: { _eq: $slug } }) { diff --git a/editor.planx.uk/src/routes/index.tsx b/editor.planx.uk/src/routes/index.tsx index 8ffb089ca1..0548f7ba34 100644 --- a/editor.planx.uk/src/routes/index.tsx +++ b/editor.planx.uk/src/routes/index.tsx @@ -31,7 +31,7 @@ const editorRoutes = mount({ }), ), - ":team/:flow/:sessionId/verify-email": map((req) => { + "/:team/:flow/:sessionId/verify-email": map((req) => { return route({ title: makeTitle("Verify your email"), view: ,