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] 마이페이지에서 자신의 기본 계좌 번호 수정 기능 추가 #880

Merged
merged 39 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 38 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
cd4d385
rename: 회원을 나타내는 USER 라는 이름을 일치하는 endpoint에 연결
pakxe Dec 22, 2024
b8534ad
chore: 이름 변경으로 인한 수정 사항
pakxe Dec 22, 2024
95c202e
feat: 불필요하게 depth가 깊은 EventId 타입을 flat하게 변경
pakxe Dec 22, 2024
cd05817
feat: EventLoader가 EditAccountPage를 내포하며, 헤더 UI부분은 그 외 children에게 감싸지…
pakxe Dec 22, 2024
f266747
feat: EventLoader의 내부 로직을 제거하고 EventData를 위한 Provider 호출
pakxe Dec 22, 2024
5940a0a
feat: EventPage들을 렌더링하기 위해 필요한 데이터 요청을 수행하는 훅 분리
pakxe Dec 22, 2024
9f935b8
feat: 데이터를 서브 트리에 뿌리기 위한 Provider 구현
pakxe Dec 22, 2024
7639328
feat: 이벤트에서 사용하는 데이터 컨텍스트를 사용하기 위한 훅 구현
pakxe Dec 22, 2024
ed80902
fix: 중복 데이터 호출 제거
pakxe Dec 22, 2024
0b3310a
feat: outletContext가 아닌 context 데이터를 사용하도록 수정
pakxe Dec 22, 2024
b222f04
feat: location.state 데이터 말고 context 데이터를 사용하도록 수정
pakxe Dec 22, 2024
574258a
chore: 불필요한 fragment 제거
pakxe Dec 22, 2024
3e98142
chore: feature/#876 땡겨오기
pakxe Dec 22, 2024
f5fd29b
feat: 타입으로 만들기 위해 as const 추가
pakxe Dec 22, 2024
bbba225
feat: BankType 사용
pakxe Dec 22, 2024
b07b6df
feat: 응답없는 patch를 위한 request함수 추가
pakxe Dec 23, 2024
d6f0d14
rename: fetcher -> request 파일명 변경에 따른 import 경로 수정
pakxe Dec 23, 2024
2ac74e0
fix: api PREFIX가 잘못되어 이상한 엔드포인트로 가던 요청 수정
pakxe Dec 23, 2024
be415bd
refactor: user와 관련된 요청을 user 요청만 있는 파일로 이동
pakxe Dec 23, 2024
566f210
rename: fetcher -> request 파일명 변경에 따른 import 경로 수정
pakxe Dec 23, 2024
9bc1eec
feat: BankName이 없는 첫 행사 생성 시기를 위해 빈문자열 유니온으로 추가
pakxe Dec 23, 2024
e0e5f67
chore: 사용하지 않는 주석 제거
pakxe Dec 23, 2024
276047b
feat: userInfo를 가져오고 하위 트리에 전달하기 위한 UserInfoLoader 구현
pakxe Dec 23, 2024
3f6c685
chore: 경로 수정
pakxe Dec 23, 2024
1d6bd84
feat: 계좌 번호 포맷에 대한 에러 메세지 추가
pakxe Dec 23, 2024
71cf6bf
feat: my page 하위 페이지 url 선언
pakxe Dec 23, 2024
7341ed5
fix: initialData의 타입 추론이 되도록 타입 할당 후 쿼리에 넘기도록 함
pakxe Dec 23, 2024
7975f20
feat: onSubmit, 계좌 정보를 외부에서 주입받도록 하고 반복되는 로직 모듈화
pakxe Dec 23, 2024
f7209e1
feat: userInfo를 뿌리기 위한 Provider와 쉽게 사용하기 위한 useContext구현
pakxe Dec 23, 2024
5f3def2
chore: 경로 수정에 의한 변경
pakxe Dec 23, 2024
cd959b9
feat: MyPage에서 컨텍스트 데이터를 사용하도록 함
pakxe Dec 23, 2024
9aadcee
feat: EditAccountPage를 재사용하기 위해 ui만 분리하고 외부 로직을 주입받도록 함
pakxe Dec 23, 2024
a995b93
refactor: 행사 계좌 수정 페이지가 계좌 수정 페이지 ui view를 재사용하도록 수정
pakxe Dec 23, 2024
d39f8ed
feat: 유저 계좌 정보 수정 페이지 구현
pakxe Dec 23, 2024
770bcdf
feat: MyPage와 EditUserAccountPage를 UserInfoLoader로 감싸도록 router 구성
pakxe Dec 23, 2024
7bab2cb
feat: 사용하지 않는 값을 내보내지 않도록 하며 에러 메세지를 상황에 맞게 띄워줄 수 있도록 수정
pakxe Dec 23, 2024
f7c47d5
fix: await을 추가하여 응답을 올바르게 받길 기다리도록 함
pakxe Dec 23, 2024
aff607f
fix: 잘못된 쿼리를 invalidate하고 있던 것을 수정
pakxe Dec 23, 2024
baed7e1
chore: 충돌 해결
pakxe Dec 27, 2024
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
4 changes: 2 additions & 2 deletions client/src/apis/endpointPrefix.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// TODO: (@weadie) 반복되서 쓰이는 이 api/events가 추후 수정 가능성이 있어서 일단 편집하기 편하게 이 변수를 재사용하도록 했습니다.
export const USER_API_PREFIX = '/api/events';
export const MEMBER_API_PREFIX = '/api/events';
export const ADMIN_API_PREFIX = '/api/admin/events';
export const MEMBER_API_PREFIX = '/api/users';
export const USER_API_PREFIX = '/api/users';
Comment on lines -2 to +4
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분은 merge할 때 다른 pr로 인해 사라졌는지? 잘 확인해야 할 것 같네요!

