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] 계좌번호 수정이 되지 않는 문제 해결 #844

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

import {ADMIN_API_PREFIX, USER_API_PREFIX} from '@apis/endpointPrefix';
Expand Down Expand Up @@ -31,14 +31,25 @@ export const requestGetEvent = async ({eventId, ...props}: WithEventId<WithError
};

export type RequestPatchEvent = WithEventId & {
eventOutline: Partial<Event>;
eventName: string;
};

export const requestPatchEvent = async ({eventId, eventOutline}: RequestPatchEvent) => {
export const requestPatchEventName = async ({eventId, eventName}: RequestPatchEvent) => {
return requestPatch({
endpoint: `${ADMIN_API_PREFIX}/${eventId}`,
body: {
...eventOutline,
eventName,
},
});
};

export type RequestPatchUser = Partial<User>;

export const requestPatchUser = async (args: RequestPatchUser) => {
return requestPatch({
endpoint: `/api/users`,
body: {
...args,
},
});
};
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ import type {Event} from 'types/serviceType';

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

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

import getEventIdByUrl from '@utils/getEventIdByUrl';

import QUERY_KEYS from '@constants/queryKeys';

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

const queryClient = useQueryClient();

const {mutateAsync, ...rest} = useMutation({
mutationFn: (eventOutline: Partial<Event>) => requestPatchEvent({eventId, eventOutline}),
mutationFn: (eventName: string) => requestPatchEventName({eventId, eventName}),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.event],
Expand All @@ -28,4 +28,4 @@ const useRequestPatchEventOutline = () => {
};
};

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

import {RequestPatchUser, requestPatchUser} from '@apis/request/event';

import QUERY_KEYS from '@constants/queryKeys';

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

const {mutateAsync, ...rest} = useMutation({
mutationFn: (args: RequestPatchUser) => requestPatchUser({...args}),
onSuccess: () => {
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.event],
});
},
});

return {
patchUser: mutateAsync,
...rest,
};
};

export default useRequestPatchUser;
6 changes: 3 additions & 3 deletions client/src/hooks/useAccount.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import validateAccountNumber from '@utils/validate/validateAccountNumber';

import RULE from '@constants/rule';

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

const useAccount = () => {
const {bankName, accountNumber} = useRequestGetEvent();
Expand All @@ -20,7 +20,7 @@ const useAccount = () => {
setAccountNumber(accountNumber);
}, [bankName, accountNumber]);

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

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

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

useEffect(() => {
Expand Down
13 changes: 10 additions & 3 deletions client/src/types/serviceType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,12 +59,19 @@ export interface EventCreationData {
password: Password;
}

export interface Event {
eventName: EventName;
export type BankAccount = {
bankName: string;
accountNumber: string;
};

export type Event = BankAccount & {
eventName: EventName;
createdByGuest: boolean;
}
};

export type User = BankAccount & {
nickname: Nickname;
};

export interface Report {
memberId: number;
Expand Down
Loading