From 5360cb511d819d49d90b905b6eae82564ece8ce7 Mon Sep 17 00:00:00 2001 From: Hariom Balhara Date: Thu, 31 Jul 2025 06:23:41 +0530 Subject: [PATCH] fix: Errors in org onboarding in some edge cases (#22711) * Automatically enable migration of a team that conflicts with Orgs slug * Allow changing the orgs slug and name if user goes back and changes it * avoid crashing on some scenarios * Revert "Allow changing the orgs slug and name if user goes back and changes it" This reverts commit f8872b0116868d59757ef911c4940df79f93c6e0. * fix: handle unpublished teams gracefully in org migration - Change 'No oldSlug for team' from error to warning for unpublished teams - Keep 'No slug for team' as error since org onboarding ensures teams have names - Add test for migrating unpublished teams without oldSlug - Add clarifying comments about when each condition can occur --- .../new/_components/AddNewTeamsForm.tsx | 13 +- .../createOrganizationFromOnboarding.test.ts | 28 ++++ .../createOrganizationFromOnboarding.ts | 14 +- .../__tests__/createTeams.handler.test.ts | 106 +++++++++++++ .../organizations/createTeams.handler.ts | 22 ++- .../inviteMember/inviteMember.handler.test.ts | 149 ++++++++++++++++++ 6 files changed, 314 insertions(+), 18 deletions(-) diff --git a/apps/web/modules/settings/organizations/new/_components/AddNewTeamsForm.tsx b/apps/web/modules/settings/organizations/new/_components/AddNewTeamsForm.tsx index 8adb8ce9a8..529363abab 100644 --- a/apps/web/modules/settings/organizations/new/_components/AddNewTeamsForm.tsx +++ b/apps/web/modules/settings/organizations/new/_components/AddNewTeamsForm.tsx @@ -78,9 +78,11 @@ const AddNewTeamsFormChild = ({ teams }: { teams: { id: number; name: string; sl teams: teamsToCreateFromStore.length ? teamsToCreateFromStore : [{ name: "" }], moveTeams: teams.map((team) => { const teamToMigrateInStore = teamsToMigrateFromStore.find((t) => t.id === team.id); + const slugConflictsWithOrg = team.slug === orgSlug; return { id: team.id, - shouldMove: !!teamToMigrateInStore, + // The team with conflicting slug must be moved + shouldMove: slugConflictsWithOrg || !!teamToMigrateInStore, newSlug: teamToMigrateInStore?.slug || getSuggestedSlug({ teamSlug: team.slug, orgSlug }), name: team.name, }; @@ -160,6 +162,9 @@ const AddNewTeamsFormChild = ({ teams }: { teams: { id: number; name: string; sl