Action flows: use company timezone for Inspection Time conditionals

Objective

  • Make Action Flow condition evaluation use each company’s Settings → Company → Timezone (IANA, e.g. America/New_York) instead of silently defaulting to Denver (America/Denver).
  • Fix Inspection Time rules (e.g. overnight windows like 7:00 PM–7:30 AM on Job Confirmed) so Eastern and other non-Mountain companies get correct send/filter behavior.
  • Align action-flow time-of-day logic with worklists and the Action Flow UI, which already assume company local time when admins configure conditions.

Background

  • Product need: run an action on order confirmation only when inspection time falls in an overnight window (example discussed: 7:00 PM–7:30 AM). That is supported via Job Confirmed + Inspection Time → is between, including overnight ranges when start > end.
  • For an Eastern company, the rule can appear correct in the UI but fail or misfire at runtime because server-side evaluation uses Mountain Time.
  • Root cause: checkCondition in conditionsResolver.ts calls evalInspectionTimeCondition(condition, actualValue, undefined) — timezone is never passed, so inspectionTimeMatch.ts falls back to INSPECTION_TIME_TZ_FALLBACK (America/Denver).
  • Contrast (working today): Worklists pass res.locals.company?.timezone into buildInspectionTimeMongoMatch in worklist.ts. Action flow send windows in flowEventTriggerer.ts and handleFlowStart.ts already load company timezone for delay/window math — only inspection-time conditionals are out of sync.
  • UI vs runtime mismatch: The condition builder in ValueConditionInput.tsx uses session useTimezone() (company tz from tools/layout.tsx); admins configure times in local company time, but BullMQ execution path handleEventTriggerdByBull.tsevaluateConditions does not.
  • Company schema default timezone is also America/Denver (companySchema.ts) when unset — separate from this bug, but Eastern companies must have timezone saved correctly for any path that reads it.

Scope

Backend

  • attik-backend/src/util/functions/actionFlows/conditionsResolver.tsinspection-time branch passes undefined timezone into evalInspectionTimeCondition; all callers of evaluateConditions / checkCondition for flows (e.g. handleEventTriggerdByBull.ts, handleActionFlowTrigger.ts, flowOnJob.ts, email/SMS render paths) need company IANA tz available when evaluating time-of-day rules.
  • attik-backend/src/util/functions/worklist/inspectionTimeMatch.ts — shared evalInspectionTimeCondition, parseBetweenHhMm, overnight time_between logic; worklist path already accepts timezone.
  • attik-backend/src/util/functions/actionFlows/FullPopulatedDataForFlow.ts — inspection payload for flow actions includes _companyId; timezone likely resolved via Company (same pattern as flowEventTriggerer.ts company lookup).
  • attik-backend/src/models/companySchema.tstimezone field (default America/Denver).
  • attik-backend/tests/unit/worklist.inspectionTimeMatch.test.ts — existing tests for time_between and timezone; extend or add action-flow integration coverage.

Frontend

  • attik-frontend/src/components/conditions/ValueConditionInput.tsx — time pickers already labeled with company timezone via useTimezone() / INSPECTION_TZ_FALLBACK.
  • attik-frontend/src/components/conditions/templatingData.tsinspection-time condition key (conditionType: 'timeOfDay').
  • attik-frontend/src/app/tools/action-flow/[flow_id]/ActionDrawer.tsx — action-level Conditionals for events like confirmed_job.
  • No UI change strictly required if backend matches company tz; decision needed whether to surface evaluated timezone in flow debug/history for support.

Product / decisions for implementer

  • Decision needed: Resolve timezone from flow _companyId, inspection _companyId, or thread explicit tz through evaluateConditions — follow existing worklist / send-window patterns.
  • Decision needed: Whether to use inspection.property.timeZone when present vs company setting only (inspection-time today uses inspection.datetime only).
  • Out of scope unless requested: Changing global America/Denver schema default on Company; fixing unrelated datetime condition types that may not pass tz today.

Investigation outcomes (acceptance)

  • [ ] Inspection Time conditions on Action Flow actions (e.g. Job Confirmed + time_between overnight) evaluate using the company’s configured timezone.
  • [ ] Eastern company (America/New_York): inspection at 8:00 PM local matches “after 7:00 PM” / overnight window; same job does not match when evaluated in Denver-only fallback.
  • [ ] Worklist behavior unchanged (still uses company timezone).
  • [ ] Unit or integration test covers action-flow evaluation with non-Denver company timezone.
  • [ ] Document or verify: company timezone must be set in Settings (not left on default) for correct local behavior.

References

  • attik-backend/src/util/functions/actionFlows/conditionsResolver.ts
  • attik-backend/src/util/functions/worklist/inspectionTimeMatch.ts
  • attik-backend/src/routes/worklist.ts
  • attik-backend/src/util/functions/actionFlows/handleEventTriggerdByBull.ts
  • attik-backend/src/util/functions/actionFlows/flowEventTriggerer.ts
  • attik-frontend/src/components/conditions/ValueConditionInput.tsx
  • attik-backend/tests/unit/worklist.inspectionTimeMatch.test.ts

Please authenticate to join the conversation.

Upvoters
Status

Planned

Board
🏠

Main App

Date

1 day ago

Author

Linear

Subscribe to post

Get notified by email when there are changes.