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

Add allowedRediretionURL field to brevo config #114

Merged
merged 12 commits into from
Jan 9, 2025
17 changes: 17 additions & 0 deletions .changeset/twelve-games-run.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
---
"@comet/brevo-api": major
"@comet/brevo-admin": minor
---

Add a brevo configuration field for `allowedRedirectionUrl`
Env vars containing this information can be removed and must be removed from the brevo module configuration.

```diff
BrevoModule.register({
brevo: {
- allowedRedirectionUrl: config.brevo.allowedRedirectionUrl,
//...
},
//..
})
```
3 changes: 3 additions & 0 deletions demo/api/schema.gql
Original file line number Diff line number Diff line change
Expand Up @@ -507,6 +507,7 @@ type BrevoConfig implements DocumentInterface {
senderName: String!
doubleOptInTemplateId: Int!
folderId: Int!
allowedRedirectionUrl: String!
createdAt: DateTime!
scope: EmailCampaignContentScope!
}
Expand Down Expand Up @@ -1034,11 +1035,13 @@ input BrevoConfigInput {
senderName: String!
doubleOptInTemplateId: Int!
folderId: Int!
allowedRedirectionUrl: String!
}

input BrevoConfigUpdateInput {
senderMail: String
senderName: String
doubleOptInTemplateId: Int
folderId: Int
allowedRedirectionUrl: String
}
2 changes: 0 additions & 2 deletions demo/api/src/app.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,13 +148,11 @@ export class AppModule {
if (scope.domain === "main") {
return {
apiKey: config.brevo.apiKey,
allowedRedirectUrl: config.brevo.allowedRedirectUrl,
redirectUrlForImport: config.brevo.redirectUrlForImport,
};
} else {
return {
apiKey: config.brevo.apiKey,
allowedRedirectUrl: config.brevo.allowedRedirectUrl,
redirectUrlForImport: config.brevo.redirectUrlForImport,
};
}
Expand Down
1 change: 0 additions & 1 deletion demo/api/src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ export function createConfig(processEnv: NodeJS.ProcessEnv) {
},
brevo: {
apiKey: envVars.BREVO_API_KEY,
allowedRedirectUrl: envVars.BREVO_ALLOWED_REDIRECT_URL,
redirectUrlForImport: envVars.REDIRECT_URL_FOR_IMPORT,
},
campaign: {
Expand Down
3 changes: 0 additions & 3 deletions demo/api/src/config/environment-variables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,6 @@ export class EnvironmentVariables {
@IsString()
BREVO_API_KEY: string;

@IsString()
BREVO_ALLOWED_REDIRECT_URL: string;

@IsString()
REDIRECT_URL_FOR_IMPORT: string;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const brevoConfigFormFragment = gql`
senderName
doubleOptInTemplateId
folderId
allowedRedirectionUrl
}
`;

Expand Down
49 changes: 46 additions & 3 deletions packages/admin/src/brevoConfiguration/BrevoConfigForm.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
Loading,
MainContent,
NumberField,
TextField,
Toolbar,
ToolbarActions,
ToolbarFillSpace,
Expand Down Expand Up @@ -50,12 +51,23 @@ type FormValues = {
sender: Option;
doubleOptInTemplate: Option;
folderId: number;
allowedRedirectionUrl: string;
};

interface FormProps {
scope: ContentScopeInterface;
}

function validateUrl(value: string): React.ReactNode | undefined {
const urlPattern = /^(https?:\/\/)?([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}(:\d{1,5})?(\/[^\s]*)?$/;
if (!urlPattern.test(value)) {
return (
<FormattedMessage id="cometBrevoModule.brevoConfig.allowedRedirectionUrl.validationError" defaultMessage="Please enter a valid URL." />
);
}
return undefined;
}

export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
const client = useApolloClient();
const formApiRef = useFormApiRef<FormValues>();
Expand Down Expand Up @@ -114,10 +126,13 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
label: `${doubleOptInTemplate?.id}: ${doubleOptInTemplate?.name}`,
}
: undefined,
allowedRedirectionUrl: data?.brevoConfig?.allowedRedirectionUrl ?? "",
folderId: data?.brevoConfig?.folderId ?? 1,
};
}, [
data?.brevoConfig?.folderId,
data?.brevoConfig?.allowedRedirectionUrl,

data?.brevoConfig?.doubleOptInTemplateId,
data?.brevoConfig?.senderMail,
data?.brevoConfig?.senderName,
Expand Down Expand Up @@ -155,7 +170,7 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {

const sender = sendersData?.senders?.find((s) => s.email === state.sender.value);

if (!sender || !state.doubleOptInTemplate) {
if (!sender || !state.doubleOptInTemplate || !state.allowedRedirectionUrl) {
throw new Error("Not all required fields are set");
}

Expand All @@ -164,6 +179,7 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
senderMail: sender?.email,
doubleOptInTemplateId: Number(state.doubleOptInTemplate.value),
folderId: state.folderId ?? 1,
allowedRedirectionUrl: state?.allowedRedirectionUrl ?? "",
};

if (mode === "edit") {
Expand All @@ -177,7 +193,10 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
} else {
const { data: mutationResponse } = await client.mutate<GQLCreateBrevoConfigMutation, GQLCreateBrevoConfigMutationVariables>({
mutation: createBrevoConfigMutation,
variables: { scope, input: output },
variables: {
scope,
input: output,
},
});
if (!event.navigatingBack) {
const id = mutationResponse?.createBrevoConfig.id;
Expand Down Expand Up @@ -222,7 +241,6 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
fullWidth
required
/>

<Field
component={FinalFormAutocomplete}
getOptionLabel={(option: Option) => option.label}
Expand Down Expand Up @@ -260,6 +278,31 @@ export function BrevoConfigForm({ scope }: FormProps): React.ReactElement {
fullWidth
required
/>
<TextField
required
fullWidth
name="allowedRedirectionUrl"
label={
<>
<FormattedMessage
id="cometBrevoModule.brevoConfig.allowedRedirectionUrl"
defaultMessage="Allowed redirection URL"
/>
<Tooltip
title={
<FormattedMessage
id="cometBrevoModule.brevoConfig.allowedRedirectionUrl.info"
defaultMessage="Defines the schema of a valid redirection URL that is set when creating contact. "
RainbowBunchie marked this conversation as resolved.
Show resolved Hide resolved
/>
}
sx={{ marginLeft: "5px" }}
>
<Info />
</Tooltip>
</>
}
validate={validateUrl}
/>
</MainContent>
</>
);
Expand Down
Loading
Loading