21 lines
521 B
TypeScript
21 lines
521 B
TypeScript
import { LaravelEnum } from "@/back/types/global";
|
|
|
|
export function mapLaravelEnumOptions<
|
|
T extends LaravelEnum,
|
|
D extends Record<string, any>
|
|
>(
|
|
enumObject: T,
|
|
data?: D[],
|
|
valueKey?: keyof D
|
|
) {
|
|
const options = Object.values(enumObject).map((opt) => ({
|
|
value: opt.value.toString(),
|
|
label: opt.label,
|
|
}));
|
|
|
|
const defaultValue =
|
|
data && valueKey
|
|
? data.map((item) => item[valueKey]?.toString()).filter(Boolean)
|
|
: [];
|
|
return { options, defaultValue };
|
|
}
|