'use client' import {useRef} from 'react' 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' import LogoutCountdown from '../../session/logout-countdown.js' import {handleSubmit} from '@/lib/directus.js' import {formatFormContent} from '@/lib/format.js' export default function CreateForm({ session, selectedTitre, isOpen, setIsOpen, setError, setSuccess, setIsErrorAlertOpen, setIsSuccessAlertOpen, dialogText, collection, title, label, hasMultiline = true }) { const countdownRef = useRef() const handleClose = () => { setIsOpen(false) } const handleFormSubmit = async e => { e.preventDefault() let requestObject const formattedContent = formatFormContent(e.currentTarget) if (collection === 'commentaires') { requestObject = { text: formattedContent, titre: selectedTitre, status: 'draft', } } else if (collection === 'titres') { requestObject = { contenu: formattedContent, status: 'draft', } } await handleSubmit({ accessToken: session.user.accessToken, content: formattedContent, collection, requestObject, setError, setSuccess, setIsErrorAlertOpen, setIsSuccessAlertOpen, countdownRef, }) handleClose() } return ( <> {title} {dialogText} ) } CreateForm.propTypes = { session: PropTypes.object, selectedTitre: PropTypes.object, isOpen: PropTypes.bool.isRequired, setIsOpen: PropTypes.func.isRequired, setError: PropTypes.func.isRequired, setSuccess: PropTypes.func, setIsErrorAlertOpen: PropTypes.func.isRequired, setIsSuccessAlertOpen: PropTypes.func, dialogText: PropTypes.string.isRequired, collection: PropTypes.string.isRequired, title: PropTypes.string.isRequired, label: PropTypes.string.isRequired, hasMultiline: PropTypes.bool }