@startujn render { direction: down; arrow_spacing: 24 } journey CALENDAR "Connect a calendar" description: "Connect a calendar from settings through the provider's consent page" unique_id_friendly: calendar start from_settings { description: "From settings" } view integrations { title: "Integrations"; description: "Calendar not connected"; route: /settings/integrations } handoff consent { title: "Provider consent page"; description: "Sign in and allow access"; channel: provider site; timeout: 10 min; resume: /oauth/calendar/callback } action exchange { title: "Exchange code for tokens" } system oauth { type: external; title: "Provider sign-in"; host: oauth.calendar.example } data connections { title: "Calendar connections"; description: "Tokens, encrypted"; location: table calendar_connections } view choose { type: modal; title: "Choose calendars"; description: "Which calendars to sync" } action first_sync { title: "Initial sync"; description: "Imports the next 90 days" } system calendar_api { type: external; title: "Provider calendar API"; host: api.calendar.example } view connected { title: "Calendar connected"; description: "Synced calendars and last sync"; route: /settings/integrations/calendar } view sync_failed { type: toast; title: "Sync failed"; description: "We'll try again in 15 minutes" } end done { type: success; description: "Calendar syncing" } ref disconnect { journey: CALENDAR_DISCONNECT; title: "Disconnect calendar"; description: "Revoke and delete the tokens" } end not_connected { type: failure; description: "Calendar not connected" } from_settings --> integrations integrations --> consent : [Connect calendar] consent ..> exchange : [Allow] valid consent ..> not_connected : [Allow] expired consent .x.> integrations : [Deny] exchange -left-> oauth { payload: [auth_code] } oauth ..> exchange { payload: [access_token, refresh_token] } exchange -right-> connections { payload: [access_token, refresh_token] } exchange --> choose : token received exchange -x-> not_connected : provider error choose --> first_sync : [Start sync] { payload: [calendar_ids] } first_sync -left-> calendar_api { payload: [access_token, calendar_ids] } calendar_api ..> first_sync { payload: [events] } first_sync --> connected : synced first_sync -x-> sync_failed : failed sync_failed .down.> connected connected -left-> done : [Done] connected -right-> disconnect : [Disconnect] @endujn