feat: Add "None" option to notification channel.

Adds a "None" option to the notification channel dropdown in the Add SSL Certificate form. This allows users to opt-out of notifications.
This commit is contained in:
Tola Leng
2025-06-26 14:10:30 +07:00
parent ab4f0aa6ea
commit 094f5fcd5e
@@ -1,4 +1,3 @@
import React, { useEffect, useState } from "react"; import React, { useEffect, useState } from "react";
import { useForm } from "react-hook-form"; import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod"; import { zodResolver } from "@hookform/resolvers/zod";
@@ -19,7 +18,7 @@ const formSchema = z.object({
domain: z.string().min(1, "Domain is required"), domain: z.string().min(1, "Domain is required"),
warning_threshold: z.coerce.number().int().min(1).max(365), warning_threshold: z.coerce.number().int().min(1).max(365),
expiry_threshold: z.coerce.number().int().min(1).max(30), expiry_threshold: z.coerce.number().int().min(1).max(30),
notification_channel: z.string().min(1, "Notification channel is required"), notification_channel: z.string().optional(), // Make it optional to allow empty string for "None"
check_interval: z.coerce.number().int().min(1).max(30).optional() check_interval: z.coerce.number().int().min(1).max(30).optional()
}); });
@@ -44,7 +43,7 @@ export const AddSSLCertificateForm = ({
domain: "", domain: "",
warning_threshold: 30, warning_threshold: 30,
expiry_threshold: 7, expiry_threshold: 7,
notification_channel: "", notification_channel: "none",
check_interval: 1 check_interval: 1
} }
}); });
@@ -66,14 +65,6 @@ export const AddSSLCertificateForm = ({
return config.enabled === true; return config.enabled === true;
}); });
setAlertConfigs(enabledConfigs); setAlertConfigs(enabledConfigs);
// Set default if available, preferring Telegram channels
const telegramChannel = enabledConfigs.find(c => c.notification_type === "telegram");
const defaultChannel = telegramChannel || enabledConfigs[0];
if (defaultChannel?.id) {
form.setValue("notification_channel", defaultChannel.id);
}
} catch (error) { } catch (error) {
console.error("Error fetching notification channels:", error); console.error("Error fetching notification channels:", error);
toast.error(t('failedToLoadCertificates')); toast.error(t('failedToLoadCertificates'));
@@ -92,7 +83,7 @@ export const AddSSLCertificateForm = ({
domain: values.domain, domain: values.domain,
warning_threshold: values.warning_threshold, warning_threshold: values.warning_threshold,
expiry_threshold: values.expiry_threshold, expiry_threshold: values.expiry_threshold,
notification_channel: values.notification_channel, notification_channel: values.notification_channel === "none" ? "" : (values.notification_channel || ""), // Convert "none" to empty string
check_interval: values.check_interval check_interval: values.check_interval
}; };
@@ -180,13 +171,14 @@ export const AddSSLCertificateForm = ({
render={({ field }) => ( render={({ field }) => (
<FormItem> <FormItem>
<FormLabel>{t('notificationChannel')}</FormLabel> <FormLabel>{t('notificationChannel')}</FormLabel>
<Select onValueChange={field.onChange} value={field.value}> <Select onValueChange={field.onChange} value={field.value || "none"}>
<FormControl> <FormControl>
<SelectTrigger> <SelectTrigger>
<SelectValue placeholder={t('chooseChannel')} /> <SelectValue placeholder={t('chooseChannel')} />
</SelectTrigger> </SelectTrigger>
</FormControl> </FormControl>
<SelectContent> <SelectContent>
<SelectItem value="none">{t('none')}</SelectItem>
{alertConfigs.length > 0 ? ( {alertConfigs.length > 0 ? (
alertConfigs.map((config) => ( alertConfigs.map((config) => (
<SelectItem key={config.id} value={config.id || ""}> <SelectItem key={config.id} value={config.id || ""}>
@@ -196,13 +188,13 @@ export const AddSSLCertificateForm = ({
) : isLoading ? ( ) : isLoading ? (
<SelectItem value="loading" disabled>{t('loadingChannels')}</SelectItem> <SelectItem value="loading" disabled>{t('loadingChannels')}</SelectItem>
) : ( ) : (
<SelectItem value="none" disabled>{t('noChannelsFound')}</SelectItem> <SelectItem value="none-disabled" disabled>{t('noChannelsFound')}</SelectItem>
)} )}
</SelectContent> </SelectContent>
</Select> </Select>
<FormDescription className="flex items-center gap-1"> <FormDescription className="flex items-center gap-1">
<Bell className="h-4 w-4" /> <Bell className="h-4 w-4" />
{t('chooseChannel')} {t('whereToSend')}
</FormDescription> </FormDescription>
<FormMessage /> <FormMessage />
</FormItem> </FormItem>