Skip to content

Commit

Permalink
Merge pull request #42 from vivid-planet/view-sent-campaigns
Browse files Browse the repository at this point in the history
#41 View sent campaigns
  • Loading branch information
RainbowBunchie authored May 27, 2024
2 parents 68b0733 + ca60613 commit 70b1c73
Show file tree
Hide file tree
Showing 4 changed files with 97 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/admin/src/emailCampaigns/EmailCampaignsGrid.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
useDataGridRemote,
usePersistentColumnState,
} from "@comet/admin";
import { Add as AddIcon, Edit, Statistics } from "@comet/admin-icons";
import { Add as AddIcon, Edit, Statistics, Visible } from "@comet/admin-icons";
import { BlockInterface } from "@comet/blocks-admin";
import { ContentScopeInterface } from "@comet/cms-admin";
import { Button, IconButton } from "@mui/material";
Expand Down Expand Up @@ -177,9 +177,14 @@ export function EmailCampaignsGrid({
</IconButton>
)}
{row.sendingState === "SENT" && (
<IconButton component={StackLink} pageName="statistics" payload={row.id}>
<Statistics color="primary" />
</IconButton>
<>
<IconButton component={StackLink} pageName="statistics" payload={row.id}>
<Statistics color="primary" />
</IconButton>
<IconButton component={StackLink} pageName="view" payload={row.id}>
<Visible color="primary" />
</IconButton>
</>
)}
<CrudContextMenu
copyData={() => {
Expand Down
7 changes: 7 additions & 0 deletions packages/admin/src/emailCampaigns/EmailCampaignsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import { useIntl } from "react-intl";
import { EmailCampaignsGrid } from "./EmailCampaignsGrid";
import { EmailCampaignForm } from "./form/EmailCampaignForm";
import { EmailCampaignStatistics } from "./statistics/EmailCampaignStatistics";
import { EmailCampaignView } from "./view/EmailCampaignView";

interface CreateEmailCampaignsPageOptions {
scopeParts: string[];
Expand All @@ -31,6 +32,12 @@ export function createEmailCampaignsPage({ scopeParts, EmailCampaignContentBlock
<EmailCampaignsGrid scope={scope} EmailCampaignContentBlock={EmailCampaignContentBlock} />
</StackPage>
<StackPage name="statistics">{(selectedId) => <EmailCampaignStatistics id={selectedId} />}</StackPage>
<StackPage name="view">
{(selectedId) => (
<EmailCampaignView id={selectedId} previewUrl={previewUrl} EmailCampaignContentBlock={EmailCampaignContentBlock} />
)}
</StackPage>

<StackPage
name="edit"
title={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.editEmailCampaign", defaultMessage: "Edit email campaign" })}
Expand Down
10 changes: 10 additions & 0 deletions packages/admin/src/emailCampaigns/view/EmailCampaignView.gql.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { gql } from "@apollo/client";

export const emailCampaignViewQuery = gql`
query EmailCampaignView($id: ID!) {
emailCampaign(id: $id) {
id
content
}
}
`;
71 changes: 71 additions & 0 deletions packages/admin/src/emailCampaigns/view/EmailCampaignView.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
import { useQuery } from "@apollo/client";
import { Loading, MainContent, Toolbar, ToolbarFillSpace, ToolbarItem, ToolbarTitleItem, useStackApi } from "@comet/admin";
import { ArrowLeft } from "@comet/admin-icons";
import { BlockInterface, IFrameBridgeProvider } from "@comet/blocks-admin";
import { BlockPreview, EditPageLayout, useBlockPreview, useCmsBlockContext } from "@comet/cms-admin";
import { IconButton } from "@mui/material";
import React from "react";
import { FormattedMessage } from "react-intl";
import { useRouteMatch } from "react-router";

import { emailCampaignViewQuery } from "./EmailCampaignView.gql";
import { GQLEmailCampaignViewQuery, GQLEmailCampaignViewQueryVariables } from "./EmailCampaignView.gql.generated";

interface EmailCampaignViewProps {
id: string;
EmailCampaignContentBlock: BlockInterface;
previewUrl: string;
}

export function EmailCampaignView({ id, EmailCampaignContentBlock, previewUrl }: EmailCampaignViewProps): React.ReactElement {
const stackApi = useStackApi();
const previewApi = useBlockPreview();
const blockContext = useCmsBlockContext();
const match = useRouteMatch();

const { data, error, loading } = useQuery<GQLEmailCampaignViewQuery, GQLEmailCampaignViewQueryVariables>(emailCampaignViewQuery, {
variables: { id },
});

if (error) throw error;

if (loading) {
return <Loading behavior="fillPageHeight" />;
}

if (!data) {
return <></>;
}

const previewContext = {
...blockContext,
parentUrl: match.url,
showVisibleOnly: previewApi.showOnlyVisible,
};

const previewState = {
emailCampaignId: id,
content: EmailCampaignContentBlock.createPreviewState(EmailCampaignContentBlock.input2State(data.emailCampaign.content), previewContext),
};

return (
<EditPageLayout>
<Toolbar>
<ToolbarItem>
<IconButton onClick={stackApi?.goBack}>
<ArrowLeft />
</IconButton>
</ToolbarItem>
<ToolbarTitleItem>
<FormattedMessage id="cometBrevoModule.emailCampaigns.EmailCampaign" defaultMessage="Email Campaign" />
</ToolbarTitleItem>
<ToolbarFillSpace />
</Toolbar>
<MainContent disablePaddingBottom>
<IFrameBridgeProvider key={previewUrl}>
<BlockPreview url={previewUrl} previewState={previewState} previewApi={previewApi} />
</IFrameBridgeProvider>
</MainContent>
</EditPageLayout>
);
}

0 comments on commit 70b1c73

Please sign in to comment.