-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat(shared): 봉사모집상세조회 api response에 shelterId 추가 * feat(volunteer): 봉사모집상세조회 fetch useQuery 추가 * feat(volunteer): 봉사모집상세조회 mock api 추가 * feat(volunteer): 보호소 간단 정보 조회 mock api 추가 * feat(volunteer): 봉사모집상세조회 msw 연결
- Loading branch information
Showing
7 changed files
with
136 additions
and
31 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
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,16 @@ | ||
import { delay, http, HttpResponse } from 'msw'; | ||
|
||
export const handlers = [ | ||
http.get('/shelters/:shelterId/profile/simple', async () => { | ||
await delay(200); | ||
return HttpResponse.json( | ||
{ | ||
shelterName: '양천구 보호소', | ||
shelterImageUrl: 'https://source.unsplash.com/random/?person', | ||
shelterAddress: '서울특별시 양천구', | ||
shelterEmail: '[email protected]', | ||
}, | ||
{ status: 200 }, | ||
); | ||
}), | ||
]; |
74 changes: 74 additions & 0 deletions
74
apps/volunteer/src/pages/volunteers/detail/_hooks/useFetchVolunteerDetail.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,74 @@ | ||
import { useQuery } from '@tanstack/react-query'; | ||
import { getRecruitmentDetail } from 'shared/apis/common/Recruitments'; | ||
import { | ||
createFormattedTime, | ||
createWeekDayLocalString, | ||
} from 'shared/utils/date'; | ||
|
||
import { getSimpleShelterProfile } from '@/apis/shelter'; | ||
|
||
const useFetchVolunteerDetail = (recruitmentId: number) => | ||
useQuery({ | ||
queryKey: ['volunteer', recruitmentId], | ||
queryFn: async () => { | ||
const { shelterId, ...recruitmentInfo } = ( | ||
await getRecruitmentDetail(recruitmentId) | ||
).data; | ||
const shelterSimpleInfo = (await getSimpleShelterProfile(shelterId)).data; | ||
|
||
return { | ||
...recruitmentInfo, | ||
shelterInfo: { shelterId, ...shelterSimpleInfo }, | ||
}; | ||
}, | ||
select: (data) => { | ||
const startDate = new Date(data.recruitmentStartTime); | ||
const endDate = new Date(data.recruitmentEndTime); | ||
const deadLine = new Date(data.recruitmentDeadline); | ||
|
||
return { | ||
imageUrls: data.recruitmentImageUrls, | ||
title: data.recruitmentTitle, | ||
content: data.recruitmentContent, | ||
applicant: data.recruitmentApplicantCount, | ||
capacity: data.recruitmentCapacity, | ||
volunteerDay: `${createFormattedTime( | ||
startDate, | ||
)}(${createWeekDayLocalString(startDate)})`, | ||
recruitmentDeadline: `${createFormattedTime( | ||
deadLine, | ||
)}(${createWeekDayLocalString(deadLine)}) ${createFormattedTime( | ||
deadLine, | ||
'hh:mm', | ||
)}`, | ||
volunteerStartTime: createFormattedTime(startDate, 'hh:mm'), | ||
volunteerEndTime: createFormattedTime(endDate, 'hh:mm'), | ||
recruitmentCreatedAt: createFormattedTime( | ||
new Date(data.recruitmentCreatedAt), | ||
), | ||
recruitmentIsClosed: data.recruitmentIsClosed, | ||
shelterInfo: data.shelterInfo, | ||
}; | ||
}, | ||
initialData: { | ||
recruitmentTitle: '', | ||
recruitmentApplicantCount: 0, | ||
recruitmentCapacity: 0, | ||
recruitmentContent: '', | ||
recruitmentStartTime: '', | ||
recruitmentEndTime: '', | ||
recruitmentIsClosed: false, | ||
recruitmentDeadline: '', | ||
recruitmentCreatedAt: '', | ||
recruitmentUpdatedAt: '', | ||
recruitmentImageUrls: [], | ||
shelterInfo: { | ||
shelterId: 0, | ||
shelterName: '', | ||
shelterImageUrl: '', | ||
shelterAddress: '', | ||
shelterEmail: '', | ||
}, | ||
}, | ||
}); | ||
export default useFetchVolunteerDetail; |
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 |
---|---|---|
|
@@ -17,38 +17,20 @@ import LabelText from 'shared/components/LabelText'; | |
import ProfileInfo from 'shared/components/ProfileInfo'; | ||
import { getDDay } from 'shared/utils/date'; | ||
|
||
const DUMMY_DATA = { | ||
imageUrls: [ | ||
'https://source.unsplash.com/random/?animal', | ||
'https://source.unsplash.com/random/300X500', | ||
], | ||
title: '강아지 봉사자를 모집합니다', | ||
content: '강아지 목욕봉사입니다.', | ||
applicant: 5, | ||
capacity: 10, | ||
volunteerDay: '2023.12.24', | ||
recruitmentDeadline: '2023.12.03', | ||
volunteerStartTime: '14:00', | ||
volunteerEndTime: '16:00', | ||
recruitmentCreatedAt: '2023.11.25', | ||
recruitmentIsClosed: true, | ||
}; | ||
|
||
const DUMMY_SHELTERINFO = { | ||
name: '양천구 보호소', | ||
profileImage: 'https://source.unsplash.com/random/?animal', | ||
address: '경기도 남양주시', | ||
email: '[email protected]', | ||
}; | ||
import useFetchVolunteerDetail from './_hooks/useFetchVolunteerDetail'; | ||
|
||
export default function VolunteersDetailPage() { | ||
const navigate = useNavigate(); | ||
const { id: recruitmentId } = useParams(); | ||
const { id } = useParams(); | ||
const recruitmentId = Number(id); | ||
const { isOpen, onOpen, onClose } = useDisclosure(); | ||
const [label, setLabel] = useState<LabelProps>({ | ||
labelTitle: '모집중', | ||
type: 'GREEN', | ||
}); | ||
|
||
const { data } = useFetchVolunteerDetail(3); | ||
|
||
const { | ||
imageUrls, | ||
title, | ||
|
@@ -61,9 +43,10 @@ export default function VolunteersDetailPage() { | |
volunteerEndTime, | ||
recruitmentCreatedAt, | ||
recruitmentIsClosed, | ||
} = DUMMY_DATA; | ||
|
||
const { name, profileImage, address, email } = DUMMY_SHELTERINFO; | ||
shelterInfo, | ||
} = data; | ||
const { shelterName, shelterImageUrl, shelterAddress, shelterEmail } = | ||
shelterInfo; | ||
|
||
useEffect(() => { | ||
if (recruitmentIsClosed) { | ||
|
@@ -78,6 +61,7 @@ export default function VolunteersDetailPage() { | |
|
||
const onApplyRecruitment = () => { | ||
onClose(); | ||
//TODO 봉사신청 API | ||
//TODO 봉사신청완료 toast | ||
}; | ||
|
||
|
@@ -115,9 +99,9 @@ export default function VolunteersDetailPage() { | |
</Text> | ||
<Divider /> | ||
<ProfileInfo | ||
infoImage={profileImage} | ||
infoTitle={name} | ||
infoTexts={[email, address]} | ||
infoImage={shelterImageUrl} | ||
infoTitle={shelterName} | ||
infoTexts={[shelterEmail, shelterAddress]} | ||
/> | ||
<Divider /> | ||
|
||
|
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