Skip to content

Commit

Permalink
feat/ headers for functions
Browse files Browse the repository at this point in the history
  • Loading branch information
k0t1k777 committed Aug 17, 2024
1 parent e26821c commit a0e059c
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 57 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
Логин: [email protected]
Пароль: admin

# Проект "Gazprom"

Проект представляет собой MVP web-приложения для онлайн-галереи, представленное командой №5 в рамках Хакатон+ по задаче от sagaart.
Проект представляет собой MVP web-приложения для онлайн-галереи, представленное командой №1 в рамках Хакатон+ по задаче от sagaart.

[**Ссылка на сайт**](https://gazprom.hopto.org)

Expand Down
19 changes: 12 additions & 7 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import Header from 'src/components/Header/Header';
import SideBar from 'src/components/SideBar/SideBar';
import { Outlet, useNavigate } from 'react-router-dom';
import { useEffect, useState } from 'react';
// import { initialCards } from 'src/services/mock';
import { useAppDispatch, useAppSelector } from 'src/store/hooks';
import Registration from 'src/pages/Registration/Registration';
import {
Expand All @@ -16,19 +15,21 @@ import { membersProps, RegisterDataProps } from 'src/services/types';
import {
registerUser,
selectUsers,
setLoading,
setLoggedIn,
} from 'src/store/features/slice/userSlice';
import Preloader from 'src/ui/Preloader/Preloader';

export default function App() {
let { loggedIn } = useAppSelector(selectUsers);
const dispatch = useAppDispatch();
const navigate = useNavigate();
let { loggedIn, loading } = useAppSelector(selectUsers);
const [droppedCards, setDroppedCards] = useState<membersProps[]>([]);
let { cards } = useAppSelector(selectMembers);

// const [cards, setCards] = useState<membersProps[]>([]);
const { members } = useAppSelector(selectMembers);
const dispatch = useAppDispatch();
const navigate = useNavigate();

function handleRegister({ email, password }: RegisterDataProps) {
dispatch(setLoading(true));
dispatch(registerUser({ email, password }))
.unwrap()
.then((data) => {
Expand All @@ -40,6 +41,9 @@ export default function App() {
})
.catch((error) => {
console.error('Ошибка регистрации:', error);
})
.finally(() => {
dispatch(setLoading(false));
});
}

Expand All @@ -49,10 +53,11 @@ export default function App() {
dispatch(setLoggedIn(true));
}
}, [dispatch]);
const { members } = useAppSelector(selectMembers);

return (
<div>
<Header droppedCards={droppedCards} />
{loading && <Preloader />}
{loggedIn ? (
<div className='container'>
<SideBar />
Expand Down
14 changes: 7 additions & 7 deletions src/components/SideBar/SideBar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ import Modal from 'src/ui/Modal/Modal';
const cx = cn.bind(styles);

export default function SideBar() {
const [isModalVisible, setIsModalVisible] = useState(false);
const [teamName, setTeamName] = useState('');
// const [isModalVisible, setIsModalVisible] = useState(false);
// const [teamName, setTeamName] = useState('');
let { shortWindow } = useAppSelector(selectMembers);
const dispatch = useAppDispatch();
const [showMore, setShorMore] = useState(true);
Expand All @@ -44,11 +44,11 @@ export default function SideBar() {
dispatch(setIsFilterOpen(true));
}

const handleOk = () => {
// Здесь можно обработать отправку имени команды
console.log('Имя команды:', teamName);
setIsModalVisible(false);
};
// const handleOk = () => {
// // Здесь можно обработать отправку имени команды
// console.log('Имя команды:', teamName);
// setIsModalVisible(false);
// };

return (
<div
Expand Down
26 changes: 18 additions & 8 deletions src/pages/Main/Main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,17 @@ import Card from 'src/ui/Card/Card';
import Arrow from 'src/ui/Arrow/Arrow';
import Preloader from 'src/ui/Preloader/Preloader';
import { id } from 'src/services/const';
import { selectUsers, setLoading } from 'src/store/features/slice/userSlice';

export default function Main() {


const dispatch = useAppDispatch();
const { team } = useAppSelector(selectTeams);
let { loading } = useAppSelector(selectUsers);

const [allCards, setAllCards] = useState<membersProps[]>([]);
const [updatedCards, setUpdatedCards] = useState<membersProps[]>([]);
const [teamCard, setTeamCard] = useState<membersProps[]>([]);
const [loading, setLoading] = useState(true);
const [drawArrows, setDrawArrows] = useState<JSX.Element[]>([]);

const collectCellIds = (card: membersProps, collected: string[]) => {
if (card.cellId) {
Expand Down Expand Up @@ -118,7 +118,6 @@ export default function Main() {
);
};

const [drawArrows, setDrawArrows] = useState<JSX.Element[]>([]);

// Находим родительскую карточку
const findArrows = (parentId: string) => {
Expand Down Expand Up @@ -158,7 +157,6 @@ export default function Main() {

useEffect(() => {
const foundParentCard = teamCard.find((card) => card.parent_id === null);

if (foundParentCard) {
const arrows = findArrows(foundParentCard.id);
setDrawArrows(arrows);
Expand All @@ -171,18 +169,30 @@ export default function Main() {

useEffect(() => {
const fetchData = async () => {
setLoading(true);
dispatch(setLoading(true));
await dispatch(fetchGetTeams());
if (id) {
const parsedId = parseInt(id, 10);
await dispatch(fetchGetTeamsId(parsedId));
}
setLoading(false);
dispatch(setLoading(false));
};

fetchData();
}, [dispatch, id]);

// const fetchData = async () => {
// setLoading(true); // Устанавливаем загрузку в true
// await dispatch(fetchGetTeams());
// if (id) {
// const parsedId = parseInt(id, 10);
// await dispatch(fetchGetTeamsId(parsedId));
// }
// setLoading(false); // Устанавливаем загрузку в false
// // setDataLoaded(true); // Данные загружены
// };
// fetchData();
// }, [dispatch, id]);

useEffect(() => {
if (team?.employees) {
const allEmployeeData = [{ ...team.employees, cellId: '1-0' }];
Expand Down
1 change: 0 additions & 1 deletion src/pages/NewTeam/NewTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ export default function NewTeam() {
const { allowDrop, handleDrop } = useOutletContext<{
allowDrop: (e: React.DragEvent<HTMLImageElement>) => void;
handleDrop: (e: React.DragEvent<HTMLDivElement>) => void;
// cards: membersProps[];
}>();
let { isFilterOpen, cards } = useAppSelector(selectMembers);

Expand Down
12 changes: 7 additions & 5 deletions src/pages/Teams/Teams.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,15 @@ import Card from 'src/ui/Card/Card';
import TeamsItem from 'src/ui/TeamsItem/TeamsItem';
import Preloader from 'src/ui/Preloader/Preloader'
import Arrow from 'src/ui/Arrow/Arrow';
import { selectUsers, setLoading } from 'src/store/features/slice/userSlice';

export default function Teams() {
const { id } = useParams();
const dispatch = useAppDispatch();
const { teams, team } = useAppSelector(selectTeams);
const [loading, setLoading] = useState(true);
let { loading } = useAppSelector(selectUsers);
const dispatch = useAppDispatch();

// const [loading, setLoading] = useState(true);

const [allCards, setAllCards] = useState<membersProps[]>([]);
const [updatedCards, setUpdatedCards] = useState<membersProps[]>([]);
Expand Down Expand Up @@ -173,15 +176,14 @@ export default function Teams() {

useEffect(() => {
const fetchData = async () => {
setLoading(true);
dispatch(setLoading(true));
await dispatch(fetchGetTeams());
if (id) {
const parsedId = parseInt(id, 10);
await dispatch(fetchGetTeamsId(parsedId));
}
setLoading(false);
dispatch(setLoading(false));
};

fetchData();
}, [dispatch, id]);

Expand Down
2 changes: 0 additions & 2 deletions src/services/dragAndDrop.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { cellHeight, cellWidth } from 'src/services/const';
// import { cardsList } from 'src/services/mock';
import { membersProps } from 'src/services/types';
import { setCards } from 'src/store/features/slice/membersSlice';
import { useAppDispatch } from 'src/store/hooks';

// Начальная область переноса
export const handleDragStart = (
Expand Down
34 changes: 19 additions & 15 deletions src/store/api.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,17 @@
export const BASE_URL = 'https://gazprom.hopto.org';
import { RegisterDataProps } from 'src/services/types';
const TOKEN = localStorage.getItem('token');
const headers = {
authorization: `Bearer ${TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',

const getToken = () => {
return localStorage.getItem('token');
};

const createHeaders = () => {
const TOKEN = getToken();
return {
authorization: `Bearer ${TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};
};

type RequestOptionsType = RequestInit & {
Expand All @@ -28,10 +35,7 @@ const request = (endpoint: string, options?: RequestOptionsType) =>
export const registration = async ({ email, password }: RegisterDataProps) => {
const options: RequestOptionsType = {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
headers: createHeaders(),
body: JSON.stringify({ email, password }),
};
return await request('/api/token/', options);
Expand All @@ -40,7 +44,7 @@ export const registration = async ({ email, password }: RegisterDataProps) => {
export const getProfile = async () => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
const response = await request('/api/v1/users/me/', options);
return response;
Expand All @@ -49,7 +53,7 @@ export const getProfile = async () => {
export const getMembersAmount = async () => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
const response = await request('/api/v1/members/', options);
return response;
Expand All @@ -58,31 +62,31 @@ export const getMembersAmount = async () => {
export const getMembers = async (page: number) => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
return await request(`/api/v1/members/?page=${page}`, options);
};

export const getTeams = async () => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
return await request('/api/v1/teams/', options);
};

export const getProjects = async () => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
return await request('/api/v1/projects/', options);
};

export const getTeamsId = async (id: number) => {
const options: RequestOptionsType = {
method: 'GET',
headers,
headers: createHeaders(),
};
return await request(`/api/v1/teams/${id}/`, options);
};
Expand Down
7 changes: 6 additions & 1 deletion src/store/features/slice/userSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface StateType {
error: string | null | unknown;
loggedIn: boolean;
profile: ProfileProps | null;
loading: boolean;
}

const initialState: StateType = {
Expand All @@ -17,6 +18,7 @@ const initialState: StateType = {
error: null,
loggedIn: false,
profile: null,
loading: false,
};
// фетч добавить
export const registerUser = createAsyncThunk(
Expand All @@ -42,6 +44,9 @@ const userSlice = createSlice({
state.access = action.payload;
state.loggedIn = true;
},
setLoading(state, action) {
state.loading = action.payload;
},
},
extraReducers: (builder) => {
builder
Expand Down Expand Up @@ -73,6 +78,6 @@ const userSlice = createSlice({
},
});

export const { setLoggedIn } = userSlice.actions;
export const { setLoggedIn, setLoading } = userSlice.actions;
export const userReducer = userSlice.reducer;
export const selectUsers = (state: RootStore) => state.user;
8 changes: 4 additions & 4 deletions src/ui/Modal/Modal.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Button, Input } from 'antd';
import styles from 'src/ui/Modal/Modal.module.scss';

interface RegistrationProps {
handleOk: () => void;
handleCancel: () => void;
}
// interface RegistrationProps {
// handleOk: () => void;
// handleCancel: () => void;
// }

export default function Modal() {

Expand Down
File renamed without changes.
10 changes: 4 additions & 6 deletions src/ui/Preloader/Preloader.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
import 'src/ui/Preloader/Preloader.scss';
import styles from 'src/ui/Preloader/Preloader.module.scss';

export default function Preloader() {

return (
<div className='preloader'>
<div className='preloader__overlay'></div>
<div
className='preloader__loader'></div>
<div className={styles.preloader}>
<div className={styles.preloader__overlay}></div>
<div className={styles.preloader__loader}></div>
</div>
);
}

0 comments on commit a0e059c

Please sign in to comment.