Skip to content

Commit 920a939

Browse files
committed
NEXT-20 - added session related logic, added new components, added definition for new screens
1 parent 077aee5 commit 920a939

Some content is hidden

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

60 files changed

+903
-80
lines changed

.docker.env.development

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
API_URL=http://mock-server:3001
22
NEXTAUTH_URL=http://localhost:3000
33
NEXTAUTH_SECRET=vVBmyUox7Mw5BphENXnNeq+71zIc0Atxl+uxfMaLbSs=
4-
NODE_OPTIONS='--inspect'

.env.development

-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
11
API_URL=http://localhost:3001
22
NEXTAUTH_URL=http://localhost:3000
33
NEXTAUTH_SECRET=vVBmyUox7Mw5BphENXnNeq+71zIc0Atxl+uxfMaLbSs=
4-
NODE_OPTIONS='--inspect'

.eslintrc.json

+2
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
"react/react-in-jsx-scope": "off",
4242
"react/jsx-uses-react": "off",
4343
"react/function-component-definition": "off",
44+
"react/require-default-props": "off",
45+
"react/button-has-type": "off",
4446
"no-useless-constructor": "off",
4547
"no-empty-function": "off",
4648
"lines-between-class-members": "off",

Dockerfile

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ FROM base as development
1515
ENV NODE_ENV=development
1616
RUN yarn install
1717
COPY . /app
18-
CMD yarn run dev
18+
CMD NODE_OPTIONS='--inspect' yarn install && yarn run dev
1919

2020
FROM node:18.17.1 as base-mock
2121
RUN mkdir -p /app

clean-mock-server.json

+40-1
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,51 @@
3131
"filePath": "",
3232
"databucketID": "",
3333
"sendFileAsBody": false,
34-
"rules": [],
34+
"rules": [
35+
{
36+
"target": "body",
37+
"modifier": "username",
38+
"value": "[email protected]",
39+
"invert": false,
40+
"operator": "equals"
41+
}
42+
],
3543
"rulesOperator": "OR",
3644
"disableTemplating": false,
3745
"fallbackTo404": false,
3846
"default": true,
3947
"crudKey": "id"
48+
},
49+
{
50+
"uuid": "307e1b6b-a9d0-40b0-9c14-18662739b4dc",
51+
"body": "{\n \"id\": \"{{faker 'string.alphanumeric' 25}}\",\n \"email\": \"{{faker 'internet.email' 25}}\",\n \"token\": \"{{faker 'string.alphanumeric' 25}}\",\n \"firstName\": \"{{faker 'person.firstName'}}\",\n \"surname\": \"{{faker 'person.lastName'}}\",\n \"role\": \"member\"\n}",
52+
"latency": 0,
53+
"statusCode": 200,
54+
"label": "",
55+
"headers": [
56+
{
57+
"key": "Content-Type",
58+
"value": "application/json"
59+
}
60+
],
61+
"bodyType": "INLINE",
62+
"filePath": "",
63+
"databucketID": "",
64+
"sendFileAsBody": false,
65+
"rules": [
66+
{
67+
"target": "body",
68+
"modifier": "username",
69+
"value": "[email protected]",
70+
"invert": false,
71+
"operator": "equals"
72+
}
73+
],
74+
"rulesOperator": "OR",
75+
"disableTemplating": false,
76+
"fallbackTo404": false,
77+
"default": false,
78+
"crudKey": "id"
4079
}
4180
],
4281
"enabled": true,

package.json

