Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
22 changes: 21 additions & 1 deletion apps/what-today/src/components/experiences/ImageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Button, DeleteIcon, PlusIcon } from '@what-today/design-system';
import { Button, DeleteIcon, PlusIcon, useToast } from '@what-today/design-system';
import { useId, useRef } from 'react';
import { twMerge } from 'tailwind-merge';

Expand All @@ -17,6 +17,7 @@ type ImageInputProps =
};

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

const MAX_FILE_SIZE = 5 * 1024 * 1024; // 파일 최대 크기 5MB
if (file.size > MAX_FILE_SIZE) {
toast({
title: '이미지 업로드 오류',
description: '파일 크기는 5MB 이하여야 합니다',
type: 'error',
});
return;
}

if (!file.type.startsWith('image/')) {
toast({
title: '이미지 업로드 오류',
description: '이미지 파일만 업로드 가능합니다',
type: 'error',
});
return;
}

const url = URL.createObjectURL(file);

if (max === 1) {
Expand Down
14 changes: 12 additions & 2 deletions packages/design-system/src/components/ProfileImageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Button from '@components/button';
import { DeleteIcon } from '@components/icons';
import { ProfileLogo } from '@components/logos';
import { useToast } from '@components/Toast';
import { useCallback, useEffect, useState } from 'react';

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

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

const MAX_FILE_SIZE = 5 * 1024 * 1024; // 파일 최대 크기 5MB
if (file.size > MAX_FILE_SIZE) {
alert('파일 크기는 5MB 이하여야 합니다.');
toast({
title: '이미지 업로드 오류',
description: '파일 크기는 5MB 이하여야 합니다',
type: 'error',
});
return;
}

if (!file.type.startsWith('image/')) {
alert('이미지 파일만 업로드 가능합니다.');
toast({
title: '이미지 업로드 오류',
description: '이미지 파일만 업로드 가능합니다',
type: 'error',
});
return;
}

Expand Down