Skip to content

Commit

Permalink
Merge pull request #127 from AJD-Archive/fix/126
Browse files Browse the repository at this point in the history
#126 fix: 블록 상태 api 변경 &  휴지통 api 연동
  • Loading branch information
sinamong0620 authored Dec 19, 2024
2 parents aa410af + 6599083 commit b050d50
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 19 deletions.
12 changes: 9 additions & 3 deletions src/api/PersonalBlockApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,16 @@ export const getPersonalBlock = async (blockId: string | null): Promise<BlockLis
};

//블록의 상태 수정
export const updatePersonalBlock = async (blockId?: string, progress?: string) => {
export const updatePersonalBlock = async (
blockId?: string,
progress?: string,
order?: BlockOrder
) => {
try {
const response = await axiosInstance.patch(`/blocks/${blockId}/progress?progress=${progress}`);
console.log(response);
const response = await axiosInstance.patch(
`/blocks/${blockId}/progress?progress=${progress}`,
order
);
return response.data;
} catch (error) {
console.error('Error fetching data:', error);
Expand Down
19 changes: 14 additions & 5 deletions src/components/PersonalDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ const PersonalDashBoard = () => {
const updateState = async (
destinationKey: string,
sourceKey: string,
targetItem: BlockListResDto
targetItem: BlockListResDto,
_items: TItems
) => {
const blockId = targetItem.blockId;

if (blockId) {
if (destinationKey === 'icon') return;
if (destinationKey !== 'delete') {
updatePersonalBlock(blockId, status(destinationKey)); // 블록 상태 업데이트
const orderArray = {
dashboardId: dashboardId,
notStartedList: _items.todo.map(item => item.blockId),
inProgressList: _items.doing.map(item => item.blockId),
completedList: _items.completed.map(item => item.blockId),
};
updatePersonalBlock(blockId, status(destinationKey), orderArray); // 블록 상태 업데이트
} else {
deleteBlock(blockId); // 블록 삭제
}
Expand Down Expand Up @@ -144,10 +151,13 @@ const PersonalDashBoard = () => {
setItems(_items);

if (sourceKey !== destinationKey) {
updateState(destinationKey, sourceKey, targetItem);
updateState(destinationKey, sourceKey, targetItem, _items);
} else {
updateOrder(_items);
}

if (destination.droppableId === 'icon') {
console.log('icon');
deleteBlock(targetItem.blockId ?? '');
}
//시작점 상태에서 종착지가 시작점 상태와는 다른 상태일때 그 아이템 개수 -1
if (source.droppableId === 'todo' && destination.droppableId !== 'todo')
Expand Down Expand Up @@ -178,7 +188,6 @@ const PersonalDashBoard = () => {
[destination.droppableId]:
blockTotal[destination.droppableId as keyof typeof blockTotal] + 1,
}));
updateOrder(_items);
};

return (
Expand Down
20 changes: 14 additions & 6 deletions src/components/TeamDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -92,12 +92,18 @@ const TeamDashBoard = () => {
};

// * 상태 변경 함수
const updateState = (destinationKey: string, targetItem: BlockListResDto) => {
const updateState = (destinationKey: string, targetItem: BlockListResDto, _items: TItems) => {
const blockId = targetItem.blockId;

if (blockId) {
if (destinationKey !== 'delete') {
updatePersonalBlock(blockId, status(destinationKey)); // 블록 상태 업데이트
const orderArray = {
dashboardId: dashboardId,
notStartedList: _items.todo.map(item => item.blockId),
inProgressList: _items.doing.map(item => item.blockId),
completedList: _items.completed.map(item => item.blockId),
};
updatePersonalBlock(blockId, status(destinationKey), orderArray); // 블록 상태 업데이트
} else {
// console.log('블록 삭제할게요');
deleteBlock(blockId); // 블록 삭제
Expand Down Expand Up @@ -134,9 +140,13 @@ const TeamDashBoard = () => {
setItems(_items);

if (sourceKey !== destinationKey) {
updateState(destinationKey, targetItem);
updateState(destinationKey, targetItem, _items);
} else {
updateOrder(_items);
}
if (destination.droppableId === 'icon') {
deleteBlock(targetItem.blockId ?? '');
}

//시작점 상태에서 종착지가 시작점 상태와는 다른 상태일때 그 아이템 개수 -1
if (source.droppableId === 'todo' && destination.droppableId !== 'todo')
setBlockTotal(prev => ({
Expand Down Expand Up @@ -166,8 +176,6 @@ const TeamDashBoard = () => {
[destination.droppableId]:
blockTotal[destination.droppableId as keyof typeof blockTotal] + 1,
}));

updateOrder(_items);
};
return (
<>
Expand Down
2 changes: 1 addition & 1 deletion src/styles/DashboardStyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ export const CardContainer = styled.div<Props>`
flex-shrink: 0;
border-radius: 10px;
background: ${({ backGroundColor }) => backGroundColor};
min-width: 19.449rem;
min-width: 15.449rem;
header {
display: flex;
Expand Down
4 changes: 0 additions & 4 deletions src/styles/MainPageStyled.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,6 @@ export const CardContainer = styled.section`
justify-content: center;
padding: 4.5vw 3.8125vw;
gap: 1.563rem;
@media screen and (min-width: 1700px) {
justify-content: space-evenly;
}
`;

export const DeleteContainer = styled.div`
Expand Down

0 comments on commit b050d50

Please sign in to comment.