-
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.
Merge pull request #577 from Availity/feat/file-selector
feat(mui-file-selector): add support for dropping files and fix removing
- Loading branch information
Showing
27 changed files
with
718 additions
and
465 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
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
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
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
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { render, screen } from '@testing-library/react'; | ||
|
||
import { ErrorAlert } from './ErrorAlert'; | ||
|
||
describe('ErrorAlert', () => { | ||
test('should render error message', () => { | ||
render(<ErrorAlert id={0} errors={[{ code: 'test', message: 'example' }]} fileName="file" onClose={jest.fn()} />); | ||
|
||
expect(screen.getByText('Error: file')).toBeDefined(); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { Alert, AlertTitle } from '@availity/mui-alert'; | ||
import type { FileRejection } from 'react-dropzone'; | ||
|
||
const codes: Record<string, string> = { | ||
'file-too-large': 'File exceeds maximum size', | ||
'file-invalid-type': 'File has an invalid type', | ||
'file-too-small': 'File is smaller than minimum size', | ||
'too-many-file': 'Too many files', | ||
'duplicate-name': 'Duplicate file selected', | ||
}; | ||
|
||
export type ErrorAlertProps = { | ||
/** | ||
* Array of file rejection errors | ||
*/ | ||
errors: FileRejection['errors']; | ||
/** | ||
* Name of the file that encountered errors | ||
*/ | ||
fileName: string; | ||
/** | ||
* Unique identifier for the error alert | ||
*/ | ||
id: number; | ||
|
||
onClose: () => void; | ||
}; | ||
|
||
export const ErrorAlert = ({ errors, fileName, id, onClose }: ErrorAlertProps) => { | ||
if (errors.length === 0) return null; | ||
|
||
return ( | ||
<> | ||
{errors.map((error) => { | ||
return ( | ||
<Alert severity="error" onClose={onClose} key={`${id}-${error.code}`}> | ||
<AlertTitle> | ||
{codes[error.code] || 'Error'}: {fileName} | ||
</AlertTitle> | ||
{error.message} | ||
</Alert> | ||
); | ||
})} | ||
</> | ||
); | ||
}; |
Oops, something went wrong.