Files
calendar/packages/lib/bookings/hostGroupUtils.ts
T
Benny JooGitHubDevin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
d3e7554835 refactor: move WebWrapper files from packages/platform to apps/web/modules (#26629)
* refactor: move WebWrapper files from packages/platform to apps/web/modules

Move the following WebWrapper files to their appropriate locations in apps/web/modules:
- EventTypeWebWrapper and related tab wrappers to apps/web/modules/event-types/components/wrappers/
- BookerWebWrapper to apps/web/modules/bookings/components/
- ConferencingAppsViewWebWrapper to apps/web/modules/apps/components/
- SelectedCalendarsSettingsWebWrapper to apps/web/modules/calendars/components/
- AddMembersWithSwitchWebWrapper to apps/web/modules/event-types/components/

This reduces the number of files in packages/platform that import from @calcom/web,
improving the separation between platform and web-specific code.

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* fix: move web-specific hooks to apps/web and update imports

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* fix

* add back comments

* fix

* fix

* fix

* fix

* fix: correct relative import paths in moved WebWrapper files

Co-Authored-By: benny@cal.com <sldisek783@gmail.com>

* final

* fix: use package alias for event-type hooks instead of deeply nested relative paths

- Move sortHosts function to @calcom/lib/bookings/hostGroupUtils.ts for shared access
- Add exports for useEventTypeForm, useHandleRouteChange, useTabsNavigations to @calcom/atoms package.json
- Update EventTypeWebWrapper.tsx to use @calcom/atoms package alias instead of ../../../../../packages/... paths
- Update useEventTypeForm.ts to import sortHosts from @calcom/lib instead of @calcom/web
- Re-export sortHosts from HostEditDialogs.tsx for backward compatibility

This addresses the Cubic AI review feedback about fragile deeply nested relative paths that bypass proper package resolution.

Co-Authored-By: unknown <>

---------

Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
2026-01-10 12:55:39 +00:00

61 lines
1.5 KiB
TypeScript

import { DEFAULT_GROUP_ID } from "@calcom/lib/constants";
export function groupHostsByGroupId<T extends { groupId?: string | null }>({
hosts,
hostGroups,
}: {
hosts: T[];
hostGroups?: { id: string }[];
}): Record<string, T[]> {
const groups: Record<string, T[]> = {};
const hasGroups = hostGroups && hostGroups.length > 0;
if (hasGroups) {
hostGroups.forEach((group) => {
groups[group.id] = [];
});
} else {
groups[DEFAULT_GROUP_ID] = [];
}
hosts.forEach((host) => {
const groupId = hasGroups && host.groupId ? host.groupId : DEFAULT_GROUP_ID;
if (groups[groupId]) {
groups[groupId].push(host);
}
});
return groups;
}
export function getHostsFromOtherGroups<T extends { groupId?: string | null }>(
hosts: readonly T[],
groupId: string | null
): T[] {
return hosts.filter(
(host) => (groupId && (!host.groupId || host.groupId !== groupId)) || (!groupId && host.groupId)
);
}
export function sortHosts(
hostA: { priority: number | null; weight: number | null },
hostB: { priority: number | null; weight: number | null },
isRRWeightsEnabled: boolean
) {
const weightA = hostA.weight ?? 100;
const priorityA = hostA.priority ?? 2;
const weightB = hostB.weight ?? 100;
const priorityB = hostB.priority ?? 2;
if (isRRWeightsEnabled) {
if (weightA === weightB) {
return priorityB - priorityA;
} else {
return weightB - weightA;
}
} else {
return priorityB - priorityA;
}
}