({ ratingModal, setRatingModal })
| 6 | import toast from 'react-hot-toast'; |
| 7 | |
| 8 | const RatingModal = ({ ratingModal, setRatingModal }) => { |
| 9 | |
| 10 | const [rating, setRating] = useState(0); |
| 11 | const [review, setReview] = useState(''); |
| 12 | |
| 13 | const handleSubmit = async () => { |
| 14 | if (rating < 0 || rating > 5) { |
| 15 | return toast('Please select a rating'); |
| 16 | } |
| 17 | if (review.length < 5) { |
| 18 | return toast('write a short review'); |
| 19 | } |
| 20 | |
| 21 | setRatingModal(null); |
| 22 | } |
| 23 | |
| 24 | return ( |
| 25 | <div className='fixed inset-0 z-120 flex items-center justify-center bg-black/10'> |
| 26 | <div className='bg-white p-8 rounded-lg shadow-lg w-96 relative'> |
| 27 | <button onClick={() => setRatingModal(null)} className='absolute top-3 right-3 text-gray-500 hover:text-gray-700'> |
| 28 | <XIcon size={20} /> |
| 29 | </button> |
| 30 | <h2 className='text-xl font-medium text-slate-600 mb-4'>Rate Product</h2> |
| 31 | <div className='flex items-center justify-center mb-4'> |
| 32 | {Array.from({ length: 5 }, (_, i) => ( |
| 33 | <Star |
| 34 | key={i} |
| 35 | className={`size-8 cursor-pointer ${rating > i ? "text-green-400 fill-current" : "text-gray-300"}`} |
| 36 | onClick={() => setRating(i + 1)} |
| 37 | /> |
| 38 | ))} |
| 39 | </div> |
| 40 | <textarea |
| 41 | className='w-full p-2 border border-gray-300 rounded-md mb-4 focus:outline-none focus:ring-2 focus:ring-green-400' |
| 42 | placeholder='Write your review (optional)' |
| 43 | rows='4' |
| 44 | value={review} |
| 45 | onChange={(e) => setReview(e.target.value)} |
| 46 | ></textarea> |
| 47 | <button onClick={e => toast.promise(handleSubmit(), { loading: 'Submitting...' })} className='w-full bg-green-500 text-white py-2 rounded-md hover:bg-green-600 transition'> |
| 48 | Submit Rating |
| 49 | </button> |
| 50 | </div> |
| 51 | </div> |
| 52 | ) |
| 53 | } |
| 54 | |
| 55 | export default RatingModal |
nothing calls this directly
no test coverage detected