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: 서랍장 서비스 삭제 API 연결 #211

Merged
merged 4 commits into from
Jun 22, 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
6 changes: 6 additions & 0 deletions src/drawer/apis/deleteProduct.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { soomsilClient } from '@/apis';

export const deleteProduct = async (productId: number) => {
const { data } = await soomsilClient.delete(`/v2/drawer/${productId}`);
return data;
};
1 change: 1 addition & 0 deletions src/drawer/components/CardLayout/CardLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export const CardLayout = ({ data, type }: CardLayoutProps) => {
isBookmarked={product.isBookmarked}
bigImgSrc={product.introductionImage[0]}
smallImgSrc={product.mainImage}
productNo={product.productNo}
/>
) : (
<BigDrawerCard
Expand Down
22 changes: 20 additions & 2 deletions src/drawer/components/Dialog/ServiceRemoveModal.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import * as Dialog from '@radix-ui/react-dialog';
import { useMutation, useQueryClient } from '@tanstack/react-query';
import { BoxButton, IcXLine, IconContext } from '@yourssu/design-system-react';
import { useTheme } from 'styled-components';

import { FlexGrowItem } from '@/components/FlexContainer/FlexContainer';
import { deleteProduct } from '@/drawer/apis/deleteProduct';

import {
StyledDialogContent,
Expand All @@ -13,11 +15,21 @@ import {

interface ServiceRemoveModalProps {
open: boolean;
productNo: number;
onOpenChange: (open: boolean) => void;
}

export const ServiceRemoveModal = ({ open, onOpenChange }: ServiceRemoveModalProps) => {
export const ServiceRemoveModal = ({ open, productNo, onOpenChange }: ServiceRemoveModalProps) => {
const theme = useTheme();
const queryClient = useQueryClient();

const deleteProductMutation = useMutation({
mutationFn: deleteProduct,
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['myRegistered', 'WEB'] });
queryClient.invalidateQueries({ queryKey: ['bookmarked', 'WEB'] });
},
});

return (
<Dialog.Root modal={true} open={open} onOpenChange={onOpenChange}>
Expand All @@ -30,7 +42,13 @@ export const ServiceRemoveModal = ({ open, onOpenChange }: ServiceRemoveModalPro

<Dialog.Close asChild>
<div>
<BoxButton size="medium" rounding={4} variant="filled" width="15.375rem">
<BoxButton
size="medium"
rounding={4}
variant="filled"
width="15.375rem"
onClick={() => deleteProductMutation.mutate(productNo)}
>
확인
</BoxButton>
</div>
Expand Down
13 changes: 11 additions & 2 deletions src/drawer/components/DrawerCard/UserDrawerCard/UserDrawerCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import { DrawerCardProps } from '../DrawerCard.type';

import { StyledCardContainer } from './UserDrawerCard.style';

interface UserDrawerCardProps extends DrawerCardProps {
productNo: number;
}

export const UserDrawerCard = ({
link,
bigImgSrc,
Expand All @@ -16,7 +20,8 @@ export const UserDrawerCard = ({
body,
bookmarkCount,
isBookmarked,
}: DrawerCardProps) => {
productNo,
}: UserDrawerCardProps) => {
const [isCardSettingClicked, setIsCardSettingClicked] = useState(false);
const [openRemoveModal, setOpenRemoveModal] = useState(false);

Expand Down Expand Up @@ -52,7 +57,11 @@ export const UserDrawerCard = ({
</CardSettingDropdownMenu.Trigger>
</CardSettingDropdownMenu>
</Card>
<ServiceRemoveModal open={openRemoveModal} onOpenChange={setOpenRemoveModal} />
<ServiceRemoveModal
open={openRemoveModal}
productNo={productNo}
onOpenChange={setOpenRemoveModal}
/>
</StyledCardContainer>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ export const ServiceAction = ({ product }: { product: ProductDetailResult }) =>

const bookmarkMutation = useMutation({
mutationFn: product.isBookmarked ? deleteBookmarked : postBookmarked,
onSettled: () => {
onSuccess: () => {
queryClient.invalidateQueries({ queryKey: ['productDetail', product.productNo] });
},
});
Expand Down