From 9152bb818b38ea64a903562bb985ab75014fa3dc Mon Sep 17 00:00:00 2001 From: pradeepkumar Date: Thu, 5 Mar 2026 05:37:10 +0530 Subject: [PATCH] refactor: Consolidate testimonial display into a single sortable list with dynamic sorting, replacing separate latest and oldest sections. --- src/components/settings/TestimonialsForm.tsx | 98 ++++++++------------ 1 file changed, 38 insertions(+), 60 deletions(-) diff --git a/src/components/settings/TestimonialsForm.tsx b/src/components/settings/TestimonialsForm.tsx index 1decf59..56790f8 100644 --- a/src/components/settings/TestimonialsForm.tsx +++ b/src/components/settings/TestimonialsForm.tsx @@ -52,29 +52,26 @@ function TestimonialCard({ testimonial }: { testimonial: Testimonial }) { export function TestimonialsForm() { const [copied, setCopied] = useState(false); const [testimonialLink, setTestimonialLink] = useState(''); - const [latestTestimonials, setLatestTestimonials] = useState([]); - const [oldestTestimonials, setOldestTestimonials] = useState([]); + const [testimonials, setTestimonials] = useState([]); + const [sortOrder, setSortOrder] = useState<'latest' | 'oldest'>('latest'); const [loading, setLoading] = useState(true); const [generating, setGenerating] = useState(false); - useEffect(() => { - const fetchTestimonials = async () => { - try { - const [latest, oldest] = await Promise.all([ - testimonialsService.getMyTestimonials('latest'), - testimonialsService.getMyTestimonials('oldest'), - ]); - setLatestTestimonials(latest); - setOldestTestimonials(oldest); - } catch (err) { - console.error('Failed to fetch testimonials:', err); - } finally { - setLoading(false); - } - }; + const fetchTestimonials = async (sort: 'latest' | 'oldest') => { + try { + setLoading(true); + const data = await testimonialsService.getMyTestimonials(sort); + setTestimonials(data); + } catch (err) { + console.error('Failed to fetch testimonials:', err); + } finally { + setLoading(false); + } + }; - fetchTestimonials(); - }, []); + useEffect(() => { + fetchTestimonials(sortOrder); + }, [sortOrder]); const handleGenerateLink = async () => { try { @@ -156,12 +153,12 @@ export function TestimonialsForm() { - {/* Testimonials Columns */} + {/* Testimonials */} {loading ? (
- ) : latestTestimonials.length === 0 ? ( + ) : testimonials.length === 0 ? (

No testimonials yet @@ -171,45 +168,26 @@ export function TestimonialsForm() {

) : ( -
- {/* Latest Column */} -
-
- - Sort By : Latest - - -
-
- {latestTestimonials.map((testimonial) => ( - - ))} -
-
- - {/* Oldest Column */} -
-
- - Sort By : Oldest - - -
-
- {oldestTestimonials.map((testimonial) => ( - - ))} -
+
+ +
+ {testimonials.map((testimonial) => ( + + ))}
)}