Skip to content

Commit

Permalink
Merge pull request #279 from Strong-Potato/277-feat-add-journy-in-det…
Browse files Browse the repository at this point in the history
…ail-page

Feat: add journey in detail page
  • Loading branch information
JeongMin83 authored Jan 28, 2024
2 parents 15a38ff + 8a6e1d3 commit fbcb2b6
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 16 deletions.
72 changes: 56 additions & 16 deletions src/components/Detail/BottomFixedBtn/BottomFixedBtn.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ import {isModalOpenState, modalContentState} from '@/recoil/vote/alertModal';
import {BottomFixedBtnProps} from '@/types/detail';
import {Cookies} from 'react-cookie';
import {useNavigate} from 'react-router-dom';
import {usePostPlaces} from '@/hooks/Spaces/space';
import CustomToast from '@/components/CustomToast/CustomToast';
import {useState} from 'react';

function BottomFixedBtn({onOpen}: BottomFixedBtnProps) {
function BottomFixedBtn({onOpen, placeId}: BottomFixedBtnProps) {
const setIsModalOpen = useSetRecoilState(isModalOpenState);
const setModalContent = useSetRecoilState(modalContentState);
const [isDisabled, setIsDisabled] = useState<boolean>(false);

const cookies = new Cookies();
const isLogin = cookies.get('isLogin');
const navigate = useNavigate();

const showToast = CustomToast();

const params = new URLSearchParams(location.search);

const tripId: number = Number(params.get('tripId'));
const journeyId: number = Number(params.get('journyId'));

const notLoginContent = {
title: '로그인이 필요한 기능입니다.',
subText: '로그인하고 모든 서비스를 이용해 보세요! ',
Expand All @@ -33,23 +44,52 @@ function BottomFixedBtn({onOpen}: BottomFixedBtnProps) {
setModalContent({...notLoginContent});
};

const {mutateAsync: addToJourneyMutateAsync} = usePostPlaces();

const handleAddJourney = async () => {
const res = await addToJourneyMutateAsync({spaceId: tripId, journeyId: journeyId, placeIds: [placeId]});
console.log('일정추가 res', res);
showToast('일정에 추가가 완료되었습니다.', true, '바로가기', () => navigate(`/trip/${tripId}`));
};

return (
<div className={styles.container}>
<div
className={styles.container__wrapper}
style={{
backgroundColor: '#2388FF',
}}
onClick={() => {
if (isLogin) {
onOpen();
} else {
showNotLoginModal();
}
}}
>
<span>이 장소 후보로 등록하기</span>
</div>
{tripId && journeyId ? (
<button
className={styles.container__wrapper}
style={{
backgroundColor: '#2388FF',
}}
onClick={() => {
if (isLogin) {
setIsDisabled(true);
handleAddJourney();
navigate(`/trip/${tripId}`);
} else {
showNotLoginModal();
}
}}
disabled={isDisabled}
>
<span>이 장소 일정에 추가하기</span>
</button>
) : (
<button
className={styles.container__wrapper}
style={{
backgroundColor: '#2388FF',
}}
onClick={() => {
if (isLogin) {
onOpen();
} else {
showNotLoginModal();
}
}}
>
<span>이 장소 후보로 등록하기</span>
</button>
)}
</div>
);
}
Expand Down
1 change: 1 addition & 0 deletions src/pages/Detail/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ function Detail() {
false,
)
}
placeId={placeInfo.id}
/>
<BottomSlideDetail
isOpen={isOpen}
Expand Down
1 change: 1 addition & 0 deletions src/types/detail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ export interface starsWrapperProps {

export interface BottomFixedBtnProps {
onOpen: () => void;
placeId: number;
}

export interface RegistrationSlideProps {
Expand Down

0 comments on commit fbcb2b6

Please sign in to comment.