Skip to content

Commit

Permalink
Merge pull request #138 from vivid-planet/merge-main-into-next
Browse files Browse the repository at this point in the history
Merge main into next
  • Loading branch information
thomasdax98 authored Dec 13, 2024
2 parents 0c79bfa + 2400a6d commit 4779ce0
Show file tree
Hide file tree
Showing 28 changed files with 907 additions and 142 deletions.
8 changes: 8 additions & 0 deletions .changeset/chilly-dogs-draw.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
---
"@comet/brevo-admin": minor
"@comet/brevo-api": minor
---

Adds `createBrevoTestContactsPage` for creating a test contacts page, that is indepent from the main list.

Remove `email` and `redirectionUrl` from `brevoContactsPageAttributesConfig`
24 changes: 23 additions & 1 deletion demo/admin/src/common/MasterMenu.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { Assets, Dashboard, Mail, PageTree, Wrench } from "@comet/admin-icons";
import { BrevoConfigPage, createBrevoContactsPage, createEmailCampaignsPage, createTargetGroupsPage } from "@comet/brevo-admin";
import {
BrevoConfigPage,
createBrevoContactsPage,
createBrevoTestContactsPage,
createEmailCampaignsPage,
createTargetGroupsPage,
} from "@comet/brevo-admin";
import {
AllCategories,
ContentScopeIndicator,
Expand Down Expand Up @@ -57,6 +63,14 @@ const getMasterMenuData = ({ brevoContactConfig }: { brevoContactConfig: BrevoCo
EmailCampaignContentBlock,
});

const BrevoTestContactsPage = createBrevoTestContactsPage({
scopeParts: ["domain", "language"],
additionalAttributesFragment: brevoContactConfig.additionalAttributesFragment,
additionalGridFields: brevoContactConfig.additionalGridFields,
additionalFormFields: brevoContactConfig.additionalFormFields,
input2State: brevoContactConfig.input2State,
});

return [
{
type: "route",
Expand Down Expand Up @@ -106,6 +120,14 @@ const getMasterMenuData = ({ brevoContactConfig }: { brevoContactConfig: BrevoCo
render: () => <BrevoContactsPage />,
},
},
{
type: "route",
primary: <FormattedMessage id="menu.newsletter.testContacts" defaultMessage="Test contacts" />,
route: {
path: "/newsletter/test-contacts",
render: () => <BrevoTestContactsPage />,
},
},
{
type: "route",
primary: <FormattedMessage id="menu.newsletter.targetGroups" defaultMessage="Target groups" />,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,6 @@ export interface BrevoContactConfig {
name: string;
};
input2State: (values?: AdditionalFormConfigInputProps) => {
email: string;
redirectionUrl: string;
attributes: { BRANCH?: Array<GQLBrevoContactBranch>; SALUTATION?: GQLBrevoContactSalutation; FIRSTNAME?: string; LASTNAME?: string };
};
exportFields: {
Expand Down Expand Up @@ -139,8 +137,6 @@ export const getBrevoContactConfig = (intl: IntlShape): BrevoContactConfig => {
),
input2State: (values?: AdditionalFormConfigInputProps) => {
return {
email: values?.email ?? "",
redirectionUrl: values?.redirectionUrl ?? "",
attributes: {
BRANCH: values?.attributes?.BRANCH ?? [],
SALUTATION: values?.attributes?.SALUTATION,
Expand Down
11 changes: 11 additions & 0 deletions demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -448,6 +448,7 @@ type TargetGroup implements DocumentInterface {
createdAt: DateTime!
title: String!
isMainList: Boolean!
isTestList: Boolean!
brevoId: Int!
totalSubscribers: Int!
scope: EmailCampaignContentScope!
Expand Down Expand Up @@ -576,6 +577,7 @@ type Query {
dontUseFileUploadDummy: FileUpload
brevoContact(id: Int!, scope: EmailCampaignContentScopeInput!): BrevoContact!
brevoContacts(targetGroupId: ID, email: String, scope: EmailCampaignContentScopeInput!, offset: Int! = 0, limit: Int! = 25): PaginatedBrevoContacts!
brevoTestContacts(targetGroupId: ID, email: String, scope: EmailCampaignContentScopeInput!, offset: Int! = 0, limit: Int! = 25): PaginatedBrevoContacts!
manuallyAssignedBrevoContacts(offset: Int! = 0, limit: Int! = 25, targetGroupId: ID!, email: String): PaginatedBrevoContacts!
emailCampaign(id: ID!): EmailCampaign!
emailCampaigns(scope: EmailCampaignContentScopeInput!, search: String, filter: EmailCampaignFilter, sort: [EmailCampaignSort!], offset: Int! = 0, limit: Int! = 25): PaginatedEmailCampaigns!
Expand Down Expand Up @@ -735,6 +737,7 @@ input TargetGroupFilter {
createdAt: DateTimeFilter
updatedAt: DateTimeFilter
title: StringFilter
isTestList: BooleanFilter
and: [TargetGroupFilter!]
or: [TargetGroupFilter!]
}
Expand Down Expand Up @@ -787,7 +790,9 @@ type Mutation {
deleteDamFolder(id: ID!): Boolean!
updateBrevoContact(id: Int!, scope: EmailCampaignContentScopeInput!, input: BrevoContactUpdateInput!): BrevoContact!
createBrevoContact(scope: EmailCampaignContentScopeInput!, input: BrevoContactInput!): SubscribeResponse!
createBrevoTestContact(scope: EmailCampaignContentScopeInput!, input: BrevoTestContactInput!): SubscribeResponse!
deleteBrevoContact(id: Int!, scope: EmailCampaignContentScopeInput!): Boolean!
deleteBrevoTestContact(id: Int!, scope: EmailCampaignContentScopeInput!): Boolean!
subscribeBrevoContact(input: SubscribeInput!, scope: EmailCampaignContentScopeInput!): SubscribeResponse!
startBrevoContactImport(fileId: ID!, targetGroupIds: [ID!], scope: EmailCampaignContentScopeInput!): CsvImportInformation!
createEmailCampaign(scope: EmailCampaignContentScopeInput!, input: EmailCampaignInput!): EmailCampaign!
Expand Down Expand Up @@ -947,6 +952,12 @@ input BrevoContactInput {
attributes: BrevoContactAttributesInput
}

input BrevoTestContactInput {
email: String!
blocked: Boolean!
attributes: BrevoContactAttributesInput
}

input SubscribeInput {
email: String!
redirectionUrl: String!
Expand Down
43 changes: 0 additions & 43 deletions demo/campaign/src/documents/pages/Page.tsx

This file was deleted.

25 changes: 0 additions & 25 deletions demo/campaign/src/documents/pages/blocks/PageContentBlock.tsx

This file was deleted.

37 changes: 0 additions & 37 deletions demo/campaign/src/documents/pages/blocks/SeoBlock.tsx

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
"private": true,
"scripts": {
"build": "pnpm recursive run build",
"build:packages": "pnpm run build",
"build:api": "pnpm recursive --filter '@comet/brevo-api' run build",
"build:admin": "pnpm recursive --filter '@comet/brevo-admin' run build",
"build:api:skippable": "test -f packages/api/lib/index.d.ts && echo 'Skipping API build' || $npm_execpath build:api",
Expand Down
38 changes: 22 additions & 16 deletions packages/admin/src/brevoContacts/form/BrevoContactForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,12 @@ import {
} from "./BrevoContactForm.gql.generated";

export type EditBrevoContactFormValues = {
[key: string]: unknown;
};

type EditBrevoContactFormValuesWithAttributes = EditBrevoContactFormValues & {
email: string;
redirectionUrl: string;
[key: string]: unknown;
};

interface FormProps {
Expand All @@ -59,14 +62,11 @@ export function BrevoContactForm({ id, scope, input2State, additionalFormFields,
const stackApi = useStackApi();
const client = useApolloClient();
const mode = id ? "edit" : "add";
const formApiRef = useFormApiRef<EditBrevoContactFormValues>();
const formApiRef = useFormApiRef<EditBrevoContactFormValuesWithAttributes>();

const brevoContactFormFragment = gql`
fragment BrevoContactForm on BrevoContact {
email
createdAt
emailBlacklisted
smsBlacklisted
${additionalAttributesFragment ? "...".concat(additionalAttributesFragment?.name) : ""}
}
${additionalAttributesFragment?.fragment ?? ""}
Expand All @@ -76,18 +76,20 @@ export function BrevoContactForm({ id, scope, input2State, additionalFormFields,
id ? { variables: { id, scope } } : { skip: true },
);

const initialValues = React.useMemo<Partial<EditBrevoContactFormValues>>(() => {
let additionalInitialValues = {};
const initialValues = React.useMemo<Partial<EditBrevoContactFormValuesWithAttributes>>(() => {
let baseInitialValues = {
email: "",
redirectionUrl: "",
};

if (input2State) {
additionalInitialValues = input2State({ email: "", redirectionUrl: "", ...data?.brevoContact });
baseInitialValues = {
...baseInitialValues,
...input2State(data?.brevoContact),
};
}
return data?.brevoContact
? {
email: data.brevoContact.email,
...additionalInitialValues,
}
: additionalInitialValues;

return data?.brevoContact?.email ? { ...baseInitialValues, email: data.brevoContact.email } : baseInitialValues;
}, [data?.brevoContact, input2State]);

const saveConflict = useFormSaveConflict({
Expand All @@ -112,7 +114,11 @@ export function BrevoContactForm({ id, scope, input2State, additionalFormFields,
},
});

const handleSubmit = async (state: EditBrevoContactFormValues, form: FormApi<EditBrevoContactFormValues>, event: FinalFormSubmitEvent) => {
const handleSubmit = async (
state: EditBrevoContactFormValuesWithAttributes,
form: FormApi<EditBrevoContactFormValuesWithAttributes>,
event: FinalFormSubmitEvent,
) => {
if (await saveConflict.checkForConflicts()) {
throw new Error("Conflicts detected");
}
Expand Down Expand Up @@ -159,7 +165,7 @@ export function BrevoContactForm({ id, scope, input2State, additionalFormFields,
}

return (
<FinalForm<EditBrevoContactFormValues> apiRef={formApiRef} onSubmit={handleSubmit} mode={mode} initialValues={initialValues}>
<FinalForm<EditBrevoContactFormValuesWithAttributes> apiRef={formApiRef} onSubmit={handleSubmit} mode={mode} initialValues={initialValues}>
{({ values }) => (
<>
{saveConflict.dialogs}
Expand Down
Loading

0 comments on commit 4779ce0

Please sign in to comment.