Skip to content

Commit 502bb33

Browse files
authored
Merge pull request #246 from What-Today-FE/fix/mongdiwoo/240
체험 등록의 이미지 등록시 파일 크기 제한
2 parents 02a36de + a11fac2 commit 502bb33

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

apps/what-today/src/components/experiences/ImageInput.tsx

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Button, DeleteIcon, PlusIcon } from '@what-today/design-system';
1+
import { Button, DeleteIcon, PlusIcon, useToast } from '@what-today/design-system';
22
import { useId, useRef } from 'react';
33
import { twMerge } from 'tailwind-merge';
44

@@ -17,6 +17,7 @@ type ImageInputProps =
1717
};
1818

1919
export default function ImageInput({ value, onChange, max, className }: ImageInputProps) {
20+
const { toast } = useToast();
2021
const inputRef = useRef<HTMLInputElement>(null);
2122
const id = useId();
2223
let urls: string[] = [];
@@ -31,6 +32,25 @@ export default function ImageInput({ value, onChange, max, className }: ImageInp
3132
const file = e.target.files?.[0];
3233
if (!file) return;
3334

35+
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 파일 최대 크기 5MB
36+
if (file.size > MAX_FILE_SIZE) {
37+
toast({
38+
title: '이미지 업로드 오류',
39+
description: '파일 크기는 5MB 이하여야 합니다',
40+
type: 'error',
41+
});
42+
return;
43+
}
44+
45+
if (!file.type.startsWith('image/')) {
46+
toast({
47+
title: '이미지 업로드 오류',
48+
description: '이미지 파일만 업로드 가능합니다',
49+
type: 'error',
50+
});
51+
return;
52+
}
53+
3454
const url = URL.createObjectURL(file);
3555

3656
if (max === 1) {
@@ -80,7 +100,7 @@ export default function ImageInput({ value, onChange, max, className }: ImageInp
80100
</label>
81101

82102
{/* 미리보기 이미지들 */}
83-
<div className='flex w-full gap-12 overflow-x-scroll'>
103+
<div className='flex w-full gap-12 overflow-x-auto'>
84104
{urls.map((preview, i) => (
85105
<div key={i} className='relative'>
86106
<div className='size-80 overflow-hidden rounded-xl border border-gray-100 bg-white md:size-100'>

packages/design-system/src/components/ProfileImageInput.tsx

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import Button from '@components/button';
22
import { DeleteIcon } from '@components/icons';
33
import { ProfileLogo } from '@components/logos';
4+
import { useToast } from '@components/Toast';
45
import { useCallback, useEffect, useState } from 'react';
56

67
interface ProfileImageInputProps {
@@ -70,6 +71,7 @@ export function DeleteButton({ onDelete }: { onDelete: () => void }) {
7071
* @param {(value: string) => void} onChange - 이미지가 변경되었을 때 호출되는 콜백 함수. base64 string 또는 URL을 인자로 받습니다.
7172
*/
7273
export default function ProfileImageInput({ src, initial = src, onChange }: ProfileImageInputProps) {
74+
const { toast } = useToast();
7375
const [initialSrc, setInitialSrc] = useState(initial);
7476
const [previewUrl, setPreviewUrl] = useState<string>(src);
7577

@@ -88,12 +90,20 @@ export default function ProfileImageInput({ src, initial = src, onChange }: Prof
8890

8991
const MAX_FILE_SIZE = 5 * 1024 * 1024; // 파일 최대 크기 5MB
9092
if (file.size > MAX_FILE_SIZE) {
91-
alert('파일 크기는 5MB 이하여야 합니다.');
93+
toast({
94+
title: '이미지 업로드 오류',
95+
description: '파일 크기는 5MB 이하여야 합니다',
96+
type: 'error',
97+
});
9298
return;
9399
}
94100

95101
if (!file.type.startsWith('image/')) {
96-
alert('이미지 파일만 업로드 가능합니다.');
102+
toast({
103+
title: '이미지 업로드 오류',
104+
description: '이미지 파일만 업로드 가능합니다',
105+
type: 'error',
106+
});
97107
return;
98108
}
99109

0 commit comments

Comments
 (0)