Skip to content

Commit

Permalink
remove factory for email campaigns
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelblum committed Nov 15, 2024
1 parent 240b1d6 commit 9f268aa
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 45 deletions.
8 changes: 2 additions & 6 deletions demo/admin/src/common/MasterMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Assets, Dashboard, Mail, PageTree, Wrench } from "@comet/admin-icons";
import { createBrevoContactsPage, createEmailCampaignsPage, createTargetGroupsPage } from "@comet/brevo-admin";
import { createBrevoContactsPage, createTargetGroupsPage, EmailCampaignsPage } from "@comet/brevo-admin";
import {
AllCategories,
ContentScopeIndicator,
Expand Down Expand Up @@ -53,10 +53,6 @@ const getMasterMenuData = ({ brevoContactConfig }: { brevoContactConfig: BrevoCo
input2State: additionalFormConfig.input2State,
});

const CampaignsPage = createEmailCampaignsPage({
EmailCampaignContentBlock,
});

return [
{
type: "route",
Expand Down Expand Up @@ -95,7 +91,7 @@ const getMasterMenuData = ({ brevoContactConfig }: { brevoContactConfig: BrevoCo
primary: <FormattedMessage id="menu.newsletter.emailCampaigns" defaultMessage="Email campaigns" />,
route: {
path: "/newsletter/email-campaigns",
component: CampaignsPage,
component: () => <EmailCampaignsPage EmailCampaignContentBlock={EmailCampaignContentBlock} />,
},
},
{
Expand Down
73 changes: 35 additions & 38 deletions packages/admin/src/emailCampaigns/EmailCampaignsPage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,48 +10,45 @@ import { EmailCampaignForm } from "./form/EmailCampaignForm";
import { EmailCampaignStatistics } from "./statistics/EmailCampaignStatistics";
import { EmailCampaignView } from "./view/EmailCampaignView";

interface CreateEmailCampaignsPageOptions {
interface EmailCampaignsPageOptions {
EmailCampaignContentBlock: BlockInterface;
}

export function createEmailCampaignsPage({ EmailCampaignContentBlock }: CreateEmailCampaignsPageOptions) {
function EmailCampaignsPage(): JSX.Element {
const { scopeParts } = useBrevoConfig();
const { scope: completeScope } = useContentScope();
const intl = useIntl();
export function EmailCampaignsPage({ EmailCampaignContentBlock }: EmailCampaignsPageOptions): JSX.Element {
const { scopeParts } = useBrevoConfig();
const { scope: completeScope } = useContentScope();
const intl = useIntl();

const scope = scopeParts.reduce((acc, scopePart) => {
acc[scopePart] = completeScope[scopePart];
return acc;
}, {} as { [key: string]: unknown });
const scope = scopeParts.reduce((acc, scopePart) => {
acc[scopePart] = completeScope[scopePart];
return acc;
}, {} as { [key: string]: unknown });

return (
<Stack topLevelTitle={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.emailCampaigns", defaultMessage: "Email campaigns" })}>
<StackSwitch>
<StackPage name="grid">
<StackToolbar scopeIndicator={<ContentScopeIndicator scope={scope} />} />
<EmailCampaignsGrid scope={scope} EmailCampaignContentBlock={EmailCampaignContentBlock} />
</StackPage>
<StackPage name="statistics">{(selectedId) => <EmailCampaignStatistics id={selectedId} />}</StackPage>
<StackPage name="view">
{(selectedId) => <EmailCampaignView id={selectedId} EmailCampaignContentBlock={EmailCampaignContentBlock} />}
</StackPage>
return (
<Stack topLevelTitle={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.emailCampaigns", defaultMessage: "Email campaigns" })}>
<StackSwitch>
<StackPage name="grid">
<StackToolbar scopeIndicator={<ContentScopeIndicator scope={scope} />} />
<EmailCampaignsGrid scope={scope} EmailCampaignContentBlock={EmailCampaignContentBlock} />
</StackPage>
<StackPage name="statistics">{(selectedId) => <EmailCampaignStatistics id={selectedId} />}</StackPage>
<StackPage name="view">
{(selectedId) => <EmailCampaignView id={selectedId} EmailCampaignContentBlock={EmailCampaignContentBlock} />}
</StackPage>

<StackPage
name="edit"
title={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.editEmailCampaign", defaultMessage: "Edit email campaign" })}
>
{(selectedId) => <EmailCampaignForm id={selectedId} EmailCampaignContentBlock={EmailCampaignContentBlock} scope={scope} />}
</StackPage>
<StackPage
name="add"
title={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.addEmailCampaign", defaultMessage: "Add email campaign" })}
>
<EmailCampaignForm EmailCampaignContentBlock={EmailCampaignContentBlock} scope={scope} />
</StackPage>
</StackSwitch>
</Stack>
);
}
return EmailCampaignsPage;
<StackPage
name="edit"
title={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.editEmailCampaign", defaultMessage: "Edit email campaign" })}
>
{(selectedId) => <EmailCampaignForm id={selectedId} EmailCampaignContentBlock={EmailCampaignContentBlock} scope={scope} />}
</StackPage>
<StackPage
name="add"
title={intl.formatMessage({ id: "cometBrevoModule.emailCampaigns.addEmailCampaign", defaultMessage: "Add email campaign" })}
>
<EmailCampaignForm EmailCampaignContentBlock={EmailCampaignContentBlock} scope={scope} />
</StackPage>
</StackSwitch>
</Stack>
);
}
2 changes: 1 addition & 1 deletion packages/admin/src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
export { createBrevoContactsPage } from "./brevoContacts/BrevoContactsPage";
export { EditBrevoContactFormValues } from "./brevoContacts/form/BrevoContactForm";
export { BrevoConfig, BrevoConfigProvider, useBrevoConfig } from "./common/BrevoConfigProvider";
export { createEmailCampaignsPage } from "./emailCampaigns/EmailCampaignsPage";
export { EmailCampaignsPage } from "./emailCampaigns/EmailCampaignsPage";
export { EditTargetGroupFinalFormValues } from "./targetGroups/TargetGroupForm";
export { createTargetGroupsPage } from "./targetGroups/TargetGroupsPage";

0 comments on commit 9f268aa

Please sign in to comment.