Skip to content

Commit

Permalink
feat: add feature flags support
Browse files Browse the repository at this point in the history
  • Loading branch information
ivorscott committed Nov 26, 2023
1 parent 29ee786 commit b1895f0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 1 deletion.
5 changes: 4 additions & 1 deletion src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,11 @@ import {
import { PinnedProvider } from "services/PinnedProvider";

import awsconfig from "./aws-exports";
import { features } from "./services/FeatureService";
import { theme } from "./theme";

features.applyOverrides();

Amplify.configure({
...awsconfig,
userPoolId: process.env.REACT_APP_USER_POOL_ID,
Expand Down Expand Up @@ -113,7 +116,7 @@ const App = withAuthenticator(
</BrowserRouter>
</QueryClientProvider>
),
{ hideSignUp: true, components }
{ hideSignUp: features.flags["F001"], components }
);

const container = document.getElementById("root");
Expand Down
28 changes: 28 additions & 0 deletions src/services/FeatureService.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
interface Features {
[id: string]: boolean;
}

class FeatureService {
public flags: Features;

constructor() {
this.flags = {
// F001 - Early Access Flow - Users can't sign up on their own
F001: true,
};
}

// applyOverrides reads feature flags from local storage and overrides
// the app's default set of enabled features.
applyOverrides() {
const flags = localStorage.getItem("flags");
if (!flags) {
return;
}

const overrides: Features = JSON.parse(flags);
this.flags = { ...this.flags, ...overrides };
}
}

export const features = new FeatureService();

0 comments on commit b1895f0

Please sign in to comment.