Refactor InfoActionButtons to Conditionally Render Buttons Based on User Permissions
All checks were successful
farmcontrol/farmcontrol-ui/pipeline/head This commit looks good

- Integrated AuthContext to access user profile permissions.
- Added logic to conditionally display DocumentPrintButton and EmailSendButton based on user permissions, enhancing security and user experience.
- Improved component structure for better maintainability and clarity.
This commit is contained in:
Tom Butcher 2026-09-12 22:09:04 +01:00
parent 483682ce44
commit a9e4c8dad3

View File

@ -2,13 +2,25 @@ import { Flex } from 'antd'
import PropTypes from 'prop-types' import PropTypes from 'prop-types'
import DocumentPrintButton from './DocumentPrintButton' import DocumentPrintButton from './DocumentPrintButton'
import EmailSendButton from './EmailSendButton' import EmailSendButton from './EmailSendButton'
import { AuthContext } from '../context/AuthContext'
const InfoActionButtons = (props) => ( import { useContext } from 'react'
<Flex gap='small'>
<DocumentPrintButton {...props} /> const InfoActionButtons = (props) => {
<EmailSendButton {...props} /> const { userProfile } = useContext(AuthContext)
</Flex> const showEmailSendButton =
) userProfile?.permissions?.emailMessage?.new &&
userProfile?.permissions?.emailTemplate?.list
const showDocumentPrintButton =
userProfile?.permissions?.documentTemplate?.list &&
userProfile?.permissions?.documentJob?.new
return (
<Flex gap='small'>
{showDocumentPrintButton && <DocumentPrintButton {...props} />}
{showEmailSendButton && <EmailSendButton {...props} />}
</Flex>
)
}
InfoActionButtons.propTypes = { InfoActionButtons.propTypes = {
type: PropTypes.string.isRequired, type: PropTypes.string.isRequired,