-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #26 from GlideRide-online/patch-01
added a timer for better user exp
- Loading branch information
Showing
2 changed files
with
61 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
// Notification.js | ||
|
||
import React, { useState, useEffect } from "react"; | ||
|
||
const Notification = ({ message, duration, onClose }) => { | ||
const [isVisible, setIsVisible] = useState(true); | ||
const [timer, setTimer] = useState(duration); | ||
|
||
useEffect(() => { | ||
const interval = setInterval(() => { | ||
setTimer((prevTimer) => { | ||
if (prevTimer === 1) { | ||
clearInterval(interval); | ||
setIsVisible(false); | ||
onClose(); | ||
} | ||
return prevTimer - 1; | ||
}); | ||
}, 1000); | ||
|
||
return () => clearInterval(interval); | ||
}, [duration, onClose]); | ||
|
||
return ( | ||
<> | ||
{isVisible && ( | ||
<div className="fixed font-roboto bottom-0 right-0 mb-4 mr-4 p-4 bg-black text-white rounded-md shadow-md"> | ||
<p>{message}</p> | ||
<p className="mt-2 text-sm">{`${timer} seconds`}</p> | ||
</div> | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default Notification; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters