-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix(web-react): FileUploader multiple upload errors discovery #DS-1472
- Loading branch information
Showing
2 changed files
with
66 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters