Skip to content

Commit

Permalink
refactor app
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Poignant <[email protected]>
  • Loading branch information
thomaspoignant committed Dec 18, 2024
1 parent 994e0d0 commit 91d5467
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 1 deletion.
6 changes: 6 additions & 0 deletions examples/openfeature_react/react-app/postcss.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
1 change: 0 additions & 1 deletion examples/openfeature_react/react-app/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ function Page() {
OpenFeature.setContext(ctx);
}


return (
<>
<div className="flex justify-center items-center pt-10">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import {existingUsers} from "../service/login.tsx";

export const AccountSelector = ({onChange}: { onChange: (name: string) => void }) => {
return <div>
<form className="max-w-md mx-auto flex">
<span className={"min-w-20 pt-2 text-gray-200 "}>Login as:</span>
<select id="users"
onChange={() => onChange((document.getElementById("users") as HTMLSelectElement).value)}
className="min-w-xs bg-gray-50 border border-gray-300 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-zinc-700 dark:border-zinc-600 dark:placeholder-zinc-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500">
{
existingUsers.map((user) => {
return <option key={user.name} value={user.name}>{user.name}</option>
})
}
</select>
</form>
</div>
}
10 changes: 10 additions & 0 deletions examples/openfeature_react/react-app/src/components/badges.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {OpenFeature, useFlag} from "@openfeature/react-sdk";

export const Badges = () => {
const {value: badgeClass} = useFlag("badge-class", "");
const userType = OpenFeature.getContext().userType ?? "" as string;

return <div className="flex justify-center items-center">
{badgeClass && <span className={badgeClass}>{userType.toString()}</span>}
</div>
}
32 changes: 32 additions & 0 deletions examples/openfeature_react/react-app/src/service/login.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import {EvaluationContext} from "@openfeature/react-sdk";

export const existingUsers: [{ name: string, ctx: EvaluationContext }] = [
{
name: "Anonymous",
ctx: {targetingKey: "anonymous"}
},
{
name: "User 1",
ctx: {targetingKey: "user-1", userType: "dev", email: "[email protected]"}
},
{
name: "User 2",
ctx: {targetingKey: "user-2", userType: "dev", email: "[email protected]"}
},
{
name: "User 3",
ctx: {targetingKey: "user-3", userType: "admin", company: "GO Feature Flag"}
},
{
name: "User 4",
ctx: {targetingKey: "user-4", userType: "customer", location: "Paris"}
},
{
name: "User 5",
ctx: {targetingKey: "user-5"}
}
]

export const login = (userName: string): EvaluationContext => {
return existingUsers.find(user => user.name === userName)?.ctx ?? {targetingKey: "anonymous"}
}
11 changes: 11 additions & 0 deletions examples/openfeature_react/react-app/tailwind.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}

0 comments on commit 91d5467

Please sign in to comment.