Skip to content

feat: 여행 계획에 장소 담기 api연동 #74

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

Merged
merged 2 commits into from
Sep 24, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { SpotResponse } from '../queries/spot/useSpotDetailQuery';
import useAuthAxios from '../useAuthAxios';
import QUERY_KEYS from '@/constants/QUERY_KEYS';

interface AddSpotToPlanRequest {
planId: number;
spotList: SpotResponse[];
}

export default function useSelectedSpotAddMutation() {
const authAxios = useAuthAxios();
const queryClient = useQueryClient();

const addSpotToPlan = async ({ planId, spotList }: AddSpotToPlanRequest) => {
await authAxios.post(
`/api/schedule/selected-spot/${planId}`,
spotList.map((spot) => ({
title: spot.title,
addr1: spot.addr1,
addr2: spot.addr2,
contentId: spot.contentId,
image: spot.image,
dist: spot.dist,
contentTypeId: spot.contentTypeId,
})),
);
};

return useMutation({
mutationFn: addSpotToPlan,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: [QUERY_KEYS.TRIP_PLANS] });
},
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ interface DetailResponse {
isLiked: boolean;
likeCount: number;
posterUrl: string;
contentTypeId: string;
dist: string;
}

export default function useDetailQuery({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export interface SpotResponse {
latitude: number;
longitude: number;
overview: string;
contentTypeId: string;
dist: string;
}

export default function useSpotDetailQuery({ id }: UseSpotDetailQueryParams) {
Expand Down
4 changes: 4 additions & 0 deletions packages/react-native/src/pages/Detail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ const Detail = withSuspense(() => {
isLiked,
city,
region,
dist,
contentTypeId,
} = data;

const handleAddPlan = () => {
Expand All @@ -50,6 +52,8 @@ const Detail = withSuspense(() => {
longitude,
latitude,
overview,
dist,
contentTypeId,
},
],
});
Expand Down
22 changes: 18 additions & 4 deletions packages/react-native/src/pages/HomeSpotAdd.tsx
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import { useState } from 'react';
import { Dimensions, View } from 'react-native';
import { Button, FloatingPlusButton, Font } from 'design-system';
import { useRoute } from '@react-navigation/native';
import { useNavigation, useRoute } from '@react-navigation/native';
import useTripPlansQuery from '@/apis/queries/tripPlan/useTripPlansQuery';
import Header from '@/components/common/Header';
import withSuspense from '@/components/HOC/withSuspense';
import EmptyPlan from '@/components/tripPlan/EmptyPlan';
import TripPlanCard, { CARD_GAP } from '@/components/tripPlan/TripPlanCard';
import BackGroundGradient from '@/layouts/BackGroundGradient';
import { StackRouteProps } from '@/types/navigation';
import { StackNavigation, StackRouteProps } from '@/types/navigation';
import useSelectedSpotAddMutation from '@/apis/mutations/useSelectedSpotAddMutation';

const { height } = Dimensions.get('window');

Expand All @@ -17,6 +18,15 @@ export default withSuspense(function HomeSpotAdd() {
const { data } = useTripPlansQuery();
const [tripId, setTripId] = useState<number>();
const isEmpty = data.length === 0;
const { mutateAsync } = useSelectedSpotAddMutation();
const navigation = useNavigation<StackNavigation<'Home/AddSpot'>>();

const add = () => {
if (tripId) {
mutateAsync({ planId: tripId, spotList: route.params.spots });
}
navigation.goBack();
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

early return도 좋을 것 같습니다!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

반영완료하였습니다!


return (
<>
Expand Down Expand Up @@ -58,13 +68,17 @@ export default withSuspense(function HomeSpotAdd() {
</View>
</BackGroundGradient>
<View className="absolute bottom-4 w-full px-4">
<Button disabled={!tripId}>
<Button disabled={!tripId} onPress={add}>
<Font type="title1" color="white">
이 여행에 담기
</Font>
</Button>
</View>
<FloatingPlusButton bottom={16} right={16} onPress={() => {}} />
<FloatingPlusButton
bottom={16}
right={16}
onPress={() => navigation.navigate('TripPlanner/Post')}
/>
</>
);
});
Loading