twentyhq/twenty · warning · Error

No date fields for calendar

Error message

No date fields for calendar

What it means

Thrown by useSetViewTypeFromLayoutOptionsMenu (useSetViewTypeFromLayoutOptionsMenu.ts:90-92) when the user switches a view to ViewType.CALENDAR but the current object has zero date fields available for the calendar. The guard runs before applying view params so the calendar never receives an invalid configuration.

Source

Thrown at packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts:89

          setRecordIndexViewType(viewType);
          await updateCurrentView(updateCurrentViewParams);
          return;
        }
        case ViewType.TABLE:
        case ViewType.LIST: {
          if (shouldChangeIcon(currentView.icon, currentView.type)) {
            updateCurrentViewParams.icon =
              viewTypeIconMapping(viewType).displayName;
          }
          updateCurrentViewParams.mainGroupByFieldMetadataId = null;
          await updateCurrentView(updateCurrentViewParams);
          setRecordIndexViewType(viewType);
          return;
        }
        case ViewType.CALENDAR: {
          if (availableFieldsForCalendar.length === 0) {
            throw new Error('No date fields for calendar');
          }

          const calendarFieldMetadataId = availableFieldsForCalendar[0].id;

          setRecordIndexViewType(viewType);

          loadRecordIndexStates(
            {
              ...currentView,
              type: viewType,
              calendarFieldMetadataId,
              calendarEndFieldMetadataId: null,
              calendarLayout: ViewCalendarLayout.MONTH,
            },
            objectMetadataItem,
          );

          if (shouldChangeIcon(currentView.icon, currentView.type)) {

View on GitHub (pinned to 1f5dd2bbd2)

Solutions

  1. Add at least one date field to the object before enabling calendar view.
  2. Ensure date fields are visible and not filtered out for the current user.
  3. Confirm object metadata (including date fields) is fully loaded before rendering the view switcher.
  4. Hide the calendar option in the UI when availableFieldsForCalendar.length === 0.

Example fix

// before
<ViewOption onClick={() => setViewType(ViewType.CALENDAR)} />
// after
<ViewOption
  onClick={() => setViewType(ViewType.CALENDAR)}
  disabled={availableFieldsForCalendar.length === 0}
/>
Defensive patterns

Strategy: validation

Validate before calling

// Disable the calendar option when there are no date fields
const canShowCalendar = availableFieldsForCalendar.length > 0;
if (viewType === ViewType.CALENDAR && !canShowCalendar) {
  enqueueErrorSnackBar({ message: t`Add a date field to use calendar view` });
  return;
}

Type guard

const canSwitchToCalendar = (fields: FieldMetadata[]): boolean =>
  fields.some((f) => isDateField(f));

Prevention

When it happens

Trigger: User clicks the calendar view option in the layout options dropdown for an object that has no date-type fields. availableFieldsForCalendar.length === 0 triggers the throw.

Common situations: A custom or new object with no date fields; all date fields hidden via view configuration; metadata not yet loaded so availableFieldsForCalendar is empty; field metadata filtered out by permission/visibility rules.

Related errors


AI-assisted analysis of twentyhq/twenty@1f5dd2bbd2 (2026-08-12). Data as JSON: /api/errors/75b9bcd9dea2ad86. Report an issue: GitHub.