Skip to content

Commit

Permalink
fix/id in string
Browse files Browse the repository at this point in the history
  • Loading branch information
k0t1k777 committed Aug 9, 2024
1 parent 490c7d0 commit 41403e4
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 104 deletions.
29 changes: 16 additions & 13 deletions src/components/App/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@ import {
selectUsers,
setLoggedIn,
} from 'src/store/features/slice/userSlice';

// import * as Api from 'src/services/utils'
export interface DroppedCard {
id: string;
cellId: string;
}

export default function App() {
let { loggedIn } = useAppSelector(selectUsers);


const dispatch = useAppDispatch();
const navigate = useNavigate();

Expand All @@ -38,19 +40,20 @@ export default function App() {
});
}

const [members, setMembers] = useState('')
console.log('members: ', members);
// const [members, setMembers] = useState('')

// useEffect(() => {
// dispatch(fetchGetMembers())
// .then((data) => {
// setMembers(data)
// console.log('data: ', data);
// } )
// .catch((error) => {
// console.error(error)
// })
// }, [])


useEffect(() => {
Api.getMembers()
.then((data) => {
setMembers(data)
console.log('data: ', data);
} )
.catch((error) => {
console.error(error)
})
}, [])

// ДНД
const [droppedCards, setDroppedCards] = useState<DroppedCard[]>([]);
Expand Down
3 changes: 2 additions & 1 deletion src/components/Filter/Filter.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@
right: 10px;
border-radius: 0 0 0 16px;
width: 354px;
height: 100%;
height: 100vh;
box-shadow: 0 0 12px 0 rgba(0, 0, 0, 0.12);
background: #fff;
padding: 56px 48px;
z-index: 3;
overflow-y: auto;
}

