dub icon indicating copy to clipboard operation
dub copied to clipboard

Group move

Open devkiran opened this issue 2 months ago β€’ 2 comments

Summary by CodeRabbit

Release Notes

  • New Features

    • Added group move rules configuration for automated partner reassignment based on performance metrics
    • Introduced new MoveGroup workflow action for partner program groups
    • Enhanced group settings with improved form-based interface and validation
  • Improvements

    • Streamlined partner metrics workflow triggers with richer contextual data
    • Improved database schema and Prisma client configuration for better performance
    • Added amount input component for consistent inline editing across partner rewards configuration

✏️ Tip: You can customize this high-level summary in your review settings.

devkiran avatar Dec 16 '25 09:12 devkiran

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Review Updated (UTC)
dub Error Error Jan 8, 2026 6:08am

vercel[bot] avatar Dec 16 '25 09:12 vercel[bot]

πŸ“ Walkthrough

Walkthrough

Adds multi-condition workflow evaluation, a MoveGroup workflow action and execution path, consolidated "partnerMetricsUpdated" trigger with richer identity/metrics payloads, group move rule UI/API/service surface, Prisma relation PartnerGroup.workflowId, migration, and tests.

Changes

Cohort / File(s) Summary
Workflow engine & evaluators
apps/web/lib/api/workflows/evaluate-workflow-conditions.ts, apps/web/lib/api/workflows/execute-workflows.ts, apps/web/lib/api/workflows/*
New multi-condition evaluator; executeWorkflows refactored to ACTION_HANDLERS, reason-based filtering, identity/metrics context shape, lazy commission fetch, and handler dispatch.
MoveGroup action & runner
apps/web/lib/api/workflows/execute-move-group-workflow.ts, apps/web/lib/api/workflows/execute-complete-bounty-workflow.ts, apps/web/lib/api/workflows/execute-send-campaign-workflow.ts
Added executeMoveGroupWorkflow; updated workflows to use identity/metrics and evaluateWorkflowConditions; skip/validate flows added for MoveGroup.
Group move domain services
apps/web/lib/api/groups/upsert-group-move-rules.ts, apps/web/lib/api/groups/get-group-move-rules.ts, apps/web/lib/api/groups/move-partners-to-group.ts, apps/web/lib/api/groups/find-groups-with-matching-rules.ts, apps/web/lib/api/groups/validate-group-move-rules.ts, apps/web/lib/api/groups/get-group-or-throw.ts
New upsert/get/validate/find helpers and movePartnersToGroup implementation; duplicate-rule detection and validation; get-group now surfaces moveRules.
Routes & orchestration
apps/web/app/(ee)/api/groups/[groupIdOrSlug]/route.ts, apps/web/app/(ee)/api/groups/[groupIdOrSlug]/partners/route.ts, apps/web/app/(ee)/api/groups/rules/route.ts, apps/web/app/(ee)/api/cron/bounties/create-draft-submissions/route.ts
PATCH/DELETE group tied to upsert/delete workflows; partners endpoint delegates to movePartnersToGroup; new GET /api/groups/rules; cron route uses evaluateWorkflowConditions.
Trigger payloads & webhooks
apps/web/app/(ee)/api/stripe/.../*.ts, apps/web/lib/actions/partners/create-manual-commission.ts, apps/web/lib/api/conversions/*.ts, apps/web/lib/partners/create-partner-commission.ts, apps/web/lib/integrations/shopify/create-sale.ts
Replaced WorkflowTrigger enum usages with "partnerMetricsUpdated" and augmented executeWorkflows payloads with reason, identity, and metrics.
UI β€” Group rules & settings
apps/web/app/.../group-move-rules.tsx, apps/web/app/.../group-additional-settings.tsx, apps/web/app/.../group-settings.tsx, apps/web/lib/swr/use-groups-rules.ts
New GroupMoveRules component, client validation, form-based save flow invoking PATCH and SWR hooks; skeleton/UI adjustments.
Schemas & types
apps/web/lib/zod/schemas/workflows.ts, apps/web/lib/zod/schemas/bounties.ts, apps/web/lib/zod/schemas/campaigns.ts, apps/web/lib/zod/schemas/groups.ts, apps/web/lib/types.ts
Added MoveGroup action, "between" operator, bounty/campaign-specific condition schemas, Group.moveRules schema, and new WorkflowContext (identity/metrics) and condition types.
Plan capability
apps/web/lib/plan-capabilities.ts
Added canUseGroupMoveRule capability flag.
DB / Prisma
packages/prisma/schema/group.prisma, packages/prisma/schema/workflow.prisma, packages/prisma/index.ts
Added PartnerGroup.workflowId relation; new WorkflowTrigger.partnerMetricsUpdated; Prisma client singleton typing/initialization adjustments.
Migrations & tests
apps/web/scripts/migrations/migrate-workflow-triggers.ts, apps/web/tests/partner-groups/index.test.ts
Migration script to consolidate triggers to partnerMetricsUpdated; tests added/updated for moveRules persistence and PATCH flows.
Bounties & condition specialization
apps/web/lib/api/bounties/generate-performance-bounty-name.ts, apps/web/app/.../add-edit-bounty-sheet.tsx, apps/web/lib/zod/schemas/bounties.ts
Introduced bountyPerformanceConditionSchema and switched bounty UI/parsing to bounty-specific condition schema.
Misc UI & icons
apps/web/ui/shared/inline-badge-popover.tsx, apps/web/ui/partners/rewards/rewards-logic.tsx, packages/ui/src/icons/nucleo/user-arrow-right.tsx
New InlineBadgePopoverAmountInput component; rewards input refactored to shared component; new SVG icon export.

Sequence Diagram(s)

sequenceDiagram
    participant Webhook as Webhook (Stripe/Shopify/Conversion)
    participant Execute as executeWorkflows
    participant DB as Prisma
    participant Engine as Workflow Engine (ACTION_HANDLERS)
    participant Eval as evaluateWorkflowConditions
    participant Move as movePartnersToGroup

    Webhook->>Execute: executeWorkflows({ trigger: "partnerMetricsUpdated", reason, identity, metrics })
    Execute->>DB: fetch program enrollment & aggregated metrics
    Execute->>Engine: iterate filtered workflows
    Engine->>Eval: evaluateWorkflowConditions({ conditions, attributes: metrics.aggregated })
    alt conditions met
        Engine->>Move: movePartnersToGroup(programId, partnerId, userId, targetGroup)
        Move->>DB: update programEnrollments (group/rewards)
        Move-->>Engine: schedule background tasks (link remap, bounties)
    else not met
        Engine-->>Execute: skip workflow
    end
sequenceDiagram
    actor User
    participant UI as Group Settings UI
    participant API as PATCH /groups/{id}
    participant Upsert as upsertGroupMoveRules
    participant Detect as findGroupsWithMatchingRules
    participant DB as Prisma

    User->>UI: Configure move rules and Save
    UI->>API: PATCH with moveRules
    API->>Upsert: upsertGroupMoveRules({ group, moveRules, workspace })
    Upsert->>Detect: findGroupsWithMatchingRules(existingGroups, moveRules)
    alt conflicts
        Detect-->>Upsert: conflicting groups
        Upsert-->>API: throw bad_request
        API-->>UI: return error
    else no conflicts
        Upsert->>DB: create or update Workflow (triggerConditions, actions)
        DB-->>Upsert: workflowId
        Upsert->>DB: update PartnerGroup.workflowId
        Upsert-->>API: { workflowId }
        API-->>UI: success
    end

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~75 minutes

Possibly related PRs

  • dubinc/dub#2735 β€” Overlaps partner-groups infra and workflow rule integrations (group/workflow lifecycle and move logic).
  • dubinc/dub#3244 β€” Related: bounties cron adjustments and evaluateWorkflowCondition β†’ evaluateWorkflowConditions call-shape changes.
  • dubinc/dub#2855 β€” Related: refactors to workflow condition evaluation and cron/workflow-triggered flows.

Suggested reviewers

  • steven-tey

Poem

πŸ‡ I nibble rules and hop with cheer,

Conditions checked and migrations near,
Groups will move when metrics sing,
Workflows hum and merry things,
Hooray β€” the rabbit ships the gear!

πŸš₯ Pre-merge checks | βœ… 1 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 8.82% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The PR title 'Group move' is vague and generic, failing to convey the specific functionality being implemented despite substantial changes across multiple systems. Use a more descriptive title that captures the primary feature, such as 'Add group move workflow automation based on partner metrics' or 'Implement partner group reassignment via workflow triggers'.
βœ… Passed checks (1 passed)
Check name Status Explanation
Description Check βœ… Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • [ ] πŸ“ Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❀️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

coderabbitai[bot] avatar Dec 16 '25 09:12 coderabbitai[bot]