import { useCallback, useState } from 'react' import { useTranslation } from 'react-i18next' import { Button, Modal } from 'react-bootstrap' import AccessibleModal from '../../../shared/components/accessible-modal' type SSOLinkingWidgetProps = { logoSrc: string title: string description: string linked?: boolean linkPath: string onUnlink: () => Promise unlinkConfirmationTitle: string unlinkConfirmationText: string } export function SSOLinkingWidget({ logoSrc, title, description, linked, linkPath, onUnlink, unlinkConfirmationTitle, unlinkConfirmationText, }: SSOLinkingWidgetProps) { const [showModal, setShowModal] = useState(false) const [unlinkRequestInflight, setUnlinkRequestInflight] = useState(false) const [errorMessage, setErrorMessage] = useState('') const handleUnlinkClick = useCallback(() => { setShowModal(true) }, []) const handleUnlinkConfirmationClick = useCallback(() => { setShowModal(false) setUnlinkRequestInflight(true) onUnlink() .catch((error: Error) => { setErrorMessage(error.message) }) .finally(() => { setUnlinkRequestInflight(false) }) }, [onUnlink]) const handleModalHide = useCallback(() => { setShowModal(false) }, []) return (
{title}

{title}

{description}

{errorMessage &&
{errorMessage}
}
) } type ActionButtonProps = { unlinkRequestInflight: boolean accountIsLinked?: boolean linkPath: string onUnlinkClick: () => void } function ActionButton({ unlinkRequestInflight, accountIsLinked, linkPath, onUnlinkClick, }: ActionButtonProps) { const { t } = useTranslation() if (unlinkRequestInflight) { return ( ) } else if (accountIsLinked) { return ( ) } else { return ( {t('link')} ) } } type UnlinkConfirmModalProps = { show: boolean title: string content: string handleConfirmation: () => void handleHide: () => void } function UnlinkConfirmModal({ show, title, content, handleConfirmation, handleHide, }: UnlinkConfirmModalProps) { const { t } = useTranslation() return ( {title}

{content}

) }