.container {
Expand Down
19 changes: 14 additions & 5 deletions src/components/Filter/Filter.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import styles from 'src/components/Filter/Filter.module.scss';
import { useRef } from 'react';
import { useEffect, useRef } from 'react';
import useOutsideClick from 'src/hooks/useOutsideClick';
import { Input } from 'antd';
import { CloseOutlined } from '@ant-design/icons';
import Card from 'src/ui/Card/Card';
import { cardsList } from 'src/services/mock';
// import { cardsList } from 'src/services/mock';
import { DroppedCard } from '../App/App';
import FilterList from 'src/ui/FilterList/FilterList';
import { fetchGetMembers, selectMembers } from 'src/store/features/slice/membersSlice';
import { useAppDispatch, useAppSelector } from 'src/store/hooks';

interface FilterProps {
isFilterOpen: boolean;
Expand All @@ -21,12 +23,19 @@ export default function Filter({
onDragStart,
droppedCards,
}: FilterProps) {
const dispatch = useAppDispatch();
const { members } = useAppSelector(selectMembers);
console.log('members: ', members);

useEffect(() => {
dispatch(fetchGetMembers());
}, [dispatch]);

const ref = useRef(null);

useOutsideClick(ref, () => {
setIsFilterOpen(false);
});
console.log('droppedCards: ', droppedCards);

return (
<div ref={ref} className={styles.filter}>
Expand All @@ -37,11 +46,11 @@ export default function Filter({
</div>
<FilterList teams='Подразделение' positions='Должность' city='Город' />
<div className={styles.containerResult}>
{cardsList.map((card, index) => (
{members.map((card, index) => (
<Card
id={card.id}
key={card.id}
name={card.name}
name={card.full_name}
position={card.position}
index={index}
isFilterOpen={isFilterOpen}
Expand Down
116 changes: 58 additions & 58 deletions src/services/mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export const initialCards = [
{
id: '0',
id: 1,
name: 'Директор',
position: 'Разработчик',
title: 'Frontend Developer',
Expand All @@ -24,68 +24,68 @@ export const initialCards = [

export const cardsList = [
{
id: '6',
id: 6,
name: 'Иван',
position: 'Разработчик',
title: 'Frontend Developer',
photo: 'https://example.com/photo1.jpg',
parentId: '',
subordinates: [],
},
{
id: '7',
name: 'Мария',
position: 'Дизайнер',
title: 'UI/UX Designer',
photo: 'https://example.com/photo2.jpg',
subordinates: [],
},
{
id: '8',
name: 'Сергей',
position: 'Менеджер',
title: 'Project Manager',
photo: 'https://example.com/photo3.jpg',
subordinates: [],
},
{
id: '9',
name: 'Ольга',
position: 'Аналитик',
title: 'Data Analyst',
photo: 'https://example.com/photo4.jpg',
subordinates: [],
},
{
id: '10',
name: 'Алексей Сидоров',
position: 'Тестировщик',
title: 'QA Engineer',
photo: 'https://example.com/photo5.jpg',
subordinates: [],
},
{
id: '11',
name: 'Петя',
position: 'Скорее бы на море',
title: 'QA Engineer',
photo: 'https://example.com/photo5.jpg',
subordinates: [],
},
{
id: '12',
name: 'Алха',
position: 'КТо',
title: 'QA Engineer',
photo: 'https://example.com/photo5.jpg',
subordinates: [],
},
{
id: '13',
name: 'Трампампам',
position: 'Никто',
title: 'QA Engineer',
photo: 'https://example.com/photo5.jpg',
subordinates: [],
},
// {
// id: '7',
// name: 'Мария',
// position: 'Дизайнер',
// title: 'UI/UX Designer',
// photo: 'https://example.com/photo2.jpg',
// subordinates: [],
// },
// {
// id: '8',
// name: 'Сергей',
// position: 'Менеджер',
// title: 'Project Manager',
// photo: 'https://example.com/photo3.jpg',
// subordinates: [],
// },
// {
// id: '9',
// name: 'Ольга',
// position: 'Аналитик',
// title: 'Data Analyst',
// photo: 'https://example.com/photo4.jpg',
// subordinates: [],
// },
// {
// id: '10',
// name: 'Алексей Сидоров',
// position: 'Тестировщик',
// title: 'QA Engineer',
// photo: 'https://example.com/photo5.jpg',
// subordinates: [],
// },
// {
// id: '11',
// name: 'Петя',
// position: 'Скорее бы на море',
// title: 'QA Engineer',
// photo: 'https://example.com/photo5.jpg',
// subordinates: [],
// },
// {
// id: '12',
// name: 'Алха',
// position: 'КТо',
// title: 'QA Engineer',
// photo: 'https://example.com/photo5.jpg',
// subordinates: [],
// },
// {
// id: '13',
// name: 'Трампампам',
// position: 'Никто',
// title: 'QA Engineer',
// photo: 'https://example.com/photo5.jpg',
// subordinates: [],
// },
];
7 changes: 7 additions & 0 deletions src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,13 @@ export interface initialCardsProps {
subordinates: initialCardsProps[];
}

export interface membersProps {
id: string;
full_name: string;
position: string;
subordinates: initialCardsProps[];
}

export interface RegisterDataProps {
email: string;
password: string;
Expand Down
45 changes: 25 additions & 20 deletions src/services/utils.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { RegisterDataProps } from './types';
export const BASE_URL = 'https://gazprom.hopto.org/api'

const getResponseData = (res: Response) => {
Expand All @@ -8,28 +7,34 @@ const getResponseData = (res: Response) => {
return res.json()
}

const headers = {
// authorization: `Bearer ${TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',
}
// const headers = {
// // authorization: `Bearer ${TOKEN}`,
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// }

export const registration = ({email, password}: RegisterDataProps) => {
return fetch(`${BASE_URL}/token/`, {
method: 'POST',
headers: {
Accept: 'application/json',
'Content-Type': 'application/json',
},
body: JSON.stringify({
email,
password,
}),
}).then(getResponseData)
}
// export const registration = ({email, password}: RegisterDataProps) => {
// return fetch(`${BASE_URL}/token/`, {
// method: 'POST',
// headers: {
// Accept: 'application/json',
// 'Content-Type': 'application/json',
// },
// body: JSON.stringify({
// email,
// password,
// }),
// }).then(getResponseData)
// }

export const getMembers = () => {
return fetch(`${BASE_URL}/members/`, {
const TOKEN = localStorage.getItem('token');
const headers = {
authorization: `Bearer ${TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};
return fetch(`${BASE_URL}/v1/members/`, {
method: 'GET',
headers,
}).then(getResponseData);
Expand Down
25 changes: 20 additions & 5 deletions src/store/api.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
export const BASE_URL = 'https://gazprom.hopto.org/api';
import { RegisterDataProps } from 'src/services/types';
const TOKEN = localStorage.getItem('token');
const headers = {
authorization: `Bearer ${TOKEN}`,
Accept: 'application/json',
'Content-Type': 'application/json',
};

type RequestOptionsType = RequestInit & {
headers: Record<string, string>;
Expand All @@ -9,11 +15,11 @@ export const checkResponse = (response: Response) => {
if (response.ok) {
return response.json();
}
return response
.json()
.then((data) => {
return Promise.reject(`Ошибка ${response.status}: ${data.message || 'Неизвестная ошибка'}`);
});
return response.json().then((data) => {
return Promise.reject(
`Ошибка ${response.status}: ${data.message || 'Неизвестная ошибка'}`
);
});
};

const request = (endpoint: string, options?: RequestOptionsType) =>
Expand All @@ -30,3 +36,12 @@ export const registration = async ({ email, password }: RegisterDataProps) => {
};
return await request('/token/', options);
};

export const getMembers = async () => {
const options: RequestOptionsType = {
method: 'GET',
headers,
};

return await request('/v1/members/', options);
};
Loading

0 comments on commit 41403e4

Please sign in to comment.