-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #46 from vivid-planet/edit-brevo-contact
Edit brevo contact
- Loading branch information
Showing
22 changed files
with
660 additions
and
139 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
--- | ||
"@comet/brevo-api": patch | ||
--- | ||
|
||
Fix bug that does not add the contact to all target groups when subscribing |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
--- | ||
"@comet/brevo-admin": minor | ||
"@comet/brevo-api": minor | ||
--- | ||
|
||
Add an edit page for brevo contacts | ||
It is possible to configure additional form fields for this page in the `createBrevoContactsPage`. | ||
|
||
```diff | ||
createBrevoContactsPage({ | ||
//... | ||
+ additionalFormFields: brevoContactConfig.additionalFormFields, | ||
+ input2State: brevoContactConfig.input2State, | ||
}); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 0 additions & 64 deletions
64
demo/admin/src/common/brevoModuleConfig/brevoContactsPageAttributesConfig.ts
This file was deleted.
Oops, something went wrong.
137 changes: 137 additions & 0 deletions
137
demo/admin/src/common/brevoModuleConfig/brevoContactsPageAttributesConfig.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import { Field, FinalFormSelect, TextField } from "@comet/admin"; | ||
import { EditBrevoContactFormValues } from "@comet/brevo-admin"; | ||
import { MenuItem } from "@mui/material"; | ||
import { GridColDef } from "@mui/x-data-grid"; | ||
import { GQLBrevoContactSalutation } from "@src/graphql.generated"; | ||
import { DocumentNode } from "graphql"; | ||
import gql from "graphql-tag"; | ||
import React from "react"; | ||
import { FormattedMessage, IntlShape } from "react-intl"; | ||
|
||
import { GQLBrevoContactAttributesFragmentFragment } from "./brevoContactsPageAttributesConfig.generated"; | ||
|
||
const attributesFragment = gql` | ||
fragment BrevoContactAttributesFragment on BrevoContact { | ||
attributes { | ||
LASTNAME | ||
FIRSTNAME | ||
SALUTATION | ||
} | ||
} | ||
`; | ||
|
||
const salutationOptions: Array<{ label: React.ReactNode; value: GQLBrevoContactSalutation }> = [ | ||
{ | ||
label: <FormattedMessage id="brevoContact.filters.salutation.male" defaultMessage="Male" />, | ||
value: "MALE", | ||
}, | ||
{ | ||
label: <FormattedMessage id="brevoContact.filters.salutation.female" defaultMessage="Female" />, | ||
value: "FEMALE", | ||
}, | ||
]; | ||
|
||
interface AdditionalFormConfigInputProps extends EditBrevoContactFormValues { | ||
attributes: { | ||
SALUTATION?: GQLBrevoContactSalutation; | ||
FIRSTNAME?: string; | ||
LASTNAME?: string; | ||
}; | ||
} | ||
|
||
export const additionalFormConfig = { | ||
nodeFragment: attributesFragment, | ||
}; | ||
|
||
export const getBrevoContactConfig = ( | ||
intl: IntlShape, | ||
): { | ||
additionalGridFields: GridColDef<GQLBrevoContactAttributesFragmentFragment>[]; | ||
additionalFormFields: React.ReactNode; | ||
additionalAttributesFragment: { | ||
fragment: DocumentNode; | ||
name: string; | ||
}; | ||
input2State: (values?: AdditionalFormConfigInputProps) => { | ||
email: string; | ||
attributes: { SALUTATION?: GQLBrevoContactSalutation; FIRSTNAME?: string; LASTNAME?: string }; | ||
}; | ||
exportFields: { | ||
renderValue: (row: GQLBrevoContactAttributesFragmentFragment) => string; | ||
headerName: string; | ||
}[]; | ||
} => { | ||
return { | ||
additionalGridFields: [ | ||
{ | ||
field: "attributes.firstName", | ||
headerName: intl.formatMessage({ id: "brevoContact.firstName", defaultMessage: "First name" }), | ||
filterable: false, | ||
sortable: false, | ||
width: 150, | ||
renderCell: ({ row }) => row.attributes?.FIRSTNAME, | ||
}, | ||
{ | ||
field: "attributes.lastName", | ||
headerName: intl.formatMessage({ id: "brevoContact.lastName", defaultMessage: "Last name" }), | ||
filterable: false, | ||
sortable: false, | ||
width: 150, | ||
renderCell: ({ row }) => row.attributes?.LASTNAME, | ||
}, | ||
], | ||
additionalFormFields: ( | ||
<> | ||
<Field | ||
label={<FormattedMessage id="brevoContact.fields.salutation" defaultMessage="Salutation" />} | ||
name="attributes.SALUTATION" | ||
fullWidth | ||
> | ||
{(props) => ( | ||
<FinalFormSelect {...props} fullWidth> | ||
{salutationOptions.map((option) => ( | ||
<MenuItem value={option.value} key={option.value}> | ||
{option.label} | ||
</MenuItem> | ||
))} | ||
</FinalFormSelect> | ||
)} | ||
</Field> | ||
<TextField | ||
label={<FormattedMessage id="brevoContact.fields.salutation" defaultMessage="First name" />} | ||
name="attributes.FIRSTNAME" | ||
fullWidth | ||
/> | ||
<TextField | ||
label={<FormattedMessage id="brevoContact.fields.salutation" defaultMessage="Last name" />} | ||
name="attributes.LASTNAME" | ||
fullWidth | ||
/> | ||
</> | ||
), | ||
input2State: (values?: AdditionalFormConfigInputProps) => { | ||
return { | ||
email: values?.email ?? "", | ||
attributes: { | ||
SALUTATION: values?.attributes?.SALUTATION, | ||
FIRSTNAME: values?.attributes?.FIRSTNAME, | ||
LASTNAME: values?.attributes?.LASTNAME, | ||
}, | ||
}; | ||
}, | ||
additionalAttributesFragment: { | ||
fragment: attributesFragment, | ||
name: "BrevoContactAttributesFragment", | ||
}, | ||
exportFields: [ | ||
{ | ||
renderValue: (row: GQLBrevoContactAttributesFragmentFragment) => row.attributes?.FIRSTNAME, | ||
headerName: intl.formatMessage({ id: "brevoContact.firstName", defaultMessage: "First name" }), | ||
}, | ||
{ | ||
renderValue: (row: GQLBrevoContactAttributesFragmentFragment) => row.attributes?.LASTNAME, | ||
headerName: intl.formatMessage({ id: "brevoContact.lastName", defaultMessage: "Last name" }), | ||
}, | ||
], | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.