Skip to content

Commit 70f7037

Browse files
committed
toast if file size greater than 1 mb
1 parent d4313ee commit 70f7037

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

apps/web/app/(org)/dashboard/settings/account/components/ProfileImage.tsx

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
66
import clsx from "clsx";
77
import Image from "next/image";
88
import { useEffect, useRef, useState } from "react";
9+
import { toast } from "sonner";
910

1011
interface ProfileImageProps {
1112
initialPreviewUrl?: string | null;
@@ -38,7 +39,13 @@ export function ProfileImage({
3839

3940
const handleFileChange = () => {
4041
const file = fileInputRef.current?.files?.[0];
41-
if (file) {
42+
if (!file) return;
43+
const sizeLimit = 1024 * 1024 * 1;
44+
if (file.size > sizeLimit) {
45+
toast.error("File size must be 1MB or less");
46+
return;
47+
}
48+
if (file && file.size <= sizeLimit) {
4249
const objectUrl = URL.createObjectURL(file);
4350
setPreviewUrl(objectUrl);
4451
onChange?.(file);

0 commit comments

Comments
 (0)