Skip to content

Commit 6009956

Browse files
Scaffold next-app
1 parent 44120df commit 6009956

18 files changed

+6343
-1
lines changed

.eslintrc.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "next/core-web-vitals"
3+
}

.gitignore

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.js
7+
8+
# testing
9+
/coverage
10+
11+
# next.js
12+
/.next/
13+
/out/
14+
15+
# production
16+
/build
17+
18+
# misc
19+
.DS_Store
20+
*.pem
21+
22+
# debug
23+
npm-debug.log*
24+
yarn-debug.log*
25+
yarn-error.log*
26+
27+
# local env files
28+
.env*.local
29+
30+
# vercel
31+
.vercel
32+
33+
# typescript
34+
*.tsbuildinfo
35+
next-env.d.ts

README.md

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,34 @@
1-
# next-js-starter-kit
1+
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
```
14+
15+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
16+
17+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
18+
19+
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
20+
21+
## Learn More
22+
23+
To learn more about Next.js, take a look at the following resources:
24+
25+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
26+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
27+
28+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
29+
30+
## Deploy on Vercel
31+
32+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
33+
34+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.

app/components/decision.tsx

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import { useDecision } from "@optimizely/react-sdk";
2+
import Pre from "./pre";
3+
4+
interface DecisionType {
5+
userId: string;
6+
setHasOnFlag: Function;
7+
}
8+
9+
export const Decision: React.FC<DecisionType> = (props: DecisionType) => {
10+
const { userId, setHasOnFlag } = props;
11+
12+
// Generally React SDK runs for one client at a time i.e for one user throughout the lifecycle.
13+
// You can provide the user Id once while wrapping the app in the Provider component and the SDK will memoize and reuse it throughout the application lifecycle.
14+
// For this example, we are simulating 10 different users so we will ignore this and pass override User IDs to the useDecision hook for demonstration purpose.
15+
// This override will not be needed for normal react sdk use cases.
16+
const [decision, clientReady] = useDecision(
17+
"product_sort",
18+
{},
19+
{ overrideUserId: userId }
20+
);
21+
22+
// Don't render the component if SDK client is not ready yet.
23+
if (!clientReady) {
24+
return "";
25+
}
26+
27+
const variationKey = decision.variationKey;
28+
29+
// did decision fail with a critical error?
30+
if (variationKey === null) {
31+
console.log(" decision error: ", decision["reasons"]);
32+
}
33+
34+
if (decision.enabled) {
35+
setTimeout(() => setHasOnFlag(true));
36+
}
37+
38+
// get a dynamic configuration variable
39+
// "sort_method" corresponds to a variable key in your Optimizely project
40+
const sortMethod = decision.variables["sort_method"];
41+
42+
return (
43+
<Pre>
44+
{`\nFlag ${
45+
decision.enabled ? "on" : "off"
46+
}. User number ${userId} saw flag variation: ${variationKey} and got products sorted by: ${sortMethod} config variable as part of flag rule: ${
47+
decision.ruleKey
48+
}`}
49+
</Pre>
50+
);
51+
};

app/components/flags-off-message.tsx

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import Pre from "./pre";
2+
3+
interface FlagsOffMessageType {
4+
projectId: string;
5+
}
6+
7+
export const FlagsOffMessage: React.FC<FlagsOffMessageType> = (
8+
props: FlagsOffMessageType
9+
) => {
10+
const { projectId } = props;
11+
const navLink = `https://app.optimizely.com/v2/projects/${projectId}/settings/implementation`;
12+
return (
13+
<div>
14+
<Pre>Flag was off for everyone. Some reasons could include:</Pre>
15+
<Pre>
16+
1. Your sample size of visitors was too small. Rerun, or increase the
17+
iterations in the FOR loop
18+
</Pre>
19+
<Pre>
20+
2. By default you have 2 keys for 2 project environments (dev/prod).
21+
Verify in Settings{">"}Environments that you used the right key for the
22+
environment where your flag is toggled to ON.
23+
</Pre>
24+
<Pre>
25+
Check your key at <a href={navLink}>{navLink}</a>
26+
</Pre>
27+
<br />
28+
</div>
29+
);
30+
};
31+
32+
export default FlagsOffMessage;

app/components/pre.tsx

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { PropsWithChildren } from "react";
2+
3+
export const Pre: React.FC<PropsWithChildren> = (props: PropsWithChildren) => {
4+
const { children } = props;
5+
6+
return <pre style={{ margin: 0 }}>{children}</pre>;
7+
};
8+
9+
export default Pre;

app/globals.css

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
2+
*, *::before, *::after {
3+
box-sizing: border-box;
4+
}
5+
6+
* {
7+
margin: 0;
8+
}
9+
10+
body {
11+
line-height: 1.5;
12+
-webkit-font-smoothing: antialiased;
13+
}
14+
15+
p, h1, h2, h3, h4, h5, h6 {
16+
overflow-wrap: break-word;
17+
}
18+
19+
#root, #__next {
20+
isolation: isolate;
21+
}

app/layout.tsx

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import './globals.css'
2+
import type { Metadata } from 'next'
3+
import { Inter } from 'next/font/google'
4+
5+
const inter = Inter({ subsets: ['latin'] })
6+
7+
export const metadata: Metadata = {
8+
title: 'Create Next App',
9+
description: 'Generated by create next app',
10+
}
11+
12+
export default function RootLayout({
13+
children,
14+
}: {
15+
children: React.ReactNode
16+
}) {
17+
return (
18+
<html lang="en">
19+
<body className={inter.className}>{children}</body>
20+
</html>
21+
)
22+
}

0 commit comments

Comments
 (0)