import clsx from 'clsx' import { MouseEventHandler, ReactNode, useState } from 'react' import toast from 'react-hot-toast' import { LinkIcon } from '@heroicons/react/solid' import { usePrivateUser, useUser } from 'web/hooks/use-user' import { updatePrivateUser } from 'web/lib/firebase/users' import { track } from 'web/lib/service/analytics' import { linkTwitchAccountRedirect, updateBotEnabledForUser, } from 'web/lib/twitch/link-twitch-account' import { copyToClipboard } from 'web/lib/util/copy' import { Button, ColorType } from './../button' import { Row } from './../layout/row' import { LoadingIndicator } from './../loading-indicator' import { PrivateUser } from 'common/user' function BouncyButton(props: { children: ReactNode onClick?: MouseEventHandler color?: ColorType className?: string }) { const { children, onClick, color, className } = props return ( ) } function BotConnectButton(props: { privateUser: PrivateUser | null | undefined }) { const { privateUser } = props const [loading, setLoading] = useState(false) const updateBotConnected = (connected: boolean) => async () => { if (!privateUser) return const twitchInfo = privateUser.twitchInfo if (!twitchInfo) return const error = connected ? 'Failed to add bot to your channel' : 'Failed to remove bot from your channel' const success = connected ? 'Added bot to your channel' : 'Removed bot from your channel' setLoading(true) toast.promise( updateBotEnabledForUser(privateUser, connected).then(() => updatePrivateUser(privateUser.id, { twitchInfo: { ...twitchInfo, botEnabled: connected }, }) ), { loading: 'Updating bot settings...', error, success } ) try { } finally { setLoading(false) } } return ( <> {privateUser?.twitchInfo?.botEnabled ? ( Remove bot from your channel ) : ( Add bot to your channel )} ) } export function TwitchPanel() { const user = useUser() const privateUser = usePrivateUser() const twitchInfo = privateUser?.twitchInfo const twitchName = twitchInfo?.twitchName const twitchToken = twitchInfo?.controlToken const linkIcon =