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'
|
2025-07-23 08:45:15 +04:00
|
|
|
import SessionExpired from '../session/session-expired.js'
|
2024-07-07 14:42:40 +02:00
|
|
|
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,
|
2024-06-23 19:18:25 +04:00
|
|
|
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>
|
2024-06-23 19:18:25 +04:00
|
|
|
{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>
|
2025-07-23 08:45:15 +04:00
|
|
|
<SessionExpired ref={countdownRef} setError={setError} setIsErrorAlertOpen={setIsErrorAlertOpen} />
|
2024-06-21 12:39:37 +04:00
|
|
|
</>
|
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
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,
|
2024-06-23 19:18:25 +04:00
|
|
|
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
|
|
|
}
|