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] 마이페이지 기능 고도화 및 행사 이름 변경 기능 구현 #869

Merged
merged 12 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 9 commits
Commits
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
16 changes: 10 additions & 6 deletions client/src/apis/request/event.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {CreatedEvents, Event, EventCreationData, EventId, EventName, User} from 'types/serviceType';
import {BankAccount, CreatedEvents, Event, EventCreationData, EventId, EventName, User} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {ADMIN_API_PREFIX, MEMBER_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
Expand Down Expand Up @@ -30,15 +30,19 @@ export const requestGetEvent = async ({eventId, ...props}: WithEventId<WithError
});
};

export type RequestPatchEvent = WithEventId & {
eventName: string;
};
export type PartialEvent = Partial<
BankAccount & {
eventName: EventName;
}
>;

export type RequestPatchEvent = WithEventId & PartialEvent;

export const requestPatchEventName = async ({eventId, eventName}: RequestPatchEvent) => {
export const requestPatchEvent = async ({eventId, ...event}: RequestPatchEvent) => {
return requestPatch({
endpoint: `${ADMIN_API_PREFIX}/${eventId}`,
body: {
eventName,
...event,
},
});
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function InProgressCheck({inProgress}: {inProgress: boolean}) {
return (
<div css={inProgressCheckStyle({theme, inProgress})}>
<Text size="tiny" className="in-progress-check-text">
{inProgress ? '진행' : '완료'}
{inProgress ? '정산 중' : '정산 완료'}
</Text>
</div>
);
Expand Down
1 change: 1 addition & 0 deletions client/src/constants/routerUrls.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const ROUTER_URLS = {
addBill: `${EVENT_WITH_EVENT_ID}/admin/add-bill`,
editBill: `${EVENT_WITH_EVENT_ID}/admin/edit-bill`,
editAccount: `${EVENT_WITH_EVENT_ID}/admin/edit-account`,
editEventName: `${EVENT_WITH_EVENT_ID}/admin/edit-event-name`,
images: `${EVENT_WITH_EVENT_ID}/images`,
addImages: `${EVENT_WITH_EVENT_ID}/admin/add-images`,
send: `${EVENT_WITH_EVENT_ID}/home/send/:memberId`,
Expand Down
4 changes: 2 additions & 2 deletions client/src/hooks/createEvent/useSetEventNameStep.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import validateEventName from '@utils/validate/validateEventName';

export type UseSetEventNameStepReturnType = ReturnType<typeof useSetEventNameStep>;

const useSetEventNameStep = () => {
const [eventName, setEventName] = useState('');
const useSetEventNameStep = (initialEventName?: string) => {
const [eventName, setEventName] = useState(initialEventName ?? '');
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [canSubmit, setCanSubmit] = useState(false);

Expand Down
2 changes: 1 addition & 1 deletion client/src/hooks/queries/auth/useRequestGetUserInfo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const useRequestGetUserInfo = () => {
initialData: {
isGuest: true,
nickname: '',
profileImage: '',
profileImage: null,
accountNumber: '',
bankName: '',
},
Expand Down
27 changes: 27 additions & 0 deletions client/src/hooks/queries/auth/useRequestSuspenseGetUserInfo.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import {useSuspenseQuery} from '@tanstack/react-query';

import {requestGetUserInfo} from '@apis/request/auth';

import QUERY_KEYS from '@constants/queryKeys';

const useRequestSuspenseGetUserInfo = () => {
const {data, ...rest} = useSuspenseQuery({
queryKey: [QUERY_KEYS.userInfo],
queryFn: () => requestGetUserInfo(),
});

const userInfo = {
isGuest: data.isGuest,
nickname: data.nickname,
profileImage: data.profileImage,
accountNumber: data.accountNumber,
bankName: data.bankName,
};

return {
userInfo,
...rest,
};
};
Copy link
Contributor

Choose a reason for hiding this comment

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

아래 코드처럼 작성하면 더 간단합니다!

return {
   userInfo: {...data} // 스프레드 안써도됨
   // etc
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

호오~~ 그러네요!! 감사합니다!


export default useRequestSuspenseGetUserInfo;
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import type {Event} from 'types/serviceType';

import {useMutation, useQueryClient} from '@tanstack/react-query';

import {requestPatchEventName} from '@apis/request/event';
import {PartialEvent, requestPatchEvent} from '@apis/request/event';

import getEventIdByUrl from '@utils/getEventIdByUrl';

import QUERY_KEYS from '@constants/queryKeys';

const useRequestPatchEventName = () => {
const useRequestPatchEvent = () => {
const eventId = getEventIdByUrl();

const queryClient = useQueryClient();

const {mutateAsync, ...rest} = useMutation({
mutationFn: (eventName: string) => requestPatchEventName({eventId, eventName}),
mutationFn: (partialEvent: PartialEvent) => requestPatchEvent({eventId, ...partialEvent}),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.event],
Expand All @@ -23,9 +21,9 @@ const useRequestPatchEventName = () => {
});

return {
patchEventOutline: mutateAsync,
patchEvent: mutateAsync,
...rest,
};
};

export default useRequestPatchEventName;
export default useRequestPatchEvent;
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import getEventBaseUrl from '@utils/getEventBaseUrl';

import RULE from '@constants/rule';

import useRequestPatchUser from './queries/event/useRequestPatchUser';
import useRequestPatchEvent from './queries/event/useRequestPatchEvent';

const useAccount = () => {
const useEventAccount = () => {
const location = useLocation();
const locationState = location.state as BankAccount | null;

Expand All @@ -30,7 +30,7 @@ const useAccount = () => {
}
}, [locationState]);

const {patchUser} = useRequestPatchUser();
const {patchEvent} = useRequestPatchEvent();

const selectBank = (name: string) => {
setBankName(name);
Expand Down Expand Up @@ -66,7 +66,7 @@ const useAccount = () => {
};

const enrollAccount = async () => {
await patchUser({bankName: bankNameState, accountNumber: accountNumberState});
await patchEvent({bankName: bankNameState, accountNumber: accountNumberState});
};

useEffect(() => {
Expand All @@ -88,4 +88,4 @@ const useAccount = () => {
};
};

export default useAccount;
export default useEventAccount;
5 changes: 5 additions & 0 deletions client/src/pages/event/[eventId]/admin/AdminPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ const AdminPage = () => {
navigate(`/event/${eventId}/admin/edit-account`, {state: {accountNumber, bankName}});
};

const navigateEditEventName = () => {
navigate(`/event/${eventId}/admin/edit-event-name`, {state: eventName});
};

const navigateEventMemberManage = () => {
navigate(`/event/${eventId}/admin/members`);
};
Expand All @@ -52,6 +56,7 @@ const AdminPage = () => {
amount={totalExpenseAmount}
dropdown={
<Dropdown>
<DropdownButton text="행사 이름 변경" onClick={navigateEditEventName} />
Copy link
Contributor

Choose a reason for hiding this comment

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

예전부터 제가 바라던 기능 드디어 생겨서 너무 좋네여..!👍🏻

<DropdownButton text="전체 참여자 관리" onClick={navigateEventMemberManage} />
<DropdownButton text="계좌번호 입력하기" onClick={navigateAccountInputPage} />
<DropdownButton text="사진 첨부하기" onClick={navigateAddImages} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import {useLocation, useNavigate} from 'react-router-dom';

import BankSelectModal from '@components/Modal/BankSelectModal/BankSelectModal';

import useAccount from '@hooks/useAccount';
import useEventAccount from '@hooks/useEventAccount';
Copy link
Contributor

Choose a reason for hiding this comment

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

혹시 EventAccount로 이름을 바꾼 이유가 무엇인가요? 아마 제가 수정한 부분과 충돌할 것 같아서..!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

계좌 번호 수정이 행사 단계와 유저 단계 두 가지가 있잖아요! 저는 재사용을 생각하지 않고 새로 훅을 만들 것이라 생각하여 useEventAccount라는 행사계좌번호 수정이라는 훅으로 이름을 바꿨어요.
웨디의 pr을 보니 useAccount 훅을 재사용해서 이 훅 이름을 그대로 사용하는 것이 더 좋을 것 같네요.


import {FixedButton, Flex, FunnelLayout, Input, MainLayout, Top, TopNav} from '@components/Design';

Expand All @@ -24,7 +24,7 @@ const EditAccountPage = () => {
handleAccount,
handleAccountOnPaste,
enrollAccount,
} = useAccount();
} = useEventAccount();

const enrollAccountAndNavigateAdmin = async () => {
await enrollAccount();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import {useLocation, useNavigate} from 'react-router-dom';
import {useEffect} from 'react';

import useSetEventNameStep from '@hooks/createEvent/useSetEventNameStep';
import useRequestPatchEvent from '@hooks/queries/event/useRequestPatchEvent';
import {EventName} from 'types/serviceType';

import {FixedButton, FunnelLayout, Input, MainLayout, Top, TopNav} from '@components/Design';

import getEventBaseUrl from '@utils/getEventBaseUrl';

const EditEventNamePage = () => {
const location = useLocation();
const locationState = location.state as EventName | null;
console.log(locationState);
Copy link
Contributor

Choose a reason for hiding this comment

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

콘솔 로그는 지워주세용!


const navigate = useNavigate();

useEffect(() => {
if (locationState === null) {
navigate(-1);
}
}, [locationState]);

const {eventName, errorMessage, canSubmit, handleEventNameChange} = useSetEventNameStep(locationState ?? '');
const {patchEvent} = useRequestPatchEvent();

const disabled = !canSubmit || eventName === locationState;

const onSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
event.preventDefault();

await patchEvent({eventName});
navigate(`/${getEventBaseUrl(location.pathname)}/admin`);
};

return (
<MainLayout backgroundColor="white">
<TopNav>
<TopNav.Item displayName="뒤로가기" noEmphasis routePath="-1" />
</TopNav>
<FunnelLayout>
<Top>
<Top.Line text="변경하려는" />
<Top.Line text="행사의 이름은 무엇인가요?" emphasize={['행사의 이름']} />
</Top>
<form onSubmit={event => onSubmit(event)}>
<Input
labelText="행사 이름"
errorText={errorMessage ?? ''}
value={eventName}
type="text"
placeholder="행동대장 야유회"
onChange={handleEventNameChange}
isError={!!errorMessage}
autoFocus
/>
<FixedButton disabled={disabled}>변경완료</FixedButton>
</form>
</FunnelLayout>
</MainLayout>
);
};

export default EditEventNamePage;
24 changes: 24 additions & 0 deletions client/src/pages/fallback/MyPageError.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import {useNavigate} from 'react-router-dom';
Copy link
Contributor

Choose a reason for hiding this comment

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

오 좋은데요! path로 들어올 수도 있긴 하니까요

Copy link
Contributor Author

Choose a reason for hiding this comment

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

이 경우는 쿠키가 없을 때 마이페이지를 접근한 경우에 대한 에러 처리 입니다!
그래서 이전 페이지로 navigate하는 기능이 들어와 있어요!

path로 들어와도 쿠키가 있으면 정상적으로 접근할 수 있어야 한다고 생각해요


import Image from '@components/Design/components/Image/Image';

import {Button, Flex, Text} from '@components/Design';

import getImageUrl from '@utils/getImageUrl';

const MyPageError = () => {
const navigate = useNavigate();

return (
<Flex flexDirection="column" justifyContent="center" alignItems="center" gap="1.5rem">
<Image src={getImageUrl('cryingDog', 'webp')} fallbackSrc={getImageUrl('cryingDog', 'png')} width={200} />
<Text
size="bodyBold"
css={{whiteSpace: 'pre-line', textAlign: 'center'}}
>{`로그인 후\n사용할 수 있는 서비스입니다.`}</Text>
<Button onClick={() => navigate(-1)}>이전으로 돌아가기</Button>
</Flex>
);
};

export default MyPageError;
19 changes: 19 additions & 0 deletions client/src/pages/fallback/MyPageLoading.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import Image from '@components/Design/components/Image/Image';

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

import getImageUrl from '@utils/getImageUrl';

const MyPageLoading = () => {
return (
<Flex flexDirection="column" justifyContent="center" alignItems="center" gap="1.5rem">
<Image src={getImageUrl('runningDog', 'webp')} fallbackSrc={getImageUrl('runningDog', 'png')} width={200} />
<Text
size="bodyBold"
css={{whiteSpace: 'pre-line', textAlign: 'center'}}
>{`로딩중입니다.\n 잠시만 기다려주세요.`}</Text>
</Flex>
);
};

export default MyPageLoading;
12 changes: 0 additions & 12 deletions client/src/pages/mypage/MyPage.style.ts

This file was deleted.

Loading
Loading