Skip to content

Commit debbdfd

Browse files
authored
Add missing return statements in sendContactEmail (#2572)
* Add missing return statements in sendContactEmail * Update error display to show Toast notification * Clean up commented code
1 parent 3a64727 commit debbdfd

2 files changed

Lines changed: 8 additions & 17 deletions

File tree

client/src/components/StaticPages/Contact.jsx

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import * as analytics from "../../services/analytics";
1919
import Footer from "../Layout/Footer";
2020
import { useSiteContext } from "contexts/siteContext";
2121
import SEO from "../SEO";
22+
import { useToasterContext } from "contexts/toasterContext";
2223

2324
const validationSchema = Yup.object().shape({
2425
name: Yup.string().required("Please enter your name"),
@@ -94,7 +95,7 @@ const Contact = () => {
9495

9596
const [open, setOpen] = useState(false);
9697
const [submitted, setSubmitted] = useState(false);
97-
const [submitError, setSubmitError] = useState("");
98+
const {setToast} = useToasterContext()
9899
const handleOpen = () => setOpen(true);
99100
const handleClose = () => setOpen(false);
100101
const { isMobile } = useBreakpoints();
@@ -176,12 +177,13 @@ const Contact = () => {
176177
sendContactForm(values)
177178
.then(() => {
178179
setSubmitted(true);
179-
setSubmitError("");
180180
handleOpen();
181181
})
182182
.catch(() => {
183-
setSubmitError(
184-
"There was an error with your submission. Please try again."
183+
setToast({
184+
message:"There was an error with your submission. Please try again.",
185+
type:"error"
186+
}
185187
);
186188
});
187189
}}
@@ -270,17 +272,6 @@ const Contact = () => {
270272
alignItems="center"
271273
gap={isMobile ? 1 : 2}
272274
>
273-
{submitError && (
274-
<Typography
275-
variant="subtitle2"
276-
color="error"
277-
sx={{
278-
marginTop: "-20px",
279-
}}
280-
>
281-
{submitError}
282-
</Typography>
283-
)}
284275
<Button type="submit" disabled={!dirty || !isValid}>
285276
Submit
286277
</Button>

server/app/services/sendgrid-service.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -472,9 +472,9 @@ const sendContactEmail = async ({
472472

473473
return sgMail.send(msg, false, (err) => {
474474
if (err) {
475-
Promise.reject("Sending contact form email failed.");
475+
return Promise.reject("Sending contact form email failed.");
476476
}
477-
Promise.resolve(true).then(() => {
477+
return Promise.resolve(true).then(() => {
478478
if (email) {
479479
sendContactConfirmation({
480480
name,

0 commit comments

Comments
 (0)