Skip to content

Commit 1262f7b

Browse files
committed
Fix types
1 parent 788de88 commit 1262f7b

File tree

9 files changed

+68
-78
lines changed

9 files changed

+68
-78
lines changed

coderd/apidoc/docs.go

Lines changed: 6 additions & 15 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/apidoc/swagger.json

Lines changed: 6 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

coderd/notifications.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,14 +152,14 @@ func (api *API) systemNotificationTemplates(rw http.ResponseWriter, r *http.Requ
152152
// @Success 200 {array} codersdk.NotificationMethodsResponse
153153
// @Router /notifications/dispatch-methods [get]
154154
func (api *API) notificationDispatchMethods(rw http.ResponseWriter, r *http.Request) {
155-
var methods []string
155+
var methods []codersdk.NotificationTemplateMethod
156156
for _, nm := range database.AllNotificationMethodValues() {
157-
methods = append(methods, string(nm))
157+
methods = append(methods, codersdk.NotificationTemplateMethod(nm))
158158
}
159159

160160
httpapi.Write(r.Context(), rw, http.StatusOK, codersdk.NotificationMethodsResponse{
161161
AvailableNotificationMethods: methods,
162-
DefaultNotificationMethod: api.DeploymentValues.Notifications.Method.Value(),
162+
DefaultNotificationMethod: codersdk.NotificationTemplateMethod(api.DeploymentValues.Notifications.Method.Value()),
163163
})
164164
}
165165

codersdk/notifications.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ type NotificationsSettings struct {
1919
type NotificationTemplateMethod string
2020

2121
const (
22-
NotificationTemplateEmailMethod NotificationTemplateMethod = "email"
23-
NotificationTemplateWebhookMethod NotificationTemplateMethod = "webhook"
24-
NotificationTemplateNotDefinedMethod NotificationTemplateMethod = ""
22+
NotificationTemplateSMTPMethod NotificationTemplateMethod = "smtp"
23+
NotificationTemplateWebhookMethod NotificationTemplateMethod = "webhook"
24+
NotificationTemplateDefaultMethod NotificationTemplateMethod = ""
2525
)
2626

2727
type NotificationTemplate struct {
@@ -31,13 +31,13 @@ type NotificationTemplate struct {
3131
BodyTemplate string `json:"body_template"`
3232
Actions string `json:"actions" format:""`
3333
Group string `json:"group"`
34-
Method NotificationTemplateMethod `json:"method" enums:"email,webhook,''"`
34+
Method NotificationTemplateMethod `json:"method"`
3535
Kind string `json:"kind"`
3636
}
3737

3838
type NotificationMethodsResponse struct {
39-
AvailableNotificationMethods []string `json:"available"`
40-
DefaultNotificationMethod string `json:"default"`
39+
AvailableNotificationMethods []NotificationTemplateMethod `json:"available"`
40+
DefaultNotificationMethod NotificationTemplateMethod `json:"default"`
4141
}
4242

4343
type NotificationPreference struct {
@@ -201,7 +201,7 @@ func (c *Client) GetNotificationDispatchMethods(ctx context.Context) (Notificati
201201
}
202202

203203
type UpdateNotificationTemplateMethod struct {
204-
Method NotificationTemplateMethod `json:"method,omitempty" enums:"email,webhook" example:"webhook"`
204+
Method NotificationTemplateMethod `json:"method,omitempty" example:"webhook"`
205205
}
206206

207207
type UpdateUserNotificationPreferences struct {

docs/api/notifications.md

Lines changed: 18 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/api/schemas.md

Lines changed: 9 additions & 17 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

enterprise/coderd/notifications_test.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ import (
1111
"golang.org/x/xerrors"
1212

1313
"github.com/coder/coder/v2/coderd/coderdtest"
14-
"github.com/coder/coder/v2/coderd/database"
1514
"github.com/coder/coder/v2/coderd/database/dbtestutil"
1615
"github.com/coder/coder/v2/coderd/notifications"
1716
"github.com/coder/coder/v2/codersdk"
@@ -45,7 +44,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
4544
api, _ := coderdenttest.New(t, createOpts(t))
4645

4746
var (
48-
method = string(database.NotificationMethodSmtp)
47+
method = codersdk.NotificationTemplateSMTPMethod
4948
templateID = notifications.TemplateWorkspaceDeleted
5049
)
5150

@@ -79,7 +78,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
7978
anotherClient, _ := coderdtest.CreateAnotherUser(t, api, firstUser.OrganizationID)
8079

8180
// When: calling the API as an unprivileged user.
82-
err := anotherClient.UpdateNotificationTemplateMethod(ctx, notifications.TemplateWorkspaceDeleted, string(database.NotificationMethodWebhook))
81+
err := anotherClient.UpdateNotificationTemplateMethod(ctx, notifications.TemplateWorkspaceDeleted, codersdk.NotificationTemplateWebhookMethod)
8382

8483
// Then: the request is denied because of insufficient permissions.
8584
var sdkError *codersdk.Error
@@ -129,7 +128,7 @@ func TestUpdateNotificationTemplateMethod(t *testing.T) {
129128
api, _ := coderdenttest.New(t, createOpts(t))
130129

131130
var (
132-
method = string(database.NotificationMethodSmtp)
131+
method = codersdk.NotificationTemplateSMTPMethod
133132
templateID = notifications.TemplateWorkspaceDeleted
134133
)
135134

site/src/api/typesGenerated.ts

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/modules/notifications/utils.tsx

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,25 @@
11
import EmailIcon from "@mui/icons-material/EmailOutlined";
22
import DeploymentIcon from "@mui/icons-material/LanguageOutlined";
33
import WebhookIcon from "@mui/icons-material/WebhookOutlined";
4+
import type { NotificationTemplateMethod } from "api/typesGenerated";
45

5-
export const methodIcons: Record<string, typeof EmailIcon> = {
6-
"": DeploymentIcon,
7-
smtp: EmailIcon,
8-
webhook: WebhookIcon,
9-
};
6+
export const methodIcons: Record<NotificationTemplateMethod, typeof EmailIcon> =
7+
{
8+
"": DeploymentIcon,
9+
smtp: EmailIcon,
10+
webhook: WebhookIcon,
11+
};
1012

11-
const methodLabels: Record<string, string> = {
13+
const methodLabels: Record<NotificationTemplateMethod, string> = {
1214
"": "Default",
1315
smtp: "SMTP",
1416
webhook: "Webhook",
1517
};
1618

17-
export const methodLabel = (method: string, defaultMethod?: string) => {
19+
export const methodLabel = (
20+
method: NotificationTemplateMethod,
21+
defaultMethod?: NotificationTemplateMethod,
22+
) => {
1823
return method === "" && defaultMethod
1924
? `${methodLabels[method]} - ${methodLabels[defaultMethod]}`
2025
: methodLabels[method];

0 commit comments

Comments
 (0)