import type { AlsoKnownAsAccount } from '@self.id/framework' import { Anchor, Box, Button, Heading, Spinner, Text, TextInput } from 'grommet' import Link from 'next/link' import Image from 'next/image' import { useRouter } from 'next/router' import { useMemo, useRef, useState } from 'react' import type { FormEvent } from 'react' import { useRemoveSocialAccount, useViewerSocialAccounts } from '../../hooks' import { GITHUB_HOST, TWITTER_HOST } from '../../identity-link' import githubIcon from '../../images/icons/social-github.svg' import twitterIcon from '../../images/icons/social-twitter.svg' import ConnectedContainer from '../ConnectedContainer' type SocialAccountType = 'github' | 'twitter' type SocialAccountsConfig = { addLabel: string addPrefix: string icon: typeof githubIcon title: string } const SOCIAL_ACCOUNTS_CONFIGS: Record = { github: { addLabel: 'github.com/', addPrefix: '/me/social-accounts/add-github/', icon: githubIcon, title: 'GitHub', }, twitter: { addLabel: 'twitter.com/', addPrefix: '/me/social-accounts/add-twitter/', icon: twitterIcon, title: 'Twitter', }, } type AccountsRecord = Record> type AddAccountProps = { label: string urlPrefix: string } function AddAccount({ label, urlPrefix }: AddAccountProps) { const router = useRouter() const inputRef = useRef(null) const onSubmit = (e: FormEvent) => { e.preventDefault() const value = inputRef.current?.value ?? '' if (value !== '') { void router.push(`${urlPrefix}${value}`) } } return ( {label}