import React, { useEffect, useState } from 'react'; import {StyleSheet, TouchableOpacity, View} from 'react-native'; import {Text} from 'react-native-ui-lib'; import CachedImage from 'expo-cached-image'; import {format} from 'date-fns'; import {colorMap, getEventTextColor} from '@/constants/colorMap'; interface EventCellProps { event: any; onPress: (event: any) => void; attendees: any[]; } export const EventCell: React.FC = React.memo(( { event, onPress, attendees }) => { const [textColor, setTextColor] = useState(getEventTextColor(event.color)); // Add optional chaining useEffect(() => { setTextColor(getEventTextColor(event?.color)) }, [event]) return ( onPress(event)} style={[styles.eventCell, {backgroundColor: event.eventColor}]} > {event.title} {format(new Date(event.start.dateTime), 'h:mm a')} - {format(new Date(event.end.dateTime), 'h:mm a')} {attendees.length > 0 && ( {attendees.slice(0, 3).map((attendee, index) => ( {attendee.pfp ? ( ) : ( {attendee?.firstName?.at(0)} {attendee?.lastName?.at(0)} )} ))} {attendees.length > 3 && ( +{attendees.length - 3} )} )} ); }); const styles = StyleSheet.create({ eventCell: { flex: 1, borderRadius: 4, paddingHorizontal: 8, paddingBottom: 8, height: '100%', }, eventTitle: { fontSize: 12, fontFamily: "PlusJakartaSans_500Medium", }, attendeesContainer: { flexDirection: 'row', marginTop: 8, height: 27.32, }, attendeeIcon: { position: 'absolute', width: 20, height: 20, borderRadius: 50, borderWidth: 2, borderColor: '#f2f2f2', overflow: 'hidden', }, attendeeImage: { width: '100%', height: '100%', }, attendeeInitials: { color: 'white', fontSize: 12, fontFamily: "Manrope_600SemiBold", }, attendeeCount: { position: 'absolute', width: 27.32, height: 27.32, borderRadius: 50, borderWidth: 2, borderColor: '#f2f2f2', backgroundColor: colorMap.pink, justifyContent: 'center', alignItems: 'center', }, attendeeCountText: { color: 'white', fontFamily: "Manrope_600SemiBold", fontSize: 12, }, });