diff --git a/.changeset/young-tigers-provide.md b/.changeset/young-tigers-provide.md
new file mode 100644
index 0000000..a3b33f6
--- /dev/null
+++ b/.changeset/young-tigers-provide.md
@@ -0,0 +1,5 @@
+---
+"saleor-app-emails-and-messages": patch
+---
+
+Events section UI has been updated. All events are displayed now as single table.
diff --git a/apps/emails-and-messages/src/components/table.tsx b/apps/emails-and-messages/src/components/table.tsx
new file mode 100644
index 0000000..8ee9ea7
--- /dev/null
+++ b/apps/emails-and-messages/src/components/table.tsx
@@ -0,0 +1,12 @@
+import { Box, BoxProps } from "@saleor/macaw-ui/next";
+
+export const Table = {
+ Container: (props: BoxProps) => ,
+ Header: (props: BoxProps) => ,
+ Row: (props: BoxProps) => ,
+ HeaderCell: (props: BoxProps) => (
+
+ ),
+ Body: (props: BoxProps) => ,
+ Cell: (props: BoxProps) => ,
+};
diff --git a/apps/emails-and-messages/src/modules/app-configuration/ui/configuration-name-description-text.tsx b/apps/emails-and-messages/src/modules/app-configuration/ui/configuration-name-description-text.tsx
index 66dc00b..35edb5f 100644
--- a/apps/emails-and-messages/src/modules/app-configuration/ui/configuration-name-description-text.tsx
+++ b/apps/emails-and-messages/src/modules/app-configuration/ui/configuration-name-description-text.tsx
@@ -2,7 +2,8 @@ import { Text } from "@saleor/macaw-ui/next";
export const ConfigurationNameDescriptionText = () => (
- The name for your configuration. You can have more than one if you want to use different settings for each channel.
+ The name for your configuration. You can have more than one if you want to use different
+ settings for each channel.
For example - production
and development
.
diff --git a/apps/emails-and-messages/src/modules/event-handlers/message-event-types.ts b/apps/emails-and-messages/src/modules/event-handlers/message-event-types.ts
index 7a51c15..1d0c589 100644
--- a/apps/emails-and-messages/src/modules/event-handlers/message-event-types.ts
+++ b/apps/emails-and-messages/src/modules/event-handlers/message-event-types.ts
@@ -22,7 +22,7 @@ export const messageEventTypesLabels: Record = {
ORDER_FULLY_PAID: "Order fully paid",
INVOICE_SENT: "Invoice sent",
ACCOUNT_CONFIRMATION: "Customer account confirmation",
- ACCOUNT_PASSWORD_RESET: "Customer account password reset",
+ ACCOUNT_PASSWORD_RESET: "Customer account password reset request",
ACCOUNT_CHANGE_EMAIL_REQUEST: "Customer account change email request",
ACCOUNT_CHANGE_EMAIL_CONFIRM: "Customer account change email confirmation",
ACCOUNT_DELETE: "Customer account delete request",
diff --git a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-config-input-schema.ts b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-config-input-schema.ts
index abc8054..de4a492 100644
--- a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-config-input-schema.ts
+++ b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-config-input-schema.ts
@@ -86,3 +86,10 @@ export const sendgridUpdateEventSchema = sendgridConfigurationEventSchema.merge(
);
export type SendgridUpdateEvent = z.infer;
+
+export const sendgridUpdateEventArraySchema = z.object({
+ configurationId: z.string(),
+ events: z.array(sendgridConfigurationEventSchema),
+});
+
+export type SendgridUpdateEventArray = z.infer;
diff --git a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.router.ts b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.router.ts
index 184dcbc..5c4231a 100644
--- a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.router.ts
+++ b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.router.ts
@@ -6,7 +6,7 @@ import {
sendgridGetEventConfigurationInputSchema,
sendgridUpdateApiConnectionSchema,
sendgridUpdateBasicInformationSchema,
- sendgridUpdateEventConfigurationInputSchema,
+ sendgridUpdateEventArraySchema,
sendgridUpdateEventSchema,
sendgridUpdateSenderSchema,
} from "./sendgrid-config-input-schema";
@@ -147,23 +147,6 @@ export const sendgridConfigurationRouter = router({
throwTrpcErrorFromConfigurationServiceError(e);
}
}),
- updateEventConfiguration: protectedWithConfigurationService
- .meta({ requiredClientPermissions: ["MANAGE_APPS"] })
- .input(sendgridUpdateEventConfigurationInputSchema)
- .mutation(async ({ ctx, input }) => {
- const logger = createLogger({ saleorApiUrl: ctx.saleorApiUrl });
-
- logger.debug(input, "sendgridConfigurationRouter.updateEventConfiguration called");
-
- try {
- return await ctx.sendgridConfigurationService.updateEventConfiguration({
- configurationId: input.configurationId,
- eventConfiguration: input,
- });
- } catch (e) {
- throwTrpcErrorFromConfigurationServiceError(e);
- }
- }),
updateBasicInformation: protectedWithConfigurationService
.meta({ requiredClientPermissions: ["MANAGE_APPS"] })
.input(sendgridUpdateBasicInformationSchema)
@@ -260,13 +243,41 @@ export const sendgridConfigurationRouter = router({
logger.debug(input, "sendgridConfigurationRouter.updateEvent called");
+ const { id: configurationId, eventType, ...eventConfiguration } = input;
+
try {
return await ctx.sendgridConfigurationService.updateEventConfiguration({
- eventConfiguration: input,
- configurationId: input.id,
+ configurationId,
+ eventType,
+ eventConfiguration,
});
} catch (e) {
throwTrpcErrorFromConfigurationServiceError(e);
}
}),
+
+ updateEventArray: protectedWithConfigurationService
+ .meta({ requiredClientPermissions: ["MANAGE_APPS"] })
+ .input(sendgridUpdateEventArraySchema)
+ .mutation(async ({ ctx, input }) => {
+ const logger = createLogger({ saleorApiUrl: ctx.saleorApiUrl });
+
+ logger.debug(input, "sendgridConfigurationRouter.updateEventArray called");
+
+ return await Promise.all(
+ input.events.map(async (event) => {
+ const { eventType, ...eventConfiguration } = event;
+
+ try {
+ return await ctx.sendgridConfigurationService.updateEventConfiguration({
+ configurationId: input.configurationId,
+ eventType,
+ eventConfiguration,
+ });
+ } catch (e) {
+ throwTrpcErrorFromConfigurationServiceError(e);
+ }
+ })
+ );
+ }),
});
diff --git a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.test.ts b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.test.ts
index ace2eeb..2856e58 100644
--- a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.test.ts
+++ b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.test.ts
@@ -512,6 +512,7 @@ describe("SendgridConfigurationService", function () {
await service.updateEventConfiguration({
configurationId: validConfig.configurations[0].id,
+ eventType: validConfig.configurations[0].events[0].eventType,
eventConfiguration: {
...validConfig.configurations[0].events[0],
template: "42",
@@ -544,6 +545,7 @@ describe("SendgridConfigurationService", function () {
await expect(async () =>
service.updateEventConfiguration({
configurationId: "this-id-does-not-exist",
+ eventType: validConfig.configurations[0].events[0].eventType,
eventConfiguration: {
...validConfig.configurations[0].events[0],
template: "42",
diff --git a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.ts b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.ts
index 35e13e0..bd693de 100644
--- a/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.ts
+++ b/apps/emails-and-messages/src/modules/sendgrid/configuration/sendgrid-configuration.service.ts
@@ -234,19 +234,19 @@ export class SendgridConfigurationService {
*/
async updateEventConfiguration({
configurationId,
+ eventType,
eventConfiguration,
}: {
configurationId: string;
- eventConfiguration: SendgridEventConfiguration;
+ eventType: SendgridEventConfiguration["eventType"];
+ eventConfiguration: Partial>;
}) {
logger.debug("Update event configuration");
const configuration = await this.getConfiguration({
id: configurationId,
});
- const eventIndex = configuration.events.findIndex(
- (e) => e.eventType === eventConfiguration.eventType
- );
+ const eventIndex = configuration.events.findIndex((e) => e.eventType === eventType);
if (eventIndex < 0) {
logger.warn("Event configuration not found, throwing an error");
@@ -256,9 +256,14 @@ export class SendgridConfigurationService {
);
}
- configuration.events[eventIndex] = eventConfiguration;
+ const updatedEventConfiguration = {
+ ...configuration.events[eventIndex],
+ ...eventConfiguration,
+ };
+
+ configuration.events[eventIndex] = updatedEventConfiguration;
await this.updateConfiguration(configuration);
- return configuration;
+ return updatedEventConfiguration;
}
}
diff --git a/apps/emails-and-messages/src/modules/sendgrid/ui/sendgrid-events-section.tsx b/apps/emails-and-messages/src/modules/sendgrid/ui/sendgrid-events-section.tsx
index 8816013..dd91cd2 100644
--- a/apps/emails-and-messages/src/modules/sendgrid/ui/sendgrid-events-section.tsx
+++ b/apps/emails-and-messages/src/modules/sendgrid/ui/sendgrid-events-section.tsx
@@ -8,8 +8,8 @@ import { defaultPadding } from "../../../components/ui-defaults";
import { useDashboardNotification } from "@saleor/apps-shared";
import { trpcClient } from "../../trpc/trpc-client";
import {
- SendgridUpdateEvent,
- sendgridUpdateEventSchema,
+ SendgridUpdateEventArray,
+ sendgridUpdateEventArraySchema,
} from "../configuration/sendgrid-config-input-schema";
import { useForm } from "react-hook-form";
import { BoxFooter } from "../../../components/box-footer";
@@ -18,91 +18,57 @@ import { useQuery } from "@tanstack/react-query";
import { fetchTemplates } from "../sendgrid-api";
import { zodResolver } from "@hookform/resolvers/zod";
import { setBackendErrors } from "../../../lib/set-backend-errors";
-import { Combobox } from "@saleor/react-hook-form-macaw";
+import { Select } from "@saleor/react-hook-form-macaw";
import { TextLink } from "@saleor/apps-ui";
-
-interface EventBoxProps {
- configuration: SendgridConfiguration;
- event: SendgridEventConfiguration;
-}
-
-const EventBox = ({ event, configuration }: EventBoxProps) => {
- const { notifySuccess, notifyError } = useDashboardNotification();
-
- const { data: templatesChoices } = useQuery({
- queryKey: ["sendgridTemplates"],
- queryFn: fetchTemplates({ apiKey: configuration.apiKey }),
- enabled: !!configuration.apiKey?.length,
- });
-
- const { handleSubmit, control, setError, register } = useForm({
- defaultValues: {
- id: configuration.id,
- ...event,
- },
- resolver: zodResolver(sendgridUpdateEventSchema),
- });
-
- const trpcContext = trpcClient.useContext();
- const { mutate } = trpcClient.sendgridConfiguration.updateEvent.useMutation({
- onSuccess: async () => {
- notifySuccess("Configuration saved");
- trpcContext.sendgridConfiguration.invalidate();
- },
- onError(error) {
- setBackendErrors({ error, setError, notifyError });
- },
- });
-
- return (
-
- );
-};
+import { messageEventTypesLabels } from "../../event-handlers/message-event-types";
+import { Table } from "../../../components/table";
interface SendgridEventsSectionProps {
configuration: SendgridConfiguration;
}
export const SendgridEventsSection = ({ configuration }: SendgridEventsSectionProps) => {
+ const { notifySuccess, notifyError } = useDashboardNotification();
+
+ // Sort events by displayed label
+ const eventsSorted = configuration.events.sort((a, b) =>
+ messageEventTypesLabels[a.eventType].localeCompare(messageEventTypesLabels[b.eventType])
+ );
+
+ const { control, register, handleSubmit, setError } = useForm({
+ defaultValues: {
+ configurationId: configuration.id,
+ events: eventsSorted,
+ },
+ resolver: zodResolver(sendgridUpdateEventArraySchema),
+ });
+
+ const trpcContext = trpcClient.useContext();
+ const { mutate } = trpcClient.sendgridConfiguration.updateEventArray.useMutation({
+ onSuccess: async () => {
+ notifySuccess("Configuration saved");
+ trpcContext.sendgridConfiguration.invalidate();
+ },
+ onError(error) {
+ setBackendErrors({ error, setError, notifyError });
+ },
+ });
+
+ const { data: sendgridTemplates } = useQuery({
+ queryKey: ["sendgridTemplates"],
+ queryFn: fetchTemplates({ apiKey: configuration.apiKey }),
+ enabled: !!configuration.apiKey?.length,
+ });
+
+ const templateChoices = [{ value: "", label: "----" }, ...(sendgridTemplates || [])];
+
return (
- Choose which Saleor events should send emails via Sendgrid. You can create and modify your templates in the
+ Choose which Saleor events should send emails via Sendgrid. You can create and modify your
+ templates in the
Sendgrid dashboard
@@ -110,11 +76,47 @@ export const SendgridEventsSection = ({ configuration }: SendgridEventsSectionPr
}
>
-
- {configuration.events.map((event) => (
-
- ))}
-
+
);
};
diff --git a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-config-input-schema.ts b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-config-input-schema.ts
index 88d99e0..0b8c989 100644
--- a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-config-input-schema.ts
+++ b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-config-input-schema.ts
@@ -72,6 +72,21 @@ export const smtpUpdateEventSchema = smtpConfigurationEventSchema.merge(
export type SmtpUpdateEvent = z.infer;
+export const smtpUpdateEventActiveStatusInputSchema = smtpConfigurationEventSchema
+ .pick({
+ active: true,
+ eventType: true,
+ })
+ .merge(
+ smtpConfigurationSchema.pick({
+ id: true,
+ })
+ );
+
+export type SmtpUpdateEventActiveStatusInput = z.infer<
+ typeof smtpUpdateEventActiveStatusInputSchema
+>;
+
export const smtpGetEventConfigurationInputSchema = smtpConfigurationIdInputSchema.merge(
z.object({
eventType: z.enum(messageEventTypes),
@@ -87,3 +102,10 @@ export const smtpUpdateEventConfigurationInputSchema = smtpConfigurationIdInputS
export type SmtpUpdateEventConfigurationInput = z.infer<
typeof smtpUpdateEventConfigurationInputSchema
>;
+
+export const smtpUpdateEventArraySchema = z.object({
+ configurationId: z.string(),
+ events: z.array(smtpConfigurationEventSchema),
+});
+
+export type SmtpUpdateEventArray = z.infer;
diff --git a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.router.ts b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.router.ts
index 9c10d23..e52ce22 100644
--- a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.router.ts
+++ b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.router.ts
@@ -15,7 +15,8 @@ import {
smtpGetConfigurationsInputSchema,
smtpGetEventConfigurationInputSchema,
smtpUpdateBasicInformationSchema,
- smtpUpdateEventConfigurationInputSchema,
+ smtpUpdateEventActiveStatusInputSchema,
+ smtpUpdateEventArraySchema,
smtpUpdateEventSchema,
smtpUpdateSenderSchema,
smtpUpdateSmtpSchema,
@@ -150,23 +151,6 @@ export const smtpConfigurationRouter = router({
throwTrpcErrorFromConfigurationServiceError(e);
}
}),
- updateEventConfiguration: protectedWithConfigurationService
- .meta({ requiredClientPermissions: ["MANAGE_APPS"] })
- .input(smtpUpdateEventConfigurationInputSchema)
- .mutation(async ({ ctx, input }) => {
- const logger = createLogger({ saleorApiUrl: ctx.saleorApiUrl });
-
- logger.debug(input, "mjmlConfigurationRouter.updateEventConfiguration or create called");
-
- try {
- return await ctx.smtpConfigurationService.updateEventConfiguration({
- configurationId: input.id,
- eventConfiguration: input,
- });
- } catch (e) {
- throwTrpcErrorFromConfigurationServiceError(e);
- }
- }),
renderTemplate: protectedWithConfigurationService
.meta({ requiredClientPermissions: ["MANAGE_APPS"] })
@@ -287,13 +271,59 @@ export const smtpConfigurationRouter = router({
logger.debug(input, "smtpConfigurationRouter.updateEvent called");
+ const { id: configurationId, eventType, ...eventConfiguration } = input;
+
try {
return await ctx.smtpConfigurationService.updateEventConfiguration({
- eventConfiguration: input,
- configurationId: input.id,
+ configurationId,
+ eventType,
+ eventConfiguration,
});
} catch (e) {
throwTrpcErrorFromConfigurationServiceError(e);
}
}),
+ updateEventActiveStatus: protectedWithConfigurationService
+ .meta({ requiredClientPermissions: ["MANAGE_APPS"] })
+ .input(smtpUpdateEventActiveStatusInputSchema)
+ .mutation(async ({ ctx, input }) => {
+ const logger = createLogger({ saleorApiUrl: ctx.saleorApiUrl });
+
+ logger.debug(input, "mjmlConfigurationRouter.updateEventActiveStatus called");
+ try {
+ return await ctx.smtpConfigurationService.updateEventConfiguration({
+ configurationId: input.id,
+ eventType: input.eventType,
+ eventConfiguration: {
+ active: input.active,
+ },
+ });
+ } catch (e) {
+ throwTrpcErrorFromConfigurationServiceError(e);
+ }
+ }),
+ updateEventArray: protectedWithConfigurationService
+ .meta({ requiredClientPermissions: ["MANAGE_APPS"] })
+ .input(smtpUpdateEventArraySchema)
+ .mutation(async ({ ctx, input }) => {
+ const logger = createLogger({ saleorApiUrl: ctx.saleorApiUrl });
+
+ logger.debug(input, "smtpConfigurationRouter.updateEventArray called");
+
+ return await Promise.all(
+ input.events.map(async (event) => {
+ const { eventType, ...eventConfiguration } = event;
+
+ try {
+ return await ctx.smtpConfigurationService.updateEventConfiguration({
+ configurationId: input.configurationId,
+ eventType,
+ eventConfiguration,
+ });
+ } catch (e) {
+ throwTrpcErrorFromConfigurationServiceError(e);
+ }
+ })
+ );
+ }),
});
diff --git a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.test.ts b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.test.ts
index c124571..5da2de5 100644
--- a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.test.ts
+++ b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.test.ts
@@ -539,6 +539,7 @@ describe("SmtpConfigurationService", function () {
await service.updateEventConfiguration({
configurationId: validConfig.configurations[0].id,
+ eventType: validConfig.configurations[0].events[0].eventType,
eventConfiguration: {
...validConfig.configurations[0].events[0],
subject: "Updated subject",
@@ -571,6 +572,7 @@ describe("SmtpConfigurationService", function () {
await expect(async () =>
service.updateEventConfiguration({
configurationId: "this-id-does-not-exist",
+ eventType: validConfig.configurations[0].events[0].eventType,
eventConfiguration: {
...validConfig.configurations[0].events[0],
subject: "Updated subject",
diff --git a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.ts b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.ts
index f5e552a..2d0ff58 100644
--- a/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.ts
+++ b/apps/emails-and-messages/src/modules/smtp/configuration/smtp-configuration.service.ts
@@ -225,18 +225,18 @@ export class SmtpConfigurationService {
async updateEventConfiguration({
configurationId,
eventConfiguration,
+ eventType,
}: {
configurationId: string;
- eventConfiguration: SmtpEventConfiguration;
+ eventType: SmtpEventConfiguration["eventType"];
+ eventConfiguration: Partial>;
}) {
logger.debug("Update event configuration");
const configuration = await this.getConfiguration({
id: configurationId,
});
- const eventIndex = configuration.events.findIndex(
- (e) => e.eventType === eventConfiguration.eventType
- );
+ const eventIndex = configuration.events.findIndex((e) => e.eventType === eventType);
if (eventIndex < 0) {
logger.warn("Event configuration not found, throwing an error");
@@ -246,9 +246,14 @@ export class SmtpConfigurationService {
);
}
- configuration.events[eventIndex] = eventConfiguration;
+ const updatedEventConfiguration = {
+ ...configuration.events[eventIndex],
+ ...eventConfiguration,
+ };
+
+ configuration.events[eventIndex] = updatedEventConfiguration;
await this.updateConfiguration(configuration);
- return configuration;
+ return updatedEventConfiguration;
}
}
diff --git a/apps/emails-and-messages/src/modules/smtp/ui/code-edtor.tsx b/apps/emails-and-messages/src/modules/smtp/ui/code-editor.tsx
similarity index 100%
rename from apps/emails-and-messages/src/modules/smtp/ui/code-edtor.tsx
rename to apps/emails-and-messages/src/modules/smtp/ui/code-editor.tsx
diff --git a/apps/emails-and-messages/src/modules/smtp/ui/event-form.tsx b/apps/emails-and-messages/src/modules/smtp/ui/event-form.tsx
index 6c4eeb0..a21d380 100644
--- a/apps/emails-and-messages/src/modules/smtp/ui/event-form.tsx
+++ b/apps/emails-and-messages/src/modules/smtp/ui/event-form.tsx
@@ -4,12 +4,8 @@ import { MessageEventTypes } from "../../event-handlers/message-event-types";
import { useDashboardNotification } from "@saleor/apps-shared";
import { trpcClient } from "../../trpc/trpc-client";
import { Controller, useForm } from "react-hook-form";
-import {
- SmtpUpdateEventConfigurationInput,
- smtpUpdateEventConfigurationInputSchema,
-} from "../configuration/smtp-config-input-schema";
import { zodResolver } from "@hookform/resolvers/zod";
-import { CodeEditor } from "./code-edtor";
+import { CodeEditor } from "./code-editor";
import { useDebounce } from "usehooks-ts";
import { useState, useEffect } from "react";
import { examplePayloads } from "../../event-handlers/default-payloads";
@@ -17,6 +13,7 @@ import { MjmlPreview } from "./mjml-preview";
import { defaultPadding } from "../../../components/ui-defaults";
import { setBackendErrors } from "../../../lib/set-backend-errors";
import { Input } from "@saleor/react-hook-form-macaw";
+import { SmtpUpdateEvent, smtpUpdateEventSchema } from "../configuration/smtp-config-input-schema";
const PREVIEW_DEBOUNCE_DELAY = 500;
interface EventFormProps {
@@ -31,15 +28,13 @@ export const EventForm = ({ configuration, eventType }: EventFormProps) => {
(eventConfiguration) => eventConfiguration.eventType === eventType
)!; // Event conf is not optional, so we can use ! here
- const { handleSubmit, control, getValues, setError } = useForm(
- {
- defaultValues: {
- id: configuration.id,
- ...eventConfiguration,
- },
- resolver: zodResolver(smtpUpdateEventConfigurationInputSchema),
- }
- );
+ const { handleSubmit, control, getValues, setError } = useForm({
+ defaultValues: {
+ id: configuration.id,
+ ...eventConfiguration,
+ },
+ resolver: zodResolver(smtpUpdateEventSchema),
+ });
const trpcContext = trpcClient.useContext();
const { mutate } = trpcClient.smtpConfiguration.updateEvent.useMutation({
@@ -48,7 +43,7 @@ export const EventForm = ({ configuration, eventType }: EventFormProps) => {
trpcContext.smtpConfiguration.invalidate();
},
onError(error) {
- setBackendErrors({
+ setBackendErrors({
error,
setError,
notifyError,
diff --git a/apps/emails-and-messages/src/modules/smtp/ui/smtp-events-section.tsx b/apps/emails-and-messages/src/modules/smtp/ui/smtp-events-section.tsx
index 41f9f41..4022c9c 100644
--- a/apps/emails-and-messages/src/modules/smtp/ui/smtp-events-section.tsx
+++ b/apps/emails-and-messages/src/modules/smtp/ui/smtp-events-section.tsx
@@ -1,89 +1,57 @@
-import { SmtpConfiguration, SmtpEventConfiguration } from "../configuration/smtp-config-schema";
+import { SmtpConfiguration } from "../configuration/smtp-config-schema";
import { BoxWithBorder } from "../../../components/box-with-border";
import { Box, Button, Text } from "@saleor/macaw-ui/next";
import { defaultPadding } from "../../../components/ui-defaults";
+import { SectionWithDescription } from "../../../components/section-with-description";
+import { useRouter } from "next/router";
+import { smtpUrls } from "../urls";
+import { TextLink } from "@saleor/apps-ui";
+import React from "react";
+import { messageEventTypesLabels } from "../../event-handlers/message-event-types";
+import { BoxFooter } from "../../../components/box-footer";
+import { Table } from "../../../components/table";
import { useDashboardNotification } from "@saleor/apps-shared";
+import {
+ SmtpUpdateEventArray,
+ smtpUpdateEventArraySchema,
+} from "../configuration/smtp-config-input-schema";
+import { zodResolver } from "@hookform/resolvers/zod";
import { trpcClient } from "../../trpc/trpc-client";
import { useForm } from "react-hook-form";
-import { BoxFooter } from "../../../components/box-footer";
-import { SectionWithDescription } from "../../../components/section-with-description";
-import { SmtpUpdateEvent, smtpUpdateEventSchema } from "../configuration/smtp-config-input-schema";
-import { useRouter } from "next/router";
-import { zodResolver } from "@hookform/resolvers/zod";
-import { smtpUrls } from "../urls";
import { setBackendErrors } from "../../../lib/set-backend-errors";
-import { TextLink } from "@saleor/apps-ui";
-
-interface EventBoxProps {
- configuration: SmtpConfiguration;
- event: SmtpEventConfiguration;
-}
-
-const EventBox = ({ event, configuration }: EventBoxProps) => {
- const router = useRouter();
- const { notifySuccess, notifyError } = useDashboardNotification();
-
- const { handleSubmit, control, setError, register } = useForm({
- defaultValues: {
- id: configuration.id,
- ...event,
- },
- resolver: zodResolver(smtpUpdateEventSchema),
- });
-
- const trpcContext = trpcClient.useContext();
- const { mutate } = trpcClient.smtpConfiguration.updateEvent.useMutation({
- onSuccess: async () => {
- notifySuccess("Configuration saved");
- trpcContext.smtpConfiguration.invalidate();
- },
- onError(error) {
- setBackendErrors({
- error,
- setError,
- notifyError,
- });
- },
- });
-
- return (
-
- );
-};
interface SmtpEventsSectionProps {
configuration: SmtpConfiguration;
}
export const SmtpEventsSection = ({ configuration }: SmtpEventsSectionProps) => {
+ const { notifySuccess, notifyError } = useDashboardNotification();
+ const router = useRouter();
+
+ // Sort events by displayed label
+ const eventsSorted = configuration.events.sort((a, b) =>
+ messageEventTypesLabels[a.eventType].localeCompare(messageEventTypesLabels[b.eventType])
+ );
+
+ const { register, handleSubmit, setError } = useForm({
+ defaultValues: {
+ configurationId: configuration.id,
+ events: eventsSorted,
+ },
+ resolver: zodResolver(smtpUpdateEventArraySchema),
+ });
+
+ const trpcContext = trpcClient.useContext();
+ const { mutate } = trpcClient.smtpConfiguration.updateEventArray.useMutation({
+ onSuccess: async () => {
+ notifySuccess("Configuration saved");
+ trpcContext.smtpConfiguration.invalidate();
+ },
+ onError(error) {
+ setBackendErrors({ error, setError, notifyError });
+ },
+ });
+
return (
}
>
-
- {configuration.events.map((event) => (
-
- ))}
-
+
);
};
diff --git a/apps/emails-and-messages/src/pages/configuration/smtp/[configurationId]/event/[eventType].tsx b/apps/emails-and-messages/src/pages/configuration/smtp/[configurationId]/event/[eventType].tsx
index f962477..0879058 100644
--- a/apps/emails-and-messages/src/pages/configuration/smtp/[configurationId]/event/[eventType].tsx
+++ b/apps/emails-and-messages/src/pages/configuration/smtp/[configurationId]/event/[eventType].tsx
@@ -9,6 +9,7 @@ import { appUrls } from "../../../../../modules/app-configuration/urls";
import { EventForm } from "../../../../../modules/smtp/ui/event-form";
import { smtpUrls } from "../../../../../modules/smtp/urls";
import { TextLink } from "@saleor/apps-ui";
+import { messageEventTypesLabels } from "../../../../../modules/event-handlers/message-event-types";
const LoadingView = () => {
return (
@@ -78,12 +79,12 @@ const EditSmtpEventPage: NextPage = () => {
breadcrumbs={[
{ name: "Configuration", href: appUrls.configuration() },
{ name: `SMTP: ${configuration.name}`, href: smtpUrls.configuration(configurationId) },
- { name: eventType },
+ { name: messageEventTypesLabels[eventType] },
]}
>
- Edit template for {eventType} event. You can learn more about MJML{" "}
+ Edit template for {eventType}
event. You can learn more about MJML{" "}
here