Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
NEXT_PUBLIC_API_BASE_URL=
NEXT_PUBLIC_DOMAIN=
NEXT_PUBLIC_GOOGLE_CLIENT_ID=
NEXT_ANALYZE=false
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v18.17.1
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"pnpm": "^8.7.0"
},
"dependencies": {
"@hookform/resolvers": "^3.3.2",
"@phosphor-icons/react": "^2.0.14",
"@react-oauth/google": "^0.11.1",
"@tw-classed/react": "^1.6.1",
Expand All @@ -36,8 +37,11 @@
"polished": "^4.2.2",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-hook-form": "^7.48.2",
"swr": "^2.2.4",
"tailwindcss": "0.0.0-insiders.803d7b5",
"typescript": "5.0.3",
"yup": "^1.3.2",
"zustand": "^4.4.6"
},
"devDependencies": {
Expand Down
61 changes: 60 additions & 1 deletion pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 10 additions & 2 deletions src/app/(authorized)/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
'use client';

import { PropsWithChildren } from 'react';
import RoleEnum from 'domain/entity/RoleEnum';
import Sidebar from 'presentation/component/layout/Sidebar';
import AuthorizedHeader from 'presentation/component/layout/AuthorizedHeader';
import createAuthorizedLayout from 'presentation/component/layout/AuthorizedLayout';

export default function AuthorizedLayout(props: PropsWithChildren) {
const BaseAuthorizedLayout = (props: PropsWithChildren) => {
const { children } = props;

return (
Expand All @@ -14,4 +18,8 @@ export default function AuthorizedLayout(props: PropsWithChildren) {
</div>
</div>
);
}
};

export default createAuthorizedLayout(BaseAuthorizedLayout, {
roles: [RoleEnum.User],
});
7 changes: 0 additions & 7 deletions src/app/(login)/login/page.tsx

This file was deleted.

5 changes: 1 addition & 4 deletions src/app/layout.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { PropsWithChildren } from 'react';
import { Inter, Kodchasan } from 'next/font/google';
import clsx from 'clsx';
import GoogleOAuthProvider from './providers/GoogleOAuthProvider';
import './globals.css';

const kodchasan = Kodchasan({ subsets: ['latin'], variable: '--font-title', weight: ['600'] });
Expand All @@ -18,9 +17,7 @@ export default function RootLayout(props: PropsWithChildren) {
return (
<html lang="en">
<body className={clsx('font-body', kodchasan.variable, inter.variable)}>
<GoogleOAuthProvider>
<main className="relative flex min-h-screen flex-col">{children}</main>
</GoogleOAuthProvider>
<main className="relative flex min-h-screen flex-col">{children}</main>
</body>
</html>
);
Expand Down
7 changes: 7 additions & 0 deletions src/app/sign-in/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SignInPage from 'presentation/component/page/SignIn';

const SignIn = () => {
return <SignInPage />;
};

export default SignIn;
7 changes: 7 additions & 0 deletions src/app/sign-up/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import SignUpPage from 'presentation/component/page/SignUp';

const SignUp = () => {
return <SignUpPage />;
};

export default SignUp;
1 change: 1 addition & 0 deletions src/constant/env.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export const IS_PRODUCTION = process.env.NODE_ENV === 'production';
export const API_BASE_URL = process.env.NEXT_PUBLIC_API_BASE_URL ?? '';
export const GOOGLE_CLIENT_ID = process.env.NEXT_PUBLIC_GOOGLE_CLIENT_ID ?? '';
5 changes: 5 additions & 0 deletions src/constant/httpCode.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export const enum HttpCode {
Ok = 200,
Unauthorized = 401,
Forbidden = 403,
}
14 changes: 11 additions & 3 deletions src/constant/route.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
export const SIGN_UP = '/sign-up';
export const SIGN_IN = '/sign-in';

export const HOME = '/';
export const NEWS = '/news';
export const DASHBOARD = '/dashboard';
export const STUDY = '/study';
export const SETTINGS = '/settings';

export const SIGN_UP = '/sign-up';
export const SIGN_IN = '/sign-in';

/**
* Dashboard sidebar items
*/
Expand All @@ -26,3 +26,11 @@ export const DICTIONARY = `${DASHBOARD}/dictionary`;
export const PROFILE = `${SETTINGS}/profile`;
export const SECURITY = `${SETTINGS}/security`;
export const ADVANCED = `${SETTINGS}/advanced`;

/**
* API routes
*/
const USER = (url: string) => `/user/${url}`;
export const GET_USER = USER('');
export const USER_LOGIN = USER('login');
export const USER_REFRESH = USER('refresh');
26 changes: 26 additions & 0 deletions src/data/driver/ApiClient/AbstractApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import type { AxiosInstance } from 'axios';
import REST from './REST';

export default abstract class AbstractApiClient {
public abstract rest: REST;

private accessToken?: string;

public setAccessToken(token?: string) {
this.accessToken = token;
}

public getAccessToken() {
return this.accessToken;
}

protected useCredentialsInterceptor(client: AxiosInstance) {
client.interceptors.request.use((request) => {
if (this.accessToken && request.headers) {
request.headers.Authorization = `Bearer ${this.accessToken}`;
}

return request;
}, Promise.reject);
}
}
14 changes: 14 additions & 0 deletions src/data/driver/ApiClient/FrontendApiClient.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { API_BASE_URL } from 'constant/env';
import AbstractApiClient from './AbstractApiClient';
import REST from './REST';

export default class FrontendApiClient extends AbstractApiClient {
public readonly rest: REST;

constructor() {
super();
this.rest = new REST(`${API_BASE_URL}/api`);

this.useCredentialsInterceptor(this.rest.client);
}
}
13 changes: 13 additions & 0 deletions src/data/driver/ApiClient/REST.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import AbstractAxiosClient from './axios';

export default class REST extends AbstractAxiosClient {
public post = this._client.post;

public postForm = this._client.postForm;

public get = this._client.get;

public delete = this._client.delete;

public patch = this._client.patch;
}
32 changes: 32 additions & 0 deletions src/data/driver/ApiClient/axios.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import axios, { AxiosInstance } from 'axios';

const TIMEOUT_ERROR_MESSAGE = 'TimeoutError';

export default abstract class AbstractAxiosClient {
protected readonly _client: AxiosInstance;

public constructor(apiBaseURL: string) {
this._client = axios.create({
baseURL: apiBaseURL,
timeout: 30000,
timeoutErrorMessage: TIMEOUT_ERROR_MESSAGE,
});

this.useTimeoutErrorInterceptor();
}

private useTimeoutErrorInterceptor(): void {
this._client.interceptors.response.use(undefined, (error) => {
if (error?.message === TIMEOUT_ERROR_MESSAGE) {
// eslint-disable-next-line no-console
console.log(JSON.stringify({ TIMEOUT_ERROR_MESSAGE, error }, null, 2));
}

throw error;
});
}

public get client(): AxiosInstance {
return this._client;
}
}
3 changes: 3 additions & 0 deletions src/data/driver/ApiClient/frontend.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import FrontendApiClient from './FrontendApiClient';

export const frontendApiClient = new FrontendApiClient();
7 changes: 7 additions & 0 deletions src/data/driver/validation/auth/messages.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import getPlural from 'helper/string/getPlural';

export const requiredField = 'Поле обязательно для заполнения';
export const minSymbols = ({ min }: { min: number }) =>
`Минимум ${min} ${getPlural(min, ['символ', 'символа', 'символов'])}`;
export const maxSymbols = ({ max }: { max: number }) =>
`Максимум ${max} ${getPlural(max, ['символ', 'символа', 'символов'])}`;
Loading