form
This commit is contained in:
1 parent
3ba3e4b865
commit
0b5e28c296
6 files changed
+240
-1
No files matched your search
@@ -0,0 +1,51 @@
|
||||
import { z } from "zod";
|
||||
|
||||
const baseSchema = z.object({
|
||||
notificationName: z
|
||||
.string()
|
||||
.min(1, "Notification name is required")
|
||||
.max(100, "Notification name must be at most 100 characters"),
|
||||
});
|
||||
|
||||
const emailSchema = baseSchema.extend({
|
||||
type: z.literal("email"),
|
||||
address: z.string().min(1, "Email is required").email("Please enter a valid email address"),
|
||||
});
|
||||
|
||||
const slackSchema = baseSchema.extend({
|
||||
type: z.literal("slack"),
|
||||
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
||||
});
|
||||
|
||||
const discordSchema = baseSchema.extend({
|
||||
type: z.literal("discord"),
|
||||
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
||||
});
|
||||
|
||||
const webhookSchema = baseSchema.extend({
|
||||
type: z.literal("webhook"),
|
||||
address: z.string().min(1, "Webhook URL is required").url("Please enter a valid URL"),
|
||||
});
|
||||
|
||||
const pagerDutySchema = baseSchema.extend({
|
||||
type: z.literal("pager_duty"),
|
||||
address: z.string().min(1, "Integration key is required"),
|
||||
});
|
||||
|
||||
const matrixSchema = baseSchema.extend({
|
||||
type: z.literal("matrix"),
|
||||
homeserverUrl: z.string().min(1, "Homeserver URL is required").url("Please enter a valid URL"),
|
||||
roomId: z.string().min(1, "Room ID is required"),
|
||||
accessToken: z.string().min(1, "Access token is required"),
|
||||
});
|
||||
|
||||
export const notificationSchema = z.discriminatedUnion("type", [
|
||||
emailSchema,
|
||||
slackSchema,
|
||||
discordSchema,
|
||||
webhookSchema,
|
||||
pagerDutySchema,
|
||||
matrixSchema,
|
||||
]);
|
||||
|
||||
export type NotificationFormData = z.infer<typeof notificationSchema>;
|
||||
Reference in new issue
Block a user