From a931f734ca957bb0c86c54408a94ea109e80716e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20FAMIBELLE-PRONZOLA?= Date: Fri, 25 Mar 2022 00:05:49 +0400 Subject: [PATCH] Create ChwaTeks component --- components/soumet/chwa-teks.js | 117 +++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 components/soumet/chwa-teks.js diff --git a/components/soumet/chwa-teks.js b/components/soumet/chwa-teks.js new file mode 100644 index 0000000..1a0f45d --- /dev/null +++ b/components/soumet/chwa-teks.js @@ -0,0 +1,117 @@ +import {useState} from 'react' +import {useSession} from 'next-auth/react' +import PropTypes from 'prop-types' +import Button from '@mui/material/Button' +import Avatar from '@mui/material/Avatar' +import List from '@mui/material/List' +import ListItem from '@mui/material/ListItem' +import ListItemAvatar from '@mui/material/ListItemAvatar' +import ListItemText from '@mui/material/ListItemText' +import DialogTitle from '@mui/material/DialogTitle' +import Dialog from '@mui/material/Dialog' +import {green} from '@mui/material/colors' +import Container from '@mui/material/Container' +import CircularProgress from '@mui/material/CircularProgress' +import Typography from '@mui/material/Typography' +import AudiotrackIcon from '@mui/icons-material/Audiotrack' + +import {jwennTeksEpiUserId} from '../../lib/oki-api' + +function Chwa(props) { + const {onClose, teksLis, selectedTeks, loading, open} = props + + const handleClose = () => { + onClose(selectedTeks) + } + + const handleListItemClick = value => { + onClose(value) + } + + return ( + + Choisir le texte à modifier + {loading ? ( + + ) : ( + + {teksLis.length > 0 ? teksLis.map(({_id, tit, awtis}) => ( + handleListItemClick(_id)}> + + + + + + alias))} - ${tit}`} /> + + )) : ( + Aucun texte + )} + + )} + + ) +} + +Chwa.defaultProps = { + selectedTeks: null +} + +Chwa.propTypes = { + onClose: PropTypes.func.isRequired, + teksLis: PropTypes.array.isRequired, + loading: PropTypes.bool.isRequired, + open: PropTypes.bool.isRequired, + selectedTeks: PropTypes.object, +} + +export default function ChwaTeks({selectedTeks, setSelectedTeks}) { + const {data: session} = useSession() + const [loading, setLoading] = useState(false) + const {user} = session + const [open, setOpen] = useState(false) + const [teksLis, setTeksLis] = useState([]) + + const handleClickOpen = async () => { + setOpen(true) + setLoading(true) + + const jwennTeks = await jwennTeksEpiUserId(user._id) + + setTeksLis(jwennTeks) + setLoading(false) + } + + const handleClose = value => { + const teks = teksLis.find(({_id}) => _id === value) + setSelectedTeks(teks) + setOpen(false) + } + + return ( + + + + * textes non publiés uniquement + + + + ) +} + +ChwaTeks.defaultProps = { + selectedTeks: null +} + +ChwaTeks.propTypes = { + selectedTeks: PropTypes.object, + setSelectedTeks: PropTypes.func.isRequired, +}