From 4a120129e7ec63547174850401775314c7054f28 Mon Sep 17 00:00:00 2001 From: DhruvPatel16120 Date: Thu, 18 Jun 2026 22:25:18 +0530 Subject: [PATCH 1/2] add reportinfo page --- src/pages/ReportInfo.tsx | 191 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 191 insertions(+) create mode 100644 src/pages/ReportInfo.tsx diff --git a/src/pages/ReportInfo.tsx b/src/pages/ReportInfo.tsx new file mode 100644 index 0000000..1cc4d93 --- /dev/null +++ b/src/pages/ReportInfo.tsx @@ -0,0 +1,191 @@ +import React, { useEffect, useState } from 'react'; +import { useParams, useNavigate } from 'react-router-dom'; +import { auth } from '../lib/firebase'; +import { getFirestore, doc, getDoc, collection, addDoc, serverTimestamp } from 'firebase/firestore'; +import { toast } from 'react-hot-toast'; +import { Loader2, ArrowLeft, ShieldAlert } from 'lucide-react'; + +const db = getFirestore(); + +const REPORT_CATEGORIES = [ + 'Harassment', + 'Hate Speech', + 'Inappropriate Media', + 'Spam', + 'Doxxing' +]; + +export default function ReportInfo() { + const { id } = useParams<{ id: string }>(); + const navigate = useNavigate(); + const [storyTitle, setStoryTitle] = useState(''); + const [storyContent, setStoryContent] = useState(''); + const [loadingStory, setLoadingStory] = useState(true); + const [submitting, setSubmitting] = useState(false); + const [reason, setReason] = useState(''); + const [details, setDetails] = useState(''); + const [user, setUser] = useState(auth.currentUser); + + useEffect(() => { + const unsubscribe = auth.onAuthStateChanged((currentUser) => { + setUser(currentUser); + if (!currentUser) { + toast.error('Please sign in to report a story'); + navigate('/auth'); + } + }); + return () => unsubscribe(); + }, [navigate]); + + useEffect(() => { + const fetchStory = async () => { + if (!id) return; + try { + const storyDoc = await getDoc(doc(db, 'stories', id)); + if (storyDoc.exists()) { + setStoryTitle(storyDoc.data().title || ''); + setStoryContent(storyDoc.data().content || ''); + } else { + toast.error('Story not found'); + navigate('/stories'); + } + } catch (error) { + console.error('Error fetching story:', error); + toast.error('Failed to load story details'); + navigate('/stories'); + } finally { + setLoadingStory(false); + } + }; + + fetchStory(); + }, [id, navigate]); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + if (!reason) { + toast.error('Please select a reason for reporting'); + return; + } + + if (!user) { + toast.error('Please sign in to report a story'); + navigate('/auth'); + return; + } + + setSubmitting(true); + try { + await addDoc(collection(db, 'reports'), { + story_id: id, + story_title: storyTitle, + reason, + details, + reported_at: serverTimestamp(), + user_id: user.uid, + status: 'pending' + }); + + toast.success('Story reported. Thank you for keeping SafeVoice safe.'); + navigate('/stories'); + } catch (error) { + console.error('Error submitting report:', error); + toast.error('Failed to submit report. Please try again.'); + } finally { + setSubmitting(false); + } + }; + + if (loadingStory) { + return ( +
+ +

Loading story details...

+
+ ); + } + + return ( +
+ + +
+
+
+ +
+
+

Report Story

+

Help us keep our community safe and supportive.

+
+
+ + {/* Story Preview */} +
+ Story Title +

{storyTitle}

+

{storyContent}

+
+ +
+ {/* Reason Selection */} +
+ + +
+ + {/* Additional Details */} +
+ +