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 ( <>