From 7ffeb515717697fce18d8c284cc9865836ab4d16 Mon Sep 17 00:00:00 2001 From: LukeGus Date: Tue, 9 Sep 2025 18:31:41 -0500 Subject: [PATCH] Improve logging more, fix credentials sync issues, migrate more to be toasts --- src/hooks/use-confirmation.ts | 65 +++++++++++++++++++++++++++++++++++ src/ui/main-axios.ts | 1 + 2 files changed, 66 insertions(+) create mode 100644 src/hooks/use-confirmation.ts diff --git a/src/hooks/use-confirmation.ts b/src/hooks/use-confirmation.ts new file mode 100644 index 00000000..cbbcf531 --- /dev/null +++ b/src/hooks/use-confirmation.ts @@ -0,0 +1,65 @@ +import { useState } from 'react'; +import { toast } from 'sonner'; + +interface ConfirmationOptions { + title: string; + description: string; + confirmText?: string; + cancelText?: string; + variant?: 'default' | 'destructive'; +} + +export function useConfirmation() { + const [isOpen, setIsOpen] = useState(false); + const [options, setOptions] = useState(null); + const [onConfirm, setOnConfirm] = useState<(() => void) | null>(null); + + const confirm = (opts: ConfirmationOptions, callback: () => void) => { + setOptions(opts); + setOnConfirm(() => callback); + setIsOpen(true); + }; + + const handleConfirm = () => { + if (onConfirm) { + onConfirm(); + } + setIsOpen(false); + setOptions(null); + setOnConfirm(null); + }; + + const handleCancel = () => { + setIsOpen(false); + setOptions(null); + setOnConfirm(null); + }; + + // For simple confirmations, we can use a toast with action + const confirmWithToast = (message: string, callback: () => void, variant: 'default' | 'destructive' = 'default') => { + const actionText = variant === 'destructive' ? 'Delete' : 'Confirm'; + const cancelText = 'Cancel'; + + toast(message, { + action: { + label: actionText, + onClick: callback + }, + cancel: { + label: cancelText, + onClick: () => {} + }, + duration: 10000, // Longer duration for confirmations + className: variant === 'destructive' ? 'border-red-500' : '' + }); + }; + + return { + isOpen, + options, + confirm, + handleConfirm, + handleCancel, + confirmWithToast + }; +} diff --git a/src/ui/main-axios.ts b/src/ui/main-axios.ts index 06b937bf..8f728103 100644 --- a/src/ui/main-axios.ts +++ b/src/ui/main-axios.ts @@ -922,6 +922,7 @@ export async function getOIDCConfig(): Promise { return response.data; } catch (error: any) { console.warn('Failed to fetch OIDC config:', error.response?.data?.error || error.message); + // Don't show toast for OIDC config as it's optional return null; } }