-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
190 additions
and
41 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
export { useAcceptCallback } from './useAcceptCallback'; | ||
export { useCancelCallback } from './useCancelCallback'; | ||
export { useCompleteCallback } from './useCompleteCallback'; | ||
export { useGetAccepted } from './useGetAccepted'; |
23 changes: 23 additions & 0 deletions
23
src/pages/sinitto/call-back/detail/api/hooks/useAcceptCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fetchInstance } from '@/shared/api/instance'; | ||
import { BASE_URI } from '@/shared/constants'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
const getacceptCallbackPath = (callbackId: number) => | ||
`${BASE_URI}/api/callbacks/accept/${callbackId}`; | ||
|
||
const acceptCallback = async (callbackId: number) => { | ||
const response = await fetchInstance.put(getacceptCallbackPath(callbackId)); | ||
return response.data; | ||
}; | ||
|
||
export const useAcceptCallback = () => { | ||
return useMutation({ | ||
mutationFn: acceptCallback, | ||
onSuccess: () => { | ||
alert('콜백 요청이 수락되었습니다.'); | ||
}, | ||
onError: (error) => { | ||
alert(`콜백 요청 수락 신청 중 오류가 발생했습니다: ${error.message}`); | ||
}, | ||
}); | ||
}; |
23 changes: 23 additions & 0 deletions
23
src/pages/sinitto/call-back/detail/api/hooks/useCancelCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fetchInstance } from '@/shared/api/instance'; | ||
import { BASE_URI } from '@/shared/constants'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
const getCancelCallbackPath = (callbackId: number) => | ||
`${BASE_URI}/api/callbacks/cancel/${callbackId}`; | ||
|
||
const CancelCallback = async (callbackId: number) => { | ||
const response = await fetchInstance.put(getCancelCallbackPath(callbackId)); | ||
return response.data; | ||
}; | ||
|
||
export const useCancelCallback = () => { | ||
return useMutation({ | ||
mutationFn: CancelCallback, | ||
onSuccess: () => { | ||
alert('진행중인 콜백 서비스가 취소되었습니다.'); | ||
}, | ||
onError: (error) => { | ||
alert(`콜백 서비스 취소 중 오류가 발생했습니다: ${error.message}`); | ||
}, | ||
}); | ||
}; |
23 changes: 23 additions & 0 deletions
23
src/pages/sinitto/call-back/detail/api/hooks/useCompleteCallback.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import { fetchInstance } from '@/shared/api/instance'; | ||
import { BASE_URI } from '@/shared/constants'; | ||
import { useMutation } from '@tanstack/react-query'; | ||
|
||
const getCompleteCallbackPath = (callbackId: number) => | ||
`${BASE_URI}/api/callbacks/complete/${callbackId}`; | ||
|
||
const CompleteCallback = async (callbackId: number) => { | ||
const response = await fetchInstance.put(getCompleteCallbackPath(callbackId)); | ||
return response.data; | ||
}; | ||
|
||
export const useCompleteCallback = () => { | ||
return useMutation({ | ||
mutationFn: CompleteCallback, | ||
onSuccess: () => { | ||
alert('진행중인 콜백 서비스가 완료되었습니다.'); | ||
}, | ||
onError: (error) => { | ||
alert(`콜백 서비스 완료 중 오류가 발생했습니다: ${error.message}`); | ||
}, | ||
}); | ||
}; |
19 changes: 19 additions & 0 deletions
19
src/pages/sinitto/call-back/detail/api/hooks/useGetAccepted.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import { fetchInstance } from '@/shared/api/instance'; | ||
import { BASE_URI } from '@/shared/constants'; | ||
import type { CallbackResponse } from '@/shared/types'; | ||
import { useQuery } from '@tanstack/react-query'; | ||
|
||
const getAcceptedPath = () => `${BASE_URI}/api/callbacks/sinitto/accepted`; | ||
|
||
const getAccepted = async () => { | ||
const response = await fetchInstance.get<CallbackResponse>(getAcceptedPath()); | ||
return response.data; | ||
}; | ||
|
||
export const useGetAccepted = () => { | ||
return useQuery({ | ||
queryKey: ['acceptedCallback'], | ||
queryFn: getAccepted, | ||
staleTime: 0, | ||
}); | ||
}; |
60 changes: 60 additions & 0 deletions
60
src/pages/sinitto/call-back/detail/components/menu/CallbackMenu.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { | ||
useAcceptCallback, | ||
useCancelCallback, | ||
useCompleteCallback, | ||
} from '../../api/hooks'; | ||
import { PostAcceptMenu } from '../../components/menu/post-accept'; | ||
import { PreAcceptMenu } from '../../components/menu/pre-accept'; | ||
import { Spinner } from '@chakra-ui/react'; | ||
|
||
type MenuProps = { | ||
callBackId: number; | ||
accept: boolean; | ||
}; | ||
|
||
export const CallbackMenu = ({ callBackId, accept }: MenuProps) => { | ||
const navigate = useNavigate(); | ||
|
||
const { | ||
mutate: acceptCallback, | ||
isPending: isAcceptLoading, | ||
isSuccess: isAcceptSuccess, | ||
} = useAcceptCallback(); | ||
if (isAcceptSuccess) { | ||
window.location.reload(); | ||
} | ||
|
||
const { | ||
mutate: completeCallback, | ||
isPending: isCompleteLoading, | ||
isSuccess: isCompleteSuccess, | ||
} = useCompleteCallback(); | ||
if (isCompleteSuccess) { | ||
navigate('/call-back'); // TODO: 완료 이후 이동 페이지 지정 필요 | ||
} | ||
|
||
const { | ||
mutate: cancelCallback, | ||
isPending: isCancelLoading, | ||
isSuccess: isCancelSuccess, | ||
} = useCancelCallback(); | ||
if (isCancelSuccess) { | ||
navigate('/call-back'); // TODO: 취소 이후 이동 페이지 지정 필요 | ||
} | ||
|
||
const isLoading = isAcceptLoading || isCancelLoading || isCompleteLoading; | ||
|
||
return isLoading ? ( | ||
<Spinner size='xl' marginTop='30px' /> | ||
) : accept ? ( | ||
<PostAcceptMenu | ||
handleComplete={() => completeCallback(callBackId)} | ||
handleCancle={() => cancelCallback(callBackId)} | ||
phoneNumber='010-1234-5678' // TODO: api로 콜백 조회 시 response에 전화번호 추가 필요 | ||
/> | ||
) : ( | ||
<PreAcceptMenu handleClick={() => acceptCallback(callBackId)} /> | ||
); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1 @@ | ||
export * from './post-accept'; | ||
export * from './pre-accept'; | ||
export { CallbackMenu } from './CallbackMenu'; |