Skip to content

Commit

Permalink
Update for async params
Browse files Browse the repository at this point in the history
  • Loading branch information
acouch committed Jan 15, 2025
1 parent 4c22d83 commit 2e38e4c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 17 deletions.
7 changes: 4 additions & 3 deletions frontend/src/app/[locale]/opportunity/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import OpportunityLink from "src/components/opportunity/OpportunityLink";
import OpportunityStatusWidget from "src/components/opportunity/OpportunityStatusWidget";

type OpportunityListingProps = {
params: { id: string };
params: Promise<{ id: string }>;
} & WithFeatureFlagProps;

export const revalidate = 600; // invalidate ten minutes
Expand Down Expand Up @@ -96,7 +96,8 @@ function emptySummary() {
}

async function OpportunityListing({ params }: OpportunityListingProps) {
const idForParsing = Number(params.id);
const { id } = await params;
const idForParsing = Number(id);
const breadcrumbs = Object.assign([], OPPORTUNITY_CRUMBS);
// Opportunity id needs to be a number greater than 1
if (isNaN(idForParsing) || idForParsing < 1) {
Expand All @@ -105,7 +106,7 @@ async function OpportunityListing({ params }: OpportunityListingProps) {

let opportunityData = {} as Opportunity;
try {
const response = await fetchOpportunity({ subPath: params.id });
const response = await fetchOpportunity({ subPath: id });
opportunityData = response.data;
} catch (error) {
if (parseErrorStatus(error as ApiRequestError) === 404) {
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/app/[locale]/search/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,24 @@
import { SEARCH_CRUMBS } from "src/constants/breadcrumbs";

import { setRequestLocale } from "next-intl/server";
import { use } from "react";

import BetaAlert from "src/components/BetaAlert";
import Breadcrumbs from "src/components/Breadcrumbs";
import SearchCallToAction from "src/components/search/SearchCallToAction";

export default function SearchLayout({
children,
params: { locale },
params
}: {
children: React.ReactNode;
params: {
params: Promise<{
locale: string;
};
}>
}) {
const { locale } = use(params);
setRequestLocale(locale);

return (
<>
<BetaAlert containerClasses="margin-top-5" />
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/app/[locale]/search/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,26 +27,27 @@ export async function generateMetadata({ params }: LocalizedPageProps) {
return meta;
}
type SearchPageProps = {
searchParams: SearchParamsTypes;
searchParams: Promise<SearchParamsTypes>;
params: Promise<{ locale: string }>;
};

function Search({ searchParams, params }: SearchPageProps) {
const { locale } = use(params);
const searchParamsRead = use(searchParams);
setRequestLocale(locale);
const t = useTranslations("Search");

const convertedSearchParams = convertSearchParamsToProperTypes(searchParams);
const convertedSearchParams = convertSearchParamsToProperTypes(searchParamsRead);
const { agency, category, eligibility, fundingInstrument, query, status } =
convertedSearchParams;

if (!("page" in searchParams)) {
searchParams.page = "1";
if (!("page" in searchParamsRead)) {
searchParamsRead.page = "1";
}

return (
<>
<SearchAnalytics params={searchParams} />
<SearchAnalytics params={searchParamsRead} />
<QueryProvider>
<div className="grid-container">
<div className="search-bar">
Expand Down
11 changes: 6 additions & 5 deletions frontend/src/hoc/withFeatureFlag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,17 @@ const withFeatureFlag = <P, R>(
}

// top level component to grab search params from the top level page props
const ComponentWithFeatureFlagAndSearchParams = (
const ComponentWithFeatureFlagAndSearchParams = async (
props: P & WithFeatureFlagProps,
) => {
const searchParams = props.searchParams || {};
const searchParams = await props.searchParams || {};
const cookiesRead = await cookies();
const ComponentWithFeatureFlag = (props: P & WithFeatureFlagProps) => {
if (
featureFlagsManager.isFeatureEnabled(
featureFlagName,
cookies(),
props.searchParams,
cookiesRead,
searchParams,
)
) {
onEnabled();
Expand All @@ -38,7 +39,7 @@ const withFeatureFlag = <P, R>(

return <WrappedComponent {...props} />;
};
return <ComponentWithFeatureFlag {...props} searchParams={searchParams} />;
return <ComponentWithFeatureFlag {...props} searchParams={props.searchParams} />;
};

return ComponentWithFeatureFlagAndSearchParams;
Expand Down
1 change: 1 addition & 0 deletions frontend/src/i18n/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ export default getRequestConfig(async ({ requestLocale }) => {
locale = defaultLocale;
}
return {
locale,
formats,
messages: await getMessagesWithFallbacks(locale),
timeZone,
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/types/uiTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export enum Breakpoints {
}

export type WithFeatureFlagProps = {
searchParams: ServerSideSearchParams;
searchParams: Promise<ServerSideSearchParams>;
};

export interface ErrorProps {
Expand Down

0 comments on commit 2e38e4c

Please sign in to comment.