diff --git a/src/components/Feedback/SubmitFeedbackPopup.tsx b/src/components/Feedback/SubmitFeedbackPopup.tsx new file mode 100644 index 000000000..cca95f5d4 --- /dev/null +++ b/src/components/Feedback/SubmitFeedbackPopup.tsx @@ -0,0 +1,140 @@ +import { useEffect, useRef, useState } from "preact/hooks"; +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 toast = useToast(); + 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: Event) => { + 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; + } + + toast.success('Team feedback submitted successfully'); + setIsSuccess(true); + }; + + const handleClosePopup = () => { + setIsLoading(false); + setError(''); + setFeedbackText(''); + + onClose(); + }; + + return ( +
+
+