Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navigate back to blocks-overview when closing the TableBlock #2805

Open
wants to merge 1 commit into
base: feature/table-block
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 10 additions & 13 deletions packages/admin/cms-admin/src/blocks/table/TableBlock.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { OkayButton } from "@comet/admin";
import { Edit } from "@comet/admin-icons";
import { OkayButton, useStackApi } from "@comet/admin";
import { BlockCategory, BlockInterface, BlocksFinalForm, createBlockSkeleton, SelectPreviewComponent } from "@comet/blocks-admin";
import { Button, Dialog, DialogActions, DialogTitle } from "@mui/material";
import { Dialog, DialogActions, DialogTitle } from "@mui/material";
import { useState } from "react";
import { FormattedMessage } from "react-intl";

Expand All @@ -16,26 +15,24 @@ export const TableBlock: BlockInterface<TableBlockData, TableBlockData, TableBlo
displayName: <FormattedMessage id="comet.blocks.table.displayName" defaultMessage="Table" />,
category: BlockCategory.TextAndContent,
AdminComponent: ({ state, updateState }) => {
const stackApi = useStackApi();
const [showDialog, setShowDialog] = useState(true);

const closeTableBlock = () => {
setShowDialog(false);
stackApi?.goBack();
};

return (
<SelectPreviewComponent>
<BlocksFinalForm<TableBlockData> onSubmit={updateState} initialValues={state}>
<Button onClick={() => setShowDialog(true)} variant="contained" color="primary" startIcon={<Edit />}>
{/**
* TODO: Remove the need for this button:
* - The Dialog should open when navigating to the block
* - The Dialog should contain the Save-Button to save the data and close the Dialog
*/}
<FormattedMessage id="comet.tableBlock.temporary.edit" defaultMessage="Edit table" />
</Button>
<Dialog open={showDialog} maxWidth="xl" onClose={() => setShowDialog(false)}>
<Dialog open={showDialog} maxWidth="xl" onClose={closeTableBlock}>
<DialogTitle>
<FormattedMessage id="comet.blocks.table.displayName" defaultMessage="Table" />
</DialogTitle>
<TableBlockGrid state={state} updateState={updateState} />
<DialogActions>
<OkayButton onClick={() => setShowDialog(false)} />
<OkayButton onClick={closeTableBlock} />
</DialogActions>
</Dialog>
</BlocksFinalForm>
Expand Down