fix: fixed showing default option label
This commit is contained in:
@ -0,0 +1,51 @@
|
||||
import { useEffect, useState } from "react";
|
||||
import { omit } from "lodash";
|
||||
import ObjectSelect from "@/components/selects/ObjectSelect/ObjectSelect";
|
||||
import useAttributeOptionsList from "@/hooks/lists/useAttributeOptionsList";
|
||||
import { AttrOptionSchema } from "@/lib/client";
|
||||
|
||||
type Props = {
|
||||
value: number;
|
||||
onChange: (val: any) => void;
|
||||
selectId: number;
|
||||
error?: string;
|
||||
label?: string;
|
||||
};
|
||||
|
||||
const AttrOptionSelect = (props: Props) => {
|
||||
const { options } = useAttributeOptionsList(props);
|
||||
|
||||
const [selectedOption, setSelectedOption] = useState<AttrOptionSchema>();
|
||||
|
||||
useEffect(() => {
|
||||
if (!props.value) {
|
||||
setSelectedOption(undefined);
|
||||
return;
|
||||
}
|
||||
setSelectedOption(options.find(option => option.id === props.value));
|
||||
}, [props.value, options]);
|
||||
|
||||
const restProps = omit(props, ["value, onChange", "selectId"]);
|
||||
|
||||
return (
|
||||
<ObjectSelect
|
||||
label={"Значение"}
|
||||
{...restProps}
|
||||
data={options}
|
||||
value={selectedOption}
|
||||
onChange={option => {
|
||||
setSelectedOption(option);
|
||||
props.onChange(option.id);
|
||||
}}
|
||||
onClear={() => {
|
||||
setSelectedOption(undefined);
|
||||
props.onChange(null);
|
||||
}}
|
||||
getLabelFn={option => option.label}
|
||||
clearable
|
||||
searchable
|
||||
/>
|
||||
);
|
||||
};
|
||||
|
||||
export default AttrOptionSelect;
|
||||
@ -1,7 +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 AttrOptionSelect from "@/app/deals/drawers/DealEditorDrawer/components/AttrOptionSelect";
|
||||
import { DealModuleAttributeSchema } from "@/lib/client";
|
||||
import { naiveDateTimeStringToUtc } from "@/utils/datetime";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user