Skip to content

Commit 33de4b8

Browse files
committed
Refactoring, tweaks and improvements
1 parent 8459bf6 commit 33de4b8

File tree

33 files changed

+301
-397
lines changed

33 files changed

+301
-397
lines changed

.env

Lines changed: 0 additions & 2 deletions
This file was deleted.

.eslintrc

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@
3737
"prettier/prettier": ["warn", { "singleQuote": true }],
3838
"no-shadow": "off",
3939
"camelcase": "off",
40+
"@typescript-eslint/camelcase": "off",
41+
"@typescript-eslint/naming-convention": "off",
4042
"no-plusplus": ["error", { "allowForLoopAfterthoughts": true }],
4143
"import/order": "off",
4244
"no-control-regex": 0,
@@ -81,6 +83,13 @@
8183
"namedComponents": "arrow-function",
8284
"unnamedComponents": "arrow-function"
8385
}
86+
],
87+
"no-param-reassign": [
88+
"error",
89+
{
90+
"props": true,
91+
"ignorePropertyModificationsFor": ["state"]
92+
}
8493
]
8594
}
8695
}

src/api/api.ts

Lines changed: 21 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,32 @@
1-
import axios, { AxiosError } from 'axios';
1+
import axios, { AxiosResponse } from 'axios';
22

3-
import { IGetToken } from '../types/token';
4-
import { IGetNewUser, IGetUsers, IGetUsersPositions } from '../types/users';
5-
import { handleError } from './config';
3+
import {
4+
IGetNewUser,
5+
IGetToken,
6+
IGetUsers,
7+
IGetUsersPositions,
8+
} from '../types/users';
69

710
const instance = axios.create({
811
baseURL: 'https://frontend-test-assignment-api.abz.agency/api/v1',
912
});
1013

11-
const usersAPI = {
12-
async getUsers(page: number, count: number) {
13-
const { data } = await instance.get<IGetUsers>(
14-
`/users?page=${page}&count=${count}`
15-
);
16-
17-
return data;
14+
export const mainAPI = {
15+
getUsers(page: number, count: number): Promise<AxiosResponse<IGetUsers>> {
16+
return instance.get<IGetUsers>(`/users?page=${page}&count=${count}`);
1817
},
19-
async getUserPositions() {
20-
const { data } = await instance.get<IGetUsersPositions>('/positions');
21-
22-
return data;
18+
getUserPositions(): Promise<AxiosResponse<IGetUsersPositions>> {
19+
return instance.get<IGetUsersPositions>('/positions');
2320
},
24-
async getToken() {
25-
const { data } = await instance.get<IGetToken>('/token');
26-
27-
return data;
21+
getToken(): Promise<AxiosResponse<IGetToken>> {
22+
return instance.get<IGetToken>('/token');
2823
},
29-
async getNewUser(userData: FormData, token: string) {
30-
try {
31-
const { data } = await instance.post<IGetNewUser>('/users', userData, {
32-
headers: { Token: token, 'content-type': 'multipart/form-data' },
33-
});
34-
35-
return {
36-
success: data.success,
37-
data,
38-
};
39-
} catch (error: unknown | AxiosError) {
40-
return handleError(error);
41-
}
24+
getNewUser(
25+
userData: FormData,
26+
token: string
27+
): Promise<AxiosResponse<IGetNewUser>> {
28+
return instance.post<IGetNewUser>('/users', userData, {
29+
headers: { Token: token, 'content-type': 'multipart/form-data' },
30+
});
4231
},
4332
};
44-
45-
export default usersAPI;

src/api/config.ts

Lines changed: 0 additions & 18 deletions
This file was deleted.
Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
const CatFootprints = () => (
1+
export const CatFootprints = () => (
22
<div className='page__cat-footprints cat-footprints' />
33
);
4-
5-
export default CatFootprints;

src/components/Footer/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const Footer = () => {
1+
export const Footer = () => {
22
return (
33
<footer className='footer'>
44
<div className='footer__container container'>
@@ -7,5 +7,3 @@ const Footer = () => {
77
</footer>
88
);
99
};
10-
11-
export default Footer;

src/components/Header/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import { Link } from 'react-scroll';
88

99
import Logo from '../../assets/images/logo.svg';
1010

11-
const Header = () => {
11+
export const Header = () => {
1212
const [isOpenMenu, setIsOpenMenu] = useState(false);
1313
const darkBackground = useRef<HTMLSpanElement>(null);
1414
const isMobile = useMediaQuery({
@@ -180,5 +180,3 @@ const Header = () => {
180180
</header>
181181
);
182182
};
183-
184-
export default Header;

src/components/MainTextField/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import styled from '@emotion/styled';
22
import { TextField, TextFieldProps } from '@mui/material';
33

4-
const MainTextField = (props: TextFieldProps) => {
4+
export const MainTextField = (props: TextFieldProps) => {
55
const CustomTextField = styled((props: TextFieldProps) => (
66
<TextField {...props} />
77
))({
@@ -51,5 +51,3 @@ const MainTextField = (props: TextFieldProps) => {
5151

5252
return <CustomTextField {...props} />;
5353
};
54-
55-
export default MainTextField;

src/components/MainTooltip/index.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ interface IMainTooltip {
66
title: string;
77
}
88

9-
const MainTooltip = ({ children }: IMainTooltip) => {
9+
export const MainTooltip = ({ children }: IMainTooltip) => {
1010
const [isOverflowed, setIsOverflow] = useState(false);
1111
const textElementRef = useRef<HTMLDivElement>(null);
1212

@@ -62,5 +62,3 @@ const MainTooltip = ({ children }: IMainTooltip) => {
6262
</CustomTooltip>
6363
);
6464
};
65-
66-
export default MainTooltip;

src/components/Modal/index.tsx

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,14 @@
22
/* eslint-disable jsx-a11y/click-events-have-key-events */
33
import cn from 'classnames';
44
import { MouseEvent, useCallback, useRef } from 'react';
5-
import { useDispatch } from 'react-redux';
65

7-
import useTypesSelector from '../../hooks/useTypesSelector';
8-
import { setShowModal } from '../../store/actions/users';
6+
import { useAppDispatch, useAppSelector } from '../../hooks/useStore';
7+
import { setShowModal } from '../../store/slices/usersSlice';
98

10-
const Modal = () => {
11-
const dispatch = useDispatch();
9+
export const Modal = () => {
10+
const dispatch = useAppDispatch();
1211
const modalBackground = useRef<HTMLDivElement>(null);
13-
const showModal = useTypesSelector(({ users }) => users.showModal);
12+
const showModal = useAppSelector(({ users }) => users.showModal);
1413

1514
const handleModalVisibility = useCallback(
1615
() => dispatch(setShowModal(false)),
@@ -50,5 +49,3 @@ const Modal = () => {
5049
</div>
5150
);
5251
};
53-
54-
export default Modal;

0 commit comments

Comments
 (0)