Skip to content

Commit

Permalink
cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
doug-s-nava committed Dec 5, 2024
1 parent 739685d commit 344affb
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 110 deletions.
112 changes: 52 additions & 60 deletions frontend/src/app/[locale]/opportunity/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import { OPPORTUNITY_CRUMBS } from "src/constants/breadcrumbs";
import { ApiRequestError, parseErrorStatus } from "src/errors";
import withFeatureFlagStatic from "src/hoc/search/withFeatureFlagStatic";
import { Opportunity } from "src/types/opportunity/opportunityResponseTypes";
import { WithFeatureFlagProps } from "src/types/uiTypes";

import { getTranslations } from "next-intl/server";
import { notFound, redirect } from "next/navigation";
Expand All @@ -23,8 +22,6 @@ import OpportunityLink from "src/components/opportunity/OpportunityLink";
import OpportunityStatusWidget from "src/components/opportunity/OpportunityStatusWidget";

type OpportunityListingProps = { params: { id: string } };
type WrappedOpportunityListingProps = OpportunityListingProps &
WithFeatureFlagProps;

export const revalidate = 600; // invalidate ten minutes

Expand Down Expand Up @@ -90,73 +87,68 @@ function emptySummary() {
}

async function OpportunityListing({ params }: OpportunityListingProps) {
const idForParsing = Number(params.id);
const breadcrumbs = Object.assign([], OPPORTUNITY_CRUMBS);
// Opportunity id needs to be a number greater than 1
if (isNaN(idForParsing) || idForParsing < 1) {
return <NotFound />;
}

let opportunityData = {} as Opportunity;
try {
const idForParsing = Number(params.id);
const breadcrumbs = Object.assign([], OPPORTUNITY_CRUMBS);
// Opportunity id needs to be a number greater than 1
if (isNaN(idForParsing) || idForParsing < 1) {
const response = await fetchOpportunity({ subPath: params.id });
opportunityData = response.data;
} catch (error) {
if (parseErrorStatus(error as ApiRequestError) === 404) {
return <NotFound />;
}
throw error;
}
opportunityData.summary = opportunityData?.summary
? opportunityData.summary
: emptySummary();

let opportunityData = {} as Opportunity;
try {
const response = await fetchOpportunity({ subPath: params.id });
opportunityData = response.data;
} catch (error) {
if (parseErrorStatus(error as ApiRequestError) === 404) {
return <NotFound />;
}
throw error;
}
opportunityData.summary = opportunityData?.summary
? opportunityData.summary
: emptySummary();

breadcrumbs.push({
title: `${opportunityData.opportunity_title}: ${opportunityData.opportunity_number}`,
path: `/opportunity/${opportunityData.opportunity_id}/`, // unused but required in breadcrumb implementation
});
breadcrumbs.push({
title: `${opportunityData.opportunity_title}: ${opportunityData.opportunity_number}`,
path: `/opportunity/${opportunityData.opportunity_id}/`, // unused but required in breadcrumb implementation
});

const nofoPath =
opportunityData.attachments.filter(
(document) =>
document.opportunity_attachment_type ===
"notice_of_funding_opportunity",
)[0]?.download_path || "";
const nofoPath =
opportunityData.attachments.filter(
(document) =>
document.opportunity_attachment_type ===
"notice_of_funding_opportunity",
)[0]?.download_path || "";

return (
<div>
<BetaAlert />
<Breadcrumbs breadcrumbList={breadcrumbs} />
<OpportunityIntro opportunityData={opportunityData} />
<GridContainer>
<div className="grid-row grid-gap">
<div className="desktop:grid-col-8 tablet:grid-col-12 tablet:order-1 desktop:order-first">
<OpportunityDescription
summary={opportunityData.summary}
nofoPath={nofoPath}
/>
<OpportunityDocuments documents={opportunityData.attachments} />
<OpportunityLink opportunityData={opportunityData} />
</div>
return (
<div>
<BetaAlert />
<Breadcrumbs breadcrumbList={breadcrumbs} />
<OpportunityIntro opportunityData={opportunityData} />
<GridContainer>
<div className="grid-row grid-gap">
<div className="desktop:grid-col-8 tablet:grid-col-12 tablet:order-1 desktop:order-first">
<OpportunityDescription
summary={opportunityData.summary}
nofoPath={nofoPath}
/>
<OpportunityDocuments documents={opportunityData.attachments} />
<OpportunityLink opportunityData={opportunityData} />
</div>

<div className="desktop:grid-col-4 tablet:grid-col-12 tablet:order-0">
<OpportunityStatusWidget opportunityData={opportunityData} />
<OpportunityCTA id={opportunityData.opportunity_id} />
<OpportunityAwardInfo opportunityData={opportunityData} />
<OpportunityHistory summary={opportunityData.summary} />
</div>
<div className="desktop:grid-col-4 tablet:grid-col-12 tablet:order-0">
<OpportunityStatusWidget opportunityData={opportunityData} />
<OpportunityCTA id={opportunityData.opportunity_id} />
<OpportunityAwardInfo opportunityData={opportunityData} />
<OpportunityHistory summary={opportunityData.summary} />
</div>
</GridContainer>
</div>
);
} catch (e) {
console.error("^^^ caught the error", e);
return <div>e</div>;
}
</div>
</GridContainer>
</div>
);
}

