From 1ccf06186ebd46cce266a1506fd4f73ee41ad98c Mon Sep 17 00:00:00 2001 From: Elhoucine Date: Wed, 10 Jul 2024 11:56:26 +0200 Subject: [PATCH] feat(#vil-): admin h5p page --- src/pages/admin/newportal/create/index.tsx | 2 +- src/pages/admin/newportal/h5p/edit/[id].tsx | 70 ++++++++++ src/pages/admin/newportal/h5p/index.tsx | 136 ++++++++++++++++++++ src/pages/admin/newportal/h5p/new.tsx | 56 ++++++++ 4 files changed, 263 insertions(+), 1 deletion(-) create mode 100644 src/pages/admin/newportal/h5p/edit/[id].tsx create mode 100644 src/pages/admin/newportal/h5p/index.tsx create mode 100644 src/pages/admin/newportal/h5p/new.tsx diff --git a/src/pages/admin/newportal/create/index.tsx b/src/pages/admin/newportal/create/index.tsx index a822bb607..42521198c 100644 --- a/src/pages/admin/newportal/create/index.tsx +++ b/src/pages/admin/newportal/create/index.tsx @@ -62,7 +62,7 @@ const Creer = () => { const links: Link[] = [ { name: 'Créer du contenu libre', link: '/admin/newportal/contenulibre/1', action: handleNewActivity }, - { name: 'Créer une activité H5P', link: 'https://' }, + { name: 'Créer une activité H5P', link: '/admin/newportal/h5p' }, { name: 'Paramétrer l’hymne', link: 'https://' }, { name: 'Mixer l’hymne', link: 'https://' }, ]; diff --git a/src/pages/admin/newportal/h5p/edit/[id].tsx b/src/pages/admin/newportal/h5p/edit/[id].tsx new file mode 100644 index 000000000..afa113383 --- /dev/null +++ b/src/pages/admin/newportal/h5p/edit/[id].tsx @@ -0,0 +1,70 @@ +import Link from 'next/link'; +import { useRouter } from 'next/router'; +import { useSnackbar } from 'notistack'; +import * as React from 'react'; +import { useQueryClient } from 'react-query'; + +import NavigateNextIcon from '@mui/icons-material/NavigateNext'; +import { Breadcrumbs, Button } from '@mui/material'; +import MaterialLink from '@mui/material/Link'; + +import { useH5pContentList } from 'src/api/h5p/h5p-content.list'; +import { AdminTile } from 'src/components/admin/AdminTile'; +import { H5pEditor } from 'src/components/h5p'; +import { getQueryString } from 'src/utils'; + +const H5pEditContentPage = () => { + const router = useRouter(); + const queryClient = useQueryClient(); + const { data: h5pContent } = useH5pContentList(); + const { enqueueSnackbar } = useSnackbar(); + + const contentId = React.useMemo(() => getQueryString(router.query.id), [router]); + const content = (h5pContent || []).find((h5p) => h5p.contentId === contentId); + + if (h5pContent && !content) { + router.push(`/admin/h5p`); + } + if (!content) { + return null; + } + + return ( +
+ } aria-label="breadcrumb" style={{ marginBottom: '1rem' }}> + + +

Contenu H5P

+
+ +

{content.title}

