From 6ed945943a841ca382e9fa88e673702769240608 Mon Sep 17 00:00:00 2001 From: Miguel Nieto A <39246879+miguelnietoa@users.noreply.github.com> Date: Mon, 21 Mar 2022 15:45:53 -0500 Subject: [PATCH] feat: :sparkles: Show dialog only for InPerson and Link locations (#2206) --- apps/web/pages/event-types/[type].tsx | 45 ++++++++++++++++----------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/apps/web/pages/event-types/[type].tsx b/apps/web/pages/event-types/[type].tsx index f7e24c6b91..90f1081356 100644 --- a/apps/web/pages/event-types/[type].tsx +++ b/apps/web/pages/event-types/[type].tsx @@ -274,6 +274,23 @@ const EventTypePage = (props: inferSSRProps) => { ); }; + const addLocation = (newLocationType: LocationType, details = {}) => { + const existingIdx = formMethods.getValues("locations").findIndex((loc) => newLocationType === loc.type); + if (existingIdx !== -1) { + const copy = formMethods.getValues("locations"); + copy[existingIdx] = { + ...formMethods.getValues("locations")[existingIdx], + ...details, + }; + formMethods.setValue("locations", copy); + } else { + formMethods.setValue( + "locations", + formMethods.getValues("locations").concat({ type: newLocationType, ...details }) + ); + } + }; + const LocationOptions = () => { if (!selectedLocation) { return null; @@ -457,8 +474,13 @@ const EventTypePage = (props: inferSSRProps) => { className="react-select-container focus:border-primary-500 focus:ring-primary-500 block w-full min-w-0 flex-1 rounded-sm border border-gray-300 sm:text-sm" onChange={(e) => { if (e?.value) { - locationFormMethods.setValue("locationType", e.value); - openLocationModal(e.value); + const newLocationType: LocationType = e.value; + locationFormMethods.setValue("locationType", newLocationType); + if (newLocationType === LocationType.InPerson || newLocationType === LocationType.Link) { + openLocationModal(newLocationType); + } else { + addLocation(newLocationType); + } } }} /> @@ -1587,26 +1609,11 @@ const EventTypePage = (props: inferSSRProps) => { if (newLocation === LocationType.InPerson) { details = { address: values.locationAddress }; } - if (newLocation === LocationType.Link) { details = { link: values.locationLink }; } - const existingIdx = formMethods - .getValues("locations") - .findIndex((loc) => values.locationType === loc.type); - if (existingIdx !== -1) { - const copy = formMethods.getValues("locations"); - copy[existingIdx] = { - ...formMethods.getValues("locations")[existingIdx], - ...details, - }; - formMethods.setValue("locations", copy); - } else { - formMethods.setValue( - "locations", - formMethods.getValues("locations").concat({ type: values.locationType, ...details }) - ); - } + + addLocation(newLocation, details); setShowLocationModal(false); }}>