Skip to content

Commit 6acaa2d

Browse files
feat: add report user functionality
1 parent c75de5a commit 6acaa2d

4 files changed

Lines changed: 129 additions & 64 deletions

File tree

firestore.rules

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
rules_version = '2';
22
service cloud.firestore {
33
match /databases/{database}/documents {
4+
match /reports/{reportId} {
5+
allow create: if request.auth != null;
6+
allow read, update, delete: if false;
7+
}
48

59
// Helper: Is the user authenticated?
610
function isAuthenticated() {

src/components/ReportModal.jsx

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
import { useState } from 'react';
2+
import { reportUser } from '../services/reportService';
3+
4+
const REASONS = ['Fake Profile', 'Spam', 'Abusive Content', 'Other'];
5+
6+
const ReportModal = ({ reportedUid, reporterUid, onClose, toast }) => {
7+
const [reason, setReason] = useState('');
8+
const [loading, setLoading] = useState(false);
9+
10+
const handleSubmit = async () => {
11+
if (!reason) return;
12+
setLoading(true);
13+
try {
14+
await reportUser(reporterUid, reportedUid, reason);
15+
toast.success('Report submitted. Thank you!');
16+
onClose();
17+
} catch (err) {
18+
toast.error(err.message);
19+
} finally {
20+
setLoading(false);
21+
}
22+
};
23+
24+
return (
25+
<div className="fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50">
26+
<div className="bg-white rounded-xl p-6 w-80 shadow-lg">
27+
<h2 className="text-lg font-semibold mb-3">Report User</h2>
28+
<p className="text-sm text-gray-500 mb-3">Select a reason:</p>
29+
30+
{REASONS.map((r) => (
31+
<label key={r} className="flex items-center gap-2 mb-2 cursor-pointer">
32+
<input
33+
type="radio"
34+
name="reason"
35+
value={r}
36+
onChange={() => setReason(r)}
37+
/>
38+
<span className="text-sm">{r}</span>
39+
</label>
40+
))}
41+
42+
<div className="flex gap-2 mt-4">
43+
<button
44+
onClick={handleSubmit}
45+
disabled={!reason || loading}
46+
className="bg-red-500 text-white px-4 py-2 rounded-lg text-sm disabled:opacity-50"
47+
>
48+
{loading ? 'Submitting...' : 'Submit'}
49+
</button>
50+
<button
51+
onClick={onClose}
52+
className="border px-4 py-2 rounded-lg text-sm"
53+
>
54+
Cancel
55+
</button>
56+
</div>
57+
</div>
58+
</div>
59+
);
60+
};
61+
62+
export default ReportModal;

0 commit comments

Comments
 (0)