fix: fixed showing default option label

This commit is contained in:
2025-11-03 10:42:13 +04:00
parent 03be3903cb
commit 311210394f
14 changed files with 98 additions and 60 deletions

View File

@ -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;

View File

@ -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";