Skip to content

Commit 04f6af4

Browse files
First commit.
0 parents  commit 04f6af4

File tree

409 files changed

+31975
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

409 files changed

+31975
-0
lines changed

.eslintrc.json

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"extends": "next/core-web-vitals",
3+
"rules": {
4+
"@next/next/no-img-element": "off",
5+
"jsx-a11y/alt-text": "off",
6+
"react/display-name": "off",
7+
"react/jsx-max-props-per-line": [
8+
1,
9+
{
10+
"maximum": 1
11+
}
12+
]
13+
}
14+
}

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=lf

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
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+
# production
12+
/build
13+
out
14+
.next
15+
16+
# misc
17+
.DS_Store
18+
.eslintcache
19+
/.env
20+
/.env.local
21+
/.env.development.local
22+
/.env.test.local
23+
/.env.production.local
24+
25+
npm-debug.log*
26+
yarn-debug.log*
27+
yarn-error.log*

README.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
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+
```
12+
13+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
14+
15+
You can start editing the page by modifying `pages/index.tsx`. The page auto-updates as you edit the file.
16+
17+
[API routes](https://nextjs.org/docs/api-routes/introduction) can be accessed on [http://localhost:3000/api/hello](http://localhost:3000/api/hello). This endpoint can be edited in `pages/api/hello.ts`.
18+
19+
The `pages/api` directory is mapped to `/api/*`. Files in this directory are treated as [API routes](https://nextjs.org/docs/api-routes/introduction) instead of React pages.
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.

_docs/analytics-configuration.md

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
title: Analytics Configuration
3+
---
4+
5+
# Configuration
6+
7+
## Create GTM account
8+
9+
In order to use the GTM platform, you need to create a GTM account. Read more about it
10+
[here](https://support.google.com/tagmanager/answer/6103696?hl=en#install&zippy=%2Cweb-pages).
11+
12+
## Set up configuration options
13+
14+
The app uses environment variables because it can be deployed with different accounts
15+
for `development`, `qa`, and `production`. This allows you to configure the GTM library differently
16+
for each environment.
17+
18+
Open `.env` file (or create) in the project's root folder and set the
19+
variable `NEXT_PUBLIC_GTM_CONTAINER_ID` with the container ID provided by GTM platform.
20+
21+
```shell
22+
NEXT_PUBLIC_GTM_CONTAINER_ID=GTM-XXXXXX
23+
```
24+
25+
If you do not want to set up environment variables, settings can be applied simply on
26+
the `gtmConfig` object found in the `src/config.js` file.
27+
28+
```js
29+
export const gtmConfig = {
30+
containerId: ''
31+
};
32+
```

_docs/analytics-event-tracking.md

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
---
2+
title: Event tracking
3+
---
4+
5+
# Event tracking
6+
7+
By default, the GTM library's push platform captures the browser location data, such as url,
8+
pathname, title, and other details. You can extend it to match your business needs. For example, you
9+
may need the event name, site section, campaign name, product name, price, process step, etc.
10+
11+
## Page view
12+
13+
```jsx
14+
// src/pages/login.js
15+
import { useEffect } from 'react';
16+
import { gtm } from '../lib/gtm';
17+
18+
const Login = () => {
19+
useEffect(() => {
20+
gtm.push({event: 'page_view'});
21+
}, []);
22+
23+
return (
24+
<div>
25+
content
26+
</div>
27+
);
28+
};
29+
```
30+
31+
This example shows you how to track the page view event once the page component gets mounted. It can
32+
also be used on mounting virtual pages, such as modals, dialogs, etc.
33+
34+
## Other action
35+
36+
```jsx
37+
// src/pages/product.js
38+
import { gtm } from '../lib/gtm';
39+
40+
const Product = () => {
41+
const handleAddToCart = () => {
42+
gtm.push({
43+
event: 'add_to_cart',
44+
price: '317,65',
45+
currency: 'EUR',
46+
name: 'Dell Monitor 27"'
47+
});
48+
};
49+
50+
return (
51+
<div>
52+
<div>Dell Monitor 27"</div>
53+
<div>EUR 317,65</div>
54+
<button onClick={handleAddToCart}>
55+
Add to cart
56+
</button>
57+
</div>
58+
);
59+
};
60+
```
61+
62+
As it can be seen, this example has multiple variables to help you identify the product that was
63+
added to cart and its price. These are called conversion variables in most systems, and they are
64+
used to determine the user behaviour after visiting a specific page or site section. If the user
65+
does not complete the checkout process, you are able to identify most products added to the cart,
66+
and make decisions based on metrics.

_docs/analytics-introduction.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
---
2+
title: Analytics Introduction
3+
---
4+
5+
# Introduction
6+
7+
For many companies is important to understand the user traffic, origin and behaviour. This may apply
8+
to your business, and you can find an example in the app.
9+
10+
## Google Tag Manager (GTM)
11+
12+
In previous versions the app used `Google Analytics` directly, but for this version it uses GTM.
13+
This enables a lot more control over the analytics implementation and also helps you display things
14+
like GDPR modal, various targeted content; control the data transfer, cookies and other aspects
15+
based on user data privacy preferences. Read more about GTM
16+
[here](https://support.google.com/tagmanager/answer/6102821?hl=en&ref_topic=3441530).
17+
18+
## How GTM it works
19+
20+
In order to use the `GTM platform` you set up a container, then you create a tag for each provider
21+
you need, for example, Google Analytics. Then, using the triggers, you control multiple tags based
22+
on data pushed to the data layer. The data pushed gets computed on the client (browser), and then
23+
the library determines which tags will be loaded.
24+
25+
## How is it implemented
26+
27+
The app uses a small singleton class to help with loading the `GTM library`, initialize it and track
28+
events via the GTM available methods.

_docs/auth-guard.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
title: Auth Guard
3+
---
4+
5+
# Auth Guard
6+
7+
This is a simple component that can be used to protect a private route. It controls whether it
8+
should allow navigation to a requested route based on given context. Similar to the GuestGuard,
9+
the app provides a `hoc` to prevent the entire page render.
10+
11+
## Example
12+
13+
```jsx
14+
// src/pages/dashboard/index.js
15+
import { withAuthGuard } from '../../hocs/with-auth-guard';
16+
17+
const Overview = () => {
18+
return (
19+
<div>
20+
content
21+
</div>
22+
);
23+
};
24+
25+
export default withAuthGuard(Overview);
26+
```
27+
28+
## How it works
29+
30+
It connects with the authentication provider (Amplify, Auth0, Firebase, or JWT, depending on your
31+
setup) and extracts the required data to detect whether it should render the children passed as
32+
props, otherwise it redirects to the `Login` component with a redirect url query string parameter
33+
to allow the Login component to redirect back to the requested url after a successful
34+
authentication.
35+
36+
## How it can be extended
37+
38+
As mentioned, this is a sample component, thus it can and should be adjusted to match your business
39+
needs.

_docs/authentication-amplify.md

Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
---
2+
title: Amplify
3+
---
4+
5+
# Amplify
6+
7+
AWS Amplify is a set of services accompanied by various tools and libraries created to help the
8+
development of apps. Their suite offers among other features, an authentication feature, which can
9+
be used as a stand-alone authentication system. The project is able to be used with this
10+
authentication system, as well. Should you want to implement any of the other features Amplify
11+
offers, you can refer to their [documentation](https://docs.amplify.aws/).
12+
13+
## Set up your Amplify account
14+
15+
The documentation for this, can be found in the official documentation of the service, mentioned
16+
above.
17+
18+
## Configuration
19+
20+
In order to configure Amplify client library you have to open (or create) `.env` file in the
21+
project's root folder and set the following variables as presented in your Amplify account settings:
22+
23+
```shell
24+
NEXT_PUBLIC_AWS_COGNITO_IDENTITY_POOL_ID=
25+
NEXT_PUBLIC_AWS_COGNITO_REGION=
26+
NEXT_PUBLIC_AWS_PROJECT_REGION=
27+
NEXT_PUBLIC_AWS_USER_POOLS_ID=
28+
NEXT_PUBLIC_AWS_USER_POOLS_WEB_CLIENT_ID=
29+
```
30+
31+
If you do not want to set up environment variables, settings can be applied simply on
32+
the `amplifyConfig` object found in the `src/config.js` file.
33+
34+
```js
35+
export const amplifyConfig = {
36+
aws_project_region: '',
37+
aws_cognito_identity_pool_id: '',
38+
aws_cognito_region: '',
39+
aws_user_pools_id: '',
40+
aws_user_pools_web_client_id: ''
41+
};
42+
```
43+
44+
## How it was implemented
45+
46+
As mentioned above, Amplify offers a set of components to help your development process, although
47+
they're not used in the app.
48+
49+
The `Auth` singleton from the library is used to provide the authentication feature to a context (
50+
which wraps the content of the `App` component).
51+
52+
This aforementioned context is then used in the component tree to access the `Auth` public methods.
53+
It provides the user authentication status and user profile, if available.
54+
55+
## How to use Amplify Provider
56+
57+
By default, the project uses a mocked `JWT provider` (as in: it doesn't use an actual JWT based
58+
authentication server). To make use of Amplify simply follow these steps:
59+
60+
### Step 1. Replace the provider and consumer
61+
62+
Open `src/pages/_app.js` file and replace the following line:
63+
64+
```js
65+
import { AuthConsumer, AuthProvider } from '../contexts/jwt-context';
66+
```
67+
68+
with
69+
70+
```js
71+
import { AuthConsumer, AuthProvider } from '../contexts/amplify-context';
72+
```
73+
74+
### Step 2. Replace the hook context
75+
76+
Open `src/hooks/use-auth.js` file and replace the following line:
77+
78+
```js
79+
import { AuthContext } from '../contexts/jwt-context';
80+
```
81+
82+
with
83+
84+
```js
85+
import { AuthContext } from '../contexts/amplify-context';
86+
```
87+
88+
## How to use auth
89+
90+
### Retrieve user profile
91+
92+
In the example below, you can find how it can be used in any component not just the `App`. Should
93+
you want to use it in any other component, you'll have to import the `useAuth` hook and use it as
94+
needed.
95+
96+
```jsx
97+
// src/pages/index.js
98+
import { useAuth } from '../hooks/use-auth';
99+
100+
const Home = () => {
101+
const { user } = useAuth();
102+
103+
return (
104+
<div>
105+
Email: {user.email}
106+
</div>
107+
);
108+
};
109+
```
110+
111+
### Auth methods / actions
112+
113+
> For simplicity and space limitations, the code below is used only to exemplify, actual code can be found in the components.
114+
115+
```jsx
116+
// src/pages/index.js
117+
import { useAuth } from '../hooks/use-auth';
118+
119+
const Home = () => {
120+
const { login } = useAuth();
121+
122+
const handleLogin = () => {
123+
// Email/username and password
124+
login('demo@devias.io', 'Password123!');
125+
};
126+
127+
return (
128+
<div>
129+
<button onClick={handleLogin}>
130+
Login
131+
</button>
132+
</div>
133+
);
134+
};
135+
```
136+
137+
## Implemented flows
138+
139+
Currently, the app only covers the main flows:
140+
141+
- Sign in
142+
- Sign up
143+
- Confirm sign up
144+
- Resend sign up
145+
- Forgot password
146+
- Forgot password submit
147+
- Logout

0 commit comments

Comments
 (0)