Skip to content

Commit

Permalink
DayLog 수정 모달에서 이미지 여러 번에 걸쳐 넣을 때 발생하는 문제 수정 (#665)
Browse files Browse the repository at this point in the history
* refactor: UseMultipleImageUploadParams 훅 input문제를 위한 코드 수정

* refactor: UseMultipleImageUpload 사진 여러번 input시 발생하는 문제 수정
  • Loading branch information
dladncks1217 authored Oct 6, 2023
1 parent 07d37b0 commit 67ec639
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import { TRIP_TYPE } from '@/constants/trip';

import { useRecoilValue } from 'recoil';

import { Button, Flex, Modal, Theme } from 'hang-log-design-system';
Expand All @@ -25,6 +23,8 @@ import { mediaQueryMobileState } from '@store/mediaQuery';
import type { TripTypeData } from '@type/trip';
import type { TripItemFormData } from '@type/tripItem';

import { TRIP_TYPE } from '@constants/trip';

interface TripItemAddModalProps {
tripId: string;
dayLogId: number;
Expand Down
15 changes: 12 additions & 3 deletions frontend/src/hooks/common/useMultipleImageUpload.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ import { TRIP_ITEM_ADD_MAX_IMAGE_UPLOAD_COUNT } from '@constants/ui';
interface UseMultipleImageUploadParams {
initialImageUrls: string[];
maxUploadCount?: number;
handleInitialImage?: (images: string[]) => void;
onSuccess?: CallableFunction;
onError?: CallableFunction;
}

export const useMultipleImageUpload = ({
initialImageUrls,
maxUploadCount = TRIP_ITEM_ADD_MAX_IMAGE_UPLOAD_COUNT,

onSuccess,
onError,
}: UseMultipleImageUploadParams) => {
const imageMutation = useImageMutation();

const { createToast } = useToast();

const [uploadedImageUrls, setUploadedImageUrls] = useState(initialImageUrls);

const handleImageUpload = useCallback(
Expand Down Expand Up @@ -76,7 +77,7 @@ export const useMultipleImageUpload = ({
{ images: imageUploadFormData },
{
onSuccess: ({ imageUrls }) => {
onSuccess?.([...prevImageUrls, ...imageUrls]);
onSuccess?.([...initialImageUrls, ...imageUrls]);
createToast('이미지 업로드에 성공했습니다', 'success');
},
onError: () => {
Expand All @@ -88,7 +89,15 @@ export const useMultipleImageUpload = ({
// eslint-disable-next-line no-param-reassign
event.target.value = '';
},
[createToast, imageMutation, maxUploadCount, onError, onSuccess, uploadedImageUrls]
[
createToast,
imageMutation,
initialImageUrls,
maxUploadCount,
onError,
onSuccess,
uploadedImageUrls,
]
);

const handleImageRemoval = useCallback(
Expand Down

0 comments on commit 67ec639

Please sign in to comment.