From 589260a7c7a8b638b2abb37473af809839d6ab7a Mon Sep 17 00:00:00 2001 From: Udit Takkar <53316345+Udit-takkar@users.noreply.github.com> Date: Tue, 10 Feb 2026 18:51:57 +0530 Subject: [PATCH] fix: host location option (#27807) Co-authored-by: Hariom Balhara <1780212+hariombalhara@users.noreply.github.com> --- .../components/locations/HostLocations.tsx | 293 ++++++++++-------- 1 file changed, 166 insertions(+), 127 deletions(-) diff --git a/apps/web/modules/event-types/components/locations/HostLocations.tsx b/apps/web/modules/event-types/components/locations/HostLocations.tsx index 220236e8e5..b7618a8459 100644 --- a/apps/web/modules/event-types/components/locations/HostLocations.tsx +++ b/apps/web/modules/event-types/components/locations/HostLocations.tsx @@ -171,15 +171,99 @@ const LocationInputDialog = ({ ); }; +const checkAppInstalledForHost = (locationValue: string, hostData?: HostWithLocationOptions): boolean => { + if (isStaticLocationType(locationValue)) return true; + if (isCalVideoLocation(locationValue)) return true; + if (!hostData) return true; + + const appSlug = getAppSlugFromLocationType(locationValue); + if (!appSlug) return true; + + return hostData.installedApps.some((app) => app.appId === appSlug || app.type === locationValue); +}; + +const annotateOptionsForHost = ( + locationOptions: TLocationOptions, + hostData: HostWithLocationOptions | undefined, + notInstalledLabel: string +): TLocationOptions => { + if (!hostData) return locationOptions; + + return locationOptions.map((group) => ({ + ...group, + options: group.options.map((opt) => { + if (checkAppInstalledForHost(opt.value, hostData)) return opt; + return { ...opt, label: `${opt.label} (${notInstalledLabel})` }; + }), + })); +}; + +const findHostCredential = (hostData: HostWithLocationOptions | undefined, locationValue: string) => { + return hostData?.installedApps.find( + (app) => app.appId === getAppSlugFromLocationType(locationValue) || app.type === locationValue + ); +}; + +const buildHostLocation = ( + userId: number, + eventTypeId: number, + locationOption: LocationOption, + hostData: HostWithLocationOptions | undefined, + inputValue?: string +): HostLocation => { + const eventLocationType = getEventLocationType(locationOption.value); + const credential = findHostCredential(hostData, locationOption.value); + + const location: HostLocation = { + userId, + eventTypeId, + type: locationOption.value, + credentialId: credential?.credentialId ?? null, + }; + + if (eventLocationType?.organizerInputType === "text") { + if (eventLocationType.defaultValueVariable === "link") { + location.link = inputValue; + } else if (eventLocationType.defaultValueVariable === "address") { + location.address = inputValue; + } + } else if (eventLocationType?.organizerInputType === "phone") { + location.phoneNumber = inputValue; + } + + return location; +}; + +const getSelectedOption = ( + currentLocation: HostLocation | null | undefined, + hostData: HostWithLocationOptions | undefined, + options: TLocationOptions +): LocationOption | undefined => { + if (currentLocation) { + return getLocationFromOptions(currentLocation.type, options); + } + + if (hostData?.defaultConferencingApp?.appSlug) { + const locationType = getAppFromSlug(hostData.defaultConferencingApp.appSlug)?.appData?.location?.type; + if (locationType) { + return getLocationFromOptions(locationType, options); + } + } + + return getLocationFromOptions("integrations:daily", options); +}; + const HostLocationRow = ({ host, hostData, locationOptions, + eventTypeId, onLocationChange, }: { host: Host; hostData?: HostWithLocationOptions; locationOptions: TLocationOptions; + eventTypeId: number; onLocationChange: (userId: number, location: HostLocation | null) => void; }) => { const { t } = useLocale(); @@ -188,127 +272,51 @@ const HostLocationRow = ({ const currentLocation = host.location; - const selectedOption = useMemo(() => { - if (currentLocation) { - return getLocationFromOptions(currentLocation.type, locationOptions); - } - - if (hostData?.defaultConferencingApp?.appSlug) { - const locationType = getAppFromSlug(hostData.defaultConferencingApp.appSlug)?.appData?.location?.type; - if (locationType) { - return getLocationFromOptions(locationType, locationOptions); - } - } - - return getLocationFromOptions("integrations:daily", locationOptions); - }, [currentLocation, hostData, locationOptions]); - const hasAppInstalled = useMemo(() => { if (!currentLocation?.type) return true; - if (isStaticLocationType(currentLocation.type)) return true; - if (isCalVideoLocation(currentLocation.type)) return true; - if (!hostData) return true; - - const appSlug = getAppSlugFromLocationType(currentLocation.type); - if (!appSlug) return true; - - return hostData.installedApps.some((app) => app.appId === appSlug || app.type === currentLocation.type); + return checkAppInstalledForHost(currentLocation.type, hostData); }, [currentLocation, hostData]); - const displayName = hostData?.name || `${t("user")} ${host.userId}`; - const avatarUrl = hostData?.avatarUrl || undefined; + const hostAnnotatedOptions = useMemo( + () => annotateOptionsForHost(locationOptions, hostData, t("app_not_installed")), + [locationOptions, hostData, t] + ); + + const selectedOption = useMemo( + () => getSelectedOption(currentLocation, hostData, locationOptions), + [currentLocation, hostData, locationOptions] + ); const currentLocationEventType = currentLocation ? getEventLocationType(currentLocation.type) : null; const hasOrganizerInput = !!currentLocationEventType?.organizerInputType; const currentLocationValue = useMemo(() => { if (!currentLocation || !currentLocationEventType) return ""; - if (currentLocationEventType.defaultValueVariable === "link") { - return currentLocation.link || ""; - } - if (currentLocationEventType.defaultValueVariable === "address") { - return currentLocation.address || ""; - } - if (currentLocationEventType.organizerInputType === "phone") { - return currentLocation.phoneNumber || ""; - } + if (currentLocationEventType.defaultValueVariable === "link") return currentLocation.link || ""; + if (currentLocationEventType.defaultValueVariable === "address") return currentLocation.address || ""; + if (currentLocationEventType.organizerInputType === "phone") return currentLocation.phoneNumber || ""; return ""; }, [currentLocation, currentLocationEventType]); - const handleEditClick = () => { - if (selectedOption) { - setPendingLocationOption(selectedOption); - setIsDialogOpen(true); - } - }; - const handleLocationSelect = (option: LocationOption | null) => { if (!option) { onLocationChange(host.userId, null); return; } - - const eventLocationType = getEventLocationType(option.value); - - if (eventLocationType?.organizerInputType) { + if (getEventLocationType(option.value)?.organizerInputType) { setPendingLocationOption(option); setIsDialogOpen(true); return; } - - const credential = hostData?.installedApps.find( - (app) => app.appId === getAppSlugFromLocationType(option.value) || app.type === option.value - ); - onLocationChange(host.userId, { - userId: host.userId, - eventTypeId: 0, - type: option.value, - credentialId: credential?.credentialId ?? null, - }); - }; - - const handleDialogSave = (inputValue: string) => { - if (!pendingLocationOption) return; - - const eventLocationType = getEventLocationType(pendingLocationOption.value); - const credential = hostData?.installedApps.find( - (app) => - app.appId === getAppSlugFromLocationType(pendingLocationOption.value) || - app.type === pendingLocationOption.value - ); - - const location: HostLocation = { - userId: host.userId, - eventTypeId: 0, - type: pendingLocationOption.value, - credentialId: credential?.credentialId ?? null, - }; - - if (eventLocationType?.organizerInputType === "text") { - if (eventLocationType.defaultValueVariable === "link") { - location.link = inputValue; - } else if (eventLocationType.defaultValueVariable === "address") { - location.address = inputValue; - } - } else if (eventLocationType?.organizerInputType === "phone") { - location.phoneNumber = inputValue; - } - - onLocationChange(host.userId, location); - setPendingLocationOption(null); - }; - - const handleDialogClose = () => { - setIsDialogOpen(false); - setPendingLocationOption(null); + onLocationChange(host.userId, buildHostLocation(host.userId, eventTypeId, option, hostData)); }; return ( <>