Skip to content

Commit

Permalink
reformated code with eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
azakharo committed Feb 9, 2025
1 parent 55fc1e1 commit b620a09
Show file tree
Hide file tree
Showing 10 changed files with 39 additions and 30 deletions.
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
"start": "vite",
"build": "vite build",
"preview": "vite preview",
"test": "vitest run"
"test": "vitest run",
"lint": "eslint .",
"ts": "tsc --noEmit"
},
"dependencies": {
"@emotion/react": "11.14.0",
Expand Down
1 change: 1 addition & 0 deletions src/app/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {BrowserRouter} from 'react-router-dom';
import {createTheme, ThemeProvider} from '@mui/material/styles';

import GlobalStyles from './GlobalStyles';

import Routes from '@/app/Routes';
import {AuthProvider} from '@/features/auth';
import {isProduction} from '@/shared/utils';
Expand Down
2 changes: 1 addition & 1 deletion src/app/Routes.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import {FC, memo} from 'react';
import {Navigate, Route, Routes as ReactRoutes} from 'react-router-dom';

import {ROUTE__LOGIN, ROUTE__MAIN} from '@/shared/constants';
import {useAuth} from '@/features/auth';
import Login from '@/pages/Login';
import Main from '@/pages/Main';
import {ROUTE__LOGIN, ROUTE__MAIN} from '@/shared/constants';

const Routes: FC = () => {
const {isAuthenticated} = useAuth();
Expand Down
2 changes: 1 addition & 1 deletion src/entities/user/index.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export * from './api';
export * from './types';
export * from './api';
8 changes: 5 additions & 3 deletions src/features/auth/AuthContext.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import {
createContext,
FC, PropsWithChildren,
FC,
PropsWithChildren,
useCallback,
useEffect,
useMemo,
useReducer,
} from 'react';
import {useNavigate} from 'react-router-dom';

import {login as loginMethod} from './api';
import {UserSignedIn} from './types';

import {ROUTE__LOGIN} from '@/shared/constants';
import {
getAuthToken as getAuthTokenFromLocalStorage,
Expand All @@ -17,8 +21,6 @@ import {
setAuthToken as putAuthTokenToLocalStorage,
setUserId as putUserIdToLocalStorage,
} from '@/shared/helpers';
import {UserSignedIn} from './types';
import {login as loginMethod} from './api';

export interface AuthState {
isAuthenticated: boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/features/auth/api.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {axi} from '@shared/api';
import axios from 'axios';

import {axi} from '@shared/api';

export const login = async (
username: string,
password: string,
Expand Down
29 changes: 17 additions & 12 deletions src/pages/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import {memo, useCallback, useState} from 'react';
import {useForm} from 'react-hook-form';
import {TextFieldElement} from 'react-hook-form-mui';
import {useNavigate, useSearchParams} from 'react-router-dom';
import {yupResolver} from '@hookform/resolvers/yup';
import {Box, Button, FormHelperText, Typography} from '@mui/material';
import * as Yup from 'yup';
import {InferType} from 'yup';

import {useAuth} from '@/features/auth';
import {InferType} from 'yup';
import {useForm} from 'react-hook-form';
import {yupResolver} from '@hookform/resolvers/yup';
import {TextFieldElement} from 'react-hook-form-mui';
import {useNavigate, useSearchParams} from 'react-router-dom';
import {ROUTE__MAIN} from '@/shared/constants';

const v8nSchema = Yup.object().shape({
Expand All @@ -31,7 +31,11 @@ const Login = () => {
password: '',
},
});
const {control, handleSubmit, formState: {isSubmitting}} = form;
const {
control,
handleSubmit,
formState: {isSubmitting},
} = form;

const onSubmit = useCallback(
async ({username, password}: FormValues) => {
Expand Down Expand Up @@ -74,7 +78,12 @@ const Login = () => {

<TextFieldElement label="Username" name="username" control={control} />

<TextFieldElement label="Password" name="password" type="password" control={control} />
<TextFieldElement
label="Password"
name="password"
type="password"
control={control}
/>

{authError && <FormHelperText error>{authError}</FormHelperText>}

Expand All @@ -90,11 +99,7 @@ const Login = () => {
</Button>
</Box>

<Typography
align="center"
variant="subtitle2"
color="textSecondary"
>
<Typography align="center" variant="subtitle2" color="textSecondary">
For login use &quot;[email protected]&quot; username with any
password
</Typography>
Expand Down
6 changes: 3 additions & 3 deletions src/pages/Main/index.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {memo, useEffect, useState} from 'react';
import {Box, Button} from '@mui/material';

import {getUsers} from '@entities/user';
import {useAuth} from '@/features/auth';
import {User} from '@entities/user';
import {getUsers, User} from '@entities/user';
import errorImg from '@images/sad-cloud.png';

import {useAuth} from '@/features/auth';

const areaColor = '#e2deed';

const asideMainCommonStyles = {
Expand Down
12 changes: 5 additions & 7 deletions src/shared/api/axiosSetup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import axios, {isAxiosError} from 'axios';

import {ROUTE__LOGIN, ROUTE__MAIN} from "../constants";
import {ROUTE__LOGIN, ROUTE__MAIN} from '../constants';

const redirectToLogin = (): void => {
const { pathname, search } = window.location;
const {pathname, search} = window.location;

if (pathname === ROUTE__LOGIN) {
return;
Expand All @@ -17,12 +17,10 @@ export const axi = axios.create({
});

axi.interceptors.response.use(
(response) => response,
response => response,
(error: unknown) => {
if (isAxiosError(error)) {
if (error.response?.status === 401) {
redirectToLogin();
}
if (isAxiosError(error) && error.response?.status === 401) {
redirectToLogin();
}

return Promise.reject(error);
Expand Down
2 changes: 1 addition & 1 deletion src/shared/api/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './axiosSetup';
export * from './axiosSetup';

0 comments on commit b620a09

Please sign in to comment.