Skip to content

Commit 8f621ec

Browse files
authored
Merge pull request #20 from GoBuildOrg/devSam
Dev sam
2 parents 5604a15 + d77b365 commit 8f621ec

2 files changed

Lines changed: 116 additions & 6 deletions

File tree

src/components/ReviewForm.tsx

Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
import React, { useState } from 'react';
2+
import { supabase } from '@/integrations/supabase/client';
3+
4+
interface ReviewFormProps {
5+
onClose: () => void;
6+
}
7+
8+
const ReviewForm: React.FC<ReviewFormProps> = ({ onClose }) => {
9+
const [reviewName, setReviewName] = useState('');
10+
const [reviewText, setReviewText] = useState('');
11+
const [reviewStars, setReviewStars] = useState(5);
12+
13+
const handleSubmitReview = async () => {
14+
if (!reviewName || !reviewText) {
15+
alert('Please fill all fields.');
16+
return;
17+
}
18+
19+
try {
20+
const { error } = await supabase
21+
.from('Review')
22+
.insert({
23+
'Customer Name': reviewName,
24+
'Customer Review': reviewText,
25+
'Rating': reviewStars,
26+
});
27+
28+
if (error) {
29+
console.error('Error submitting Review:', error);
30+
alert('Failed to submit review.');
31+
return;
32+
}
33+
34+
alert('Review submitted successfully!');
35+
onClose(); // close popup after success
36+
} catch (err) {
37+
console.error('Unexpected error:', err);
38+
alert('An unexpected error occurred.');
39+
}
40+
};
41+
42+
return (
43+
<div className="fixed inset-0 z-50 flex items-center justify-center bg-black bg-opacity-50">
44+
<div className="bg-white rounded-xl shadow-xl w-full max-w-md p-6 relative">
45+
<h2 className="text-2xl font-bold mb-4">Leave a Review</h2>
46+
<button
47+
onClick={onClose}
48+
className="absolute top-4 right-4 text-gray-600 hover:text-gray-900 text-2xl font-bold leading-none"
49+
>
50+
&times;
51+
</button>
52+
<input
53+
type="text"
54+
className="border border-gray-300 rounded p-3 w-full mb-4 focus:outline-blue-500"
55+
placeholder="Your Name"
56+
value={reviewName}
57+
onChange={(e) => setReviewName(e.target.value)}
58+
/>
59+
<textarea
60+
className="border border-gray-300 rounded p-3 resize-none w-full h-24 mb-4 focus:outline-blue-500"
61+
placeholder="Write your review here..."
62+
value={reviewText}
63+
onChange={(e) => setReviewText(e.target.value)}
64+
/>
65+
<div className="mb-4">
66+
<label className="block mb-1 font-semibold">Rating</label>
67+
<div className="flex space-x-1">
68+
{[1, 2, 3, 4, 5].map((star) => (
69+
<svg
70+
key={star}
71+
onClick={() => setReviewStars(star)}
72+
xmlns="http://www.w3.org/2000/svg"
73+
fill={star <= reviewStars ? "yellow" : "none"}
74+
stroke="black"
75+
strokeWidth={0.5}
76+
className="w-6 h-6 cursor-pointer"
77+
viewBox="0 0 20 20"
78+
>
79+
<path d="M9.049 2.927c.3-.921 1.603-.921 1.902 0l1.286 3.904a1 1 0 00.95.69h4.105c.969 0 1.371 1.24.588 1.81l-3.3 2.4a1 1 0 00-.364 1.118l1.286 3.904c.3.92-.755 1.688-1.54 1.118l-3.3-2.4a1 1 0 00-1.176 0l-3.3 2.4c-.784.57-1.838-.197-1.54-1.118l1.286-3.904a1 1 0 00-.363-1.118L2.17 9.43c-.783-.57-.38-1.81.588-1.81h4.106a1 1 0 00.95-.69l1.286-3.904z" />
80+
</svg>
81+
))}
82+
</div>
83+
</div>
84+
85+
<button
86+
onClick={handleSubmitReview}
87+
className="w-full bg-green-600 hover:bg-green-700 text-white py-3 rounded-lg font-bold transition"
88+
>
89+
Submit Review
90+
</button>
91+
</div>
92+
</div>
93+
);
94+
};
95+
96+
export default ReviewForm;

src/pages/Profile.tsx

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import React, { useEffect, useState } from 'react';
22
import { useNavigate, Link } from 'react-router-dom';
33
import { useAuth } from '@/contexts/AuthContext';
44
import Navbar from '@/components/Navbar';
5+
import ReviewForm from '@/components/ReviewForm'; // ✅ Imported ReviewForm
56

67
const accentColor = 'text-blue-600';
78

@@ -16,6 +17,8 @@ const Profile: React.FC = () => {
1617
const [password, setPassword] = useState('');
1718
const [deleting, setDeleting] = useState(false);
1819

20+
const [showReviewPopup, setShowReviewPopup] = useState(false);
21+
1922
const navigate = useNavigate();
2023

2124
const activeRequests = [{name:"Mason",status:"Doing",id:1234},{name:"Plumber",status:"Doing",id:1234}]; //is format me data dalna hai
@@ -72,12 +75,20 @@ const Profile: React.FC = () => {
7275
Manage your <span className={accentColor}>service requests</span> and track their progress.
7376
</p>
7477
</div>
75-
<button
76-
className="bg-blue-600 text-white px-4 py-3 rounded-lg font-bold flex items-center justify-center gap-3 hover:bg-blue-700 transition text-base sm:text-lg shadow-lg min-w-[180px]"
77-
onClick={() => navigate('/services')}
78-
>
79-
<span className="text-3xl font-extrabold leading-none">+</span> New Service Request
80-
</button>
78+
<div className="flex gap-4">
79+
<button
80+
className="bg-blue-600 text-white px-4 py-3 rounded-lg font-bold flex items-center justify-center gap-3 hover:bg-blue-700 transition text-base sm:text-lg shadow-lg min-w-[180px]"
81+
onClick={() => navigate('/services')}
82+
>
83+
<span className="text-3xl font-extrabold leading-none">+</span> New Service Request
84+
</button>
85+
<button
86+
onClick={() => setShowReviewPopup(true)}
87+
className="bg-green-600 text-white px-4 py-3 rounded-lg font-bold hover:bg-green-700 transition text-base sm:text-lg shadow-lg min-w-[180px]"
88+
>
89+
Leave a Review
90+
</button>
91+
</div>
8192
</div>
8293

8394
{/* Tabs */}
@@ -214,6 +225,9 @@ const Profile: React.FC = () => {
214225
</button>
215226
</div>
216227
)}
228+
229+
{/* Review Popup (from separate component) */}
230+
{showReviewPopup && <ReviewForm onClose={() => setShowReviewPopup(false)} />}
217231
</div>
218232
</div>
219233
);

0 commit comments

Comments
 (0)