From 71198ab18ad6b7f08d450cb8648ad6a412cb8061 Mon Sep 17 00:00:00 2001 From: Fringg Date: Wed, 4 Mar 2026 15:46:53 +0300 Subject: [PATCH] refactor: extract shared ProviderIcon, fix canUnlink hiding all buttons - Extract TelegramIcon + EmailIcon to shared ProviderIcon component - Remove duplicated icons from ConnectedAccounts and MergeAccounts - Remove isPending from canUnlink (buttons already have disabled prop) - Add onSettled to reset confirmingUnlink state after mutation --- src/components/ProviderIcon.tsx | 49 +++++++++++++++++++++++++++++++++ src/pages/ConnectedAccounts.tsx | 48 +++----------------------------- src/pages/MergeAccounts.tsx | 41 ++------------------------- 3 files changed, 55 insertions(+), 83 deletions(-) create mode 100644 src/components/ProviderIcon.tsx diff --git a/src/components/ProviderIcon.tsx b/src/components/ProviderIcon.tsx new file mode 100644 index 0000000..758f0b3 --- /dev/null +++ b/src/components/ProviderIcon.tsx @@ -0,0 +1,49 @@ +import { cn } from '@/lib/utils'; +import OAuthProviderIcon from './OAuthProviderIcon'; + +export function TelegramIcon({ className = 'h-5 w-5' }: { className?: string }) { + return ( + + ); +} + +export function EmailIcon({ className = 'h-5 w-5' }: { className?: string }) { + return ( + + ); +} + +export default function ProviderIcon({ + provider, + className, +}: { + provider: string; + className?: string; +}) { + switch (provider) { + case 'telegram': + return ; + case 'email': + return ; + default: + return ; + } +} diff --git a/src/pages/ConnectedAccounts.tsx b/src/pages/ConnectedAccounts.tsx index 31c23c5..2b8053e 100644 --- a/src/pages/ConnectedAccounts.tsx +++ b/src/pages/ConnectedAccounts.tsx @@ -7,7 +7,7 @@ import { useToast } from '../components/Toast'; import { Card } from '@/components/data-display/Card'; import { Button } from '@/components/primitives/Button'; import { staggerContainer, staggerItem } from '@/components/motion/transitions'; -import OAuthProviderIcon from '../components/OAuthProviderIcon'; +import ProviderIcon from '../components/ProviderIcon'; import { LINK_OAUTH_STATE_KEY, LINK_OAUTH_PROVIDER_KEY } from './LinkOAuthCallback'; import type { LinkedProvider } from '../types'; @@ -15,48 +15,6 @@ const OAUTH_PROVIDERS = ['google', 'yandex', 'discord', 'vk']; const isOAuthProvider = (provider: string): boolean => OAUTH_PROVIDERS.includes(provider); -// Icons for providers not covered by OAuthProviderIcon -function TelegramIcon({ className = 'h-5 w-5' }: { className?: string }) { - return ( - - ); -} - -function EmailIcon({ className = 'h-5 w-5' }: { className?: string }) { - return ( - - ); -} - -function ProviderIcon({ provider }: { provider: string }) { - switch (provider) { - case 'telegram': - return ; - case 'email': - return ; - default: - return ; - } -} - function LoadingSkeleton() { return (
@@ -103,12 +61,14 @@ export default function ConnectedAccounts() { message: t('profile.accounts.unlinkError'), }); }, + onSettled: () => { + setConfirmingUnlink(null); + }, }); const canUnlink = (provider: LinkedProvider): boolean => { if (!provider.linked) return false; if (!isOAuthProvider(provider.provider)) return false; - if (unlinkMutation.isPending) return false; const linkedCount = data?.providers.filter((p) => p.linked).length ?? 0; return linkedCount > 1; }; diff --git a/src/pages/MergeAccounts.tsx b/src/pages/MergeAccounts.tsx index c410ba6..89a6abc 100644 --- a/src/pages/MergeAccounts.tsx +++ b/src/pages/MergeAccounts.tsx @@ -10,7 +10,7 @@ import { Card, CardHeader, CardTitle, CardContent } from '@/components/data-disp import { Button } from '@/components/primitives/Button'; import { staggerContainer, staggerItem } from '@/components/motion/transitions'; import { cn } from '@/lib/utils'; -import OAuthProviderIcon from '../components/OAuthProviderIcon'; +import ProviderIcon from '../components/ProviderIcon'; import type { MergeAccountPreview } from '../types'; // -- Icons -- @@ -72,47 +72,10 @@ function CheckCircleIcon({ className = 'h-5 w-5' }: { className?: string }) { ); } -function TelegramIcon({ className = 'h-5 w-5' }: { className?: string }) { - return ( - - ); -} - -function EmailIcon({ className = 'h-5 w-5' }: { className?: string }) { - return ( - - ); -} - // -- Helpers -- function ProviderBadgeIcon({ provider }: { provider: string }) { - switch (provider) { - case 'telegram': - return ; - case 'email': - return ; - default: - return ; - } + return ; } function formatCountdown(seconds: number): string {