From 122c6073933d23795bab3acef1ca982c61a53edd Mon Sep 17 00:00:00 2001 From: David Klakurka Date: Sat, 20 Dec 2025 18:07:29 -0800 Subject: [PATCH] Added secondary alphabetical sort on timezone selector --- components/Timezone Selector/index.tsx | 21 ++++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/components/Timezone Selector/index.tsx b/components/Timezone Selector/index.tsx index 9d8367458..c2e3cdcd7 100644 --- a/components/Timezone Selector/index.tsx +++ b/components/Timezone Selector/index.tsx @@ -1,5 +1,6 @@ -import React, { useState } from 'react' -import Select from 'react-timezone-select' +import React, { useState, useMemo } from 'react' +import { useTimezoneSelect, allTimezones } from 'react-timezone-select' +import Select from 'react-select' import style from './timezone-selector.module.css' interface TimezoneSelectorProps { @@ -14,6 +15,16 @@ const TimezoneSelector: React.FC = ({ value }) => { const [error, setError] = useState('') const [success, setSuccess] = useState('') + const { options, parseTimezone } = useTimezoneSelect({ timezones: allTimezones, displayValue: 'UTC' }) + + const sortedOptions = useMemo(() => { + return [...options].sort((a, b) => { + if (a.offset !== b.offset) return (a.offset ?? 0) - (b.offset ?? 0) + // secondary sort by timezone name + return a.value.localeCompare(b.value) + }) + }, [options]) + const handleChange = (selectedOption: any): void => { const updateTimezone = async (): Promise => { const oldTimezone = selectedTimezone @@ -62,12 +73,12 @@ const TimezoneSelector: React.FC = ({ value }) => { return ( <>