Skip to content
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] Populate support form from search params #12324

Merged
merged 2 commits into from
Dec 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions apps/playwright/tests/support-page.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,21 @@ test.describe("Support page", () => {
const accessibilityScanResults = await makeAxeBuilder().analyze();
expect(accessibilityScanResults.violations).toEqual([]);
});
test("populates from search param", async ({ page }) => {
await page.goto("/en/support?subject=bug&description=test");
await expect(
page.getByRole("combobox", { name: /looking to/i }),
).toHaveValue("bug");
await expect(page.getByRole("textbox", { name: /details/i })).toHaveValue(
"test",
);
});
test("does not populate invalid subject param", async ({ page }) => {
await page.goto("/en/support?subject=invalid");
await expect(
page.getByRole("combobox", { name: /looking to/i }),
).toHaveValue("");
});
});
test.describe("Support form", () => {
test("send POST request to existing API endpoint", async ({ request }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// Note: Disable camelcase since variables are being used by API
import { FormProvider, SubmitHandler, useForm } from "react-hook-form";
import { defineMessage, useIntl } from "react-intl";
import { useLocation, Location } from "react-router";
import { useLocation, Location, useSearchParams } from "react-router";
import { useQuery } from "urql";
import { ReactNode, useState } from "react";

Expand Down Expand Up @@ -50,6 +50,15 @@ const anchorTag = (chunks: ReactNode) => (
<a href={`mailto:${TALENTSEARCH_SUPPORT_EMAIL}`}>{chunks}</a>
);

const availableSubjects = ["bug", "feedback", "question"];
function defaultSubject(subject?: string | null): string {
if (subject && availableSubjects.includes(subject)) {
return subject;
}

return "";
}

const SupportFormSuccess = ({ onFormToggle }: SupportFormSuccessProps) => {
const intl = useIntl();
return (
Expand Down Expand Up @@ -118,10 +127,13 @@ const SupportForm = ({
}: SupportFormProps) => {
const intl = useIntl();
const location = useLocation() as Location<LocationState>;
const [params] = useSearchParams();
const previousUrl = location?.state?.referrer ?? document?.referrer ?? "";
const userAgent = window?.navigator.userAgent ?? "";
const methods = useForm<FormValues>({
defaultValues: {
subject: defaultSubject(params.get("subject")),
description: params.get("description") ?? "",
user_id: currentUser?.id ?? "",
name: currentUser
? getFullNameLabel(currentUser.firstName, currentUser.lastName, intl)
Expand Down
Loading