-
Notifications
You must be signed in to change notification settings - Fork 5
Feature/delete modal #79
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
Changes from 8 commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
b14c518
Feat : 모달창만띄워둠
llmojoll ef31b7f
Merge branch 'dev' into feature/delete-modal
llmojoll 42632fb
Chore
llmojoll d98837b
Feat : 와인 삭제하기 모달 api연결 및 테스트완
llmojoll 83983fa
Feat : Delete 컴포넌트 재사용하게끔 구현 , 리뷰삭제 추가
llmojoll 68ff870
Refactor : 테스트코드삭제
llmojoll 481b9bd
Refactor : react-query Mutation 방식으로 변경
llmojoll 7b78057
Merge branch 'dev' into feature/delete-modal
llmojoll 1e00e68
Fix : Star.svg 아이콘 수정
llmojoll db50d1f
Chore : star.svg >> Star.svg
llmojoll fca2ebb
Chore : Star >> star
llmojoll ada694e
Chore
llmojoll f6ff42c
Chore : Star >> star
llmojoll 4ac769b
Chore : star삭제
llmojoll 5ee380e
Chore : star추가
llmojoll b459c77
Merge branch 'dev' into feature/delete-modal
llmojoll cfe761d
Refactor : 모달 of off 상태값 props로 받도록
llmojoll File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import apiClient from '@/api/apiClient'; | ||
|
|
||
| export interface DeleteResponse { | ||
| success: boolean; | ||
| message?: string; | ||
| } | ||
|
|
||
| export const deleteWine: (wineId: number) => Promise<DeleteResponse> = async (wineId) => { | ||
| const response = await apiClient.delete<DeleteResponse>( | ||
| `/${process.env.NEXT_PUBLIC_TEAM}/wines/${wineId}`, | ||
| ); | ||
| return response.data; | ||
| }; | ||
|
|
||
| export const deleteReview = async (reviewId: number): Promise<DeleteResponse> => { | ||
| const response = await apiClient.delete<DeleteResponse>( | ||
| `/${process.env.NEXT_PUBLIC_TEAM}/reviews/${reviewId}`, | ||
| ); | ||
| return response.data; | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| import React, { useState } from 'react'; | ||
|
|
||
| import { useMutation, useQueryClient } from '@tanstack/react-query'; | ||
| import { AxiosError } from 'axios'; | ||
|
|
||
| import { deleteReview, deleteWine, DeleteResponse } from '@/api/delete'; | ||
| import BasicModal from '@/components/common/Modal/BasicModal'; | ||
| import { Button } from '@/components/ui/button'; | ||
|
|
||
| interface DeleteModalProps { | ||
| type: 'wine' | 'review'; | ||
| id: number; | ||
| trigger: React.ReactNode; | ||
| } | ||
|
|
||
| const DeleteModal = ({ type, id, trigger }: DeleteModalProps) => { | ||
| const [showDeleteModal, setShowDeleteModal] = useState(false); | ||
| const queryClient = useQueryClient(); | ||
|
|
||
| const deleteWineMutation = useMutation<DeleteResponse, AxiosError, number>({ | ||
| mutationFn: (id) => deleteWine(id), | ||
| }); | ||
| const deleteReviewMutation = useMutation<DeleteResponse, AxiosError, number>({ | ||
| mutationFn: (id) => deleteReview(id), | ||
| }); | ||
|
|
||
| const handleDelete = () => { | ||
| if (type === 'wine') { | ||
| deleteWineMutation.mutate(id, { | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ['wines'] }); //삭제후 관련데이터 바로 갱신 | ||
| console.log('와인 삭제 성공'); | ||
| setShowDeleteModal(false); | ||
| }, | ||
| onError: (error) => { | ||
| console.error('와인 삭제 실패', error); | ||
| }, | ||
| }); | ||
| } else if (type === 'review') { | ||
| deleteReviewMutation.mutate(id, { | ||
| onSuccess: () => { | ||
| queryClient.invalidateQueries({ queryKey: ['reviews'] }); | ||
| console.log('리뷰 삭제 성공'); | ||
| setShowDeleteModal(false); | ||
| }, | ||
| onError: (error) => { | ||
| console.error('리뷰 삭제 실패', error); | ||
| }, | ||
| }); | ||
| } | ||
| }; | ||
|
|
||
| // const handleDelete = async () => { | ||
| // try { | ||
| // if (type === 'wine') { | ||
| // await deleteWine(id); | ||
| // console.log('와인 삭제 성공'); | ||
| // } else if (type === 'review') { | ||
| // await deleteReview(id); | ||
| // console.log('리뷰 삭제 성공'); | ||
| // } | ||
| // setShowDeleteModal(false); | ||
| // } catch (error) { | ||
| // console.log('삭제실패 : ', error); | ||
| // } | ||
| // }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <span onClick={() => setShowDeleteModal(true)}>{trigger}</span> | ||
| <BasicModal | ||
| type='register' | ||
| title='' | ||
| open={showDeleteModal} | ||
| onOpenChange={(isOpen: boolean) => setShowDeleteModal(isOpen)} | ||
| showCloseButton={false} | ||
| buttons={ | ||
| <div className='flex w-full gap-2'> | ||
| <Button | ||
| onClick={() => setShowDeleteModal(false)} | ||
| type='button' | ||
| variant='onlyCancel' | ||
| size='xl' | ||
| width='full' | ||
| fontSize='lg' | ||
| > | ||
| 취소 | ||
| </Button> | ||
| <Button | ||
| onClick={handleDelete} | ||
| type='button' | ||
| variant='purpleDark' | ||
| size='xl' | ||
| width='full' | ||
| fontSize='lg' | ||
| > | ||
| 삭제 | ||
| </Button> | ||
| </div> | ||
| } | ||
| > | ||
| <span className='flex justify-center mb-8 custom-text-2lg-bold md:custom-text-xl-bold'> | ||
| 정말로 삭제하시겠습니까? | ||
| </span> | ||
| </BasicModal> | ||
| </div> | ||
| ); | ||
| }; | ||
| export default DeleteModal; | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
이런 방법으로 onSuccess, onError 처리도 가능하군요? 항상 Mutation 선언할 때만 썼는데 새롭네요