diff --git a/front/src/modules/settings/profile/components/ProfilePictureUploader.tsx b/front/src/modules/settings/profile/components/ProfilePictureUploader.tsx index 0741e53e2..b68f4d095 100644 --- a/front/src/modules/settings/profile/components/ProfilePictureUploader.tsx +++ b/front/src/modules/settings/profile/components/ProfilePictureUploader.tsx @@ -12,12 +12,13 @@ import { } from '~/generated/graphql'; export function ProfilePictureUploader() { - const [uploadPicture] = useUploadProfilePictureMutation(); + const [uploadPicture, { loading: isUploading }] = + useUploadProfilePictureMutation(); const [removePicture] = useRemoveProfilePictureMutation(); const [currentUser] = useRecoilState(currentUserState); const [uploadController, setUploadController] = useState(null); - const [error, setError] = useState(null); + const [errorMessage, setErrorMessage] = useState(null); async function handleUpload(file: File) { if (!file) { @@ -41,10 +42,10 @@ export function ProfilePictureUploader() { }); setUploadController(null); - setError(null); + setErrorMessage(null); return result; } catch (error) { - setError(error as Error); + setErrorMessage('An error occured while uploading the picture.'); } } @@ -72,7 +73,8 @@ export function ProfilePictureUploader() { onUpload={handleUpload} onRemove={handleRemove} onAbort={handleAbort} - error={error} + isUploading={isUploading} + errorMessage={errorMessage} /> ); } diff --git a/front/src/modules/ui/input/image/components/ImageInput.tsx b/front/src/modules/ui/input/image/components/ImageInput.tsx index 67f4aaa51..003c88a45 100644 --- a/front/src/modules/ui/input/image/components/ImageInput.tsx +++ b/front/src/modules/ui/input/image/components/ImageInput.tsx @@ -3,7 +3,7 @@ import { useTheme } from '@emotion/react'; import styled from '@emotion/styled'; import { Button } from '@/ui/button/components/Button'; -import { IconFileUpload, IconTrash, IconUpload } from '@/ui/icon'; +import { IconFileUpload, IconTrash, IconUpload, IconX } from '@/ui/icon'; const StyledContainer = styled.div` display: flex; @@ -67,6 +67,12 @@ const StyledText = styled.span` font-size: ${({ theme }) => theme.font.size.xs}; `; +const StyledErrorText = styled.span` + color: ${({ theme }) => theme.font.color.danger}; + font-size: ${({ theme }) => theme.font.size.xs}; + margin-top: ${({ theme }) => theme.spacing(1)}; +`; + const StyledHiddenFileInput = styled.input` display: none; `; @@ -76,7 +82,8 @@ type Props = Omit, 'children'> & { onUpload?: (file: File) => void; onRemove?: () => void; onAbort?: () => void; - error?: Error | null; + isUploading?: boolean; + errorMessage?: string | null; disabled?: boolean; }; @@ -85,7 +92,8 @@ export function ImageInput({ onUpload, onRemove, onAbort, - error, + isUploading = false, + errorMessage, disabled = false, ...restProps }: Props) { @@ -125,37 +133,38 @@ export function ImageInput({ } }} /> -