All files / src/pages Testimonials.jsx

84.61% Statements 11/13
100% Branches 4/4
71.42% Functions 5/7
90.9% Lines 10/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227                  2x                           5x 5x   5x                                                                                                                                                                                                                                 5x   5x         5x                         15x         40x                                                                                             1x                              
import {useState} from "react";
import {useTranslation} from "react-i18next";
import {Disclosure} from "@headlessui/react";
import {ChevronDown} from "lucide-react";
import {Card} from "../components/ui/Card";
import {CardContent} from "../components/ui/CardContent";
import PageSection from "../components/ui/PageSection";
import {AnimatePresence, motion} from "framer-motion";
 
const ITEMS_PER_PAGE = 3;
 
/**
 * Testimonials component renders a paginated list of testimonial cards.
 * Each card displays the name, role, and a collapsible quote of a person.
 * Pagination allows browsing through all testimonials, showing a fixed number per page.
 *
 * Uses translations for all textual content via react-i18next.
 *
 * @component
 * @module pages/Testimonials
 * @returns {JSX.Element} The Testimonials section with pagination and collapsible testimonial cards.
 */
export default function Testimonials() {
    const {t} = useTranslation();
    const [currentPage, setCurrentPage] = useState(1);
 
    const testimonials = [
        {
            nameKey: "testimonials_people.mirko.name",
            roleKey: "testimonials_people.mirko.role",
            quoteKey: "testimonials_people.mirko.quote"
        },
        {
            nameKey: "testimonials_people.alessia.name",
            roleKey: "testimonials_people.alessia.role",
            quoteKey: "testimonials_people.alessia.quote"
        },
        {
            nameKey: "testimonials_people.federico.name",
            roleKey: "testimonials_people.federico.role",
            quoteKey: "testimonials_people.federico.quote"
        },
        {
            nameKey: "testimonials_people.daniela.name",
            roleKey: "testimonials_people.daniela.role",
            quoteKey: "testimonials_people.daniela.quote"
        },
        {
            nameKey: "testimonials_people.fabio.name",
            roleKey: "testimonials_people.fabio.role",
            quoteKey: "testimonials_people.fabio.quote"
        },
        {
            nameKey: "testimonials_people.antonio.name",
            roleKey: "testimonials_people.antonio.role",
            quoteKey: "testimonials_people.antonio.quote"
        },
        {
            nameKey: "testimonials_people.andreaM.name",
            roleKey: "testimonials_people.andreaM.role",
            quoteKey: "testimonials_people.andreaM.quote"
        },
        {
            nameKey: "testimonials_people.francescaM.name",
            roleKey: "testimonials_people.francescaM.role",
            quoteKey: "testimonials_people.francescaM.quote"
        },
        {
            nameKey: "testimonials_people.luca.name",
            roleKey: "testimonials_people.luca.role",
            quoteKey: "testimonials_people.luca.quote"
        },
        {
            nameKey: "testimonials_people.antonino.name",
            roleKey: "testimonials_people.antonino.role",
            quoteKey: "testimonials_people.antonino.quote"
        },
        {
            nameKey: "testimonials_people.romolo.name",
            roleKey: "testimonials_people.romolo.role",
            quoteKey: "testimonials_people.romolo.quote"
        },
        {
            nameKey: "testimonials_people.riccardo.name",
            roleKey: "testimonials_people.riccardo.role",
            quoteKey: "testimonials_people.riccardo.quote"
        },
        {
            nameKey: "testimonials_people.lucaC.name",
            roleKey: "testimonials_people.lucaC.role",
            quoteKey: "testimonials_people.lucaC.quote"
        },
        {
            nameKey: "testimonials_people.ivan.name",
            roleKey: "testimonials_people.ivan.role",
            quoteKey: "testimonials_people.ivan.quote"
        },
        {
            nameKey: "testimonials_people.daniele.name",
            roleKey: "testimonials_people.daniele.role",
            quoteKey: "testimonials_people.daniele.quote"
        },
        {
            nameKey: "testimonials_people.marco.name",
            roleKey: "testimonials_people.marco.role",
            quoteKey: "testimonials_people.marco.quote"
        },
        {
            nameKey: "testimonials_people.raffaele.name",
            roleKey: "testimonials_people.raffaele.role",
            quoteKey: "testimonials_people.raffaele.quote"
        },
        {
            nameKey: "testimonials_people.francescaR.name",
            roleKey: "testimonials_people.francescaR.role",
            quoteKey: "testimonials_people.francescaR.quote"
        },
        {
            nameKey: "testimonials_people.mattia.name",
            roleKey: "testimonials_people.mattia.role",
            quoteKey: "testimonials_people.mattia.quote"
        },
        {
            nameKey: "testimonials_people.davide.name",
            roleKey: "testimonials_people.davide.role",
            quoteKey: "testimonials_people.davide.quote"
        },
        {
            nameKey: "testimonials_people.jacopo.name",
            roleKey: "testimonials_people.jacopo.role",
            quoteKey: "testimonials_people.jacopo.quote"
        },
        {
            nameKey: "testimonials_people.yuri.name",
            roleKey: "testimonials_people.yuri.role",
            quoteKey: "testimonials_people.yuri.quote"
        }
    ];
 
    const totalPages = Math.ceil(testimonials.length / ITEMS_PER_PAGE);
 
    const displayedTestimonials = testimonials.slice(
        (currentPage - 1) * ITEMS_PER_PAGE,
        currentPage * ITEMS_PER_PAGE
    );
 
    return (
        <PageSection title={t("testimonials_page.title")}>
 
            <AnimatePresence mode="wait">
                <motion.div
                    key={`page-${currentPage}`}
                    initial={{opacity: 0, y: 40}}
                    animate={{opacity: 1, y: 0}}
                    exit={{opacity: 0, y: -40}}
                    transition={{duration: 0.4}}
                    className="flex flex-wrap gap-6"
                >
                    {displayedTestimonials.map((testi, idx) => (
                        <Card key={idx}
                              className="bg-white dark:bg-gray-900 border border-gray-200 dark:border-gray-700 shadow-sm">
                            <CardContent>
                                <Disclosure>
                                    {({open}) => (
                                        <>
                                            <Disclosure.Button
                                                className="flex justify-between w-full items-center text-left">
                                                <div className="flex items-center space-x-4">
                                                    <img
                                                        src={`https://api.dicebear.com/7.x/bottts/svg?seed=${encodeURIComponent(t(testi.nameKey))}`}
                                                        alt={`${t(testi.nameKey)} avatar`}
                                                        className="w-10 h-10 rounded-full ring-1 ring-gray-300 dark:ring-gray-700 bg-white"
                                                    />
                                                    <div>
                                                        <p className="font-semibold">{t(testi.nameKey)}</p>
                                                        <p className="text-sm text-gray-500 dark:text-gray-400">{t(testi.roleKey)}</p>
                                                    </div>
                                                </div>
                                                <ChevronDown
                                                    className={`h-5 w-5 transform ${open ? "rotate-180" : ""}`}/>
                                            </Disclosure.Button>
                                            <Disclosure.Panel className="mt-2 text-sm text-gray-700 dark:text-gray-300">
                                                {t(testi.quoteKey)}
                                            </Disclosure.Panel>
                                        </>
                                    )}
                                </Disclosure>
                            </CardContent>
                        </Card>
                    ))}
                </motion.div>
            </AnimatePresence>
 
            {/* Pagination Controls */}
            {totalPages > 1 && (
                <div className="flex justify-center mt-8 space-x-4">
                    <button
                        onClick={() => setCurrentPage(p => Math.max(p - 1, 1))}
                        disabled={currentPage === 1}
                        className="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium
                           text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-900
                           hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50 transition"
                    >
                        ← {t("testimonials_page.prev")}
                    </button>
 
                    <span className="px-4 py-2 text-sm text-gray-600 dark:text-gray-300">
                        {currentPage} / {totalPages}
                    </span>
 
                    <button
                        onClick={() => setCurrentPage(p => Math.min(p + 1, totalPages))}
                        disabled={currentPage === totalPages}
                        className="px-4 py-2 border border-gray-300 dark:border-gray-600 rounded-md text-sm font-medium
                           text-gray-800 dark:text-gray-200 bg-white dark:bg-gray-900
                           hover:bg-gray-100 dark:hover:bg-gray-800 disabled:opacity-50 transition"
                    >
                        {t("testimonials_page.next")} →
                    </button>
                </div>
            )}
 
 
        </PageSection>
    );
}