From c8f0f7cb1b8aeb0fa67bdc1f9a31486eb4f0ab93 Mon Sep 17 00:00:00 2001 From: Anish Sarkar <104695310+AnishSarkar22@users.noreply.github.com> Date: Tue, 19 May 2026 01:41:09 +0530 Subject: [PATCH] refactor: update alert components to use warning variant and clean up unused alerts in settings manager --- .../components/obsidian-config.tsx | 2 +- .../settings/general-settings-manager.tsx | 22 ++++++++----------- .../settings/prompt-config-manager.tsx | 14 +++++++----- surfsense_web/components/ui/alert.tsx | 2 ++ 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/obsidian-config.tsx b/surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/obsidian-config.tsx index de7ea8230..d4f18cb3a 100644 --- a/surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/obsidian-config.tsx +++ b/surfsense_web/components/assistant-ui/connector-popup/connector-configs/components/obsidian-config.tsx @@ -47,7 +47,7 @@ export const ObsidianConfig: FC = ({ connector }) => { const LegacyBanner: FC = () => { return (
- + Sync stopped, install the plugin to migrate diff --git a/surfsense_web/components/settings/general-settings-manager.tsx b/surfsense_web/components/settings/general-settings-manager.tsx index b01342cfc..44177e52d 100644 --- a/surfsense_web/components/settings/general-settings-manager.tsx +++ b/surfsense_web/components/settings/general-settings-manager.tsx @@ -2,12 +2,10 @@ import { useQuery } from "@tanstack/react-query"; import { useAtomValue } from "jotai"; -import { Info } from "lucide-react"; import { useTranslations } from "next-intl"; import { useCallback, useEffect, useState } from "react"; import { toast } from "sonner"; import { updateSearchSpaceMutationAtom } from "@/atoms/search-spaces/search-space-mutation.atoms"; -import { Alert, AlertDescription } from "@/components/ui/alert"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; @@ -41,6 +39,9 @@ export function GeneralSettingsManager({ searchSpaceId }: GeneralSettingsManager const [description, setDescription] = useState(""); const [saving, setSaving] = useState(false); const [isExporting, setIsExporting] = useState(false); + const hasSearchSpace = !!searchSpace; + const searchSpaceName = searchSpace?.name; + const searchSpaceDescription = searchSpace?.description; const handleExportKB = useCallback(async () => { if (isExporting) return; @@ -74,11 +75,11 @@ export function GeneralSettingsManager({ searchSpaceId }: GeneralSettingsManager // Initialize state from fetched search space useEffect(() => { - if (searchSpace) { - setName(searchSpace.name || ""); - setDescription(searchSpace.description || ""); + if (hasSearchSpace) { + setName(searchSpaceName || ""); + setDescription(searchSpaceDescription || ""); } - }, [searchSpace?.name, searchSpace?.description]); + }, [hasSearchSpace, searchSpaceName, searchSpaceDescription]); // Derive hasChanges during render const hasChanges = @@ -98,9 +99,9 @@ export function GeneralSettingsManager({ searchSpaceId }: GeneralSettingsManager }); await fetchSearchSpace(); - } catch (error: any) { + } catch (error: unknown) { console.error("Error saving search space details:", error); - toast.error(error.message || "Failed to save search space details"); + toast.error(error instanceof Error ? error.message : "Failed to save search space details"); } finally { setSaving(false); } @@ -135,11 +136,6 @@ export function GeneralSettingsManager({ searchSpaceId }: GeneralSettingsManager return (
- - - Update your search space name and description. - -
diff --git a/surfsense_web/components/settings/prompt-config-manager.tsx b/surfsense_web/components/settings/prompt-config-manager.tsx index 04e20fe17..ac7da9547 100644 --- a/surfsense_web/components/settings/prompt-config-manager.tsx +++ b/surfsense_web/components/settings/prompt-config-manager.tsx @@ -32,13 +32,15 @@ export function PromptConfigManager({ searchSpaceId }: PromptConfigManagerProps) const [customInstructions, setCustomInstructions] = useState(""); const [saving, setSaving] = useState(false); + const hasSearchSpace = !!searchSpace; + const searchSpaceInstructions = searchSpace?.qna_custom_instructions; // Initialize state from fetched search space useEffect(() => { - if (searchSpace) { - setCustomInstructions(searchSpace.qna_custom_instructions || ""); + if (hasSearchSpace) { + setCustomInstructions(searchSpaceInstructions || ""); } - }, [searchSpace?.qna_custom_instructions]); + }, [hasSearchSpace, searchSpaceInstructions]); // Derive hasChanges during render const hasChanges = @@ -69,9 +71,9 @@ export function PromptConfigManager({ searchSpaceId }: PromptConfigManagerProps) toast.success("System instructions saved successfully"); await fetchSearchSpace(); - } catch (error: any) { + } catch (error: unknown) { console.error("Error saving system instructions:", error); - toast.error(error.message || "Failed to save system instructions"); + toast.error(error instanceof Error ? error.message : "Failed to save system instructions"); } finally { setSaving(false); } @@ -102,7 +104,7 @@ export function PromptConfigManager({ searchSpaceId }: PromptConfigManagerProps) return (
{/* Work in Progress Notice */} - + Work in Progress diff --git a/surfsense_web/components/ui/alert.tsx b/surfsense_web/components/ui/alert.tsx index bf1c4e5c2..2d777db67 100644 --- a/surfsense_web/components/ui/alert.tsx +++ b/surfsense_web/components/ui/alert.tsx @@ -9,6 +9,8 @@ const alertVariants = cva( variants: { variant: { default: "border-popover-border bg-accent text-accent-foreground", + warning: + "border-highlight/40 bg-highlight/10 text-foreground *:data-[slot=alert-description]:text-muted-foreground [&>svg]:text-highlight", destructive: "border-destructive/30 bg-destructive/10 text-destructive *:data-[slot=alert-description]:text-destructive/90 [&>svg]:text-current", },