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(feature-flag): add feature flag from gb #1462

Merged
merged 3 commits into from
Aug 30, 2023
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
3 changes: 3 additions & 0 deletions src/constants/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const FEATURE_FLAGS = {
STYLING_REVAMP: "styles",
} as const
14 changes: 9 additions & 5 deletions src/layouts/FeatureFlaggedContactUs.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { useFeatureIsOn } from "@growthbook/growthbook-react"
import { useParams } from "react-router-dom"

import { OGP_SITES, TESTING_SITES } from "constants/sites"
import { FEATURE_FLAGS } from "constants/featureFlags"

import { FeatureFlags } from "types/featureFlags"

import EditContactUs from "./EditContactUs"
import LegacyEditContactUs from "./LegacyEditContactUs"

export const FeatureFlaggedContactUs = (): JSX.Element => {
const params = useParams<{ siteName: string }>()
const isOgpSite =
OGP_SITES.includes(params.siteName) ||
TESTING_SITES.includes(params.siteName)
return isOgpSite ? (
const shouldShowNewStyles = useFeatureIsOn<FeatureFlags>(
FEATURE_FLAGS.STYLING_REVAMP
)

return shouldShowNewStyles ? (
<EditContactUs match={{ params }} />
) : (
<LegacyEditContactUs match={{ params }} />
Expand Down
14 changes: 9 additions & 5 deletions src/layouts/FeatureFlaggedHomepage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { useFeatureIsOn } from "@growthbook/growthbook-react"
import { useParams } from "react-router-dom"

import { OGP_SITES, TESTING_SITES } from "constants/sites"
import { FEATURE_FLAGS } from "constants/featureFlags"

import { FeatureFlags } from "types/featureFlags"

import EditHomepage from "./EditHomepage"
import LegacyEditHomepage from "./LegacyEditHomepage/LegacyEditHomepage"

export const FeatureFlaggedHomepage = (): JSX.Element => {
const params = useParams<{ siteName: string }>()
const isOgpSite =
OGP_SITES.includes(params.siteName) ||
TESTING_SITES.includes(params.siteName)
return isOgpSite ? (
const shouldShowNewStyles = useFeatureIsOn<FeatureFlags>(
FEATURE_FLAGS.STYLING_REVAMP
)

return shouldShowNewStyles ? (
<EditHomepage match={{ params }} />
) : (
<LegacyEditHomepage match={{ params }} />
Expand Down
14 changes: 9 additions & 5 deletions src/layouts/FeatureFlaggedNavBar.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
import { useFeatureIsOn } from "@growthbook/growthbook-react"
import { useParams } from "react-router-dom"

import { OGP_SITES, TESTING_SITES } from "constants/sites"
import { FEATURE_FLAGS } from "constants/featureFlags"

import { FeatureFlags } from "types/featureFlags"

import EditNavBar from "./EditNavBar"
import LegacyEditNavBar from "./LegacyEditNavBar"

export const FeatureFlaggedNavBar = (): JSX.Element => {
const params = useParams<{ siteName: string }>()
const isOgpSite =
OGP_SITES.includes(params.siteName) ||
TESTING_SITES.includes(params.siteName)
return isOgpSite ? (
const shouldShowNewStyles = useFeatureIsOn<FeatureFlags>(
FEATURE_FLAGS.STYLING_REVAMP
)

return shouldShowNewStyles ? (
<EditNavBar match={{ params }} />
) : (
<LegacyEditNavBar match={{ params }} />
Expand Down
9 changes: 5 additions & 4 deletions src/types/featureFlags.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { FEATURE_FLAGS } from "constants/featureFlags"

// Example usage: const gb = useGrowthBook<FeatureFlags>();
// export interface FeatureFlags {
// sampleFlag: string
// sampleFlag2: boolean
// }
export interface FeatureFlags {
[FEATURE_FLAGS.STYLING_REVAMP]: boolean
}

export type GBAttributes = {
userId: string
Expand Down