work on order type "select" in menu header
This commit is contained in:
30
src/utils/helpers/helperFunctions.ts
Normal file
30
src/utils/helpers/helperFunctions.ts
Normal 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}`);
|
||||
*/
|
||||
Reference in New Issue
Block a user