feat: discord decoration switch

This commit is contained in:
João Gabriel
2024-12-22 00:42:00 -03:00
parent 8c06296503
commit 055b59e6fa
6 changed files with 145 additions and 90 deletions

View File

@@ -64,6 +64,7 @@ export const notificationSchema = z.discriminatedUnion("type", [
.object({
type: z.literal("discord"),
webhookUrl: z.string().min(1, { message: "Webhook URL is required" }),
decoration: z.boolean().default(true),
})
.merge(notificationBaseSchema),
z
@@ -195,6 +196,7 @@ export const AddNotification = () => {
dokployRestart: dokployRestart,
databaseBackup: databaseBackup,
webhookUrl: data.webhookUrl,
decoration: data.decoration,
name: data.name,
dockerCleanup: dockerCleanup,
});
@@ -397,6 +399,7 @@ export const AddNotification = () => {
)}
{type === "discord" && (
<>
<FormField
control={form.control}
name="webhookUrl"
@@ -414,6 +417,29 @@ export const AddNotification = () => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="decoration"
defaultValue={true}
render={({ field }) => (
<FormItem className="flex items-center justify-between rounded-lg border p-3 shadow-sm">
<div className="space-y-0.5">
<FormLabel>Decoration</FormLabel>
<FormDescription>
Decorate the notification with emojis.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
</>
)}
{type === "email" && (

View File

@@ -72,7 +72,9 @@ export const ShowNotifications = () => {
{notification.name}
</span>
<span className="text-xs font-medium text-muted-foreground">
{notification.notificationType?.[0]?.toUpperCase() + notification.notificationType?.slice(1)} notification
{notification.notificationType?.[0]?.toUpperCase() +
notification.notificationType?.slice(1)}{" "}
notification
</span>
</div>
</div>

View File

@@ -28,7 +28,7 @@ import { api } from "@/utils/api";
import { zodResolver } from "@hookform/resolvers/zod";
import { Mail, Pen } from "lucide-react";
import { useEffect, useState } from "react";
import { FieldErrors, useFieldArray, useForm } from "react-hook-form";
import { useFieldArray, useForm } from "react-hook-form";
import { toast } from "sonner";
import {
type NotificationSchema,
@@ -113,6 +113,7 @@ export const UpdateNotification = ({ notificationId }: Props) => {
databaseBackup: data.databaseBackup,
type: data.notificationType,
webhookUrl: data.discord?.webhookUrl,
decoration: data.discord?.decoration || undefined,
name: data.name,
dockerCleanup: data.dockerCleanup,
});
@@ -218,9 +219,7 @@ export const UpdateNotification = ({ notificationId }: Props) => {
return (
<Dialog open={isOpen} onOpenChange={setIsOpen}>
<DialogTrigger className="" asChild>
<Button variant="ghost"
size="icon"
className="h-9 w-9">
<Button variant="ghost" size="icon" className="h-9 w-9">
<Pen className="size-4 text-muted-foreground" />
</Button>
</DialogTrigger>
@@ -358,6 +357,7 @@ export const UpdateNotification = ({ notificationId }: Props) => {
)}
{type === "discord" && (
<>
<FormField
control={form.control}
name="webhookUrl"
@@ -375,6 +375,29 @@ export const UpdateNotification = ({ notificationId }: Props) => {
</FormItem>
)}
/>
<FormField
control={form.control}
name="decoration"
defaultValue={true}
render={({ field }) => (
<FormItem className="flex items-center justify-between rounded-lg border p-3 shadow-sm">
<div className="space-y-0.5">
<FormLabel>Decoration</FormLabel>
<FormDescription>
Decorate the notification with emojis.
</FormDescription>
</div>
<FormControl>
<Switch
checked={field.value}
onCheckedChange={field.onChange}
/>
</FormControl>
</FormItem>
)}
/>
</>
)}
{type === "email" && (
<>

View File

@@ -172,6 +172,7 @@ export const apiCreateDiscord = notificationsSchema
})
.extend({
webhookUrl: z.string().min(1),
decoration: z.boolean(),
})
.required();
@@ -183,6 +184,7 @@ export const apiUpdateDiscord = apiCreateDiscord.partial().extend({
export const apiTestDiscordConnection = apiCreateDiscord.pick({
webhookUrl: true,
decoration: true,
});
export const apiCreateEmail = notificationsSchema

View File

@@ -204,6 +204,7 @@ export const createDiscordNotification = async (
.insert(discord)
.values({
webhookUrl: input.webhookUrl,
decoration: input.decoration,
})
.returning()
.then((value) => value[0]);
@@ -272,6 +273,7 @@ export const updateDiscordNotification = async (
.update(discord)
.set({
webhookUrl: input.webhookUrl,
decoration: input.decoration,
})
.where(eq(discord.discordId, input.discordId))
.returning()