import { FormEvent, useEffect, useRef, useState } from 'react'; import { useToast } from '../../hooks/use-toast'; import { useTeamId } from '../../hooks/use-team-id'; import { useOutsideClick } from '../../hooks/use-outside-click'; import { useKeydown } from '../../hooks/use-keydown'; import { httpPost } from '../../lib/http'; import { CheckIcon } from '../ReactIcons/CheckIcon'; type SubmitFeedbackPopupProps = { onClose: () => void; }; export function SubmitFeedbackPopup(props: SubmitFeedbackPopupProps) { const { onClose } = props; const popupBodyEl = useRef(null); const inputEl = useRef(null); const [isLoading, setIsLoading] = useState(false); const [error, setError] = useState(''); const [feedbackText, setFeedbackText] = useState(''); const [isSuccess, setIsSuccess] = useState(false); const { teamId } = useTeamId(); useOutsideClick(popupBodyEl, () => { onClose(); }); useKeydown('Escape', () => { onClose(); }); useEffect(() => { inputEl.current?.focus(); }, []); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); setIsLoading(true); setError(''); const { response, error } = await httpPost<{ status: 'ok' }>( `${import.meta.env.PUBLIC_API_URL}/v1-submit-team-feedback/${teamId}`, { feedback: feedbackText, } ); if (error || !response) { setIsLoading(false); setError(error?.message || 'Something went wrong'); return; } setIsSuccess(true); }; const handleClosePopup = () => { setIsLoading(false); setError(''); setFeedbackText(''); onClose(); }; return (
{!isSuccess && ( <>

Enter your feedback

Help us improve your experience.