export default withFeatureFlagStatic<WrappedOpportunityListingProps, never>(
export default withFeatureFlagStatic<OpportunityListingProps, never>(
OpportunityListing,
"opportunityOff",
() => redirect("/maintenance"),
Expand Down
43 changes: 0 additions & 43 deletions frontend/src/hoc/search/withFeatureFlag.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,47 +23,4 @@ const withFeatureFlag = <P extends WithFeatureFlagProps, R>(
return ComponentWithFeatureFlag;
};

export const withFeatureFlagStatic = <P extends WithFeatureFlagProps, R>(
WrappedComponent: ComponentType<P>,
featureFlagName: string,
onEnabled: () => R,
) => {
const ComponentWithFeatureFlag = (props: P) => {
const featureFlagsManager = new FeatureFlagsManager();
const { searchParams } = props;

if (featureFlagsManager.isFeatureEnabled(featureFlagName, searchParams)) {
return onEnabled();
}

return <WrappedComponent {...props} />;
};

return ComponentWithFeatureFlag;
};

// const withFeatureFlag = <P extends WithFeatureFlagProps, R>(
// WrappedComponent: ComponentType<P>,
// featureFlagName: string,
// onEnabled: () => R,
// ) =>
// wrapComponentWithFeatureFlag<P, R>(
// WrappedComponent,
// featureFlagName,
// onEnabled,
// new FeatureFlagsManager(cookies()),
// );

// export const withStaticFeatureFlag = <P extends WithFeatureFlagProps, R>(
// WrappedComponent: ComponentType<P>,
// featureFlagName: string,
// onEnabled: () => R,
// ) =>
// wrapComponentWithFeatureFlag<P, R>(
// WrappedComponent,
// featureFlagName,
// onEnabled,
// new FeatureFlagsManager(),
// );

export default withFeatureFlag;
9 changes: 2 additions & 7 deletions frontend/src/hoc/search/withFeatureFlagStatic.tsx
Original file line number Diff line number Diff line change
@@ -1,26 +1,21 @@
import { FeatureFlagsManager } from "src/services/FeatureFlagManager";
import { WithFeatureFlagProps } from "src/types/uiTypes";
import { ServerSideSearchParams } from "src/types/searchRequestURLTypes";

import React, { ComponentType } from "react";

export const withFeatureFlagStatic = <P extends WithFeatureFlagProps, R>(
export const withFeatureFlagStatic = <P extends ServerSideSearchParams, R>(
WrappedComponent: ComponentType<P>,
featureFlagName: string,
onEnabled: () => R,
) => {
const ComponentWithFeatureFlag = (props: P) => {
// try {
const featureFlagsManager = new FeatureFlagsManager();

if (featureFlagsManager.isFeatureEnabled(featureFlagName)) {
return onEnabled();
}

return <WrappedComponent {...props} />;
// } catch (e) {
// console.error("^^^ caught in wrapped component", e);
// return <div>hi</div>;
// }
};

return ComponentWithFeatureFlag;
Expand Down

0 comments on commit 344affb

Please sign in to comment.