import { Page } from "@/pages/base"; import { Management } from "@/management/main"; import { Box, Button, CircularProgress, Container, IconButton, Tooltip, Typography } from "@material-ui/core"; import React, { useEffect, useState } from "react"; import { Trans, useTranslation } from "react-i18next"; import { useAsyncState } from "@/hooks"; import api from "@/management/api"; import { Async } from "@/components/async"; import MaterialTable, { Action, Column } from "material-table"; import { default as StaticPage } from "@/data/page"; import { Delete, FileFind, Pencil, Refresh } from "mdi-material-ui"; import { encapsulate, one } from "@/helpers"; import { Actions } from "@/components"; import { useSpacing } from "@/styles"; import { useHistory } from "react-router-dom"; import { Add } from "@material-ui/icons"; import { createPortal } from "react-dom"; import { CreateStaticPageDialog } from "@/management/page/create"; import { Confirm } from "@/components/confirm"; export const StaticPageManagement = () => { const { t } = useTranslation("management"); const [ result, setPagesPromise ] = useAsyncState(); const spacing = useSpacing(2); const updatePageList = () => { setPagesPromise(api.page.all()); } useEffect(updatePageList, []); const CreateStaticPageAction = () => { const [ open, setOpen ] = useState(false); const handlePageCreation = async (page: StaticPage) => { await api.page.save(page); setOpen(false); updatePageList(); } return <> { createPortal( setOpen(false) }/>, document.getElementById("modals") as Element ) } } const DeleteStaticPageAction = ({ page }: { page: StaticPage }) => { const handlePageDeletion = async () => { await api.page.remove(page); updatePageList(); } const confirmation = <> Czy na pewno chcesz usunąć stronę { page.title.pl }? ; return { action => } ; } const PreviewStaticPageAction = ({ page }: { page: StaticPage }) => { const history = useHistory(); const handlePagePreview = async () => history.push(`/${page.slug}`); return ; } const columns: Column[] = [ { render: page => page.title.pl, title: t("page.field.title"), }, { field: "slug", title: t("page.field.slug"), }, { title: t("actions.label"), render: page => , sorting: false, width: 0, resizable: false, removable: false, searchable: false, }, ]; const PagePreview = ({ page }: { page: StaticPage }) =>
Polski { page.title.pl }
English { page.title.en }
return { t("page.index.title") } { t("page.index.title") } { pages => { t("page.index.title") } { result.isLoading && }
} columns={ columns } data={ pages } detailPanel={ page => } /> } } export default StaticPageManagement;