Skip to content

feat: 담은 SPOT 삭제 API 연결 #100

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
Oct 1, 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
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useMutation, useQueryClient } from '@tanstack/react-query';
import useAuthAxios from '../useAuthAxios';
import QUERY_KEYS from '@/constants/QUERY_KEYS';

export default function useDeleteSelectedSpotMutation(
tripId: number,
options?: { onSuccess?: () => void },
) {
const authAxios = useAuthAxios();
const queryClient = useQueryClient();

const deleteSelectedSpots = async (id: number) => {
await authAxios.delete(`/api/schedule/selected-spot/${id}`);
};

return useMutation({
mutationFn: deleteSelectedSpots,
onSuccess: async () => {
await queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.TRIP_PLAN_DETAIL, tripId],
});
if (options?.onSuccess) options.onSuccess();
},
});
}
3 changes: 3 additions & 0 deletions packages/react-native/src/apis/mutations/useRecordMutation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,9 @@ export default function useRecordMutation({
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.RECORDS, location],
});
queryClient.invalidateQueries({
queryKey: [QUERY_KEYS.MY_BADGES],
});
};

const { mutateAsync: postMutate, isPending: isPostPending } = useMutation({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ interface UseSpotDetailQueryParams {
}

export interface SpotResponse {
id: number;
contentId: number;
title: string;
image: string;
Expand Down
13 changes: 13 additions & 0 deletions packages/react-native/src/components/detail/AroundCard.tsx
Original file line number Diff line number Diff line change
@@ -1,19 +1,24 @@
import { ImageBackground, TouchableOpacity, View } from 'react-native';
import { Font, CheckBox } from 'design-system';
import { SpotResponse } from '@/apis/queries/spot/useSpotDetailQuery';
import DotMenuIcon from '@/assets/DotMenuIcon';

interface AroundCardProps {
data: SpotResponse;
withMenuIcon?: boolean;
onCardClick: (spot: SpotResponse) => void;
onMenuClick?: () => void;
selectedSpots?: SpotResponse[];
selectionMode?: boolean;
}

export default function AroundCard({
data,
withMenuIcon,
selectedSpots,
selectionMode,
onCardClick,
onMenuClick,
}: AroundCardProps) {
const { image, title } = data;

Expand Down Expand Up @@ -43,6 +48,14 @@ export default function AroundCard({
{title}
</Font.Bold>
</View>
{withMenuIcon && (
<TouchableOpacity
className="absolute top-0 right-0 p-2"
onPress={onMenuClick}
>
<DotMenuIcon />
</TouchableOpacity>
)}
</TouchableOpacity>
</ImageBackground>
);
Expand Down
39 changes: 39 additions & 0 deletions packages/react-native/src/pages/TripPlanner/TripPlannerDetail.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,26 @@ import AroundCard from '@/components/detail/AroundCard';
import SpotDetailBottomSheet from '@/components/common/SpotDetailBottomSheet';
import useTripPlanMySpotQuery from '@/apis/queries/tripPlan/useTripPlanMySpotQuery';
import Spacing from '@/components/common/Spacing';
import useDeleteSelectedSpotMutation from '@/apis/mutations/useDeleteSelectedSpotMutation';
import BottomSheet from '@/components/common/BottomSheet';
import { SpotResponse } from '@/apis/queries/spot/useSpotDetailQuery';

export default withSuspense(function TripPlannerDetail() {
const route = useRoute<StackRouteProps<'TripPlanner/Detail'>>();
const { tripId, region, city, startDate, endDate } = route.params;
const { data } = useTripPlanMySpotQuery({ id: tripId });
const [selectedSpot, setSelectedSpot] = useState<number>();
const [targetSpot, setTargetSpot] = useState<SpotResponse>();
const navigation = useNavigation<StackNavigation<'TripPlanner/Detail'>>();
const { mutate: deleteSelectedSpots } = useDeleteSelectedSpotMutation(
tripId,
{ onSuccess: () => setTargetSpot(undefined) },
);

const deleteSpot = () => {
if (!targetSpot) return;
deleteSelectedSpots(targetSpot.id);
};

return (
<BackGroundGradient withoutScroll>
Expand Down Expand Up @@ -66,6 +79,8 @@ export default withSuspense(function TripPlannerDetail() {
renderItem={({ item }) => (
<AroundCard
data={item}
withMenuIcon
onMenuClick={() => setTargetSpot(item)}
onCardClick={() => setSelectedSpot(item.contentId)}
/>
)}
Expand All @@ -80,6 +95,8 @@ export default withSuspense(function TripPlannerDetail() {
renderItem={({ item }) => (
<AroundCard
data={item}
withMenuIcon
onMenuClick={() => setTargetSpot(item)}
onCardClick={() => setSelectedSpot(item.contentId)}
/>
)}
Expand All @@ -94,6 +111,8 @@ export default withSuspense(function TripPlannerDetail() {
renderItem={({ item }) => (
<AroundCard
data={item}
withMenuIcon
onMenuClick={() => setTargetSpot(item)}
onCardClick={() => setSelectedSpot(item.contentId)}
/>
)}
Expand All @@ -106,6 +125,26 @@ export default withSuspense(function TripPlannerDetail() {
selectedDetailSpotId={selectedSpot}
onClose={() => setSelectedSpot(undefined)}
/>
<BottomSheet
snapPoints={['20%']}
isShow={Boolean(targetSpot)}
handleClose={() => setTargetSpot(undefined)}
>
<View className="items-center p-4">
<Font.Bold type="mainTitle" color="black" ellipsis>
{targetSpot?.title}
</Font.Bold>
<Spacing height={20} />
<TouchableOpacity
className="w-full items-center"
onPress={deleteSpot}
>
<Font type="title1" color="black">
삭제
</Font>
</TouchableOpacity>
</View>
</BottomSheet>
</BackGroundGradient>
);
});
Loading