Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions src/components/Layout/Feedback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Copyright (c) Facebook, Inc. and its affiliates.
*/

import {useState} from 'react';
import {useState, useEffect} from 'react';
import {useRouter} from 'next/router';
import {ga} from '../../utils/analytics';

Expand Down Expand Up @@ -60,8 +60,30 @@ function sendGAEvent(isPositive: boolean) {

function SendFeedback({onSubmit}: {onSubmit: () => void}) {
const [isSubmitted, setIsSubmitted] = useState(false);
const [isVisible, setIsVisible] = useState(true);

useEffect(() => {
let timer: NodeJS.Timeout | null = null;

if (isSubmitted) {
timer = setTimeout(() => {
setIsVisible(false);
}, 3000);
}

return () => {
if (timer) {
clearTimeout(timer);
}
};
}, [isSubmitted]);
return (
<div className="max-w-xs w-80 lg:w-auto py-3 shadow-lg rounded-lg m-4 bg-wash dark:bg-gray-95 px-4 flex">
<div
className="max-w-xs w-80 lg:w-auto py-3 shadow-lg rounded-lg m-4 bg-wash dark:bg-gray-95 px-4 flex transition-opacity duration-300"
style={{
display: isVisible ? 'flex' : 'none',
pointerEvents: isVisible ? 'auto' : 'none',
}}>
<p className="w-full font-bold text-primary dark:text-primary-dark text-lg mr-4">
{isSubmitted ? 'Thank you for your feedback!' : 'Is this page useful?'}
</p>
Expand Down