Skip to content

Feat/pre built workflows#26

Merged
dager-mohamed merged 3 commits intomainfrom
feat/pre-built-workflows
Oct 19, 2025
Merged

Feat/pre built workflows#26
dager-mohamed merged 3 commits intomainfrom
feat/pre-built-workflows

Conversation

@dager-mohamed
Copy link
Member

No description provided.

…DB models, and customer->project wiring

- prisma/schema.prisma
  - Tighten zod-prisma-types generator config (disable many auto-created input types, keep model types, enable some options)
  - Add PrebuiltWorkflowRun model for persisting execution runs
  - Add relation Project.customerId -> Customer (nullable) and Customer.projects relation
  - Wire Organization.prebuiltWorkflowRuns
  - Add indexes for customerId on Project

- prisma/migrations
  - Add SQL migrations for PrebuiltWorkflowConfig and PrebuiltWorkflowRun tables (migration files created)

- src/workflows/prebuilt/executor.ts
  - New large PrebuiltWorkflowExecutor implementation
    - Loads configured prebuilt workflows, evaluates handlers, creates run records, updates status/results
    - Handlers provided for common scenarios: lead->client conversion, client onboarding, project lifecycle, invoice tracking, contract renewal, internal health
    - Utilities for template rendering, email sending, invoice/project/customer helpers, safe coercion and formatting
    - Exposes prebuiltWorkflowExecutor singleton and PrebuiltWorkflowExecutionSummary type
  - Uses prisma client and EmailService, records run metadata and execution details

- src/lib/workflow-dispatcher.ts
  - Integrate prebuiltWorkflowExecutor.execute(event) into dispatch flow
  - Capture summary results and return them on DispatchResult.prebuiltExecutions
  - Error-tolerant call (logs and continues if prebuilt execution fails)

- src/server/api/routers/crm/contacts.ts
- src/server/api/routers/crm/interactions.ts
  - Adjust to z.custom<Prisma.*> fallbacks for input schemas (generator no longer produces input zod types)

- src/server/api/routers/projects/project.ts
  - Add support to filter projects by customerId and validate access
  - Include customer preview info in project queries (select customer fields)
  - Support customerId in create/update payloads, resolve and validate customer, and include customer metadata in WorkflowEvents payloads
  - Add deriveCustomerName helper to compute a display name from customer first/last/company
  - Stronger typing for project payloads and included relations

- src/types/{expenses,finance,hr}.ts
  - Rework type exports: continue to re-export model schemas/types from generated zod
  - Provide local zod.custom<Prisma.*CreateInput|UpdateInput> fallbacks for input schemas that are no longer generated by the zod generator
  - Reorganize and export additional model/enums where appropriate

Why:
- Introduce a pluggable "prebuilt workflows" system to run canned automation (email notifications, provisioning, invoice drafts, etc.) without requiring user-created workflows
- Persist workflow run records for visibility and troubleshooting
- Adjust zod generation strategy to avoid generating input types; provide local fallbacks to keep compile-time validation and typing consistent
- Wire customers to projects and enhance projects API so workflows and UI can show customer metadata

Notes:
- Large new executor file implements many domain-specific heuristics — review handlers and templates for org-specific needs and edge cases.
- Migration SQL files added; run prisma migrate to apply DB changes.
- Some runtime behavior depends on EmailService and PREBUILT_WORKFLOWS definitions (not modified here).
…project->customer wiring, executor improvements and UI polish

- prisma: add messageTemplateId to PrebuiltWorkflowConfig (nullable) and customerId to Project; add indexes and FK; add migration SQL
- generated/zod: update PrebuiltWorkflowConfig schema to include messageTemplateId
- server/workflows/prebuilt: enhance prebuilt router to resolve and link message templates (system & action templates), return preview/linkedTemplate metadata, accept templateId in updateTemplate
- workflows/executor & dispatcher & logger:
  - add detailed prebuilt execution logging (logPrebuiltExecutionSummary) and emit summary from dispatcher
  - refactor and harden PrebuiltWorkflowExecutor: improved matching, richer logging, new invoice creation for project-based invoice tracking, better recipient/customer resolution, more robust handlers and error handling
  - add helper utilities (createProjectInvoice, buildInvoiceTrackingVariablesFromProject, etc.)
- UI:
  - add Switch UI component (Radix wrapper) and use it in workflows list for toggle control
  - add "Beta" badge to Workflows nav item and badge support in NavMain
  - message-template-picker: add showCreateButton toggle
  - project create/edit dialogs: wire customerId field to contacts API and add customer select to forms
- next.config: remove bundle-analyzer wrapper and export config directly
- package/bun.lock: add @radix-ui/react-switch dependency
- cosmetic & UX: numerous UI improvements to workflows list/detail (cards, badges, skeletons, alerts, separators) and clearer error / loading states
@dager-mohamed dager-mohamed merged commit 8b01fdb into main Oct 19, 2025
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant