Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: add journey in detail page #279

Merged
merged 1 commit into from
Jan 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading