11import { zodResolver } from '@hookform/resolvers/zod' ;
22import { Camera , Pencil , X } from 'lucide-react' ;
33import Cropper , { type Area } from 'react-easy-crop' ;
4- import React , { useCallback , useMemo , useRef , useState } from 'react' ;
4+ import React , { useCallback , useMemo , useState } from 'react' ;
55import { useForm } from 'react-hook-form' ;
66import { type TFunction , useTranslation } from 'next-i18next' ;
77import { toast } from 'sonner' ;
88import { z } from 'zod' ;
99
10- import { env } from '~/env' ;
1110import { prepareImageForUpload , uploadImage , validateUploadSize } from '~/utils/imageUpload' ;
1211
1312import { AppDrawer } from '../ui/drawer' ;
@@ -17,6 +16,7 @@ import { Input } from '../ui/input';
1716import { Label } from '../ui/label' ;
1817import { Slider } from '../ui/slider' ;
1918import { Button } from '../ui/button' ;
19+ import { useAppStore } from '~/store/appStore' ;
2020
2121const createImage = async ( url : string ) => {
2222 const image = new Image ( ) ;
@@ -91,6 +91,7 @@ export const UpdateName: React.FC<{
9191 const [ crop , setCrop ] = useState ( { x : 0 , y : 0 } ) ;
9292 const [ zoom , setZoom ] = useState ( 1 ) ;
9393 const [ croppedAreaPixels , setCroppedAreaPixels ] = useState < Area | null > ( null ) ;
94+ const maxUploadFileSizeMB = useAppStore ( ( s ) => s . maxUploadFileSizeMB ) ;
9495
9596 const { t } = useTranslation ( ) ;
9697
@@ -151,14 +152,14 @@ export const UpdateName: React.FC<{
151152 let croppedFile = new File ( [ croppedBlob ] , 'avatar.jpg' , { type : 'image/jpeg' } ) ;
152153
153154 try {
154- croppedFile = await prepareImageForUpload ( croppedFile ) ;
155+ croppedFile = await prepareImageForUpload ( croppedFile , maxUploadFileSizeMB ) ;
155156 } catch ( error ) {
156157 console . error ( 'Compression failed:' , error ) ;
157158 toast . error ( t ( 'errors.image_compression_failed' ) ) ;
158159 }
159160
160- if ( ! validateUploadSize ( croppedFile ) ) {
161- toast . error ( t ( 'errors.less_than' , { size : env . NEXT_PUBLIC_UPLOAD_MAX_FILE_SIZE_MB } ) ) ;
161+ if ( ! validateUploadSize ( croppedFile , maxUploadFileSizeMB ) ) {
162+ toast . error ( t ( 'errors.less_than' , { size : maxUploadFileSizeMB } ) ) ;
162163 return ;
163164 }
164165
@@ -183,7 +184,7 @@ export const UpdateName: React.FC<{
183184 setZoom ( 1 ) ;
184185 setCroppedAreaPixels ( null ) ;
185186 } ) ( ) ;
186- } , [ croppedAreaPixels , detailForm , imageSrc , onNameSubmit , t ] ) ;
187+ } , [ croppedAreaPixels , detailForm , imageSrc , maxUploadFileSizeMB , onNameSubmit , t ] ) ;
187188
188189 const handleFileChange = useCallback (
189190 ( event : React . ChangeEvent < HTMLInputElement > ) => {
0 commit comments