Skip to content

Commit

Permalink
feat: 서비스 삭제 API 연결
Browse files Browse the repository at this point in the history
- 내 서비스를 북마크했을 수도 있어서 내 서랍장 쿼리 2개 모두 무효화
  • Loading branch information
nijuy committed Jun 4, 2024
1 parent 55545eb commit 3abb2f5
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 4 deletions.
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,
onSettled: () => {
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 @@ -13,6 +13,10 @@ import {
StyledServiceTextContainer,
} from './UserDrawerCard.style';

interface UserDrawerCardProps extends DrawerCardProps {
productNo: number;
}

export const UserDrawerCard = ({
link,
bigImgSrc,
Expand All @@ -21,7 +25,8 @@ export const UserDrawerCard = ({
body,
bookmarkCount,
isBookmarked,
}: DrawerCardProps) => {
productNo,
}: UserDrawerCardProps) => {
const [isCardSettingClicked, setIsCardSettingClicked] = useState(false);
const [openRemoveModal, setOpenRemoveModal] = useState(false);
const dropdownRef = useRef<HTMLDivElement | null>(null);
Expand Down Expand Up @@ -81,7 +86,11 @@ export const UserDrawerCard = ({
</StyledServiceTextContainer>
</Dropdown>
)}
<ServiceRemoveModal open={openRemoveModal} onOpenChange={setOpenRemoveModal} />
<ServiceRemoveModal
open={openRemoveModal}
productNo={productNo}
onOpenChange={setOpenRemoveModal}
/>
</StyledCardContainer>
);
};

0 comments on commit 3abb2f5

Please sign in to comment.