/** * OAuth Buttons Component * Displays OAuth provider buttons with icons and brand colors */ import React from 'react'; import { Loader2 } from 'lucide-react'; import { useInitiateOAuth, useOAuthProviders } from '../hooks/useOAuth'; interface OAuthButtonsProps { onSuccess?: () => void; disabled?: boolean; } // Provider configurations with colors and icons const providerConfig: Record< string, { name: string; bgColor: string; hoverColor: string; textColor: string; icon: string; } > = { google: { name: 'Google', bgColor: 'bg-white', hoverColor: 'hover:bg-gray-50', textColor: 'text-gray-900', icon: 'G', }, apple: { name: 'Apple', bgColor: 'bg-black', hoverColor: 'hover:bg-gray-900', textColor: 'text-white', icon: '', }, facebook: { name: 'Facebook', bgColor: 'bg-[#1877F2]', hoverColor: 'hover:bg-[#166FE5]', textColor: 'text-white', icon: 'f', }, linkedin: { name: 'LinkedIn', bgColor: 'bg-[#0A66C2]', hoverColor: 'hover:bg-[#095196]', textColor: 'text-white', icon: 'in', }, microsoft: { name: 'Microsoft', bgColor: 'bg-[#00A4EF]', hoverColor: 'hover:bg-[#0078D4]', textColor: 'text-white', icon: 'M', }, x: { name: 'X', bgColor: 'bg-black', hoverColor: 'hover:bg-gray-900', textColor: 'text-white', icon: 'X', }, twitch: { name: 'Twitch', bgColor: 'bg-[#9146FF]', hoverColor: 'hover:bg-[#7D3ACE]', textColor: 'text-white', icon: 'T', }, }; const OAuthButtons: React.FC = ({ onSuccess, disabled = false }) => { const { data: providers, isLoading } = useOAuthProviders(); const initiateMutation = useInitiateOAuth(); const handleOAuthClick = (providerId: string) => { if (disabled || initiateMutation.isPending) return; initiateMutation.mutate(providerId, { onSuccess: () => { onSuccess?.(); }, onError: (error) => { console.error('OAuth initiation error:', error); }, }); }; if (isLoading) { return (
); } if (!providers || providers.length === 0) { return null; } return (
{providers.map((provider) => { const config = providerConfig[provider.name] || { name: provider.display_name, bgColor: 'bg-gray-600', hoverColor: 'hover:bg-gray-700', textColor: 'text-white', icon: provider.display_name.charAt(0).toUpperCase(), }; const isCurrentlyLoading = initiateMutation.isPending && initiateMutation.variables === provider.name; return ( ); })}
); }; export default OAuthButtons;