Skip to content

Commit

Permalink
feat/ finish add team
Browse files Browse the repository at this point in the history
  • Loading branch information
k0t1k777 committed Aug 15, 2024
1 parent bdc7452 commit 5c4c83b
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 35 deletions.
11 changes: 9 additions & 2 deletions src/pages/NewTeam/NewTeam.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ export default function NewTeam() {
});

setAllCards(newAllCards);
setOriginalCards(newAllCards);
setBusyCells(newBusyCells);
}, [cards]);

Expand All @@ -60,7 +61,10 @@ export default function NewTeam() {
}
}, [allCards]);
console.log('allCards: ', allCards);


const [originalCards, setOriginalCards] = useState<membersProps[]>([]);
console.log('originalCards: ', originalCards);

return (
<section
className={styles.newTeam}
Expand All @@ -71,7 +75,10 @@ export default function NewTeam() {
<div className={styles.title}>Добавьте члена команды сюда</div>
) : (
<div className={styles.cardContainer}>
{allCards.map((card) => renderCards(card, setAllCards))}{' '}
{allCards.map((card) =>
renderCards(card, setAllCards, originalCards, setOriginalCards
)
)}
{renderEmptyCells(busyCells, isFilterOpen)}
{arrows}
</div>
Expand Down
19 changes: 16 additions & 3 deletions src/services/helpers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ import Card from 'src/ui/Card/Card';
// Рендер карточек в дереве
export const renderCards = (
card: membersProps,
setAllCards: React.Dispatch<React.SetStateAction<membersProps[]>>
setAllCards: React.Dispatch<React.SetStateAction<membersProps[]>>,
originalCards: membersProps[],
setOriginalCards: React.Dispatch<React.SetStateAction<membersProps[]>>,
) => {

if (!card.cellId || !card.subordinates) {
return null;
}
const handleButtonClick = () => {
const hideMembers = () => {
console.log('Прячем')

setOriginalCards(allCards => [...allCards]);
if (!card.cellId) {
return card;
}
Expand Down Expand Up @@ -46,6 +52,12 @@ export const renderCards = (
}
};

const restoreMembers = () => {
// Восстанавливаем оригинальные карточки
console.log('Восстанавливаем')
setAllCards(originalCards);
};

const [col, row] = card.cellId.split('-').map(Number);
return (
<div
Expand All @@ -59,7 +71,8 @@ export const renderCards = (
full_name={card.full_name}
department={card.department}
count={card.subordinates.length}
handleButtonClick={handleButtonClick}
hideMembers={hideMembers}
restoreMembers={restoreMembers}
/>
</div>
);
Expand Down
3 changes: 2 additions & 1 deletion src/services/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ export interface membersProps {
photo?: string;
count?: number;
subordinates?: membersProps[];
handleButtonClick?: () => void;
hideMembers?: () => void;
restoreMembers?: () => void;
onDragStart?: (e: React.DragEvent<HTMLDivElement>) => void;
draggable?: boolean;
isFilterOpen?: boolean;
Expand Down
6 changes: 0 additions & 6 deletions src/store/features/slice/membersSlice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ export interface StateType {
membersAmount: number;
shortWindow: boolean;
membersValue: string;
showMembers: boolean;
}

const initialState: StateType = {
Expand All @@ -24,7 +23,6 @@ const initialState: StateType = {
membersAmount: 0,
shortWindow: false,
membersValue: '',
showMembers: false,
};

export const fetchGetMembersAmount = createAsyncThunk(
Expand Down Expand Up @@ -64,9 +62,6 @@ const membersSlice = createSlice({
setShortWindow(state, action) {
state.shortWindow = action.payload;
},
setShowMembers(state, action) {
state.showMembers = action.payload;
},
},
extraReducers: (builder) => {
builder
Expand Down Expand Up @@ -101,7 +96,6 @@ export const {
setIsFilterOpen,
setCurrentPage,
setShortWindow,
setShowMembers,
} = membersSlice.actions;
export const membersReducer = membersSlice.reducer;
export const selectMembers = (state: RootStore) => state.members;
38 changes: 15 additions & 23 deletions src/ui/Card/Card.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
import {
CloseOutlined,
DownOutlined,
EditOutlined,
UpOutlined,
} from '@ant-design/icons';
import styles from 'src/ui/Card/Card.module.scss';
import Avatar from 'src/assets/images/Avatar.png';
import { useState } from 'react';
import cn from 'classnames/bind';
import { membersProps } from 'src/services/types';
import {
selectMembers,
setShowMembers,
} from 'src/store/features/slice/membersSlice';
import { useAppDispatch, useAppSelector } from 'src/store/hooks';
CloseOutlined,
DownOutlined,
EditOutlined,
UpOutlined,
} from '@ant-design/icons';

const cx = cn.bind(styles);

Expand All @@ -26,12 +21,12 @@ export default function Card({
title,
count,
id,
handleButtonClick,
hideMembers,
restoreMembers,
onDragStart,
}: membersProps) {
const [isOpen, setIsopen] = useState(true);
// let { showMembers } = useAppSelector(selectMembers);
// const dispatch = useAppDispatch();
const [showMembers, setShowMembers] = useState(true);
console.log('showMembers: ', showMembers);

return (
<div
Expand Down Expand Up @@ -86,18 +81,15 @@ export default function Card({
className={cx(styles.countImg, {
[styles.disabled]: employesRout,
})}
onClick={() => setIsopen(!isOpen)}
onClick={() => setShowMembers(!showMembers)}
>
{isOpen ? (
<UpOutlined
onClick={handleButtonClick}
// onClick={() => dispatch(setShowMembers(!showMembers))}
{showMembers ? (
<DownOutlined
onClick={hideMembers}
/>
) : (
<DownOutlined
onClick={handleButtonClick}

// onClick={() => dispatch(setShowMembers(!showMembers))}
<UpOutlined
onClick={restoreMembers}
/>
)}
</div>
Expand Down

0 comments on commit 5c4c83b

Please sign in to comment.