Skip to content

Commit 4be7cea

Browse files
committed
linting for error component
1 parent 24de4eb commit 4be7cea

File tree

1 file changed

+34
-26
lines changed

1 file changed

+34
-26
lines changed

src/components/Error/Error.jsx

Lines changed: 34 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,42 +1,50 @@
11
/* eslint react/no-array-index-key: 0 */
2-
import React from 'react'
2+
import React, { useState } from 'react'
33
import PropTypes from 'prop-types'
44
import { Alert, Button, Container } from 'react-bootstrap'
55

6-
const Error = ({ errors, showBackButton, router }) => {
7-
const { errorTitle, errorText, variant} = errors
6+
const Error = ({ errors, showBackButton, canDismissAlert, router }) => {
7+
const { errorTitle, errorText, variant } = errors
8+
const [show, setShow] = useState(true)
89
return (
9-
<Container>
10-
<Alert className='my-5 text-break' variant={variant}>
11-
{errorTitle && (
12-
<Alert.Heading>{errorTitle}</Alert.Heading>
13-
)}
14-
{errorText && (errorText)}
15-
{showBackButton && (
16-
<>
17-
<hr />
18-
<div className='d-flex justify-content-end'>
19-
<Button onClick={() => router.back()} variant={`outline-${variant}`}>
20-
Click to return to the previous page.
21-
</Button>
22-
</div>
23-
</>
24-
)}
25-
</Alert>
26-
</Container>
10+
show && (
11+
<Container>
12+
<Alert className='my-5 text-break' variant={variant} onClose={() => setShow(false)} dismissible={canDismissAlert}>
13+
{errorTitle && (
14+
<Alert.Heading>{errorTitle}</Alert.Heading>
15+
)}
16+
{errorText.map((errorMessage, index) => (
17+
<p key={index}>{errorMessage}</p>
18+
))}
19+
{showBackButton && (
20+
<>
21+
<hr />
22+
<div className='d-flex justify-content-end'>
23+
<Button onClick={() => router.back()} variant={`outline-${variant}`}>
24+
Click to return to the previous page.
25+
</Button>
26+
</div>
27+
</>
28+
)}
29+
</Alert>
30+
</Container>
31+
)
2732
)
2833
}
2934

3035
Error.propTypes = {
31-
errorText: PropTypes.string.isRequired,
32-
errorTitle: PropTypes.string,
33-
router: PropTypes.shape({}).isRequired,
36+
canDismissAlert: PropTypes.bool,
37+
errors: PropTypes.shape({
38+
errorText: PropTypes.string.isRequired,
39+
errorTitle: PropTypes.string,
40+
variant: PropTypes.string.isRequired,
41+
}).isRequired,
3442
showBackButton: PropTypes.bool,
35-
variant: PropTypes.string.isRequired,
43+
router: PropTypes.shape({}).isRequired,
3644
}
3745

3846
Error.defaultProps = {
39-
errorTitle: '',
47+
canDismissAlert: false,
4048
showBackButton: true,
4149
}
4250

0 commit comments

Comments
 (0)