4 changes: 4 additions & 0 deletions client/src/apis/fetcher.ts → client/src/apis/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ export const requestPatch = ({headers = {}, ...args}: RequestMethodProps) => {
return request({method: 'PATCH', headers, ...args});
};

export const requestPatchWithoutResponse = async ({headers = {}, ...args}: RequestMethodProps) => {
await request({method: 'PATCH', headers, ...args});
};

export const requestPut = ({headers = {}, ...args}: RequestMethodProps) => {
return request({method: 'PUT', headers, ...args});
};
Expand Down
8 changes: 4 additions & 4 deletions client/src/apis/request/auth.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {UserInfo} from 'types/serviceType';

import {BASE_URL} from '@apis/baseUrl';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestGetWithoutResponse, requestPostWithoutResponse} from '@apis/fetcher';
import {ADMIN_API_PREFIX, USER_API_PREFIX, MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet, requestGetWithoutResponse, requestPostWithoutResponse} from '@apis/request';
import {WithEventId} from '@apis/withId.type';

import getKakaoRedirectUrl from '@utils/getKakaoRedirectUrl';
Expand All @@ -21,7 +21,7 @@ export interface RequestPostToken {
export const requestPostToken = async ({eventId, password}: WithEventId<RequestPostToken>) => {
await requestPostWithoutResponse({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/login`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/login`,
body: {
password: password,
},
Expand All @@ -48,7 +48,7 @@ export const requestGetKakaoLogin = async (code: string) => {
export const requestGetUserInfo = async () => {
return await requestGet<UserInfo>({
baseUrl: BASE_URL.HD,
endpoint: `${MEMBER_API_PREFIX}/mine`,
endpoint: `${USER_API_PREFIX}/mine`,
errorHandlingStrategy: 'unsubscribe',
});
};
6 changes: 3 additions & 3 deletions client/src/apis/request/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {BillDetails} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {BASE_URL} from '@apis/baseUrl';
import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestGet, requestPostWithoutResponse, requestPut} from '@apis/fetcher';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestGet, requestPostWithoutResponse, requestPut} from '@apis/request';
import {WithBillId, WithEventId} from '@apis/withId.type';

export interface RequestPostBill {
Expand Down Expand Up @@ -52,7 +52,7 @@ export const requestGetBillDetails = async ({
}: WithEventId<WithErrorHandlingStrategy<WithBillId>>) => {
return requestGet<BillDetails>({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/bills/${billId}/details`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/bills/${billId}/details`,
...props,
});
};
Expand Down
30 changes: 9 additions & 21 deletions client/src/apis/request/event.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,22 @@
import {CreatedEvents, Event, EventCreationData, EventId, EventName, User} from 'types/serviceType';
import {CreatedEvents, Event, EventCreationData, EventName, User} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

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

export const requestPostGuestEvent = async (postEventArgs: EventCreationData) => {
return await requestPostWithResponse<EventId>({
endpoint: `${USER_API_PREFIX}/guest`,
return await requestPostWithResponse<WithEventId>({
endpoint: `${MEMBER_API_PREFIX}/guest`,
body: {
...postEventArgs,
},
});
};

export const requestPostUserEvent = async (eventName: EventName) => {
return await requestPostWithResponse<EventId>({
endpoint: USER_API_PREFIX,
return await requestPostWithResponse<WithEventId>({
endpoint: MEMBER_API_PREFIX,
body: {
eventName,
},
Expand All @@ -25,7 +25,7 @@ export const requestPostUserEvent = async (eventName: EventName) => {

export const requestGetEvent = async ({eventId, ...props}: WithEventId<WithErrorHandlingStrategy>) => {
return await requestGet<Event>({
endpoint: `${USER_API_PREFIX}/${eventId}`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}`,
...props,
});
};
Expand All @@ -43,20 +43,8 @@ export const requestPatchEventName = async ({eventId, eventName}: RequestPatchEv
});
};

export type RequestPatchUser = Partial<User>;

// TODO: (@soha) 해당 요청은 user.ts 파일로 이동하는 건 어떨지?
export const requestPatchUser = async (args: RequestPatchUser) => {
return requestPatch({
endpoint: MEMBER_API_PREFIX,
body: {
...args,
},
});
};

export const requestGetCreatedEvents = async () => {
return await requestGet<CreatedEvents>({
endpoint: `${USER_API_PREFIX}/mine`,
endpoint: `${MEMBER_API_PREFIX}/mine`,
});
};
6 changes: 3 additions & 3 deletions client/src/apis/request/images.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import {EventId, Images} from 'types/serviceType';

import {BASE_URL} from '@apis/baseUrl';
import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestGet, requestPostWithoutResponse} from '@apis/fetcher';
import {ADMIN_API_PREFIX, MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestGet, requestPostWithoutResponse} from '@apis/request';
import {WithEventId} from '@apis/withId.type';

export interface RequestPostImages {
Expand All @@ -16,7 +16,7 @@ export const requestPostImages = async ({eventId, formData}: WithEventId<Request
export const requestGetImages = async ({eventId}: WithEventId) => {
return await requestGet<Images>({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/images`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/images`,
});
};

Expand Down
8 changes: 4 additions & 4 deletions client/src/apis/request/member.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import type {AllMembers, Members} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

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

export interface PostMember {
Expand Down Expand Up @@ -59,14 +59,14 @@ export const requestPutMembers = async ({eventId, members}: WithEventId<RequestP
export const requestGetCurrentMembers = async ({eventId, ...props}: WithEventId<WithErrorHandlingStrategy>) => {
return await requestGet<Members>({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/members/current`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/members/current`,
...props,
});
};

export const requestGetAllMembers = async ({eventId, ...props}: WithEventId<WithErrorHandlingStrategy>) => {
return await requestGet<AllMembers>({
endpoint: `${USER_API_PREFIX}/${eventId}/members`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/members`,
...props,
});
};
6 changes: 3 additions & 3 deletions client/src/apis/request/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ import type {Reports} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {BASE_URL} from '@apis/baseUrl';
import {USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet} from '@apis/fetcher';
import {MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet} from '@apis/request';
import {WithEventId} from '@apis/withId.type';

export const requestGetReports = async ({eventId, ...props}: WithEventId<WithErrorHandlingStrategy>) => {
return await requestGet<Reports>({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/reports`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/reports`,
...props,
});
};
6 changes: 3 additions & 3 deletions client/src/apis/request/step.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import {Steps} from 'types/serviceType';
import {WithErrorHandlingStrategy} from '@errors/RequestGetError';

import {BASE_URL} from '@apis/baseUrl';
import {USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet} from '@apis/fetcher';
import {MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestGet} from '@apis/request';
import {WithEventId} from '@apis/withId.type';

export const requestGetSteps = async ({eventId, ...props}: WithEventId<WithErrorHandlingStrategy>) => {
const {steps} = await requestGet<Steps>({
baseUrl: BASE_URL.HD,
endpoint: `${USER_API_PREFIX}/${eventId}/bills`,
endpoint: `${MEMBER_API_PREFIX}/${eventId}/bills`,
...props,
});

Expand Down
26 changes: 19 additions & 7 deletions client/src/apis/request/user.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,32 @@
import {User} from 'types/serviceType';
import {User, UserInfo} from 'types/serviceType';

import {BASE_URL} from '@apis/baseUrl';
import {MEMBER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete} from '@apis/fetcher';
import {requestGet} from '@apis/fetcher';
import {USER_API_PREFIX} from '@apis/endpointPrefix';
import {requestDelete, requestPatchWithoutResponse} from '@apis/request';
import {requestGet} from '@apis/request';

export const requestDeleteUser = async () => {
await requestDelete({
baseUrl: BASE_URL.HD,
endpoint: `${MEMBER_API_PREFIX}`,
endpoint: USER_API_PREFIX,
});
};

export const requestGetUserInfo = async () => {
return await requestGet<User>({
return await requestGet<UserInfo>({
baseUrl: BASE_URL.HD,
endpoint: `/api/users/mine`,
endpoint: `${USER_API_PREFIX}/mine`,
errorHandlingStrategy: 'unsubscribe',
});
};

export type RequestPatchUser = Partial<User>;

export const requestPatchUser = async (args: RequestPatchUser) => {
await requestPatchWithoutResponse({
endpoint: USER_API_PREFIX,
body: {
...args,
},
});
};
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
/** @jsxImportSource @emotion/react */
import {BankName} from 'types/serviceType';

import BANKS from '@constants/bank';

import Text from '../Text/Text';
Expand All @@ -7,7 +9,7 @@ import Flex from '../Flex/Flex';
import {bankSelectStyle, iconStyle} from './BankSelect.style';

type BankSelectProps = {
onSelect: (name: string) => void;
onSelect: (name: BankName) => void;
};

const BankSelect = ({onSelect}: BankSelectProps) => {
Expand Down
95 changes: 95 additions & 0 deletions client/src/components/EditAccountPageView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
import {useState} from 'react';
import {useNavigate} from 'react-router-dom';

import BankSelectModal from '@components/Modal/BankSelectModal/BankSelectModal';
import {BankAccount, BankName} from 'types/serviceType';

import useAccount from '@hooks/useAccount';

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

type EditAccountPageProps = {
bankName: BankName;
accountNumber: string;
onSubmit: (args: Partial<BankAccount>) => Promise<void>;
redirectUrlOnSubmit: string;
};

const EditAccountPageView = ({
bankName: defaultBankName,
accountNumber: defaultAccountNumber,
onSubmit,
redirectUrlOnSubmit,
}: EditAccountPageProps) => {
const navigate = useNavigate();

const [isBottomSheetOpen, setIsBottomSheetOpen] = useState(false);

const {
bankName,
accountNumber,
accountNumberErrorMessage,
canSubmit,
selectBank,
handleAccountOnTyping,
handleAccountOnPaste,
enrollAccount,
} = useAccount({
bankName: defaultBankName,
accountNumber: defaultAccountNumber,
onSubmit,
});

const enrollAccountAndRedirectTo = async () => {
await enrollAccount();

navigate(redirectUrlOnSubmit);
Comment on lines +44 to +46
Copy link
Contributor

Choose a reason for hiding this comment

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

이 부분에서 await을 해줘서 이전 데이터가 보이는 문제를 해결했다는 거죠? 좋습니다.
저도 이 부분 궁금해서 mutate 함수와 mutate async를 사용했을 때 onSuccess 콜백은 언제 실행되는지 테스트해봤어요!

image

사진을 보면 mutate async, await과 onSuccess의 경우 함수가 실행되어 요청을 기다린 후 onSuccess가 호출된 후 navigate하는 모습을 보여줬어요.

하지만 mutate와 onSuccess의 경우 함수가 실행되어 navigate하게 되어 함수가 종료된 후 onSuccess가 실행되는 모습을 확인할 수 있었어요.

이 부분에서 일어난 오류가 아니었을까.. 예상합니다

Copy link
Contributor Author

@pakxe pakxe Dec 24, 2024

Choose a reason for hiding this comment

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

오..! 신기한 내용을 알아봐주셔서 감사합니다.
그렇지만 제가 사용한 mutate는 처음부터 mutateAsync였습니다. 흐흑.. ㅜㅜ 아마 프로미스에 관련된 문제 같아요.

Copy link
Contributor

Choose a reason for hiding this comment

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

해결되었으니 다행이에요~

};

return (
<MainLayout backgroundColor="white">
<TopNav>
<TopNav.Item displayName="뒤로가기" noEmphasis routePath="-1" />
</TopNav>
<FunnelLayout>
<Top>
<Top.Line text="행사 정산 금액은" />
<Top.Line text="어떤 계좌로 받을까요?" emphasize={['어떤 계좌']} />
</Top>
<Flex flexDirection="column" gap="1rem">
<Input
labelText="은행"
placeholder="은행을 선택해주세요"
value={bankName ?? ''}
errorText={null}
autoFocus={false}
readOnly
onClick={() => setIsBottomSheetOpen(true)}
/>
<Input
labelText="계좌번호"
placeholder="ex) 030302-04-191806"
errorText={accountNumberErrorMessage}
isError={accountNumberErrorMessage !== null}
value={accountNumber ?? ''}
onChange={handleAccountOnTyping}
onPaste={handleAccountOnPaste}
autoFocus={false}
/>
{isBottomSheetOpen && (
<BankSelectModal
isBottomSheetOpened={isBottomSheetOpen}
setIsBottomSheetOpened={setIsBottomSheetOpen}
selectBank={selectBank}
/>
)}
</Flex>
</FunnelLayout>
<FixedButton disabled={!canSubmit} onClick={enrollAccountAndRedirectTo} onBackClick={() => navigate(-1)}>
확인
</FixedButton>
</MainLayout>
);
};

export default EditAccountPageView;
17 changes: 17 additions & 0 deletions client/src/components/Loader/EventData/EventDataLoader.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import {Outlet} from 'react-router-dom';

import useEventPageLoader from '@hooks/useEventPageLoader';

import EventDataProvider from './EventDataProvider';

const EventDataLoader = () => {
const eventData = useEventPageLoader();

return (
<EventDataProvider {...eventData}>
<Outlet />
</EventDataProvider>
);
};

export default EventDataLoader;
Loading
Loading