From 4d3026495068c49bc50974efe0ee6668f9316932 Mon Sep 17 00:00:00 2001 From: Jaideep Guntupalli <63718527+JaideepGuntupalli@users.noreply.github.com> Date: Tue, 13 Jun 2023 20:24:53 +0530 Subject: [PATCH] fix: Multiple In Person Locations not working as expected in Event Setup Tab (#9465) Co-authored-by: Bailey Pumfleet --- .../components/dialog/EditLocationDialog.tsx | 18 +++++++++- .../components/eventtype/EventSetupTab.tsx | 33 ++++++++++++++++--- .../web/components/ui/form/LocationSelect.tsx | 1 + packages/app-store/locations.ts | 1 + 4 files changed, 47 insertions(+), 6 deletions(-) diff --git a/apps/web/components/dialog/EditLocationDialog.tsx b/apps/web/components/dialog/EditLocationDialog.tsx index 5b59ff4cd1..b8c8d219df 100644 --- a/apps/web/components/dialog/EditLocationDialog.tsx +++ b/apps/web/components/dialog/EditLocationDialog.tsx @@ -91,6 +91,9 @@ export const EditLocationDialog = (props: ISetLocationDialog) => { useEffect(() => { if (selection) { locationFormMethods.setValue("locationType", selection?.value); + if (selection?.address) { + locationFormMethods.setValue("locationAddress", selection?.address); + } } // eslint-disable-next-line react-hooks/exhaustive-deps }, [selection]); @@ -152,12 +155,25 @@ export const EditLocationDialog = (props: ISetLocationDialog) => { name: "locationType", }); + const selectedAddrValue = useWatch({ + control: locationFormMethods.control, + name: "locationAddress", + }); + const eventLocationType = getEventLocationType(selectedLocation); const defaultLocation = defaultValues?.find( - (location: { type: EventLocationType["type"] }) => location.type === eventLocationType?.type + (location: { type: EventLocationType["type"]; address?: string }) => { + if (location.type === LocationType.InPerson) { + return location.type === eventLocationType?.type && location.address === selectedAddrValue; + } else { + return location.type === eventLocationType?.type; + } + } ); + console.log(defaultLocation); + const LocationOptions = (() => { if (eventLocationType && eventLocationType.organizerInputType && LocationInput) { if (!eventLocationType.variable) { diff --git a/apps/web/components/eventtype/EventSetupTab.tsx b/apps/web/components/eventtype/EventSetupTab.tsx index 82e46844b7..f88f6028b3 100644 --- a/apps/web/components/eventtype/EventSetupTab.tsx +++ b/apps/web/components/eventtype/EventSetupTab.tsx @@ -136,9 +136,17 @@ export const EventSetupTab = ( selectedMultipleDuration.find((opt) => opt.value === eventType.length) ?? null ); - const openLocationModal = (type: EventLocationType["type"]) => { + const openLocationModal = (type: EventLocationType["type"], address = "") => { const option = getLocationFromType(type, locationOptions); - setSelectedLocation(option); + if (option && option.value === LocationType.InPerson) { + const inPersonOption = { + ...option, + address, + }; + setSelectedLocation(inPersonOption); + } else { + setSelectedLocation(option); + } setShowLocationModal(true); }; @@ -298,10 +306,14 @@ export const EventSetupTab = ( onClick={() => { locationFormMethods.setValue("locationType", location.type); locationFormMethods.unregister("locationLink"); - locationFormMethods.unregister("locationAddress"); + if (location.type === LocationType.InPerson) { + locationFormMethods.setValue("locationAddress", location.address); + } else { + locationFormMethods.unregister("locationAddress"); + } locationFormMethods.unregister("locationPhoneNumber"); setEditingLocationType(location.type); - openLocationModal(location.type); + openLocationModal(location.type, location.address); }} aria-label={t("edit")} className="hover:text-emphasis text-subtle mr-1 p-1"> @@ -517,7 +529,18 @@ export const EventSetupTab = ( defaultValues={formMethods.getValues("locations")} selection={ selectedLocation - ? { value: selectedLocation.value, label: t(selectedLocation.label), icon: selectedLocation.icon } + ? selectedLocation.address + ? { + value: selectedLocation.value, + label: t(selectedLocation.label), + icon: selectedLocation.icon, + address: selectedLocation.address, + } + : { + value: selectedLocation.value, + label: t(selectedLocation.label), + icon: selectedLocation.icon, + } : undefined } setSelectedLocation={setSelectedLocation} diff --git a/apps/web/components/ui/form/LocationSelect.tsx b/apps/web/components/ui/form/LocationSelect.tsx index 846082b26d..95f1a7eebe 100644 --- a/apps/web/components/ui/form/LocationSelect.tsx +++ b/apps/web/components/ui/form/LocationSelect.tsx @@ -11,6 +11,7 @@ export type LocationOption = { value: EventLocationType["type"]; icon?: string; disabled?: boolean; + address?: string; }; export type SingleValueLocationOption = SingleValue; diff --git a/packages/app-store/locations.ts b/packages/app-store/locations.ts index 5eac81100f..31ae8af722 100644 --- a/packages/app-store/locations.ts +++ b/packages/app-store/locations.ts @@ -148,6 +148,7 @@ export const defaultLocations: DefaultEventLocationType[] = [ export type LocationObject = { type: string; + address?: string; displayLocationPublicly?: boolean; } & Partial< Record<"address" | "attendeeAddress" | "link" | "hostPhoneNumber" | "hostDefault" | "phone", string>