|
| 1 | +'use client'; |
| 2 | + |
| 3 | +import Link from 'next/link'; |
| 4 | +import Image from 'next/image'; |
| 5 | +import React, { useState } from 'react'; |
| 6 | +import { EventProps } from '@/types'; |
| 7 | +import { useUserCtx } from '@/context/UserCtx'; |
| 8 | +import { Location, Timer1 } from 'iconsax-react'; |
| 9 | +import { convertUTCtoLocalTime } from '@/utils'; |
| 10 | +import { useExploreCtx } from '@/context/ExploreCtx'; |
| 11 | + |
| 12 | +const ExploreCard = ({ |
| 13 | + imageURL, |
| 14 | + eventID, |
| 15 | + startDate, |
| 16 | + organizerID, |
| 17 | + tickets, |
| 18 | + participants, |
| 19 | + location, |
| 20 | + title, |
| 21 | +}: EventProps) => { |
| 22 | + const [weekday, monthDay] = convertUTCtoLocalTime(startDate!); |
| 23 | + const [, , , time] = convertUTCtoLocalTime(startDate!); |
| 24 | + const { eventsSearchTerm } = useExploreCtx(); |
| 25 | + const { user } = useUserCtx(); |
| 26 | + |
| 27 | + return ( |
| 28 | + <> |
| 29 | + <Link |
| 30 | + href={organizerID === user.userID ? `/event-management/?eventid=${eventID}` : `/event/?eventid=${eventID}`} |
| 31 | + className="block border border-Grey-G80/50 dark:border-dark-two card-shadow rounded-lg hover:scale-[1.01]" |
| 32 | + > |
| 33 | + <div className="relative w-full h-[180px] rounded-t-lg overflow-hidden"> |
| 34 | + <Image src={imageURL!} fill alt="Event Image" className="object-cover" /> |
| 35 | + </div> |
| 36 | + <div className="p-4"> |
| 37 | + <div className="flex justify-between items-center mb-1 font-nunito"> |
| 38 | + <span className="font-bold text-sm text-primary-100 dark:text-dark-two "> |
| 39 | + {weekday}, {monthDay} |
| 40 | + </span> |
| 41 | + {tickets?.map((ticket) => ( |
| 42 | + <div key={ticket.ticketID}> |
| 43 | + <span className="text-primary-100 bg-secondary-100 dark:bg-dark-two dark:text-dark-one rounded block px-3 py-1 capitalize"> |
| 44 | + {ticket.ticketType === 'Free' ? 'Free' : `$${ticket.ticketPrice}`} |
| 45 | + </span> |
| 46 | + </div> |
| 47 | + ))} |
| 48 | + </div> |
| 49 | + <h2 className="text-Grey-G800 dark:text-dark-two text-lg whitespace-nowrap overflow-hidden text-ellipsis sm:text-xl font-bold pt-1 pb-2 font-montserrat"> |
| 50 | + {/* {title!} */} |
| 51 | + <strong> |
| 52 | + <span |
| 53 | + dangerouslySetInnerHTML={{ |
| 54 | + __html: title!.replace( |
| 55 | + new RegExp(`(${eventsSearchTerm})`, 'gi'), |
| 56 | + (match, group) => |
| 57 | + `<span style="color: black; background-color: ${ |
| 58 | + group.toLowerCase() === eventsSearchTerm.toLowerCase() ? 'yellow' : 'inherit' |
| 59 | + }">${match}</span>`, |
| 60 | + ), |
| 61 | + }} |
| 62 | + /> |
| 63 | + </strong> |
| 64 | + </h2> |
| 65 | + <p className="text-Grey-G500 dark:text-dark-two text-sm flex items-center gap-0.5 mb-1 font-nunito"> |
| 66 | + <Location size={16} /> |
| 67 | + <span className="font-medium">{location!}</span> |
| 68 | + </p> |
| 69 | + <p className="text-Grey-G500 dark:text-dark-two flex items-center gap-0.5 mb-2 font-nunito"> |
| 70 | + <Timer1 size={16} /> |
| 71 | + <span className="font-medium">{time}</span> |
| 72 | + </p> |
| 73 | + <div className="flex items-center font-montserrat"> |
| 74 | + {participants?.length !== 0 && ( |
| 75 | + <div className="flex items-center"> |
| 76 | + {participants?.map((item, index) => { |
| 77 | + if (index >= 3) return; |
| 78 | + return ( |
| 79 | + <div key={index} className="h-8 w-8 first:ml-0 -ml-1.5 rounded-full overflow-hidden"> |
| 80 | + <Image |
| 81 | + src={item?.profileImage ?? '/assets/avatar.png'} |
| 82 | + height={32} |
| 83 | + width={32} |
| 84 | + alt="Attendant" |
| 85 | + className="object-top object-cover" |
| 86 | + /> |
| 87 | + </div> |
| 88 | + ); |
| 89 | + })} |
| 90 | + {participants && participants?.length > 3 && ( |
| 91 | + <span className="pl-3 text-sm font-medium font-nunito"> |
| 92 | + +{participants?.length - 3} People registered |
| 93 | + </span> |
| 94 | + )} |
| 95 | + </div> |
| 96 | + )} |
| 97 | + </div> |
| 98 | + </div> |
| 99 | + </Link> |
| 100 | + </> |
| 101 | + ); |
| 102 | +}; |
| 103 | + |
| 104 | +export default ExploreCard; |
0 commit comments