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 {jwennUserEpiToken} 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, titre, artistes}) => ( handleListItemClick(id)}> alias))} - ${titre}`} /> )) : ( 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 [open, setOpen] = useState(false) const [teksLis, setTeksLis] = useState([]) const handleClickOpen = async () => { setOpen(true) setLoading(true) const user = await jwennUserEpiToken(session?.jwt) const {paroles} = user const parolesList = paroles && paroles.length > 0 ? paroles : [] setTeksLis(parolesList) setLoading(false) } const handleClose = value => { const teks = teksLis.find(({id}) => id === value) setSelectedTeks(teks) setOpen(false) } return ( ) } ChwaTeks.defaultProps = { selectedTeks: null } ChwaTeks.propTypes = { selectedTeks: PropTypes.object, setSelectedTeks: PropTypes.func.isRequired, }