-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: verify email before downloading application #4000
Open
jamdelion
wants to merge
37
commits into
main
Choose a base branch
from
jh/verify-email-page
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 27 commits
Commits
Show all changes
37 commits
Select commit
Hold shift + click to select a range
40c1f2d
Redirect download link to basic verify email page
jamdelion 766abcc
try to download application file on email submit - no verification
jamdelion 56f08cc
Merge branch 'main' into jh/verify-email-page
jamdelion aff54ca
Fix global import problem
jamdelion e660026
Works with permission error
jamdelion 99a447c
Use existing endpoint to check email address
jamdelion 1c07974
Move helper to utils file
jamdelion 08e62da
Use react query
jamdelion e39f856
Lint fix
jamdelion 2ad7978
Tidy up
jamdelion 139c1d9
Add test todos
jamdelion 5de9aa2
Fix typing
jamdelion 03454a3
Display errors nicely
jamdelion 4260930
Fix error wrapper type issue
jamdelion 725ea12
Revert moving urlWithParams
jamdelion fbcca1f
Update wording to be more appropriate
jamdelion db050b0
Rename files to verifySubmissionEmail
jamdelion 795497a
Rename url to download-application
jamdelion e7c5171
Merge branch 'main' into jh/verify-email-page
jamdelion ce3b34a
Replace react-query with axios
jamdelion 810c7e4
Readd loading state
jamdelion 6c183e4
Add application summary
jamdelion ea18fcf
Add one more test.todo
jamdelion 2147de4
Remove react query
jamdelion a0e28f8
Remove queryProvider
jamdelion c58ef33
Remove rq lint plugin
jamdelion 570df3d
Remove rq from test utils
jamdelion 868c820
Use correct zip filename
jamdelion 2b8c421
Move application summary and capitalise team name
jamdelion 60cd604
Wrap verifySubmissionPage in PlanX headers
jamdelion d35c7da
Revert error typing
jamdelion 9d9e967
Merge branch 'main' into jh/verify-email-page
jamdelion 8aa35df
Merge branch 'main' into jh/verify-email-page
jamdelion 88f1252
Merge branch 'main' into jh/verify-email-page
jamdelion cc6b34c
Account for recent changes to searchParams
jamdelion e577c01
lint
jamdelion bc746c0
Merge branch 'main' into jh/verify-email-page
jamdelion File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
editor.planx.uk/src/pages/SubmissionDownload/VerifySubmissionEmail.stories.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { Meta, StoryObj } from "@storybook/react"; | ||
import React from "react"; | ||
|
||
import { VerifySubmissionEmail } from "./VerifySubmissionEmail"; | ||
|
||
const meta = { | ||
title: "Design System/Pages/VerifySubmissionEmail", | ||
component: VerifySubmissionEmail, | ||
} satisfies Meta<typeof VerifySubmissionEmail>; | ||
|
||
export default meta; | ||
|
||
type Story = StoryObj<typeof meta>; | ||
|
||
export const Basic = { | ||
render: () => ( | ||
<VerifySubmissionEmail params={{ sessionId: "1", team: "PlanX" }} /> | ||
), | ||
}; |
121 changes: 121 additions & 0 deletions
121
editor.planx.uk/src/pages/SubmissionDownload/VerifySubmissionEmail.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
import Box from "@mui/material/Box"; | ||
import Container from "@mui/material/Container"; | ||
import Typography from "@mui/material/Typography"; | ||
import Card from "@planx/components/shared/Preview/Card"; | ||
import { CardHeader } from "@planx/components/shared/Preview/CardHeader/CardHeader"; | ||
import { SummaryListTable } from "@planx/components/shared/Preview/SummaryList"; | ||
import axios, { isAxiosError } from "axios"; | ||
import DelayedLoadingIndicator from "components/DelayedLoadingIndicator/DelayedLoadingIndicator"; | ||
import { useFormik } from "formik"; | ||
import React, { useState } from "react"; | ||
import InputLabel from "ui/public/InputLabel"; | ||
import ErrorWrapper from "ui/shared/ErrorWrapper"; | ||
import Input from "ui/shared/Input/Input"; | ||
import InputRow from "ui/shared/InputRow"; | ||
import { object, string } from "yup"; | ||
|
||
import { downloadZipFile } from "./helpers/downloadZip"; | ||
import { VerifySubmissionEmailProps } from "./types"; | ||
|
||
export const DOWNLOAD_APPLICATION_FILE_URL = `${ | ||
import.meta.env.VITE_APP_API_URL | ||
}/download-application-files`; | ||
|
||
const verifySubmissionEmailSchema = object({ | ||
email: string().email("Invalid email").required("Email address required"), | ||
}); | ||
export const VerifySubmissionEmail = ({ | ||
params, | ||
}: VerifySubmissionEmailProps): JSX.Element => { | ||
const { sessionId, team } = params; | ||
const [downloadApplicationError, setDownloadApplicationError] = useState(""); | ||
const [loading, setLoading] = useState(false); | ||
|
||
const formik = useFormik({ | ||
initialValues: { | ||
email: "", | ||
}, | ||
onSubmit: async (values, { resetForm }) => { | ||
setDownloadApplicationError(""); | ||
setLoading(true); | ||
const url = `${DOWNLOAD_APPLICATION_FILE_URL}/${sessionId}/?email=${encodeURIComponent( | ||
values.email, | ||
)}&localAuthority=${team}`; | ||
try { | ||
const { data } = await axios.get(url, { | ||
responseType: "arraybuffer", | ||
}); | ||
downloadZipFile(data); | ||
resetForm(); | ||
setLoading(false); | ||
} catch (error) { | ||
setLoading(false); | ||
if (isAxiosError(error)) { | ||
setDownloadApplicationError( | ||
"Sorry, something went wrong. Please try again.", | ||
); | ||
resetForm(); | ||
} | ||
console.error(error); | ||
} | ||
}, | ||
validateOnChange: false, | ||
validateOnBlur: false, | ||
validationSchema: verifySubmissionEmailSchema, | ||
}); | ||
return ( | ||
<Container maxWidth="contentWrap"> | ||
<Typography maxWidth="formWrap" variant="h1" pt={5} gutterBottom> | ||
Download application | ||
</Typography> | ||
{loading ? ( | ||
<DelayedLoadingIndicator /> | ||
) : ( | ||
<Box width="100%"> | ||
<Card handleSubmit={formik.handleSubmit}> | ||
<ErrorWrapper error={downloadApplicationError}> | ||
<> | ||
<CardHeader | ||
title="Verify your submission email address" | ||
description="We will use this to confirm that you have access to the submission email inbox that is set up for your team. Entering the correct email address will start the file download automatically." | ||
/> | ||
<InputRow> | ||
<InputLabel label={"Email address"} htmlFor={"email"}> | ||
<Input | ||
bordered | ||
errorMessage={ | ||
formik.touched.email && formik.errors.email | ||
? formik.errors.email | ||
: undefined | ||
} | ||
id="email" | ||
name="email" | ||
onBlur={formik.handleBlur} | ||
onChange={formik.handleChange} | ||
type="email" | ||
value={formik.values.email} | ||
jamdelion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
/> | ||
</InputLabel> | ||
</InputRow> | ||
<Typography | ||
maxWidth="formWrap" | ||
variant="h2" | ||
pt={5} | ||
gutterBottom | ||
> | ||
Application details | ||
</Typography> | ||
<SummaryListTable> | ||
<Box component="dt">Session ID</Box> | ||
<Box component="dd">{sessionId}</Box> | ||
<Box component="dt">Local Authority</Box> | ||
<Box component="dd">{team}</Box> | ||
</SummaryListTable> | ||
</> | ||
</ErrorWrapper> | ||
</Card> | ||
</Box> | ||
)} | ||
</Container> | ||
); | ||
}; |
19 changes: 19 additions & 0 deletions
19
editor.planx.uk/src/pages/SubmissionDownload/helpers/downloadZip.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
export const downloadZipFile = (data: string) => { | ||
if (!data) { | ||
console.error("No data to download"); | ||
return; | ||
} | ||
const blobData = new Blob([data], { type: "application/zip" }); | ||
try { | ||
const href = URL.createObjectURL(blobData); | ||
const link = document.createElement("a"); | ||
link.href = href; | ||
link.setAttribute("download", "application.zip"); | ||
jamdelion marked this conversation as resolved.
Show resolved
Hide resolved
|
||
document.body.appendChild(link); | ||
link.click(); | ||
document.body.removeChild(link); | ||
URL.revokeObjectURL(href); | ||
} catch (error) { | ||
console.error("Error creating object URL:", error); | ||
} | ||
}; |
33 changes: 33 additions & 0 deletions
33
editor.planx.uk/src/pages/SubmissionDownload/tests/VerifySubmissionEmail.test.tsx
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good to see these |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { screen } from "@testing-library/react"; | ||
import React from "react"; | ||
import { setup } from "testUtils"; | ||
|
||
import { VerifySubmissionEmail } from "../VerifySubmissionEmail"; | ||
|
||
describe("when the VerifySubmissionEmail component renders", () => { | ||
it("displays the email address input", () => { | ||
setup(<VerifySubmissionEmail params={{ sessionId: "1" }} />); | ||
|
||
expect( | ||
screen.queryByText("Verify your submission email address"), | ||
).toBeInTheDocument(); | ||
expect(screen.queryByLabelText("Email address")).toBeInTheDocument(); | ||
}); | ||
it.todo("should not display an error message"); | ||
it.todo( | ||
"shows sessionId and local authority in the application details table", | ||
); | ||
}); | ||
|
||
describe("when the user submits a correct email address", () => { | ||
it.todo("displays visual feedback to the user"); | ||
it.todo("downloads the application file"); | ||
}); | ||
|
||
describe("when the user submits an incorrect email address", () => { | ||
it.todo("displays a suitable error message"); | ||
}); | ||
|
||
describe("when user submits an email address and there is a server-side issue", () => { | ||
it.todo("displays a suitable error message"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export interface VerifySubmissionEmailProps { | ||
params: Record<string, string>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Always good to see stories included - appreciate it!