Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(web-react): FileUploader multiple upload errors discovery #DS-1472 #1679

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 64 additions & 2 deletions examples/next-with-pages-router/src/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,67 @@
import { Heading } from '@lmc-eu/spirit-web-react';
import {
FileUploader,
FileUploaderAttachment,
FileUploaderInput,
FileUploaderList,
useFileQueue,
SpiritFileUploaderAttachmentProps,
} from '@lmc-eu/spirit-web-react';
import React, { useState } from 'react';

const Home = () => <Heading size="large">Spirit Pages App</Heading>;
const Home = () => {
const [errorMessage, setErrorMessage] = useState<(string | Error)[]>([]);

const {
fileQueue: fileQueueWarning,
addToQueue: addToQueueWarning,
clearQueue: clearQueueWarning,
onDismiss: onDismissWarning,
findInQueue: findInQueueWarning,
updateQueue: updateQueueWarning,
} = useFileQueue();

const attachmentComponent = ({ id, ...props }: SpiritFileUploaderAttachmentProps) => (
<FileUploaderAttachment key={id} id={id} {...props} />
);

return (
<FileUploader
addToQueue={(key, file) => {
return addToQueueWarning(key, file);
}}
clearQueue={clearQueueWarning}
fileQueue={fileQueueWarning}
findInQueue={findInQueueWarning}
id="file-uploader-validation-states-warning"
onDismiss={onDismissWarning}
updateQueue={updateQueueWarning}
>
<FileUploaderInput
helperText="Max file size is 50 kb"
id="file-uploader-validation-states-warning-input"
label="Label"
labelText="or drag and drop here"
linkText="Upload your file"
name="attachmentsWarning"
onError={(error) => {
setErrorMessage((prevErrors) => [...prevErrors, error]);
}}
validationText={`${errorMessage.join(', ')}`}
validationState="warning"
isRequired
isMultiple
maxFileSize={51200} // 50 kb
// add onInput callback should solve issue if upload files by select them (not for drag and drop)
// onInput={() => setErrorMessage([])}
/>
<FileUploaderList
attachmentComponent={attachmentComponent}
id="file-uploader-validation-states-warning-attachment"
inputName="attachmentsWarning"
label="Attachments"
/>
</FileUploader>
);
};

export default Home;
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ const FileUploaderInput = (props: SpiritFileUploaderInputProps) => {
...restProps
} = props;

const isDragAndDropSupported = 'draggable' in document.createElement('span');
const isDragAndDropSupported =
typeof document !== 'undefined' ? 'draggable' in document.createElement('span') : false;

const {
isDisabledByQueueLimitBehavior,
Expand Down
Loading