refactor: use HandleComments to read & write comments

This commit is contained in:
2024-06-19 14:44:49 +04:00
parent f4eb07c9a3
commit 1e587b5d6b
4 changed files with 79 additions and 40 deletions
@@ -0,0 +1,57 @@
'use client'
import PropTypes from 'prop-types'
import WriteComment from './write-comment.js'
import ReadComments from './read-comments.js'
export default function HandleComments({
session,
selectedTitre,
isOpen,
setIsOpen,
setError,
setSuccess,
setIsErrorAlertOpen,
setIsSuccessAlertOpen,
operation
}) {
if (operation === 'write') {
return (
<WriteComment
session={session}
selectedTitre={selectedTitre}
isOpen={isOpen}
setIsOpen={setIsOpen}
setError={setError}
setSuccess={setSuccess}
setIsErrorAlertOpen={setIsErrorAlertOpen}
setIsSuccessAlertOpen={setIsSuccessAlertOpen}
/>
)
}
if (operation === 'read') {
return (
<ReadComments
session={session}
selectedTitre={selectedTitre}
isOpen={isOpen}
setIsOpen={setIsOpen}
setError={setError}
setIsErrorAlertOpen={setIsErrorAlertOpen}
/>
)
}
}
HandleComments.propTypes = {
session: PropTypes.object,
selectedTitre: PropTypes.object.isRequired,
isOpen: PropTypes.bool.isRequired,
setIsOpen: PropTypes.func.isRequired,
setError: PropTypes.func.isRequired,
setSuccess: PropTypes.func.isRequired,
setIsErrorAlertOpen: PropTypes.func.isRequired,
setIsSuccessAlertOpen: PropTypes.func.isRequired,
operation: PropTypes.oneOf(['write', 'read']).isRequired
}