turkmentv_front/components/vote/ParticipantCard.tsx

291 lines
10 KiB
TypeScript
Raw Normal View History

2025-05-07 11:05:59 +00:00
"use client";
2024-09-05 11:31:36 +00:00
2025-05-07 11:05:59 +00:00
import Image from "next/image";
import placeholder from "@/public/person placeholder.svg";
import clsx from "clsx";
import { motion, usePresence, Variant, Transition } from "framer-motion";
import RollingCounter from "react-slot-counter";
2024-08-19 12:44:56 +00:00
interface IProps {
number: number;
name: string | null;
2025-05-07 11:05:59 +00:00
description: string | null;
2024-08-19 12:44:56 +00:00
photo: string | null;
votes: number;
progress: number;
voteCode: string;
smsNumber: string;
isFirst: boolean;
voteStatus: string;
winner: boolean;
2024-09-05 11:31:36 +00:00
hasUrl: boolean;
2024-09-10 12:36:03 +00:00
index: number;
2024-08-19 12:44:56 +00:00
}
const ParticipantCard = ({
number,
name,
2025-05-07 11:05:59 +00:00
description,
2024-08-19 12:44:56 +00:00
photo,
votes,
progress,
voteCode,
2024-09-10 12:36:03 +00:00
index,
2024-09-05 11:31:36 +00:00
hasUrl,
2024-08-19 12:44:56 +00:00
isFirst,
voteStatus,
winner,
}: IProps) => {
const substractedProgress = progress > 99 ? progress - 2 : progress;
2024-09-10 12:36:03 +00:00
const transition: Transition = {
2025-05-07 11:05:59 +00:00
type: "spring",
2024-09-10 12:36:03 +00:00
stiffness: 500,
damping: 50,
mass: 1,
delay: index * 0.1,
};
const [isPresent, safeToRemove] = usePresence();
const animations = {
layout: true,
2025-05-07 11:05:59 +00:00
initial: "out",
2024-09-10 12:36:03 +00:00
style: {
2025-05-07 11:05:59 +00:00
position: (isPresent ? "static" : "absolute") as "static" | "absolute", // Corrected cast
2024-09-10 12:36:03 +00:00
},
2025-05-07 11:05:59 +00:00
animate: isPresent ? "in" : "out",
2024-09-10 12:36:03 +00:00
variants: {
in: { scaleY: 1, opacity: 1 },
out: { scaleY: 0, opacity: 0, zIndex: -1 },
tapped: { scale: 0.98, opacity: 0.5, transition: { duration: 0.1 } },
},
onAnimationComplete: () => !isPresent && safeToRemove(),
transition,
};
2024-08-19 12:44:56 +00:00
return winner && votes !== 0 ? (
2024-09-03 12:35:46 +00:00
////////////////////////////////////////////// Winner card
2024-09-10 12:36:03 +00:00
<motion.div
// {...animations}
2025-05-07 11:05:59 +00:00
className="flex flex-col overflow-hidden bg-fillNavyBlue max-w-[940px] w-full group"
>
2024-08-19 12:44:56 +00:00
<div className="flex items-center gap-[5px] sm:gap-[20px] p-[5px] pt-[10px] w-full">
<h3 className="text-[26px] sm:text-[80px] leading-[100%] font-bold text-fillNavyBlue text-stroke">
{number}
</h3>
{photo && name ? (
2024-09-03 12:35:46 +00:00
// If there an image, show image
2024-09-05 11:31:36 +00:00
<div className="relative min-w-[60px] rounded-[10px] h-[60px] sm:min-w-[140px] sm:h-[140px] overflow-hidden">
2024-08-19 12:44:56 +00:00
<Image
fill
src={photo}
alt={name}
2025-05-07 11:05:59 +00:00
className={clsx(" object-cover", {
"group-hover:scale-110 transition-all duration-300 ease-out":
hasUrl,
2024-09-05 11:31:36 +00:00
})}
2024-08-19 12:44:56 +00:00
unoptimized
unselectable="off"
/>
</div>
) : (
2024-09-03 12:35:46 +00:00
// If there is no image, show placeholder
2024-09-05 11:31:36 +00:00
<div className="relative overflow-hidden rounded-[10px] min-w-[60px] h-[60px] sm:min-w-[140px] sm:h-[140px]">
2024-08-19 12:44:56 +00:00
<Image
fill
src={placeholder}
2025-05-07 11:05:59 +00:00
alt={"placeholder"}
className={clsx(" object-cover", {
"group-hover:scale-110 transition-all duration-300 ease-out":
hasUrl,
2024-09-05 11:31:36 +00:00
})}
2024-08-19 12:44:56 +00:00
unoptimized
unselectable="off"
/>
</div>
)}
<div className="flex flex-col gap-[10px] sm:gap-[24px] w-full">
<div className="flex justify-between items-center w-full">
<div className="flex justify-between items-center sm:items-start w-full sm:w-fit sm:justify-start sm:flex-col gap-[14px]">
{name ? (
2024-09-05 11:31:36 +00:00
<h2
className={clsx(
2025-05-07 11:05:59 +00:00
"text-[18px] transition-all sm:text-[24px] leading-[100%] font-bold text-white",
2024-09-05 11:31:36 +00:00
{
// 'group-hover:text-[28px] transition-all duration-300 ease-out': hasUrl,
2025-05-07 11:05:59 +00:00
}
)}
>
2024-08-19 12:44:56 +00:00
{name}
</h2>
) : null}
2024-09-03 12:35:46 +00:00
2025-05-07 11:05:59 +00:00
{description ? (
<p
className={clsx(
"text-[14px] transition-all font-[400] text-[#B7B7D1]",
{
// 'group-hover:text-[28px] transition-all duration-300 ease-out': hasUrl,
}
)}
>
{description}
</p>
) : null}
2024-09-03 12:35:46 +00:00
{/* If we have voteCode and voting not closed, then show badge with code. Else dont show */}
2025-05-07 11:05:59 +00:00
{voteCode && voteStatus !== "closed" ? (
2024-09-03 12:35:46 +00:00
// Desktop version
<p className="hidden sm:block py-[10px] px-[8px] bg-[#1E1E7B] text-fillLightGray text-[14px] leading-[125%] max-w-[232px] rounded-[10px]">
2024-09-05 11:31:36 +00:00
Ses bermek üçin
2024-09-03 12:35:46 +00:00
<span className="inline-block w-fit px-1 py-[4px] mx-[4px] font-bold text-white text-[16px] border rounded-md">
{voteCode}
</span>
ugrat
</p>
) : null}
</div>
<div className="flex flex-col items-end gap-[8px]">
<h4 className="text-[12px] sm:text-[48px] text-white leading-[100%] font-bold">
{/* {votes ? votes : 0} */}
<RollingCounter
value={votes ? votes : 0}
startValueOnce={true}
animateOnVisible={false}
autoAnimationStart={false}
/>
2024-09-03 12:35:46 +00:00
</h4>
<h4 className="text-[12px] sm:text-[24px] text-white leading-[100%] font-bold">
ses
2024-08-19 12:44:56 +00:00
</h4>
</div>
</div>
</div>
</div>
2024-09-03 12:35:46 +00:00
{/* If we have voteCode and voting not closed, then show badge with code. Else dont show */}
2025-05-07 11:05:59 +00:00
{voteCode && voteStatus !== "closed" ? (
2024-09-03 12:35:46 +00:00
// Mobile version
2024-08-19 12:44:56 +00:00
<p className="block sm:hidden py-[10px] px-[4px] font-medium bg-[#1E1E7B] rounded-md text-fillLightGray text-[10px] leading-[125%] ">
2025-05-07 11:05:59 +00:00
Ses bermek üçin{" "}
2024-08-19 12:44:56 +00:00
<span className="inline-block w-fit px-1 py-[4px] mx-[4px] font-bold text-white text-[16px] border rounded-md">
{voteCode}
2025-05-07 11:05:59 +00:00
</span>{" "}
2024-08-19 12:44:56 +00:00
ugrat
</p>
) : null}
2024-09-10 12:36:03 +00:00
</motion.div>
2024-08-19 12:44:56 +00:00
) : (
2024-09-03 12:35:46 +00:00
////////////////////////////////////////////// Simple card
2024-09-10 12:36:03 +00:00
<motion.div
className="flex flex-col max-w-[940px] items-center w-full gap-[5px] sm:gap-[20px] group"
// {...animations}
>
2024-08-19 12:44:56 +00:00
<div className="flex items-center gap-[5px] sm:gap-[20px] max-w-[900px] w-full px-[5px] sm:p-0">
2025-05-07 11:05:59 +00:00
<h3 className="w-[24px] text-[16px] sm:text-[20px] leading-[100%] font-bold">
{number}
</h3>
2024-08-19 12:44:56 +00:00
{photo && name ? (
2024-09-05 11:31:36 +00:00
<div className="relative min-w-[50px] rounded-[10px] overflow-hidden sm:min-w-[80px] h-[50px] sm:h-[80px]">
2024-08-19 12:44:56 +00:00
<Image
fill
src={photo}
alt={name}
2025-05-07 11:05:59 +00:00
className={clsx(" object-cover", {
"group-hover:scale-110 transition-all duration-300 ease-out":
hasUrl,
2024-09-05 11:31:36 +00:00
})}
2024-08-19 12:44:56 +00:00
unoptimized
unselectable="off"
/>
</div>
) : (
2024-09-05 11:31:36 +00:00
<div className="relative min-w-[50px] sm:min-w-[80px] h-[50px] sm:h-[80px] rounded-[10px] overflow-hidden">
2024-08-19 12:44:56 +00:00
<Image
fill
src={placeholder}
2025-05-07 11:05:59 +00:00
alt={"placeholder"}
className={clsx(" object-cover", {
"group-hover:scale-110 transition-all duration-300 ease-out":
hasUrl,
2024-09-05 11:31:36 +00:00
})}
2024-08-19 12:44:56 +00:00
unoptimized
unselectable="off"
/>
</div>
)}
<div className="flex flex-col gap-[10px] sm:gap-[12px] w-full">
<div className="flex justify-between items-center w-full">
2024-09-03 12:35:46 +00:00
<div className="flex justify-between sm:justify-start sm:flex-col gap-[8px]">
2024-08-19 12:44:56 +00:00
{name ? (
2024-09-05 11:31:36 +00:00
<h2
className={clsx(
2025-05-07 11:05:59 +00:00
"text-textBlack text-[16px] sm:text-[18px] leading-[100%] font-bold"
)}
>
2024-08-19 12:44:56 +00:00
{name}
</h2>
) : null}
2025-05-07 11:05:59 +00:00
{description ? (
<p
className={clsx(
"text-[14px] transition-all font-[400] text-[#4D4D4D]",
{
// 'group-hover:text-[28px] transition-all duration-300 ease-out': hasUrl,
}
)}
>
{description}
</p>
) : null}
2024-09-03 12:35:46 +00:00
{/* If we have voteCode and voting not closed, then show badge with code. Else dont show */}
2025-05-07 11:05:59 +00:00
{voteCode && voteStatus !== "closed" ? (
2024-09-03 12:35:46 +00:00
// Desktop version
<p className="hidden sm:block py-[5px] px-[8px] bg-[#EAEAFF] text-[#9393DA] text-[14px] leading-[125%] rounded-[10px] w-fit">
Ses bermek üçin
<span className="inline-block w-fit px-1 py-[2px] mx-[4px] font-bold leading-[100%] text-fillNavyBlue text-[16px] border border-fillNavyBlue rounded-md">
{voteCode}
</span>
ugrat
</p>
) : null}
</div>
<div className="flex flex-col gap-[4px] items-end">
<h4 className="text-[12px] sm:text-[32px] text-[#808080] font-bold leading-[100%] ">
{/* {votes ? votes : 0} */}
<RollingCounter
value={votes ? votes : 0}
startValueOnce={true}
animateOnVisible={false}
autoAnimationStart={false}
/>
2024-09-03 12:35:46 +00:00
</h4>
<h4 className="text-[12px] sm:text-[16px] text-[#808080] font-bold leading-[100%] ">
ses
2024-08-19 12:44:56 +00:00
</h4>
</div>
</div>
</div>
</div>
2024-09-03 12:35:46 +00:00
{/* If we have voteCode and voting not closed, then show badge with code. Else dont show */}
2025-05-07 11:05:59 +00:00
{voteCode && voteStatus !== "closed" ? (
2024-09-03 12:35:46 +00:00
// Mobile version
2024-08-19 12:44:56 +00:00
<p className="block sm:hidden text-[#9393DA] text-[10px] leading-[125%] w-full">
2025-05-07 11:05:59 +00:00
Ses bermek üçin{" "}
2024-08-19 12:44:56 +00:00
<span className="inline-block w-fit px-1 py-[4px] leading-[100%] mx-[4px] font-bold text-fillNavyBlue text-[16px] border border-fillNavyBlue rounded-md">
{voteCode}
2025-05-07 11:05:59 +00:00
</span>{" "}
2024-08-19 12:44:56 +00:00
ugrat
</p>
) : null}
<div className="w-full h-[1px] bg-[#EDEDFA]"></div>
2024-09-10 12:36:03 +00:00
</motion.div>
2024-08-19 12:44:56 +00:00
);
};
export default ParticipantCard;