"use client"; import { authClient } from "@repo/auth/client"; import { type OAuthProvider, oAuthProviders, } from "@saas/auth/constants/oauth-providers"; import { useUserAccountsQuery } from "@saas/auth/lib/api"; import { SettingsItem } from "@saas/shared/components/SettingsItem"; import { Button } from "@ui/components/button"; import { Skeleton } from "@ui/components/skeleton"; import { CheckCircle2Icon, LinkIcon } from "lucide-react"; import { useTranslations } from "next-intl"; export function ConnectedAccountsBlock() { const t = useTranslations(); const { data, isPending } = useUserAccountsQuery(); const isProviderLinked = (provider: OAuthProvider) => data?.some((account) => account.provider === provider); const linkProvider = (provider: OAuthProvider) => { const callbackURL = window.location.href; if (!isProviderLinked(provider)) { authClient.linkSocial({ provider, callbackURL, }); } }; return (
{Object.entries(oAuthProviders).map( ([provider, providerData]) => { const isLinked = isProviderLinked( provider as OAuthProvider, ); return (
{providerData.name}
{isPending ? ( ) : isLinked ? ( ) : ( )}
); }, )}
); }