From 551ebe863b0a7b6f304ba631883b5a76dbaa0e43 Mon Sep 17 00:00:00 2001 From: "GitStart-Cal.com" <121884634+gitstart-calcom@users.noreply.github.com> Date: Thu, 2 Feb 2023 18:27:56 +0545 Subject: [PATCH] [CAL-90] Event Types Single / Allow multiple physical locations (#6692) Co-authored-by: gitstart-calcom --- .../components/eventtype/EventSetupTab.tsx | 30 +++++++++++++------ 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/apps/web/components/eventtype/EventSetupTab.tsx b/apps/web/components/eventtype/EventSetupTab.tsx index 5783a5a829..83667c4ffe 100644 --- a/apps/web/components/eventtype/EventSetupTab.tsx +++ b/apps/web/components/eventtype/EventSetupTab.tsx @@ -9,7 +9,12 @@ import { Controller, useForm, useFormContext } from "react-hook-form"; import { MultiValue } from "react-select"; import { z } from "zod"; -import { EventLocationType, getEventLocationType, MeetLocationType } from "@calcom/app-store/locations"; +import { + EventLocationType, + getEventLocationType, + MeetLocationType, + LocationType, +} from "@calcom/app-store/locations"; import { CAL_URL } from "@calcom/lib/constants"; import { useLocale } from "@calcom/lib/hooks/useLocale"; import { slugify } from "@calcom/lib/slugify"; @@ -79,7 +84,12 @@ export const EventSetupTab = ( const removeLocation = (selectedLocation: typeof eventType.locations[number]) => { formMethods.setValue( "locations", - formMethods.getValues("locations").filter((location) => location.type !== selectedLocation.type), + formMethods.getValues("locations").filter((location) => { + if (location.type === LocationType.InPerson) { + return location.address !== selectedLocation.address; + } + return location.type !== selectedLocation.type; + }), { shouldValidate: true } ); }; @@ -94,14 +104,14 @@ export const EventSetupTab = ( ...details, type: newLocationType, }; - } else { - copy[existingIdx] = { - ...formMethods.getValues("locations")[existingIdx], - ...details, - }; } - formMethods.setValue("locations", copy); + formMethods.setValue("locations", [ + ...copy, + ...(newLocationType === LocationType.InPerson && editingLocationType === "" + ? [{ ...details, type: newLocationType }] + : []), + ]); } else { formMethods.setValue( "locations", @@ -187,7 +197,9 @@ export const EventSetupTab = ( return null; } return ( -
  • +