Robust Photo Uploader, handling unsupported file types, upload error, apollo uploader (#1400)

* added uploaded controller, handled unsupported image formatting and error uploading styling

* remove callbacks
This commit is contained in:
Matthew
2023-09-01 07:41:07 -04:00
committed by GitHub
parent 5653b89114
commit aa47579289
2 changed files with 57 additions and 10 deletions

View File

@ -75,6 +75,8 @@ type Props = Omit<React.ComponentProps<'div'>, 'children'> & {
picture: string | null | undefined;
onUpload?: (file: File) => void;
onRemove?: () => void;
onAbort?: () => void;
error?: Error | null;
disabled?: boolean;
};
@ -82,6 +84,8 @@ export function ImageInput({
picture,
onUpload,
onRemove,
onAbort,
error,
disabled = false,
...restProps
}: Props) {
@ -112,6 +116,7 @@ export function ImageInput({
<StyledHiddenFileInput
type="file"
ref={hiddenFileInput}
accept="image/jpeg, image/png, image/gif" // to desired specification
onChange={(event) => {
if (onUpload) {
if (event.target.files) {
@ -136,10 +141,21 @@ export function ImageInput({
disabled={!picture || disabled}
fullWidth
/>
{onAbort && (
<Button
icon={<IconTrash size={theme.icon.size.sm} />}
onClick={onAbort}
variant="secondary"
title="Abort"
disabled={!picture || disabled}
fullWidth
/>
)}
</StyledButtonContainer>
<StyledText>
We support your best PNGs, JPEGs and GIFs portraits under 10MB
</StyledText>
{error && <StyledText>{error.message}</StyledText>}
</StyledContent>
</StyledContainer>
);