Files
konstitisyon.nu/components/konstitisyon/form-handler.js
T

93 lines
2.6 KiB
JavaScript
Raw Normal View History

2024-06-21 12:39:37 +04:00
'use client'
import PropTypes from 'prop-types'
import Button from '@mui/material/Button'
import TextField from '@mui/material/TextField'
import Dialog from '@mui/material/Dialog'
import DialogActions from '@mui/material/DialogActions'
import DialogContent from '@mui/material/DialogContent'
import DialogContentText from '@mui/material/DialogContentText'
import DialogTitle from '@mui/material/DialogTitle'
2024-07-07 14:42:40 +02:00
import LogoutCountdown from '../session/logout-countdown.js'
import ListItems from './create/list-items.js'
2024-06-21 12:39:37 +04:00
2024-07-07 14:42:40 +02:00
export default function FormHandler({
2024-06-21 12:39:37 +04:00
isOpen,
setIsOpen,
setError,
setIsErrorAlertOpen,
dialogText,
title,
2024-06-22 07:52:32 +04:00
label,
hasMultiline = true,
2024-07-07 12:09:10 +02:00
listItems,
handleFormSubmit,
countdownRef,
2024-07-28 17:35:44 +02:00
setSelectValue,
contenu
2024-06-21 12:39:37 +04:00
}) {
const handleClose = () => {
setIsOpen(false)
}
return (
<>
<Dialog
open={isOpen}
PaperProps={{
component: 'form',
onSubmit: handleFormSubmit,
}}
onClose={handleClose}
>
<DialogTitle>{title}</DialogTitle>
<DialogContent sx={{color: 'white'}}>
<DialogContentText sx={{color: 'white'}}>
{dialogText}
</DialogContentText>
{listItems && listItems.length > 0 && (
<ListItems
items={listItems}
selectLabel='Titre associé *'
setSelectValue={setSelectValue}
/>
)}
2024-06-21 12:39:37 +04:00
<TextField
autoFocus
required
fullWidth
2024-09-01 14:43:19 +04:00
defaultValue={contenu}
2024-06-22 07:52:32 +04:00
multiline={Boolean(hasMultiline)}
2024-06-21 12:39:37 +04:00
mt={2}
rows={4}
id='content'
name='content'
label={label}
/>
</DialogContent>
<DialogActions>
2024-07-28 18:10:29 +02:00
<Button variant='contained' color='error' onClick={handleClose}>Annuler</Button>
<Button variant='contained' color='success' type='submit'>Valider</Button>
2024-06-21 12:39:37 +04:00
</DialogActions>
</Dialog>
<LogoutCountdown ref={countdownRef} setError={setError} setIsErrorAlertOpen={setIsErrorAlertOpen} />
</>
)
}
2024-07-07 14:42:40 +02:00
FormHandler.propTypes = {
2024-06-21 12:39:37 +04:00
isOpen: PropTypes.bool.isRequired,
setIsOpen: PropTypes.func.isRequired,
2024-07-07 12:09:10 +02:00
countdownRef: PropTypes.object,
2024-06-21 12:39:37 +04:00
setError: PropTypes.func.isRequired,
setIsErrorAlertOpen: PropTypes.func.isRequired,
2024-07-07 12:09:10 +02:00
handleFormSubmit: PropTypes.func.isRequired,
setSelectValue: PropTypes.func.isRequired,
2024-06-21 12:39:37 +04:00
dialogText: PropTypes.string.isRequired,
title: PropTypes.string.isRequired,
2024-06-22 07:52:32 +04:00
label: PropTypes.string.isRequired,
hasMultiline: PropTypes.bool,
2024-07-28 17:35:44 +02:00
listItems: PropTypes.array.isRequired,
contenu: PropTypes.string
2024-06-21 12:39:37 +04:00
}