|
| 1 | +import { Progress } from '@/components/ui/progress'; |
| 2 | +import { formatNumber } from '@/lib/utils'; |
| 3 | + |
| 4 | +type ProjectCardProps = { |
| 5 | + creatorName: string; |
| 6 | + creatorLogo: string; |
| 7 | + projectImage: string; |
| 8 | + projectTitle: string; |
| 9 | + projectDescription: string; |
| 10 | + status: 'Validation' | 'Funding' | 'Funded' | 'Completed'; |
| 11 | + deadlineInDays: number; |
| 12 | + milestoneRejected?: boolean; |
| 13 | + votes?: { |
| 14 | + current: number; |
| 15 | + goal: number; |
| 16 | + }; |
| 17 | + funding?: { |
| 18 | + current: number; |
| 19 | + goal: number; |
| 20 | + currency: string; |
| 21 | + }; |
| 22 | + milestones?: { |
| 23 | + current: number; |
| 24 | + goal: number; |
| 25 | + }; |
| 26 | +}; |
| 27 | +function ProjectCard({ |
| 28 | + creatorName, |
| 29 | + creatorLogo, |
| 30 | + projectImage, |
| 31 | + projectTitle, |
| 32 | + projectDescription, |
| 33 | + status, |
| 34 | + deadlineInDays, |
| 35 | + milestoneRejected, |
| 36 | + votes, |
| 37 | + funding, |
| 38 | + milestones, |
| 39 | +}: ProjectCardProps) { |
| 40 | + const getStatusStyles = () => { |
| 41 | + switch (status) { |
| 42 | + case 'Funding': |
| 43 | + return 'bg-blue-ish border-blue-ish-darker text-blue-ish-darker'; |
| 44 | + case 'Funded': |
| 45 | + return 'bg-transparent border-primary text-primary'; |
| 46 | + case 'Completed': |
| 47 | + return 'bg-success-green border-success-green-darker text-success-green-darker'; |
| 48 | + case 'Validation': |
| 49 | + return 'bg-warning-orange border-warning-orange-darker text-warning-orange-darker'; |
| 50 | + default: |
| 51 | + return ''; |
| 52 | + } |
| 53 | + }; |
| 54 | + |
| 55 | + const getDeadlineInfo = () => { |
| 56 | + if (status === 'Completed' && milestoneRejected) { |
| 57 | + return { |
| 58 | + text: '1 Milestone Rejected', |
| 59 | + className: 'text-red-500', |
| 60 | + }; |
| 61 | + } |
| 62 | + |
| 63 | + if (deadlineInDays <= 3) { |
| 64 | + return { |
| 65 | + text: `${deadlineInDays} days to deadline`, |
| 66 | + className: 'text-error-status', |
| 67 | + }; |
| 68 | + } |
| 69 | + |
| 70 | + if (deadlineInDays <= 15) { |
| 71 | + return { |
| 72 | + text: `${deadlineInDays} days to deadline`, |
| 73 | + className: 'text-warning-orange-darker', |
| 74 | + }; |
| 75 | + } |
| 76 | + |
| 77 | + return { |
| 78 | + text: `${deadlineInDays} days to deadline`, |
| 79 | + className: 'text-success-green-darker', |
| 80 | + }; |
| 81 | + }; |
| 82 | + |
| 83 | + const deadlineInfo = getDeadlineInfo(); |
| 84 | + |
| 85 | + return ( |
| 86 | + <main className='w-[397px] flex flex-col gap-4 p-5 rounded-[8px] bg-[#030303] border border-gray-900 font-inter hover:bg-primary/5 hover:border-primary/25 cursor-pointer'> |
| 87 | + <header className='flex items-center justify-between'> |
| 88 | + <main className='flex items-center gap-2'> |
| 89 | + <div |
| 90 | + style={{ backgroundImage: `url(${creatorLogo})` }} |
| 91 | + className='size-6 rounded-full bg-white bg-cover bg-center' |
| 92 | + ></div> |
| 93 | + <h4 className='font-normal text-sm text-gray-500'>{creatorName}</h4> |
| 94 | + </main> |
| 95 | + <main className='flex items-center gap-3'> |
| 96 | + <div className='w-[63px] px-1 py-0.5 rounded-[4px] bg-office-brown border border-office-brown-darker text-office-brown-darker font-semibold text-xs flex items-center justify-center '> |
| 97 | + Category |
| 98 | + </div> |
| 99 | + <div |
| 100 | + className={`px-1 py-0.5 rounded-[4px] ${getStatusStyles()} border font-semibold text-xs flex items-center justify-center `} |
| 101 | + > |
| 102 | + {status} |
| 103 | + </div> |
| 104 | + </main> |
| 105 | + </header> |
| 106 | + <article className='flex items-center gap-5'> |
| 107 | + <main |
| 108 | + style={{ backgroundImage: `url(${projectImage})` }} |
| 109 | + className='bg-white w-[79.41px] h-[90px] rounded-[8px] bg-cover bg-center' |
| 110 | + ></main> |
| 111 | + <main className='flex flex-col gap-2 w-[257px]'> |
| 112 | + <h2 className='font-semibold text-base text-white text-left'> |
| 113 | + {projectTitle} |
| 114 | + </h2> |
| 115 | + <div className='relative h-[60px] group'> |
| 116 | + <p className='font-normal text-sm text-white text-left line-clamp-3 cursor-pointer group-hover:absolute group-hover:z-10 group-hover:bg-[#030303] group-hover:rounded-md group-hover:line-clamp-none group-hover:w-full'> |
| 117 | + {projectDescription} |
| 118 | + </p> |
| 119 | + </div> |
| 120 | + </main> |
| 121 | + </article> |
| 122 | + <footer className='flex flex-col gap-2'> |
| 123 | + <main className='flex items-center justify-between'> |
| 124 | + {status === 'Validation' && votes && ( |
| 125 | + <h3 className='font-medium text-sm text-[#f5f5f5]'> |
| 126 | + {formatNumber(votes.current)}/{formatNumber(votes.goal)}{' '} |
| 127 | + <span className='text-gray-500'>Votes</span> |
| 128 | + </h3> |
| 129 | + )} |
| 130 | + {status === 'Funding' && funding && ( |
| 131 | + <h3 className='font-medium text-sm text-[#f5f5f5]'> |
| 132 | + {formatNumber(funding.current)}/{formatNumber(funding.goal)}{' '} |
| 133 | + <span className='text-gray-500'>{funding.currency} raised</span> |
| 134 | + </h3> |
| 135 | + )} |
| 136 | + {(status === 'Funded' || status === 'Completed') && milestones && ( |
| 137 | + <h3 className='font-medium text-sm text-[#f5f5f5]'> |
| 138 | + {milestones.current}/{milestones.goal}{' '} |
| 139 | + <span className='text-gray-500'>Milestones Submitted</span> |
| 140 | + </h3> |
| 141 | + )} |
| 142 | + |
| 143 | + <h3 className={`font-medium text-sm ${deadlineInfo.className}`}> |
| 144 | + {deadlineInfo.text} |
| 145 | + </h3> |
| 146 | + </main> |
| 147 | + <div> |
| 148 | + <Progress |
| 149 | + value={ |
| 150 | + status === 'Validation' |
| 151 | + ? votes |
| 152 | + ? (votes.current / votes.goal) * 100 |
| 153 | + : 0 |
| 154 | + : status === 'Funding' |
| 155 | + ? funding |
| 156 | + ? (funding.current / funding.goal) * 100 |
| 157 | + : 0 |
| 158 | + : milestones |
| 159 | + ? (milestones.current / milestones.goal) * 100 |
| 160 | + : 0 |
| 161 | + } |
| 162 | + className='w-[357px] h-2 rounded-full' |
| 163 | + /> |
| 164 | + </div> |
| 165 | + </footer> |
| 166 | + </main> |
| 167 | + ); |
| 168 | +} |
| 169 | + |
| 170 | +export default ProjectCard; |
0 commit comments