Skip to content

Commit d77b365

Browse files
authored
Merge pull request #19 from MYSTICxSAM/review
Made review button and form
2 parents b3cc3b4 + 638f821 commit d77b365

4 files changed

Lines changed: 271 additions & 8 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/integrations/supabase/types.ts

Lines changed: 154 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ export type Json =
77
| Json[]
88

99
export type Database = {
10-
// Allows to automatically instanciate createClient with right options
10+
// Allows to automatically instantiate createClient with right options
1111
// instead of createClient<Database, { PostgrestVersion: 'XX' }>(URL, KEY)
1212
__InternalSupabase: {
1313
PostgrestVersion: "12.2.3 (519615d)"
@@ -20,20 +20,23 @@ export type Database = {
2020
content: string
2121
created_at: string | null
2222
id: string
23+
image_url: string | null
2324
title: string
2425
}
2526
Insert: {
2627
author_id?: string | null
2728
content: string
2829
created_at?: string | null
2930
id?: string
31+
image_url?: string | null
3032
title: string
3133
}
3234
Update: {
3335
author_id?: string | null
3436
content?: string
3537
created_at?: string | null
3638
id?: string
39+
image_url?: string | null
3740
title?: string
3841
}
3942
Relationships: [
@@ -46,6 +49,93 @@ export type Database = {
4649
},
4750
]
4851
}
52+
Contractors: {
53+
Row: {
54+
created_at: string
55+
Description: string | null
56+
id: number
57+
Location: string | null
58+
Name: string | null
59+
Payments: string | null
60+
"Phone No": number | null
61+
"Project Details": string | null
62+
}
63+
Insert: {
64+
created_at?: string
65+
Description?: string | null
66+
id?: number
67+
Location?: string | null
68+
Name?: string | null
69+
Payments?: string | null
70+
"Phone No"?: number | null
71+
"Project Details"?: string | null
72+
}
73+
Update: {
74+
created_at?: string
75+
Description?: string | null
76+
id?: number
77+
Location?: string | null
78+
Name?: string | null
79+
Payments?: string | null
80+
"Phone No"?: number | null
81+
"Project Details"?: string | null
82+
}
83+
Relationships: []
84+
}
85+
Financial: {
86+
Row: {
87+
created_at: string
88+
Description: string | null
89+
id: number
90+
Income: number | null
91+
Name: string | null
92+
Profit: number | null
93+
TranIN: string[] | null
94+
TranOut: string[] | null
95+
UserRequestID: number | null
96+
WorkersID: number | null
97+
}
98+
Insert: {
99+
created_at?: string
100+
Description?: string | null
101+
id: number
102+
Income?: number | null
103+
Name?: string | null
104+
Profit?: number | null
105+
TranIN?: string[] | null
106+
TranOut?: string[] | null
107+
UserRequestID?: number | null
108+
WorkersID?: number | null
109+
}
110+
Update: {
111+
created_at?: string
112+
Description?: string | null
113+
id?: number
114+
Income?: number | null
115+
Name?: string | null
116+
Profit?: number | null
117+
TranIN?: string[] | null
118+
TranOut?: string[] | null
119+
UserRequestID?: number | null
120+
WorkersID?: number | null
121+
}
122+
Relationships: [
123+
{
124+
foreignKeyName: "Financial_UserRequestID_fkey"
125+
columns: ["UserRequestID"]
126+
isOneToOne: false
127+
referencedRelation: "User Request"
128+
referencedColumns: ["id"]
129+
},
130+
{
131+
foreignKeyName: "Financial_WorkersID_fkey"
132+
columns: ["WorkersID"]
133+
isOneToOne: false
134+
referencedRelation: "GoBuild"
135+
referencedColumns: ["id"]
136+
},
137+
]
138+
}
49139
GoBuild: {
50140
Row: {
51141
Age: number | null
@@ -57,6 +147,7 @@ export type Database = {
57147
MobileNo: string
58148
Name: string | null
59149
Skill: string | null
150+
WorkerCode: string | null
60151
}
61152
Insert: {
62153
Age?: number | null
@@ -68,6 +159,7 @@ export type Database = {
68159
MobileNo: string
69160
Name?: string | null
70161
Skill?: string | null
162+
WorkerCode?: string | null
71163
}
72164
Update: {
73165
Age?: number | null
@@ -79,12 +171,14 @@ export type Database = {
79171
MobileNo?: string
80172
Name?: string | null
81173
Skill?: string | null
174+
WorkerCode?: string | null
82175
}
83176
Relationships: []
84177
}
85178
"Material Suppliers": {
86179
Row: {
87180
created_at: string
181+
History: string | null
88182
id: number
89183
Location: string | null
90184
Name: string | null
@@ -93,6 +187,7 @@ export type Database = {
93187
}
94188
Insert: {
95189
created_at?: string
190+
History?: string | null
96191
id?: number
97192
Location?: string | null
98193
Name?: string | null
@@ -101,6 +196,7 @@ export type Database = {
101196
}
102197
Update: {
103198
created_at?: string
199+
History?: string | null
104200
id?: number
105201
Location?: string | null
106202
Name?: string | null
@@ -109,12 +205,43 @@ export type Database = {
109205
}
110206
Relationships: []
111207
}
208+
"Monthly Workers": {
209+
Row: {
210+
Attendence: number | null
211+
created_at: string
212+
id: number
213+
Location: string | null
214+
Name: string | null
215+
Payment: number | null
216+
PhoneNo: number | null
217+
}
218+
Insert: {
219+
Attendence?: number | null
220+
created_at?: string
221+
id?: number
222+
Location?: string | null
223+
Name?: string | null
224+
Payment?: number | null
225+
PhoneNo?: number | null
226+
}
227+
Update: {
228+
Attendence?: number | null
229+
created_at?: string
230+
id?: number
231+
Location?: string | null
232+
Name?: string | null
233+
Payment?: number | null
234+
PhoneNo?: number | null
235+
}
236+
Relationships: []
237+
}
112238
profiles: {
113239
Row: {
114240
avatar_url: string | null
115241
created_at: string
116242
full_name: string | null
117243
id: string
244+
PhoneNo: number | null
118245
updated_at: string
119246
user_role: string
120247
}
@@ -123,6 +250,7 @@ export type Database = {
123250
created_at?: string
124251
full_name?: string | null
125252
id: string
253+
PhoneNo?: number | null
126254
updated_at?: string
127255
user_role?: string
128256
}
@@ -131,11 +259,36 @@ export type Database = {
131259
created_at?: string
132260
full_name?: string | null
133261
id?: string
262+
PhoneNo?: number | null
134263
updated_at?: string
135264
user_role?: string
136265
}
137266
Relationships: []
138267
}
268+
Review: {
269+
Row: {
270+
created_at: string
271+
"Customer Name": string
272+
"Customer Review": string | null
273+
id: number
274+
Rating: number
275+
}
276+
Insert: {
277+
created_at?: string
278+
"Customer Name": string
279+
"Customer Review"?: string | null
280+
id?: number
281+
Rating: number
282+
}
283+
Update: {
284+
created_at?: string
285+
"Customer Name"?: string
286+
"Customer Review"?: string | null
287+
id?: number
288+
Rating?: number
289+
}
290+
Relationships: []
291+
}
139292
"User Request": {
140293
Row: {
141294
created_at: string

0 commit comments

Comments
 (0)