= {
+ "America/Port_Of_Spain": "America/Port_of_Spain",
+ "Africa/Porto-novo": "Africa/Porto-Novo",
+ "Africa/Dar_Es_Salaam": "Africa/Dar_es_Salaam",
+ };
+
+ const correctedValue = corrections[selectedOption.value] || selectedOption.value;
+ props.onChange({ ...selectedOption, value: correctedValue });
+ },
+ [props.onChange]
+ );
+
+ const formatOption = useCallback(
+ (option: unknown) => {(option as ITimezoneOption).value.replace(/_/g, " ")}
,
+ []
+ );
+
+ const getLabel = useCallback(
+ (option: unknown) => handleOptionLabel(option as ITimezoneOption, additionalTimezones),
+ [additionalTimezones]
+ );
return (
Object.assign({}, base, {
@@ -128,28 +167,9 @@ export function TimezoneSelectComponent({
}}
onInputChange={handleInputChange}
{...props}
- onChange={(selectedOption) => {
- if (!props.onChange) return;
-
- if (!selectedOption) {
- props.onChange(selectedOption);
- return;
- }
-
- // Fix inconsistent timezone naming formats
- const corrections: Record = {
- "America/Port_Of_Spain": "America/Port_of_Spain",
- "Africa/Porto-novo": "Africa/Porto-Novo",
- "Africa/Dar_Es_Salaam": "Africa/Dar_es_Salaam",
- };
-
- const correctedValue = corrections[selectedOption.value] || selectedOption.value;
- props.onChange({ ...selectedOption, value: correctedValue });
- }}
- formatOptionLabel={(option) => (
- {(option as ITimezoneOption).value.replace(/_/g, " ")}
- )}
- getOptionLabel={(option) => handleOptionLabel(option as ITimezoneOption, additionalTimezones)}
+ onChange={handleChange}
+ formatOptionLabel={formatOption}
+ getOptionLabel={getLabel}
classNames={{
...timezoneClassNames,
input: (state) =>
@@ -175,8 +195,8 @@ export function TimezoneSelectComponent({
? "p-1 h-fit"
: "px-3 h-fit"
: size === "sm"
- ? "h-7 px-2"
- : "h-9 py-0 px-3",
+ ? "h-7 px-2"
+ : "h-9 py-0 px-3",
props.isDisabled && "bg-subtle",
"rounded-[10px]",
timezoneClassNames?.control && timezoneClassNames.control(state)