|
| 1 | +import { motion } from 'framer-motion'; |
| 2 | +import SectionContainer from '@/components/shared/SectionContainer'; |
| 3 | +import SectionTitle from '@/components/shared/SectionTitle'; |
| 4 | +import { |
| 5 | + goals, |
| 6 | + progressItems, |
| 7 | + sectionContent, |
| 8 | +} from '@/constants/aboutUs/goals'; |
| 9 | +import { |
| 10 | + slideInLeft, |
| 11 | + subtleRise, |
| 12 | + statCard, |
| 13 | + staggerContainer, |
| 14 | + container, |
| 15 | + statGrid, |
| 16 | +} from '@/styles/Animations'; |
| 17 | +import { useMemo, FC } from 'react'; |
| 18 | + |
| 19 | +interface GoalStat { |
| 20 | + total: number; |
| 21 | + completed: number; |
| 22 | + inProgress: number; |
| 23 | + percentComplete: number; |
| 24 | +} |
| 25 | + |
| 26 | +const GoalsSection: FC = () => { |
| 27 | + const renderProgressBars = (items) => { |
| 28 | + return items.map((item, index) => ( |
| 29 | + <motion.div |
| 30 | + key={index} |
| 31 | + className="mb-6" |
| 32 | + custom={index} |
| 33 | + viewport={{ once: true }} |
| 34 | + > |
| 35 | + <div className="flex justify-between mb-1"> |
| 36 | + <span className="text-sm font-medium text-gray-700"> |
| 37 | + {item.label} |
| 38 | + </span> |
| 39 | + <span className="text-sm font-medium text-gray-700"> |
| 40 | + {item.percent}% |
| 41 | + </span> |
| 42 | + </div> |
| 43 | + <div className="w-full bg-gray-200 rounded-full h-2.5"> |
| 44 | + <motion.div |
| 45 | + className={`h-2.5 rounded-full bg-gradient-to-r ${item.color}`} |
| 46 | + initial={{ width: 0 }} |
| 47 | + whileInView={{ width: `${item.percent}%` }} |
| 48 | + viewport={{ once: true }} |
| 49 | + transition={{ duration: 1, delay: index * 0.2 }} |
| 50 | + ></motion.div> |
| 51 | + </div> |
| 52 | + </motion.div> |
| 53 | + )); |
| 54 | + }; |
| 55 | + |
| 56 | + // Memoize the goal stats for performance |
| 57 | + const goalStats: GoalStat = useMemo(() => { |
| 58 | + const totalGoals = goals.length; |
| 59 | + const completedGoals = progressItems.filter( |
| 60 | + (item) => item.percent >= 75, |
| 61 | + ).length; |
| 62 | + const inProgressGoals = progressItems.filter( |
| 63 | + (item) => item.percent >= 25 && item.percent < 75, |
| 64 | + ).length; |
| 65 | + |
| 66 | + return { |
| 67 | + total: totalGoals, |
| 68 | + completed: completedGoals, |
| 69 | + inProgress: inProgressGoals, |
| 70 | + percentComplete: Math.round((completedGoals / totalGoals) * 100), |
| 71 | + }; |
| 72 | + }, []); |
| 73 | + |
| 74 | + return ( |
| 75 | + <> |
| 76 | + <SectionTitle> |
| 77 | + {sectionContent.title.main} |
| 78 | + <span className="text-red-500">{sectionContent.title.highlight}</span> |
| 79 | + </SectionTitle> |
| 80 | + <SectionContainer id="goals"> |
| 81 | + <div className="flex flex-col md:flex-row gap-8 w-full"> |
| 82 | + <div className="md:w-1/2"> |
| 83 | + <div className="space-y-6"> |
| 84 | + <motion.p |
| 85 | + className="text-base md:text-lg text-gray-700 leading-relaxed" |
| 86 | + variants={subtleRise} |
| 87 | + initial="hidden" |
| 88 | + whileInView="visible" |
| 89 | + viewport={{ once: true }} |
| 90 | + > |
| 91 | + {sectionContent.introduction} |
| 92 | + </motion.p> |
| 93 | + |
| 94 | + {/* Dynamic goals rendering from goals array */} |
| 95 | + <motion.div |
| 96 | + className="space-y-4" |
| 97 | + variants={staggerContainer} |
| 98 | + initial="hidden" |
| 99 | + whileInView="visible" |
| 100 | + viewport={{ once: true }} |
| 101 | + > |
| 102 | + {goals.map((goal, i) => ( |
| 103 | + <motion.div |
| 104 | + key={i} |
| 105 | + className="p-6 border-l-4 border-red-500 bg-white rounded-lg shadow-sm |
| 106 | + hover:shadow-lg transition-all duration-300" |
| 107 | + variants={slideInLeft} |
| 108 | + custom={i} |
| 109 | + whileHover={{ x: 10, backgroundColor: '#fef2f2' }} |
| 110 | + > |
| 111 | + <h4 className="font-bold text-gray-800 text-lg mb-2"> |
| 112 | + {goal.title} |
| 113 | + </h4> |
| 114 | + <p className="text-gray-600 leading-relaxed"> |
| 115 | + {goal.description} |
| 116 | + </p> |
| 117 | + </motion.div> |
| 118 | + ))} |
| 119 | + </motion.div> |
| 120 | + </div> |
| 121 | + </div> |
| 122 | + |
| 123 | + <div className="md:w-1/2"> |
| 124 | + <motion.div |
| 125 | + className="rounded-xl p-6 bg-white border-2 border-gray-100 shadow-lg" |
| 126 | + variants={subtleRise} |
| 127 | + initial="hidden" |
| 128 | + whileInView="visible" |
| 129 | + viewport={{ once: true }} |
| 130 | + > |
| 131 | + {/* Progress Overview */} |
| 132 | + <div className="mb-8"> |
| 133 | + <h3 className="text-xl font-bold text-gray-800 mb-4"> |
| 134 | + {sectionContent.progressTitle} |
| 135 | + </h3> |
| 136 | + |
| 137 | + {/* Progress summary stats */} |
| 138 | + <motion.div |
| 139 | + className="grid grid-cols-2 md:grid-cols-4 gap-4 mb-6" |
| 140 | + variants={statGrid} |
| 141 | + initial="hidden" |
| 142 | + whileInView="visible" |
| 143 | + viewport={{ once: true }} |
| 144 | + > |
| 145 | + <motion.div |
| 146 | + className="bg-red-50 p-4 rounded-lg text-center" |
| 147 | + variants={statCard} |
| 148 | + whileHover="hover" |
| 149 | + > |
| 150 | + <p className="text-3xl font-bold text-red-500"> |
| 151 | + {goalStats.total} |
| 152 | + </p> |
| 153 | + <p className="text-sm text-gray-600">Total Goals</p> |
| 154 | + </motion.div> |
| 155 | + |
| 156 | + <motion.div |
| 157 | + className="bg-green-50 p-4 rounded-lg text-center" |
| 158 | + variants={statCard} |
| 159 | + whileHover="hover" |
| 160 | + > |
| 161 | + <p className="text-3xl font-bold text-green-500"> |
| 162 | + {goalStats.completed} |
| 163 | + </p> |
| 164 | + <p className="text-sm text-gray-600">Completed</p> |
| 165 | + </motion.div> |
| 166 | + |
| 167 | + <motion.div |
| 168 | + className="bg-yellow-50 p-4 rounded-lg text-center" |
| 169 | + variants={statCard} |
| 170 | + whileHover="hover" |
| 171 | + > |
| 172 | + <p className="text-3xl font-bold text-yellow-500"> |
| 173 | + {goalStats.inProgress} |
| 174 | + </p> |
| 175 | + <p className="text-sm text-gray-600">In Progress</p> |
| 176 | + </motion.div> |
| 177 | + |
| 178 | + <motion.div |
| 179 | + className="bg-blue-50 p-4 rounded-lg text-center" |
| 180 | + variants={statCard} |
| 181 | + whileHover="hover" |
| 182 | + > |
| 183 | + <p className="text-3xl font-bold text-blue-500"> |
| 184 | + {goalStats.percentComplete}% |
| 185 | + </p> |
| 186 | + <p className="text-sm text-gray-600">Overall Progress</p> |
| 187 | + </motion.div> |
| 188 | + </motion.div> |
| 189 | + |
| 190 | + {/* Overall progress bar */} |
| 191 | + <div className="mb-8"> |
| 192 | + <div className="flex justify-between mb-1"> |
| 193 | + <span className="text-sm font-medium text-gray-700"> |
| 194 | + Overall Completion |
| 195 | + </span> |
| 196 | + <span className="text-sm font-medium text-gray-700"> |
| 197 | + {goalStats.percentComplete}% |
| 198 | + </span> |
| 199 | + </div> |
| 200 | + <div className="w-full bg-gray-200 rounded-full h-4"> |
| 201 | + <motion.div |
| 202 | + className="h-4 rounded-full bg-gradient-to-r from-red-400 to-red-600" |
| 203 | + initial={{ width: 0 }} |
| 204 | + whileInView={{ width: `${goalStats.percentComplete}%` }} |
| 205 | + viewport={{ once: true }} |
| 206 | + transition={{ duration: 1.5 }} |
| 207 | + ></motion.div> |
| 208 | + </div> |
| 209 | + </div> |
| 210 | + </div> |
| 211 | + |
| 212 | + {/* Individual progress bars */} |
| 213 | + <motion.div |
| 214 | + className="mt-6" |
| 215 | + variants={container} |
| 216 | + initial="hidden" |
| 217 | + whileInView="visible" |
| 218 | + viewport={{ once: true }} |
| 219 | + > |
| 220 | + <h4 className="font-bold text-gray-800 text-lg mb-4"> |
| 221 | + Individual Progress |
| 222 | + </h4> |
| 223 | + {renderProgressBars(progressItems)} |
| 224 | + </motion.div> |
| 225 | + |
| 226 | + {/* Goal insights */} |
| 227 | + <motion.div |
| 228 | + className="mt-8 p-5 border border-gray-200 rounded-lg bg-gray-50" |
| 229 | + variants={subtleRise} |
| 230 | + initial="hidden" |
| 231 | + whileInView="visible" |
| 232 | + viewport={{ once: true }} |
| 233 | + transition={{ delay: 0.6 }} |
| 234 | + > |
| 235 | + <h5 className="font-bold text-gray-700 mb-2"> |
| 236 | + {sectionContent.insightsTitle || 'Progress Insights'} |
| 237 | + </h5> |
| 238 | + <p className="text-sm text-gray-600"> |
| 239 | + Our goals are on track with {goalStats.percentComplete}% |
| 240 | + overall completion. We've fully achieved {goalStats.completed}{' '} |
| 241 | + goals, with {goalStats.inProgress} more in progress. We |
| 242 | + continue to work towards our mission with steady progress |
| 243 | + across all initiatives. |
| 244 | + </p> |
| 245 | + </motion.div> |
| 246 | + </motion.div> |
| 247 | + </div> |
| 248 | + </div> |
| 249 | + </SectionContainer> |
| 250 | + </> |
| 251 | + ); |
| 252 | +}; |
| 253 | + |
| 254 | +export default GoalsSection; |
0 commit comments