From f401aa76695e1d11cbe90911878ee7796dc5cd6e Mon Sep 17 00:00:00 2001 From: Harsh Singh <51085015+harshsinghatz@users.noreply.github.com> Date: Fri, 9 Dec 2022 05:46:08 +0530 Subject: [PATCH] Harsh/fix avail time order (#5900) * fix: 404 page for undefined events * remove prev code merge * add: sorting in available durations * fix: sort only once * remove: console logs Co-authored-by: Guest Co-authored-by: Peer Richelsen Co-authored-by: alannnc --- .../components/eventtype/EventSetupTab.tsx | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/web/components/eventtype/EventSetupTab.tsx b/apps/web/components/eventtype/EventSetupTab.tsx index 1204d1d6b6..e957442460 100644 --- a/apps/web/components/eventtype/EventSetupTab.tsx +++ b/apps/web/components/eventtype/EventSetupTab.tsx @@ -250,23 +250,24 @@ export const EventSetupTab = ( isSearchable={false} className="h-auto !min-h-[36px] text-sm" options={multipleDurationOptions} + value={selectedMultipleDuration} onChange={(options) => { - const values = options - .map((opt) => opt.value) - .sort(function (a, b) { - return a - b; - }); + let newOptions = [...options]; + newOptions = newOptions.sort((a, b) => { + return a?.value - b?.value; + }); + const values = newOptions.map((opt) => opt.value); setMultipleDuration(values); - setSelectedMultipleDuration(options); - if (!options.find((opt) => opt.value === defaultDuration?.value)) { - if (options.length > 0) { - setDefaultDuration(options[0]); + setSelectedMultipleDuration(newOptions); + if (!newOptions.find((opt) => opt.value === defaultDuration?.value)) { + if (newOptions.length > 0) { + setDefaultDuration(newOptions[0]); } else { setDefaultDuration(null); } } - if (options.length === 1 && defaultDuration === null) { - setDefaultDuration(options[0]); + if (newOptions.length === 1 && defaultDuration === null) { + setDefaultDuration(newOptions[0]); } formMethods.setValue("metadata.multipleDuration", values); }}