Skip to content

Commit

Permalink
Merge pull request #4179 from cds-snc/fix/perf-issues
Browse files Browse the repository at this point in the history
* Move redirects from server to client on Contact and Support
  • Loading branch information
ShadeWyrm authored Aug 8, 2024
2 parents b960d03 + 3b53550 commit 1c79684
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 7 deletions.
4 changes: 1 addition & 3 deletions app/(gcforms)/[locale]/(support)/contact/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import { serverTranslation } from "@i18n";
import { createTicket } from "@lib/integration/freshdesk";
import { logMessage } from "@lib/logger";
import { redirect } from "next/navigation";
import { email, minLength, object, safeParse, string, toLowerCase, toTrimmed } from "valibot";

export interface ErrorStates {
Expand Down Expand Up @@ -121,6 +120,5 @@ ${description}<br/>
logMessage.error(`Failed to send contact request: ${(error as Error).message}`);
return { error: "Internal Service Error: Failed to send request", validationErrors: [] };
}
// The redirect must be outside of the try/catch block to avoid the NEXT_REDIRECT being caught by the error boundary
redirect(`/${language}/contact?success`);
return { error: "", validationErrors: [] };
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TextInput } from "../../../components/client/TextInput";
import { MultipleChoiceGroup } from "../../../components/client/MultipleChoiceGroup";
import { TextArea } from "../../../components/client/TextArea";
import { SubmitButton } from "../../../components/client/SubmitButton";
import { redirect } from "next/navigation";

export const ContactForm = () => {
const {
Expand All @@ -28,6 +29,11 @@ export const ContactForm = () => {
return state.validationErrors.find((e) => e.fieldKey === fieldKey)?.fieldValue || "";
};

if (state.error === "") {
//Route through the client.
redirect(`/${language}/contact?success`);
}

return (
<>
{/* @todo Add general error to show user there was an internal service error */}
Expand Down
5 changes: 2 additions & 3 deletions app/(gcforms)/[locale]/(support)/support/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { serverTranslation } from "@i18n";
import { createTicket } from "@lib/integration/freshdesk";
import { logMessage } from "@lib/logger";
import { redirect } from "next/navigation";

import { email, minLength, object, safeParse, string, toLowerCase, toTrimmed } from "valibot";

export interface ErrorStates {
Expand Down Expand Up @@ -97,6 +97,5 @@ ${description}<br/>
logMessage.error(`Failed to send support request: ${(error as Error).message}`);
return { error: "Internal Service Error: Failed to send request", validationErrors: [] };
}
// The redirect must be outside of the try/catch block to avoid the NEXT_REDIRECT being caught by the error boundary
redirect(`/${language}/support?success`);
return { error: "", validationErrors: [] };
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import { TextInput } from "../../../components/client/TextInput";
import { MultipleChoiceGroup } from "../../../components/client/MultipleChoiceGroup";
import { TextArea } from "../../../components/client/TextArea";
import { SubmitButton } from "../../../components/client/SubmitButton";
import { redirect } from "next/navigation";

export const SupportForm = () => {
const {
Expand All @@ -28,6 +29,11 @@ export const SupportForm = () => {
return state.validationErrors.find((e) => e.fieldKey === fieldKey)?.fieldValue || "";
};

if (state.error === "") {
//Route through the client.
redirect(`/${language}/support?success`);
}

return (
<>
{/* @todo Add general error to show user there was an internal service error */}
Expand Down Expand Up @@ -56,7 +62,9 @@ export const SupportForm = () => {
<h1>{t("support.title")}</h1>
<p className="mb-6 mt-[-2rem] text-[1.6rem]">
{t("support.experience")}
<Link href={`https://articles.alpha.canada.ca/forms-formulaires/${language}/guidance`}>{t("support.guidanceLink")}</Link>
<Link href={`https://articles.alpha.canada.ca/forms-formulaires/${language}/guidance`}>
{t("support.guidanceLink")}
</Link>
{t("support.useThisForm")}
</p>
<p className="mb-14">
Expand Down

0 comments on commit 1c79684

Please sign in to comment.