Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FE] 행사 삭제 기능 구현 #903

Merged
merged 23 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7d3dcaa
feat: 항목 터치를 길게 했을 때 애니메이션 발생하는 기능 구현
jinhokim98 Jan 2, 2025
b5df826
Merge branch 'fe-dev' of https://github.com/woowacourse-teams/2024-ha…
jinhokim98 Jan 3, 2025
49ad133
refactor: long press 애니메이션 커스텀 훅으로 분리
jinhokim98 Jan 3, 2025
60a8128
refactor: animation hook으로 분리한 것 적용
jinhokim98 Jan 3, 2025
f4e4cc8
feat: mode와 선택된 행사를 관리할 수 있는 context 생성
jinhokim98 Jan 3, 2025
ae12825
feat: 체크박스 label 숨길 수 있도록 기능 추가
jinhokim98 Jan 3, 2025
e139fd0
feat: 현재 리스트에 포함되어있는지를 찾는 함수 추가
jinhokim98 Jan 3, 2025
26cde86
feat: 편집하기를 누른 후 체크박스를 선택할 수 있도록 기능추가
jinhokim98 Jan 3, 2025
763cc1d
style: 불필요한 theme 주입 삭제
jinhokim98 Jan 3, 2025
a0765e2
fix: 애니메이션 색 보이지 않던 문제 해결
jinhokim98 Jan 3, 2025
4f12343
feat: 행사 목록에서 행사를 지우는 기능 추가
jinhokim98 Jan 3, 2025
3623755
refactor: toast를 query hook으로 이동
jinhokim98 Jan 3, 2025
e903cea
feat: 행사 페이지 내에서 행사 삭제 기능 추가
jinhokim98 Jan 3, 2025
38b70d8
style: default 값 상수화
jinhokim98 Jan 3, 2025
b30c41f
refactor: handleTouchEnd와 handleTouchMove 기능 하나로 합침
jinhokim98 Jan 3, 2025
8d561c8
style: console.log 제거거
jinhokim98 Jan 3, 2025
530e74a
style: CreatedEventList 컴포넌트 분리
jinhokim98 Jan 7, 2025
b6795b4
style: isAlreadySelected로 메서드 이름 변경
jinhokim98 Jan 7, 2025
fe6fbab
style: labelText를 option으로 주어 hideLabelText prop 삭제
jinhokim98 Jan 7, 2025
62025e2
feat: 편집 모드가 켜졌을 때 애니메이션 보이지 않도록 설정
jinhokim98 Jan 8, 2025
2d2b459
feat: 애니메이션 비활성화
jinhokim98 Jan 8, 2025
2e9b234
feat: 시간보다 행사 상태를 기준으로 먼저 정렬하는 기능 추가
jinhokim98 Jan 8, 2025
919c9a3
feat: 행사 삭제 시 회원이면 마이페이지, 비회원이면 랜딩으로 보내는 기능
jinhokim98 Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions client/src/apis/request/event.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {BankAccount, CreatedEvents, Event, EventCreationData, EventName} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {ADMIN_API_PREFIX, MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestPatchWithoutResponse, requestPostWithResponse} from '@apis/request';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestGet, requestPatchWithoutResponse, requestPostWithResponse} from '@apis/request';
import {WithEventId} from '@apis/withId.type';

export const requestPostGuestEvent = async (postEventArgs: EventCreationData) => {
Expand Down Expand Up @@ -52,3 +52,14 @@ export const requestGetCreatedEvents = async () => {
endpoint: `${MEMBER_API_PREFIX}/mine`,
});
};

type DeleteEvents = {
eventIds: string[];
};

export const requestDeleteEvents = async (args: DeleteEvents) => {
await requestDelete({
endpoint: MEMBER_API_PREFIX,
body: args,
});
};
59 changes: 59 additions & 0 deletions client/src/components/CreatedEventList/index.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import useRequestDeleteEvents from '@hooks/queries/event/useRequestDeleteEvents';
import {useCreatedEventsPageContext} from '@pages/mypage/events/CreatedEvent.context';
import {CreatedEvent} from 'types/serviceType';
import {CreatedEventItem} from '@components/Design/components/CreatedEvent/CreatedEvent';

import {FixedButton, Flex, Input} from '@components/Design';

type CreatedEventListProps = {
eventName: string;
onSearch: ({target}: React.ChangeEvent<HTMLInputElement>) => void;
placeholder: string;
createdEvents: CreatedEvent[];
};

