Skip to content

Commit

Permalink
feat: added T&C consent to file upload and refactor feature flags
Browse files Browse the repository at this point in the history
  • Loading branch information
atrincas committed Jan 8, 2025
1 parent efd07e7 commit 7dfff7d
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 10 deletions.
17 changes: 17 additions & 0 deletions client/src/containers/profile/file-upload/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@ import React, { FC, useCallback, useState } from "react";

import { useDropzone } from "react-dropzone";

import Link from "next/link";

import { FileUpIcon, XIcon } from "lucide-react";
import { useSession } from "next-auth/react";

import { TERMS_AND_CONDITIONS_URL } from "@/lib/constants";
import { client } from "@/lib/query-client";
import { cn } from "@/lib/utils";

Expand Down Expand Up @@ -173,6 +176,20 @@ const FileUpload: FC = () => {
</div>
</div>
)}
<p className="text-sm text-muted-foreground">
By sharing your data with us, you consent to being contacted for future
follow-ups. For more details, please review our&nbsp;
<Button
variant="link"
className="h-auto p-0 text-sm text-muted-foreground underline underline-offset-auto"
asChild
>
<Link href={TERMS_AND_CONDITIONS_URL} target="_blank">
Terms and Conditions
</Link>
</Button>
.
</p>
</div>
);
};
Expand Down
50 changes: 40 additions & 10 deletions client/src/hooks/use-feature-flags.ts
Original file line number Diff line number Diff line change
@@ -1,30 +1,60 @@
const FEATURE_FLAGS = {
import { useMemo } from "react";

interface FeatureFlags {
/** Controls whether users can edit project details and settings in:
* - /projects/custom-project/details
* - /projects/custom-project/summary
*/
"edit-project": false,
"edit-project": boolean;

/** Controls the visibility and sharing functionality in:
* - /profile
*/
"share-information": false,
"share-information": boolean;
/** Controls the project comparison functionality in:
* - /overview/project-details (scorecard ratings and cost estimates comparison)
*/
"project-comparison": false,
"project-comparison": boolean;
/** Controls the actions dropdown functionality in:
* - /my-projects table
*/
"update-selection": false,
"update-selection": boolean;
/** Controls the visibility of the methodology page */
"methodology-page": boolean;
"compare-with-other-project": boolean;
}

const DEFAULT_FEATURE_FLAGS: FeatureFlags = {
"edit-project": false,
"share-information": false,
"project-comparison": false,
"update-selection": false,
"methodology-page": false,
"compare-with-other-project": false,
} as const;

type FeatureFlags = typeof FEATURE_FLAGS;
};

/**
* Hook to get the feature flags for the current user.
* Checks the environment variable FEATURE_FLAGS to see which flags are enabled.
* If the environment variable is not set, falls back to default flags.
*
* @returns The feature flags for the current user.
*/
export function useFeatureFlags(): FeatureFlags {
// TODO: Implement feature flags with env variable
return FEATURE_FLAGS;
return useMemo(() => {
const enabledFeatures = new Set(
process.env.NEXT_PUBLIC_FEATURE_FLAGS?.split(",").map((f) => f.trim()) ||
[],
);

return (
Object.keys(DEFAULT_FEATURE_FLAGS) as Array<keyof FeatureFlags>
).reduce(
(flags, key) => ({
...flags,
[key]: enabledFeatures.has(key) || DEFAULT_FEATURE_FLAGS[key],
}),
{} as FeatureFlags,
);
}, []);
}

0 comments on commit 7dfff7d

Please sign in to comment.