import { View, Text, ScrollView, TouchableOpacity, TextInput, ActivityIndicator, Alert } from 'react-native' import React, { useState } from 'react' import { useNavigation, useRoute } from '@react-navigation/native' import { StarIcon } from 'react-native-heroicons/solid' import { StarIcon as StarOutlineIcon } from 'react-native-heroicons/outline' import { widthPercentageToDP as wp, heightPercentageToDP as hp } from 'react-native-responsive-screen' import { rateProduct } from '../api' export default function LeaveReviewScreen() { const navigation = useNavigation(); const route = useRoute(); const { productId } = route.params; const [rating, setRating] = useState(0); const [comment, setComment] = useState(''); const [loading, setLoading] = useState(false); const handleSubmit = async () => { if (rating === 0) { Alert.alert('Error', 'Please select a rating'); return; } try { setLoading(true); await rateProduct(productId, rating, comment); Alert.alert('Success', 'Thank you for your review!'); navigation.goBack(); // Go back to previous screen } catch (error) { console.error('Error submitting review:', error); Alert.alert('Error', 'Failed to submit review. Please try again.'); } finally { setLoading(false); } }; return ( navigation.goBack()}> Cancel Leave a Review {loading ? 'Submitting...' : 'Submit'} How would you rate this product? {[1, 2, 3, 4, 5].map((star) => ( setRating(star)} className="mx-1" > {star <= rating ? ( ) : ( )} ))} Your Review {loading && ( )} ); }