export const CreatedEventList = ({createdEvents, eventName, onSearch, placeholder}: CreatedEventListProps) => {
const {mode, handleMode, selectedEvents, isAlreadySelected, handleSelectedEvents} = useCreatedEventsPageContext();
const setViewMode = () => handleMode('view');

const {deleteEvents} = useRequestDeleteEvents();

const onDeleteClick = async () => {
const selectedEventsId = selectedEvents.map(event => event.eventId);
await deleteEvents({eventIds: selectedEventsId});
handleMode('view');
};

return (
<>
<Flex
flexDirection="column"
width="100%"
backgroundColor="white"
padding="0.5rem 1rem"
paddingInline="0.5rem"
gap="0.5rem"
height="100%"
cssProp={{borderRadius: '1rem'}}
>
<Input inputType="search" value={eventName} onChange={onSearch} placeholder={placeholder} />
{createdEvents.length !== 0 &&
createdEvents.map(createdEvent => (
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

나중에 생성된 이벤트들을 목록에서 보여줄때 정산중인 행사들이 시간순으로 상단에 오면 좋을 것 같아요!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오 좋아요~~ 반영해봤습니다. 지금 isFinished 상태가 반전돼서 상태가 반대로 보이지만 토다리 pr이 반영되면 정상적으로 보일거예요

image

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

오~ 반영해주신 부분 너무 좋아요!
다만, 제가 생각했던 순서는 정산중이 목록 상단, 정산 완료가 목록 하단으로 오는 것이었습니다!
아래 처럼요!

  • 정산중
  • 정산중
  • 정산완료
  • 정산완료
  • 정산완료

<CreatedEventItem
key={createdEvent.eventId}
isEditMode={mode === 'edit'}
setEditMode={() => handleMode('edit')}
isChecked={isAlreadySelected(createdEvent)}
onChange={handleSelectedEvents}
createdEvent={createdEvent}
/>
))}
</Flex>
{mode === 'edit' && (
<FixedButton variants="tertiary" onDeleteClick={onDeleteClick} onClick={setViewMode}>
편집완료
</FixedButton>
)}
</>
);
};
4 changes: 2 additions & 2 deletions client/src/components/Design/components/Checkbox/Checkbox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import Icon from '../Icon/Icon';
import {checkboxStyle, inputGroupStyle} from './Checkbox.style';

interface Props {
labelText: string;
labelText?: string;
isChecked: boolean;
onChange: () => void;
}
Expand All @@ -20,7 +20,7 @@ const Checkbox = ({labelText, isChecked = false, onChange}: Props) => {
{isChecked ? <Icon iconType="check" iconColor="onPrimary" className="check-icon" /> : null}
<input type="checkbox" checked={isChecked} onChange={onChange} className="checkbox-input" />
</div>
<Text size="bodyBold">{labelText}</Text>
{labelText && <Text size="bodyBold">{labelText}</Text>}
</label>
);
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,10 @@ export const inProgressCheckStyle = ({inProgress, theme}: WithTheme<{inProgress:
paddingTop: '0.0625rem',
},
});

