Skip to content

Commit

Permalink
fix(bookings): fix console error and crash when enter in agenda/booki…
Browse files Browse the repository at this point in the history
…ng (#595)
  • Loading branch information
miky41195 authored Mar 3, 2025
1 parent 1ce8185 commit 1350029
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 6 deletions.
4 changes: 3 additions & 1 deletion lib/ui/components/calendar/CalendarEvent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,10 @@ export const CalendarEvent = <T extends ICalendarEventBase>({
],
});

const key = `${event.start.toISO()}_${event.title}`;

if (renderEvent) {
return renderEvent(event, touchableOpacityProps);
return renderEvent(event, touchableOpacityProps, key);
}

return (
Expand Down
1 change: 0 additions & 1 deletion lib/ui/hooks/calendar/useCalendarTouchableOpacityProps.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ export function useCalendarTouchableOpacityProps<T extends ICalendarEventBase>({

const touchableOpacityProps: CalendarTouchableOpacityProps = {
delayPressIn: 20,
key: `${event.start.toISO()}_${event.title}`,
style: [...injectedStyles, getEventStyle(event)],
onPress: _onPress,
disabled: !onPressEvent,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/types/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ export interface ICalendarEventBase {

export type CalendarTouchableOpacityProps = {
delayPressIn: number;
key: string;
style: RecursiveArray<ViewStyle | undefined> | ViewStyle;
onPress: () => void;
disabled: boolean;
Expand Down Expand Up @@ -50,6 +49,7 @@ export type HorizontalDirection = 'RIGHT' | 'LEFT';
export type EventRenderer<T extends ICalendarEventBase = ICalendarEventBase> = (
event: T,
touchableOpacityProps: CalendarTouchableOpacityProps,
key: string,
) => JSX.Element;

export type HeaderRenderer = ComponentType<
Expand Down
3 changes: 2 additions & 1 deletion src/features/agenda/screens/AgendaWeekScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -270,9 +270,10 @@ export const AgendaWeekScreen = ({ navigation, route }: Props) => {
renderHeader={props => (
<CalendarHeader {...props} cellHeight={-1} />
)}
renderEvent={(item: AgendaItem, touchableOpacityProps) => {
renderEvent={(item: AgendaItem, touchableOpacityProps, key) => {
return (
<TouchableOpacity
key={key}
{...touchableOpacityProps}
style={[touchableOpacityProps.style, styles.event]}
>
Expand Down
3 changes: 2 additions & 1 deletion src/features/bookings/screens/BookingSlotScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ export const BookingSlotScreen = ({ route, navigation }: Props) => {
events={calendarEvents}
height={calendarHeight}
startHour={currentTopic.startHour || 8}
renderEvent={(item, touchableOpacityProps) => {
renderEvent={(item, touchableOpacityProps, key) => {
const isMini = item.duration <= 15;
const { color, backgroundColor } = getBookingStyle(
item,
Expand All @@ -313,6 +313,7 @@ export const BookingSlotScreen = ({ route, navigation }: Props) => {

return (
<Pressable
key={key}
{...touchableOpacityProps}
style={[
touchableOpacityProps.style,
Expand Down
2 changes: 1 addition & 1 deletion src/utils/bookings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export const getCalendarPropsFromTopic = (
topicId?: string,
) => {
const topicIndex = topics?.findIndex(topic => topic.id === topicId);
if (!!topicIndex && topicIndex > -1 && topics) {
if (topicIndex !== undefined && topicIndex > -1 && topics) {
return topics[topicIndex];
}
const topicWithSubtopics = topics?.find(topic =>
Expand Down

0 comments on commit 1350029

Please sign in to comment.