+
+ +
+ { + enqueueSnackbar('Contenu H5P modifié avec succès!', { + variant: 'success', + }); + queryClient.invalidateQueries('h5p'); + router.push(`/admin/h5p`); + }} + onError={(message) => { + enqueueSnackbar(message, { + variant: 'error', + }); + }} + > +
+
+ + + +
+ ); +}; + +export default H5pEditContentPage; diff --git a/src/pages/admin/newportal/h5p/index.tsx b/src/pages/admin/newportal/h5p/index.tsx new file mode 100644 index 000000000..09f8b1928 --- /dev/null +++ b/src/pages/admin/newportal/h5p/index.tsx @@ -0,0 +1,136 @@ +import Link from 'next/link'; +import { useRouter } from 'next/router'; +import { useSnackbar } from 'notistack'; +import * as React from 'react'; +import { useQueryClient } from 'react-query'; + +import AddCircleIcon from '@mui/icons-material/AddCircle'; +import DeleteIcon from '@mui/icons-material/Delete'; +import EditIcon from '@mui/icons-material/Edit'; +import { Button, NoSsr, IconButton, Tooltip } from '@mui/material'; + +import { useDeleteH5pContentMutation } from 'src/api/h5p/h5p-content.delete'; +import { useH5pContentList } from 'src/api/h5p/h5p-content.list'; +import { Modal } from 'src/components/Modal'; +import { AdminTable } from 'src/components/admin/AdminTable'; +import { AdminTile } from 'src/components/admin/AdminTile'; +import { defaultContainedButtonStyle } from 'src/styles/variables.const'; +import BackArrow from 'src/svg/back-arrow.svg'; + +const H5pList = () => { + const router = useRouter(); + const queryClient = useQueryClient(); + const { enqueueSnackbar } = useSnackbar(); + const { data: h5pContent } = useH5pContentList(); + const [deleteIndex, setDeleteIndex] = React.useState(-1); + const { mutate: deleteH5pMutate, isLoading } = useDeleteH5pContentMutation(); + + const actions = (id: string) => ( + <> + + { + router.push(`/admin/newportal/h5p/edit/${id}`); + }} + > + + + + + { + setDeleteIndex((h5pContent || []).findIndex((h5p) => h5p.contentId === id)); + }} + > + + + + + ); + + return ( +
+ +
+ +

Villages-mondes

+
+ + + + + } + > + + {"Vous n'avez pas encore de contenu H5P ! "} + + En créer un ? + + + } + data={(h5pContent || []).map((h5p) => ({ ...h5p, id: h5p.contentId }))} + columns={[ + { key: 'title', label: 'Nom du contenu', sortable: true }, + { key: 'mainLibrary', label: 'Type' }, + ]} + actions={actions} + /> + + + { + setDeleteIndex(-1); + }} + onConfirm={() => { + deleteH5pMutate(h5pContent?.[deleteIndex]?.contentId || '', { + onSettled: () => { + queryClient.invalidateQueries('h5p'); + setDeleteIndex(-1); + }, + onError: () => { + enqueueSnackbar('Une erreur est survenue...', { + variant: 'error', + }); + }, + onSuccess: () => { + enqueueSnackbar('Contenu H5P supprimé avec succès!', { + variant: 'success', + }); + }, + }); + }} + loading={isLoading} + fullWidth + maxWidth="sm" + ariaLabelledBy="delete-h5p-id" + ariaDescribedBy="delete-h5p-desc" + error + > +
+ Voulez vous vraiment supprimer le contenu H5P {(h5pContent || [])[deleteIndex]?.title} ? +
+
+
+
+ ); +}; + +export default H5pList; diff --git a/src/pages/admin/newportal/h5p/new.tsx b/src/pages/admin/newportal/h5p/new.tsx new file mode 100644 index 000000000..16c884ead --- /dev/null +++ b/src/pages/admin/newportal/h5p/new.tsx @@ -0,0 +1,56 @@ +import Link from 'next/link'; +import { useRouter } from 'next/router'; +import { useSnackbar } from 'notistack'; +import * as React from 'react'; +import { useQueryClient } from 'react-query'; + +import NavigateNextIcon from '@mui/icons-material/NavigateNext'; +import { Breadcrumbs, Button } from '@mui/material'; +import MaterialLink from '@mui/material/Link'; + +import { AdminTile } from 'src/components/admin/AdminTile'; +import { H5pEditor } from 'src/components/h5p'; + +const H5pNewContentPage = () => { + const router = useRouter(); + const queryClient = useQueryClient(); + const { enqueueSnackbar } = useSnackbar(); + + return ( +
+ } aria-label="breadcrumb" style={{ marginBottom: '1rem' }}> + + +

Contenu H5P

+
+ +

Nouveau

+
+ +
+ { + enqueueSnackbar('Contenu H5P créé avec succès!', { + variant: 'success', + }); + queryClient.invalidateQueries('h5p'); + router.push(`/admin/newportal/h5p`); + }} + onError={(message) => { + enqueueSnackbar(message, { + variant: 'error', + }); + }} + > +
+
+ + + +
+ ); +}; + +export default H5pNewContentPage;