-
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.
feat: 나눔 상태 변경, 나눔 신청, 나눔 신청 취소 API 연동 (#41)
* refactor: type import 수정 * style: RadioButtonField component style 수정 * chore: eslint @typescript-eslint/no-misused-promises off * feat: usePutShareStatus hook 생성 * feat: 나눔 상태 변경 API 연동 * feat: ShareStatusBadge component 생성, 적용 * feat: useApplyShare, useDeleteApplyShare hook 생성 * feat: 나눔 신청, 나눔 신청 취소 API 연동
- Loading branch information
1 parent
8ac1dd4
commit 6370504
Showing
15 changed files
with
241 additions
and
54 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
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,35 @@ | ||
import React, { useMemo } from 'react'; | ||
|
||
import type { ShareStatusType } from '@/types/friendship'; | ||
|
||
const ShareStatusBadge: React.FC<{ status: ShareStatusType }> = ({ status }) => { | ||
const text = useMemo(() => { | ||
switch (status) { | ||
case 'SHARE_START': | ||
return '나눔 신청'; | ||
case 'SHARE_IN_PROGRESS': | ||
return '나눔 중'; | ||
case 'SHARE_COMPLETE': | ||
return '나눔 완료'; | ||
default: | ||
return ''; | ||
} | ||
}, [status]); | ||
|
||
const className = useMemo(() => { | ||
switch (status) { | ||
case 'SHARE_START': | ||
return 'bg-[#DCF3ED] text-primary2'; | ||
case 'SHARE_IN_PROGRESS': | ||
return 'bg-[#FFEBE6] text-point3'; | ||
case 'SHARE_COMPLETE': | ||
return 'bg-gray0 text-gray4'; | ||
default: | ||
return ''; | ||
} | ||
}, [status]); | ||
|
||
return <div className={`px-[8px] py-[4px] rounded-[6px] body2-medium ${className} `}>{text}</div>; | ||
}; | ||
|
||
export default ShareStatusBadge; |
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
61 changes: 61 additions & 0 deletions
61
src/components/organisms/ShareDetailFriendBottomWrapper.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,61 @@ | ||
import { useApplyShare, useDeleteApplyShare } from '@/hooks/queries/share'; | ||
|
||
import React from 'react'; | ||
import type { ShareStatusType } from '@/types/friendship'; | ||
import useToast from '@/hooks/useToast'; | ||
|
||
const APPLY_SUCCESS_MESSAGE = '나눔 신청이 완료되었습니다.'; | ||
const APPLY_DELETE_SUCCESS_MESSAGE = '나눔 신청이 취소되었습니다.'; | ||
|
||
const ShareDetailFriendBottomWrapper: React.FC<{ | ||
id: string | string[] | undefined; | ||
isApplied: boolean; | ||
curStatus: ShareStatusType; | ||
refetch: () => void; | ||
}> = ({ id, isApplied, curStatus, refetch }) => { | ||
const { showToast } = useToast(); | ||
const applyShare = useApplyShare({ | ||
onSuccess: () => { | ||
showToast(APPLY_SUCCESS_MESSAGE, 'success'); | ||
refetch(); | ||
}, | ||
}); | ||
const deleteShare = useDeleteApplyShare({ | ||
id: Number(id), | ||
onSuccess: () => { | ||
showToast(APPLY_DELETE_SUCCESS_MESSAGE, 'success'); | ||
refetch(); | ||
}, | ||
}); | ||
|
||
const onApply = () => { | ||
applyShare.mutate({ shareId: Number(id) }); | ||
}; | ||
|
||
const onApplyCancel = () => { | ||
deleteShare.mutate({}); | ||
}; | ||
|
||
if (curStatus === 'SHARE_COMPLETE') { | ||
return ( | ||
<div className="fixed w-full max-w-[480px] bottom-0 p-[20px] pb-[32px] z-300 bg-gray1"> | ||
<p className="w-full text-center py-[16px] rounded-[12px] text-gray0 bg-gray3 heading4-semibold"> | ||
나눔 신청 종료 | ||
</p> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="fixed w-full max-w-[480px] bottom-0 p-[20px] pb-[32px] z-300 bg-gray1"> | ||
<button | ||
onClick={isApplied ? onApplyCancel : onApply} | ||
className="w-full text-center py-[16px] rounded-[12px] text-white bg-primary2 heading4-semibold" | ||
> | ||
{isApplied ? '나눔 신청 완료' : '나눔 신청'} | ||
</button> | ||
</div> | ||
); | ||
}; | ||
|
||
export default ShareDetailFriendBottomWrapper; |
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
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,7 @@ | ||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseMutation } from '../useBaseMutation'; | ||
|
||
const useApplyShare = ({ onSuccess }: { onSuccess: () => void }) => { | ||
return useBaseMutation<{ shareId: number }>(queryKeys.APPLY_SHARE(), `/shares/applies`, onSuccess); | ||
}; | ||
export default useApplyShare; |
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,7 @@ | ||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseMutation } from '../useBaseMutation'; | ||
|
||
const useDeleteApplyShare = ({ id, onSuccess }: { id: number; onSuccess: () => void }) => { | ||
return useBaseMutation(queryKeys.DELETE_APPLY_SHARE(), `/shares/applies/${id}`, onSuccess, 'DELETE'); | ||
}; | ||
export default useDeleteApplyShare; |
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,26 @@ | ||
import type { ShareStatusType } from '@/types/friendship'; | ||
import { queryClient } from '@/pages/_app'; | ||
import { queryKeys } from '../queryKeys'; | ||
import { useBaseMutation } from '../useBaseMutation'; | ||
|
||
const usePutShareStatus = ({ | ||
id, | ||
status, | ||
onSuccessParam, | ||
}: { | ||
id: number; | ||
status: ShareStatusType; | ||
onSuccessParam: () => void; | ||
}) => { | ||
const onSuccess = () => { | ||
onSuccessParam(); | ||
void queryClient.invalidateQueries(); | ||
}; | ||
return useBaseMutation( | ||
queryKeys.MODIFY_SHARE_STATUS(), | ||
`/shares/${id}/status?updateShareStatusRequest=${status}`, | ||
onSuccess, | ||
'PUT', | ||
); | ||
}; | ||
export default usePutShareStatus; |
Oops, something went wrong.