Skip to content

Commit

Permalink
fix: 백엔드 계좌번호 구조 변경으로 인한 api 변동을 반영
Browse files Browse the repository at this point in the history
  • Loading branch information
jinhokim98 committed Dec 7, 2024
1 parent 7535987 commit efceb01
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 11 deletions.
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

0 comments on commit efceb01

Please sign in to comment.