feat: deal attributes with select and options
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import { CSSProperties, FC, JSX } from "react";
|
||||
import { Checkbox, NumberInput, TextInput } from "@mantine/core";
|
||||
import { DatePickerInput, DateTimePicker } from "@mantine/dates";
|
||||
import AttrOptionSelect from "@/app/module-editor/[moduleId]/components/shared/AttrOptionSelect/AttrOptionSelect";
|
||||
import { DealModuleAttributeSchema } from "@/lib/client";
|
||||
import { naiveDateTimeStringToUtc } from "@/utils/datetime";
|
||||
|
||||
@ -25,15 +26,13 @@ const AttributeValueInput: FC<Props> = ({
|
||||
error,
|
||||
};
|
||||
|
||||
const renderCheckbox = () => {
|
||||
return (
|
||||
<Checkbox
|
||||
{...commonProps}
|
||||
checked={Boolean(value)}
|
||||
onChange={e => onChange(e.currentTarget.checked)}
|
||||
/>
|
||||
);
|
||||
};
|
||||
const renderCheckbox = () => (
|
||||
<Checkbox
|
||||
{...commonProps}
|
||||
checked={Boolean(value)}
|
||||
onChange={e => onChange(e.currentTarget.checked)}
|
||||
/>
|
||||
);
|
||||
|
||||
const renderDatePicker = () => (
|
||||
<DatePickerInput
|
||||
@ -84,6 +83,18 @@ const AttributeValueInput: FC<Props> = ({
|
||||
/>
|
||||
);
|
||||
|
||||
const renderSelect = () => {
|
||||
if (!attrInfo.select?.id) return <></>;
|
||||
return (
|
||||
<AttrOptionSelect
|
||||
{...commonProps}
|
||||
value={value}
|
||||
onChange={onChange}
|
||||
selectId={attrInfo.select.id}
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
const renderingFuncMap: Record<string, () => JSX.Element> = {
|
||||
bool: renderCheckbox,
|
||||
date: renderDatePicker,
|
||||
@ -91,6 +102,7 @@ const AttributeValueInput: FC<Props> = ({
|
||||
str: renderTextInput,
|
||||
int: renderNumberInput,
|
||||
float: renderNumberInput,
|
||||
select: renderSelect,
|
||||
};
|
||||
|
||||
const render = renderingFuncMap[attrInfo.type.type];
|
||||
|
||||
Reference in New Issue
Block a user