Skip to content

Commit 341f550

Browse files
committed
Add alerts when SMTP or Webhook config are enabled but not set
1 parent e037423 commit 341f550

File tree

2 files changed

+55
-1
lines changed

2 files changed

+55
-1
lines changed

site/src/pages/DeploySettingsPage/NotificationsPage/NotificationsPage.stories.tsx

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ const meta: Meta<typeof NotificationsPage> = {
3939
webhook: {
4040
endpoint: "https://example.com",
4141
},
42+
email: {
43+
smarthost: "smtp.example.com",
44+
},
4245
},
4346
} as DeploymentValues,
4447
},
@@ -56,6 +59,36 @@ type Story = StoryObj<typeof NotificationsPage>;
5659

5760
export const Default: Story = {};
5861

62+
export const NoEmailSmarthost: Story = {
63+
parameters: {
64+
deploymentValues: {
65+
notifications: {
66+
webhook: {
67+
endpoint: "https://example.com",
68+
},
69+
email: {
70+
smarthost: "",
71+
},
72+
},
73+
} as DeploymentValues,
74+
},
75+
};
76+
77+
export const NoWebhookEndpoint: Story = {
78+
parameters: {
79+
deploymentValues: {
80+
notifications: {
81+
webhook: {
82+
endpoint: "",
83+
},
84+
email: {
85+
smarthost: "smtp.example.com",
86+
},
87+
},
88+
} as DeploymentValues,
89+
},
90+
};
91+
5992
export const Toggle: Story = {
6093
play: async ({ canvasElement }) => {
6194
spyOn(API, "updateNotificationTemplateMethod").mockResolvedValue();

site/src/pages/DeploySettingsPage/NotificationsPage/NotificationsPage.tsx

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import {
1717
systemNotificationTemplates,
1818
updateNotificationTemplateMethod,
1919
} from "api/queries/notifications";
20+
import type { DeploymentValues } from "api/typesGenerated";
21+
import { Alert } from "components/Alert/Alert";
2022
import { displaySuccess } from "components/GlobalSnackbar/utils";
2123
import { Loader } from "components/Loader/Loader";
2224
import { Stack } from "components/Stack/Stack";
@@ -149,13 +151,14 @@ export const NotificationsPage: FC = () => {
149151
{ready ? (
150152
tab === "events" ? (
151153
<EventsView
154+
templatesByGroup={templatesByGroup.data}
155+
deploymentValues={deploymentValues.config}
152156
defaultMethod={castNotificationMethod(
153157
dispatchMethods.data.default,
154158
)}
155159
availableMethods={dispatchMethods.data.available.map(
156160
castNotificationMethod,
157161
)}
158-
templatesByGroup={templatesByGroup.data}
159162
/>
160163
) : (
161164
<OptionsTable
@@ -177,15 +180,33 @@ type EventsViewProps = {
177180
defaultMethod: NotificationMethod;
178181
availableMethods: NotificationMethod[];
179182
templatesByGroup: ReturnType<typeof selectTemplatesByGroup>;
183+
deploymentValues: DeploymentValues;
180184
};
181185

182186
const EventsView: FC<EventsViewProps> = ({
183187
defaultMethod,
184188
availableMethods,
185189
templatesByGroup,
190+
deploymentValues,
186191
}) => {
187192
return (
188193
<Stack spacing={3}>
194+
{availableMethods.includes("smtp") &&
195+
deploymentValues.notifications?.webhook.endpoint === "" && (
196+
<Alert severity="warning">
197+
Webhook notifications are enabled, but no endpoint has been
198+
configured.
199+
</Alert>
200+
)}
201+
202+
{availableMethods.includes("smtp") &&
203+
deploymentValues.notifications?.email.smarthost === "" && (
204+
<Alert severity="warning">
205+
SMTP notifications are enabled, but no smart host has been
206+
configured.
207+
</Alert>
208+
)}
209+
189210
{Object.entries(templatesByGroup).map(([group, templates]) => (
190211
<Card
191212
key={group}

0 commit comments

Comments
 (0)