From 5deea2c5f643fabc01dcbbb4365c9a83222f6d7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Omar=20L=C3=B3pez?= Date: Tue, 14 Dec 2021 15:14:35 -0700 Subject: [PATCH] Fixing items readded to location dropdown issue (#1316) Co-authored-by: Manoj Co-authored-by: Peer Richelsen --- pages/event-types/[type].tsx | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/pages/event-types/[type].tsx b/pages/event-types/[type].tsx index f1b32db7d6..22a0585244 100644 --- a/pages/event-types/[type].tsx +++ b/pages/event-types/[type].tsx @@ -59,6 +59,19 @@ import * as RadioArea from "@components/ui/form/radio-area"; dayjs.extend(utc); dayjs.extend(timezone); +const addDefaultLocationOptions = ( + defaultLocations: OptionTypeBase[], + locationOptions: OptionTypeBase[] +): void => { + const existingLocationOptions = locationOptions.flatMap((locationOptionItem) => [locationOptionItem.value]); + + defaultLocations.map((item) => { + if (!existingLocationOptions.includes(item.value)) { + locationOptions.push(item); + } + }); +}; + const EventTypePage = (props: inferSSRProps) => { const { t } = useLocale(); const PERIOD_TYPES = [ @@ -77,10 +90,15 @@ const EventTypePage = (props: inferSSRProps) => { ]; const { eventType, locationOptions, availability, team, teamMembers, hasPaymentIntegration, currency } = props; - locationOptions.push( + + /** Appending default locations */ + + const defaultLocations = [ { value: LocationType.InPerson, label: t("in_person_meeting") }, - { value: LocationType.Phone, label: t("phone_call") } - ); + { value: LocationType.Phone, label: t("phone_call") }, + ]; + + addDefaultLocationOptions(defaultLocations, locationOptions); const router = useRouter();