{"record":{"id":"75b9bcd9dea2ad86","repo":"twentyhq/twenty","slug":"no-date-fields-for-calendar","errorCode":null,"errorMessage":"No date fields for calendar","messagePattern":"No date fields for calendar","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"warning","filePath":"packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts","lineNumber":89,"sourceCode":"\n          setRecordIndexViewType(viewType);\n          await updateCurrentView(updateCurrentViewParams);\n          return;\n        }\n        case ViewType.TABLE:\n        case ViewType.LIST: {\n          if (shouldChangeIcon(currentView.icon, currentView.type)) {\n            updateCurrentViewParams.icon =\n              viewTypeIconMapping(viewType).displayName;\n          }\n          updateCurrentViewParams.mainGroupByFieldMetadataId = null;\n          await updateCurrentView(updateCurrentViewParams);\n          setRecordIndexViewType(viewType);\n          return;\n        }\n        case ViewType.CALENDAR: {\n          if (availableFieldsForCalendar.length === 0) {\n            throw new Error('No date fields for calendar');\n          }\n\n          const calendarFieldMetadataId = availableFieldsForCalendar[0].id;\n\n          setRecordIndexViewType(viewType);\n\n          loadRecordIndexStates(\n            {\n              ...currentView,\n              type: viewType,\n              calendarFieldMetadataId,\n              calendarEndFieldMetadataId: null,\n              calendarLayout: ViewCalendarLayout.MONTH,\n            },\n            objectMetadataItem,\n          );\n\n          if (shouldChangeIcon(currentView.icon, currentView.type)) {","sourceCodeStart":71,"sourceCodeEnd":107,"githubUrl":"https://github.com/twentyhq/twenty/blob/1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6/packages/twenty-front/src/modules/object-record/object-options-dropdown/hooks/useSetViewTypeFromLayoutOptionsMenu.ts#L71-L107","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Add at least one date field to the object before enabling calendar view.","Ensure date fields are visible and not filtered out for the current user.","Confirm object metadata (including date fields) is fully loaded before rendering the view switcher.","Hide the calendar option in the UI when availableFieldsForCalendar.length === 0."],"exampleFix":"// before\n<ViewOption onClick={() => setViewType(ViewType.CALENDAR)} />\n// after\n<ViewOption\n  onClick={() => setViewType(ViewType.CALENDAR)}\n  disabled={availableFieldsForCalendar.length === 0}\n/>","handlingStrategy":"validation","validationCode":"// Disable the calendar option when there are no date fields\nconst canShowCalendar = availableFieldsForCalendar.length > 0;\nif (viewType === ViewType.CALENDAR && !canShowCalendar) {\n  enqueueErrorSnackBar({ message: t`Add a date field to use calendar view` });\n  return;\n}","typeGuard":"const canSwitchToCalendar = (fields: FieldMetadata[]): boolean =>\n  fields.some((f) => isDateField(f));","tryCatchPattern":null,"preventionTips":["Hide or disable the calendar option when no date fields exist.","Ensure metadata (including date fields) is loaded before showing view options.","Validate availableFieldsForCalendar before applying the switch.","Prompt the user to add a date field when none exist."],"tags":["frontend","object-record","calendar","view","validation"],"backgroundTag":null,"analyzedSha":"1f5dd2bbd2a8da3419c8cfd52dd545c0024df1a6","analyzedAt":"2026-08-12T15:37:27.593Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}