Skip to content

Commit

Permalink
refactor(upload): rename Error component to ErrorComponent
Browse files Browse the repository at this point in the history
  • Loading branch information
AdrianBielecAriane committed Oct 23, 2024
1 parent 182fad2 commit 61b5497
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 23 deletions.
16 changes: 2 additions & 14 deletions packages/react-kit/src/components/form/Field.styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,10 @@ export type FileUploadWrapperTheme = Partial<{
error: Partial<{
borderColor: CSSProperties["borderColor"];
}>;
overrides: Partial<CSSProperties>;
}>;
export const FileUploadWrapper = styled.div<{
$error: unknown;
$v2?: boolean;
theme: FileUploadWrapperTheme | undefined;
}>`
position: relative;
Expand Down Expand Up @@ -189,19 +189,7 @@ export const FileUploadWrapper = styled.div<{
cursor: not-allowed;
opacity: 0.5;
}
${({ $v2 }) =>
$v2 &&
css`
aspect-ratio: 1/1;
padding-inline: 1.5rem;
background: ${colors.white};
min-width: 9.375rem;
width: auto;
height: auto;
border-radius: 12px;
border: 2px solid ${theme.colors.light.border};
color: ${theme.colors.light.greyText};
`}
${({ theme: { overrides } }) => overrides}
`;

export const FieldFileUpload = styled(FieldInput)`
Expand Down
6 changes: 3 additions & 3 deletions packages/react-kit/src/components/form/Upload/BaseUpload.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,6 @@ function BaseUpload({
removeFile,
saveButtonTheme,
errorComponent,
v2,
theme,
...props
}: UploadPropsWithNoIpfs & WithUploadToIpfsProps) {
Expand Down Expand Up @@ -220,7 +219,7 @@ function BaseUpload({
}
handleLoading(true);
try {
const files = await saveToIpfs(efiles, true);
const files = await saveToIpfs(efiles, { throwOnError: true });
setErrorMessage(undefined);
if (files) {
setFiles(files);
Expand All @@ -233,6 +232,8 @@ function BaseUpload({
} catch (err) {
if (err instanceof Error) {
setErrorMessage(err.message);
} else {
setErrorMessage("Something went wrong");
}
} finally {
handleLoading(false);
Expand Down Expand Up @@ -319,7 +320,6 @@ function BaseUpload({
data-disabled={disabled}
onClick={handleChooseFile}
$error={errorMessage}
$v2={v2}
style={style}
theme={theme?.triggerTheme}
>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const SUPPORTED_FORMATS = [
export interface WithUploadToIpfsProps {
saveToIpfs: (
files: File[] | null,
throwOnError?: boolean
options?: { throwOnError?: boolean }
) => Promise<false | FileProps[] | undefined>;
loadMedia: (src: string) => Promise<string | undefined>;
removeFile: (src: string) => Promise<void>;
Expand All @@ -40,7 +40,10 @@ export function WithUploadToIpfs<P extends WithUploadToIpfsProps>(
const { saveFile, loadMedia, removeFile } = useSaveImageToIpfs();

const saveToIpfs: WithUploadToIpfsProps["saveToIpfs"] = useCallback(
async (filesArray: File[] | null, throwOnError?: boolean) => {
async (
filesArray: File[] | null,
options: { throwOnError?: boolean } = {}
) => {
if (!filesArray) {
return;
}
Expand All @@ -54,12 +57,12 @@ export function WithUploadToIpfs<P extends WithUploadToIpfsProps>(
const err = `File ${
file?.name
} size cannot exceed more than ${bytesToSize(sizeValidation)}!`;
if (throwOnError) throw new Error(err);
if (options?.throwOnError) throw new Error(err);
filesErrors.push(err);
}
if (!formatValidation.includes(file?.type)) {
const err = `Uploaded file has unsupported format of ${file?.type}!`;
if (throwOnError) throw new Error(err);
if (options?.throwOnError) throw new Error(err);
filesErrors.push(err);
}
}
Expand Down
6 changes: 4 additions & 2 deletions packages/react-kit/src/components/form/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,11 @@ export type UploadProps = BaseProps & {
width?: number;
height?: number;
errorComponent?: (errorMessage: string) => React.ReactNode;
v2?: boolean;
imgPreviewStyle?: Pick<CSSProperties, "objectFit">;
theme?: Partial<{ triggerTheme: FileUploadWrapperTheme }>;
theme?: Partial<{
triggerTheme: FileUploadWrapperTheme;
overrides: React.CSSProperties;
}>;
} & (
| {
withEditor: true;
Expand Down

0 comments on commit 61b5497

Please sign in to comment.