work on order type "select" in menu header

This commit is contained in:
2025-10-28 14:56:29 +03:00
parent 1abb63e8bd
commit 788bdc061d
5 changed files with 74 additions and 4 deletions

View File

@@ -0,0 +1,30 @@
/**
* Utility functions for the application
*/
import { TFunction } from "i18next";
export function enumToSelectOptions<T extends Record<string, string | number>>(
enumObj: T,
t: TFunction,
translationKey?: string,
): { label: string; value: string | number }[] {
return Object.entries(enumObj).map(([key, value]) => {
return {
label: t(translationKey ? `${translationKey}.${value}` : value),
value: value,
};
});
}
/**
* Example usage:
*
* import { OrderType } from "pages/checkout/hooks/types";
*
* // Basic usage
* const orderTypeOptions = enumToSelectOptions(OrderType);
*
* // With custom label formatter
* const customOptions = enumToSelectOptions(OrderType, (label) => `Order: ${label}`);
*/