export const touchAreaStyle = css({
position: 'relative',
overflow: 'hidden',

width: '100%',
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,15 @@
import {useNavigate} from 'react-router-dom';

import Text from '@HDcomponents/Text/Text';
import {CreatedEvent} from 'types/serviceType';

import {useTheme} from '@components/Design';
import useLongPressAnimation from '@hooks/useLongPressAnimation';

import {Checkbox, useTheme} from '@components/Design';

import Flex from '../Flex/Flex';
import Input from '../Input/Input';

import {CreatedEventItemProps, CreatedEventListProps} from './CreatedEvent.type';
import {inProgressCheckStyle} from './CreatedEvent.style';
import {inProgressCheckStyle, touchAreaStyle} from './CreatedEvent.style';

function InProgressCheck({inProgress}: {inProgress: boolean}) {
const {theme} = useTheme();
Expand All @@ -23,48 +24,52 @@ function InProgressCheck({inProgress}: {inProgress: boolean}) {
);
}

function CreatedEventItem({createdEvent}: CreatedEventItemProps) {
export interface CreatedEventItemProps {
setEditMode: () => void;
isEditMode: boolean;
isChecked: boolean;
onChange: (event: CreatedEvent) => void;
createdEvent: CreatedEvent;
}

export function CreatedEventItem({isEditMode, setEditMode, isChecked, onChange, createdEvent}: CreatedEventItemProps) {
const navigate = useNavigate();

const onLongPress = () => {
setEditMode();
if (!isChecked) onChange(createdEvent);
};

const {handleTouchStart, handleTouchEnd, handleTouchMove} = useLongPressAnimation(onLongPress, {
disabled: isEditMode,
});

const onClick = () => {
navigate(`/event/${createdEvent.eventId}/admin`);
isEditMode ? onChange(createdEvent) : navigate(`/event/${createdEvent.eventId}/admin`);
};

return (
<Flex
justifyContent="spaceBetween"
alignItems="center"
height="2.5rem"
padding="0.5rem 1rem"
paddingInline="0.5rem"
onClick={onClick}
>
<Flex gap="0.5rem" alignItems="center">
<InProgressCheck inProgress={createdEvent.isFinished} />
<Text size="bodyBold" color="onTertiary">
{createdEvent.eventName}
</Text>
<Flex>
{isEditMode && <Checkbox isChecked={isChecked} onChange={() => onChange(createdEvent)} />}
<Flex
justifyContent="spaceBetween"
alignItems="center"
height="2.5rem"
padding="0.5rem 1rem"
paddingInline="0.5rem"
onClick={onClick}
css={touchAreaStyle}
onTouchStart={handleTouchStart}
onTouchMove={handleTouchMove}
onTouchEnd={handleTouchEnd}
>
<Flex gap="0.5rem" alignItems="center">
<InProgressCheck inProgress={createdEvent.isFinished} />
<Text size="bodyBold" color="onTertiary">
{createdEvent.eventName}
</Text>
</Flex>
</Flex>
</Flex>
);
}

function CreatedEventList({createdEvents, eventName, onSearch, placeholder}: CreatedEventListProps) {
return (
<Flex
flexDirection="column"
width="100%"
backgroundColor="white"
padding="0.5rem 1rem"
paddingInline="0.5rem"
gap="0.5rem"
height="100%"
cssProp={{borderRadius: '1rem'}}
>
<Input inputType="search" value={eventName} onChange={onSearch} placeholder={placeholder} />
{createdEvents.length !== 0 &&
createdEvents.map(createdEvent => <CreatedEventItem key={createdEvent.eventId} createdEvent={createdEvent} />)}
</Flex>
);
}

export default CreatedEventList;

This file was deleted.

24 changes: 24 additions & 0 deletions client/src/hooks/queries/event/useRequestDeleteEvents.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {useMutation, useQueryClient} from '@tanstack/react-query';

import {requestDeleteEvents} from '@apis/request/event';
import toast from '@hooks/useToast/toast';

import QUERY_KEYS from '@constants/queryKeys';

const useRequestDeleteEvents = () => {
const queryClient = useQueryClient();

const {mutateAsync} = useMutation({
mutationFn: requestDeleteEvents,
onSuccess: () => {
toast.confirm('행사가 정상적으로 삭제되었습니다');
queryClient.invalidateQueries({queryKey: [QUERY_KEYS.createdEvents]});
},
});

return {
deleteEvents: mutateAsync,
};
};

export default useRequestDeleteEvents;
11 changes: 10 additions & 1 deletion client/src/hooks/queries/event/useRequestGetCreatedEvents.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,25 @@
import {useQuery} from '@tanstack/react-query';

import {requestGetCreatedEvents} from '@apis/request/event';
import {CreatedEvent} from 'types/serviceType';

import QUERY_KEYS from '@constants/queryKeys';

const useRequestGetCreatedEvents = () => {
const sortByCreatedAndFinishedStatus = (a: CreatedEvent, b: CreatedEvent) => {
if (a.isFinished !== b.isFinished) {
return a.isFinished ? 1 : -1;
}

return new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime();
};

const {data, ...rest} = useQuery({
queryKey: [QUERY_KEYS.createdEvents],
queryFn: () => requestGetCreatedEvents(),
select: data => ({
...data,
events: data.events.sort((a, b) => new Date(b.createdAt).getTime() - new Date(a.createdAt).getTime()),
events: data.events.sort(sortByCreatedAndFinishedStatus),
}),
});

Expand Down
3 changes: 2 additions & 1 deletion client/src/hooks/useAdminPage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import useEventDataContext from './useEventDataContext';

const useAdminPage = () => {
const eventId = getEventIdByUrl();
const {isAdmin, bankName, accountNumber, eventName} = useEventDataContext();
const {isAdmin, bankName, accountNumber, eventName, createdByGuest} = useEventDataContext();

const {totalExpenseAmount} = useTotalExpenseAmountStore();

Expand All @@ -26,6 +26,7 @@ const useAdminPage = () => {
isAdmin,
eventName,
bankName,
createdByGuest,
accountNumber,
totalExpenseAmount,
isShowAccountBanner,
Expand Down
Loading
Loading