Improve logging more, fix credentials sync issues, migrate more to be toasts
This commit is contained in:
65
src/hooks/use-confirmation.ts
Normal file
65
src/hooks/use-confirmation.ts
Normal file
@@ -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<ConfirmationOptions | null>(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
|
||||||
|
};
|
||||||
|
}
|
||||||
@@ -922,6 +922,7 @@ export async function getOIDCConfig(): Promise<any> {
|
|||||||
return response.data;
|
return response.data;
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
console.warn('Failed to fetch OIDC config:', error.response?.data?.error || error.message);
|
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;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user