diff --git a/src/components/calendar/AddOccurrenceDialog.test.tsx b/src/components/calendar/AddOccurrenceDialog.test.tsx index 47aa942..0a2e0b4 100644 --- a/src/components/calendar/AddOccurrenceDialog.test.tsx +++ b/src/components/calendar/AddOccurrenceDialog.test.tsx @@ -27,7 +27,7 @@ describe(AddOccurrenceDialog.name, () => { const date = new Date(2021, 1, 1, 12); const props = { - open: true, + isOpen: true, onClose: mockOnClose, date, }; @@ -56,60 +56,6 @@ describe(AddOccurrenceDialog.name, () => { expect(getByText('Add habit entry for 2021-01-01')).toBeInTheDocument(); }); - it('should not render if date is null', () => { - (useHabitsStore as unknown as jest.Mock).mockReturnValue({ habits: [] }); - (useNotesStore as unknown as jest.Mock).mockReturnValue({ - addNote: jest.fn(), - addingNote: false, - }); - (useUser as jest.Mock).mockReturnValue({ id: '1' }); - (format as jest.Mock).mockReturnValue('2021-01-01'); - (useOccurrencesStore as unknown as jest.Mock).mockReturnValue({ - addOccurrence: jest.fn(), - addingOccurrence: false, - }); - const { container } = render( - - ); - expect(container.firstChild).toBeNull(); - }); - - it('should not render if open is false', () => { - (useHabitsStore as unknown as jest.Mock).mockReturnValue({ habits: [] }); - (useNotesStore as unknown as jest.Mock).mockReturnValue({ - addNote: jest.fn(), - addingNote: false, - }); - (useUser as jest.Mock).mockReturnValue({ id: '1' }); - (format as jest.Mock).mockReturnValue('2021-01-01'); - (useOccurrencesStore as unknown as jest.Mock).mockReturnValue({ - addOccurrence: jest.fn(), - addingOccurrence: false, - }); - const { container } = render( - - ); - expect(container.firstChild).toBeNull(); - }); - - it('should not render if date is null', () => { - (useHabitsStore as unknown as jest.Mock).mockReturnValue({ habits: [] }); - (useNotesStore as unknown as jest.Mock).mockReturnValue({ - addNote: jest.fn(), - addingNote: false, - }); - (useUser as jest.Mock).mockReturnValue({ id: '1' }); - (format as jest.Mock).mockReturnValue('2021-01-01'); - (useOccurrencesStore as unknown as jest.Mock).mockReturnValue({ - addOccurrence: jest.fn(), - addingOccurrence: false, - }); - const { container } = render( - - ); - expect(container.firstChild).toBeNull(); - }); - it('if no habits are available, should show a message', () => { (useHabitsStore as unknown as jest.Mock).mockReturnValue({ habits: [] }); (useNotesStore as unknown as jest.Mock).mockReturnValue({ diff --git a/src/components/calendar/AddOccurrenceDialog.tsx b/src/components/calendar/AddOccurrenceDialog.tsx index 799d3a9..cdc2ea4 100644 --- a/src/components/calendar/AddOccurrenceDialog.tsx +++ b/src/components/calendar/AddOccurrenceDialog.tsx @@ -21,13 +21,13 @@ import React, { type MouseEventHandler } from 'react'; import { Link } from 'react-router-dom'; type AddOccurrenceDialogProps = { - open: boolean; + isOpen: boolean; onClose: () => void; date: Date | null; }; const AddOccurrenceDialog = ({ - open, + isOpen, onClose, date, }: AddOccurrenceDialogProps) => { @@ -44,10 +44,6 @@ const AddOccurrenceDialog = ({ return Object.groupBy(habits, (habit) => habit.trait?.name || 'Unknown'); }, [habits]); - if (!date || !open) { - return null; - } - const hasHabits = habits.length > 0; const handleSubmit: MouseEventHandler = async (event) => { @@ -58,9 +54,11 @@ const AddOccurrenceDialog = ({ } const newOccurrence = await addOccurrence({ - day: date.toISOString().split('T')[0], - timestamp: +date, - habitId: +selectedHabitId, + day: date!.toISOString().split('T')[0], + timestamp: +date!, + // eslint-disable-next-line @typescript-eslint/ban-ts-comment + // @ts-ignore + habitId: +selectedHabitId.currentKey, userId: user?.id as string, time: null, // TODO: Add time picker }); @@ -85,13 +83,15 @@ const AddOccurrenceDialog = ({ return ( e.stopPropagation()} > - Add habit entry for {format(date, 'iii, LLL d, y')} + {date && `Add habit entry for ${format(date || '', 'iii, LLL d, y')}`}