+4-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"version": "0.1.0",
44
"private": true,
55
"scripts": {
6-
"dev": "next dev",
6+
"dev": "NODE_OPTIONS='--inspect' next dev",
77
"build": "next build",
88
"build-storybook": "storybook build",
99
"storybook": "storybook dev -p 6006",
@@ -31,7 +31,8 @@
3131
"next-auth": "^4.24.4",
3232
"next-themes": "^0.2.1",
3333
"react": "^18.2.0",
34-
"react-dom": "^18.2.0"
34+
"react-dom": "^18.2.0",
35+
"react-icons": "^4.12.0"
3536
},
3637
"devDependencies": {
3738
"@cucumber/cucumber": "^10.0.1",
@@ -50,6 +51,7 @@
5051
"@stryker-mutator/jest-runner": "^7.3.0",
5152
"@testing-library/jest-dom": "^6.1.4",
5253
"@testing-library/react": "^14.1.0",
54+
"@types/css-modules": "^1.0.5",
5355
"@types/jest": "^29.5.8",
5456
"@types/node": "^20.9.0",
5557
"@types/react": "^18.2.37",

src/app/admin/clients/page.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
import { ClientsView } from 'ui/Clients/Admin/clients.view';
4+
5+
export default function Clients() {
6+
return <ClientsView />;
7+
}

src/app/admin/dashboard/page.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
import { DashboardView } from 'ui/Dashboard/Admin/dashboard.view';
4+
5+
export default function Dashboard() {
6+
return <DashboardView />;
7+
}

src/app/admin/packages/page.tsx

+7
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import React from 'react';
2+
3+
import { PackagesView } from 'ui/Packages/Admin/packages.view';
4+
5+
export default function Packages() {
6+
return <PackagesView />;
7+
}

src/app/dashboard/page.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { DashboardView } from 'ui/Dashboard/dashboard.view';
1+
import { DashboardView } from 'ui/Dashboard/Member/dashboard.view';
22

33
const Dashboard = () => {
44
return <DashboardView />;

src/app/globals.scss

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,10 @@
1919
}
2020

2121
body {
22-
background-color: $martinique;
22+
background-color: $mirage;
2323
color: rgb(var(--foreground-rgb));
2424
}
2525

2626
.dark body {
27-
background-color: $martinique-dark;
27+
background-color: $mirage;
2828
}

src/app/layout.tsx

+5-22
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,12 @@
11
import { ReactNode } from 'react';
22

33
import type { Metadata } from 'next';
4-
import { Inter } from 'next/font/google';
54

6-
import { TopHeader } from 'ui/common/components/layout/TopHeader/TopHeader';
7-
import { TopNavigation } from 'ui/common/components/layout/TopNavigation/TopNavigation';
8-
9-
import { ThemeProvider } from 'ui/common/providers/theme.provider';
10-
import { THEME } from 'ui/common/consts/theme';
11-
12-
import './globals.scss';
135
import { AuthenticationProvider } from 'ui/common/providers/authentication.provider';
6+
import { AppLayout } from 'ui/common/layouts/AppLayout/AppLayout';
7+
import { lato } from 'ui/common/assets/fonts/fonts';
148

15-
const inter = Inter({ subsets: ['latin'] });
9+
import './globals.scss';
1610

1711
export const metadata: Metadata = {
1812
title: 'Clean Architecture Next.js React Boilerplate',
@@ -22,20 +16,9 @@ export const metadata: Metadata = {
2216
export default function RootLayout({ children }: { children: ReactNode }) {
2317
return (
2418
<html lang="en">
25-
<body className={inter.className}>
19+
<body className={lato.className}>
2620
<AuthenticationProvider>
27-
<ThemeProvider
28-
attribute="class"
29-
defaultTheme={THEME.DARK}
30-
themes={[THEME.DARK, THEME.DARK]}
31-
enableSystem
32-
disableTransitionOnChange
33-
>
34-
<TopHeader>
35-
<TopNavigation />
36-
</TopHeader>
37-
{children}
38-
</ThemeProvider>
21+
<AppLayout>{children}</AppLayout>
3922
</AuthenticationProvider>
4023
</body>
4124
</html>

src/app/page.module.scss

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@import 'src/ui/common/styles/colors.module';
22

33
.container {
4-
background-color: $martinique;
4+
background-color: $port-gore;
55
}

src/app/page.tsx

+2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import React from 'react';
2+
13
export default function Home() {
24
return (
35
<main className="flex min-h-screen items-center justify-center p-24">

src/middleware.ts

+24-2
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,32 @@
11
import { withAuth, NextRequestWithAuth } from 'next-auth/middleware';
22
import { NextResponse } from 'next/server';
33

4+
import { APP_ADMIN_ROUTES, APP_ROUTES } from 'ui/common/navigation/routes';
5+
46
export default withAuth(
57
function middleware(request: NextRequestWithAuth) {
8+
if (request.nextUrl.pathname === '/' && !request.nextauth.token) {
9+
return NextResponse.redirect(new URL(APP_ROUTES.LOGIN, request.url));
10+
}
11+
12+
if (
13+
request.nextUrl.pathname === '/' &&
14+
request.nextauth.token?.role === 'member'
15+
) {
16+
return NextResponse.redirect(new URL(APP_ROUTES.DASHBOARD, request.url));
17+
}
18+
19+
if (
20+
request.nextUrl.pathname === '/' &&
21+
request.nextauth.token?.role === 'admin'
22+
) {
23+
return NextResponse.redirect(
24+
new URL(APP_ADMIN_ROUTES.DASHBOARD, request.url)
25+
);
26+
}
27+
628
if (
7-
request.nextUrl.pathname.startsWith('/dashboard') &&
29+
request.nextUrl.pathname.startsWith('/admin') &&
830
request.nextauth.token?.role !== 'admin'
931
) {
1032
return NextResponse.redirect(new URL('/forbidden', request.url));
@@ -19,4 +41,4 @@ export default withAuth(
1941
}
2042
);
2143

22-
export const config = { matcher: ['/dashboard'] };
44+
export const config = { matcher: ['/', '/admin/:path*'] };
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.header {
2+
flex: 0.3;
3+
margin: 0 60px;
4+
}
5+
6+
.container {
7+
background: radial-gradient(100% 100% at 50% 0%, #374676, #1d243e);
8+
border-radius: 10px;
9+
box-shadow: rgb(0 0 0 / 15%) 0 -10px 15px 0;
10+
display: flex;
11+
flex: 1;
12+
margin: 0 60px;
13+
padding: 30px;
14+
}

src/ui/Clients/Admin/clients.view.tsx

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
import React from 'react';
2+
3+
import styles from 'ui/Clients/Admin/clients.module.scss';
4+
5+
import { PageHeader } from 'ui/common/components/typography/PageHeader/PageHeader';
6+
7+
export const ClientsView = () => {
8+
return (
9+
<>
10+
<div className={styles.header} />
11+
<div className={styles.container}>
12+
<PageHeader>Clients</PageHeader>
13+
</div>
14+
</>
15+
);
16+
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
@import 'src/ui/common/styles/colors.module';
2+
3+
.header {
4+
flex: 0.3;
5+
margin: 0 60px;
6+
}
7+
8+
.container {
9+
background: radial-gradient(100% 100% at 50% 0%, $san-juan, $mirage);
10+
border-radius: 10px;
11+
box-shadow: $box-shadow 0 -10px 15px 0;
12+
display: flex;
13+
flex: 1;
14+
margin: 0 60px;
15+
padding: 30px;
16+
}
+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
'use client';
2+
3+
import React from 'react';
4+
5+
import styles from 'ui/Dashboard/Admin/dashboard.module.scss';
6+
7+
import { PageHeader } from 'ui/common/components/typography/PageHeader/PageHeader';
8+
9+
export const DashboardView = () => {
10+
return (
11+
<>
12+
<div className={styles.header} />
13+
<div className={styles.container}>
14+
<PageHeader>Dashboard</PageHeader>
15+
</div>
16+
</>
17+
);
18+
};
+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
'use client';
2+
3+
import React from 'react';
4+
5+
import { TopNavigation } from 'ui/common/components/layout/TopNavigation/TopNavigation';
6+
7+
export const DashboardView = () => {
8+
return (
9+
<>
10+
<TopNavigation />
11+
<span>Dashboard</span>
12+
</>
13+
);
14+
};

src/ui/Dashboard/dashboard.view.tsx

-9
This file was deleted.

src/ui/Login/login.hooks.ts

+19-4
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,33 @@
1-
import { useTheme } from 'next-themes';
1+
import { useRouter } from 'next/navigation';
22

33
import { useLoginData } from 'ui/Login/login.data';
4+
import { useAuthentication } from 'ui/shared/Application/Authentication/authentication.hooks';
45

56
type UseLoginHook = {
6-
theme: string | undefined;
7+
onSubmit: (formData: FormData) => void;
78
};
89

910
export const useLogin = (): UseLoginHook => {
10-
const { theme } = useTheme();
11+
const { logIn } = useAuthentication();
12+
const router = useRouter();
1113

1214
// eslint-disable-next-line no-empty-pattern
1315
const {} = useLoginData();
1416

17+
const onSubmit = async (formData: FormData) => {
18+
const email = (formData.get('login') as string) || '';
19+
const password = (formData.get('password') as string) || '';
20+
21+
const result = await logIn({
22+
email,
23+
password,
24+
});
25+
if (result.ok) {
26+
router.push('/');
27+
}
28+
};
29+
1530
return {
16-
theme,
31+
onSubmit,
1732
};
1833
};

src/ui/Login/login.module.scss

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
@import 'src/ui/common/styles/colors.module';
22

33
.container {
4-
background-color: $martinique;
4+
background-color: $port-gore;
55
}
66

77
.dark.container {
8-
background-color: $martinique-dark;
8+
background-color: $port-gore;
9+
}
10+
11+
.logo {
12+
margin-bottom: 20px;
13+
}
14+
15+
.signInButton {
16+
margin-top: 20px;
917
}

0 commit comments

Comments
 (0)