From e0eccaa30efa8faa154a80eb34daed7474099eeb Mon Sep 17 00:00:00 2001 From: Arik Chakma Date: Thu, 17 Aug 2023 18:45:22 +0600 Subject: [PATCH] Add team feedback popup (#4341) * wip: submit feedback popup * wip: feedback popup state --- .../Feedback/SubmitFeedbackPopup.tsx | 145 ++++++++++++++++++ src/components/TeamSidebar.tsx | 36 +++-- 2 files changed, 167 insertions(+), 14 deletions(-) create mode 100644 src/components/Feedback/SubmitFeedbackPopup.tsx diff --git a/src/components/Feedback/SubmitFeedbackPopup.tsx b/src/components/Feedback/SubmitFeedbackPopup.tsx new file mode 100644 index 000000000..8af5e358a --- /dev/null +++ b/src/components/Feedback/SubmitFeedbackPopup.tsx @@ -0,0 +1,145 @@ +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 ( +
+
+