import { type FormEvent, useEffect, useRef, useState } from 'react'; import { httpDelete } from '../../lib/http'; import { useTeamId } from '../../hooks/use-team-id'; import { useOutsideClick } from '../../hooks/use-outside-click'; type LeaveTeamPopupProps = { onClose: () => void; }; export function LeaveTeamPopup(props: LeaveTeamPopupProps) { const { onClose } = props; const popupBodyRef = useRef(null); const confirmationEl = useRef(null); const [confirmationText, setConfirmationText] = useState(''); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const { teamId } = useTeamId(); useEffect(() => { setError(''); setConfirmationText(''); confirmationEl?.current?.focus(); }, []); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); if (confirmationText.toUpperCase() !== 'LEAVE') { setError('Verification text does not match'); setIsLoading(false); return; } const { response, error } = await httpDelete( `${import.meta.env.PUBLIC_API_URL}/v1-leave-team/${teamId}`, {} ); if (error || !response) { setIsLoading(false); setError(error?.message || 'Something went wrong'); return; } window.location.href = '/account?c=tl'; }; const handleClosePopup = () => { setIsLoading(false); setError(''); setConfirmationText(''); onClose(); }; useOutsideClick(popupBodyRef, handleClosePopup); return (

Leave Team

You will lose access to the team, the roadmaps and progress of other team members.

Please type "leave" to confirm.

setConfirmationText((e.target as HTMLInputElement).value) } /> {error && (

{error}

)}
); }