fix: applied timezone to default values, removed value nesting

This commit is contained in:
2025-10-28 11:43:13 +04:00
parent 3575b9f34a
commit ea6a6df371
6 changed files with 61 additions and 56 deletions

View File

@ -26,11 +26,10 @@ const AttributeValueInput: FC<Props> = ({
};
const renderCheckbox = () => {
const localValue = value === undefined ? false : value;
return (
<Checkbox
{...commonProps}
checked={localValue}
checked={Boolean(value)}
onChange={e => onChange(e.currentTarget.checked)}
/>
);
@ -80,7 +79,7 @@ const AttributeValueInput: FC<Props> = ({
<NumberInput
{...commonProps}
allowDecimal={attrInfo.type.type === "float"}
value={Number(value)}
value={value ? Number(value) : undefined}
onChange={value => onChange(Number(value))}
/>
);

View File

@ -23,8 +23,9 @@ type Props = {
deal: DealSchema;
};
type Value = {
type AttrInfo = {
value?: any;
isApplicableToGroup: boolean;
};
const CustomTab: FC<Props> = ({ module, deal }) => {
@ -35,16 +36,19 @@ const CustomTab: FC<Props> = ({ module, deal }) => {
});
const [attributeValuesMap, setAttributeValuesMap] = useState<
Map<number, Value | null>
Map<number, AttrInfo | null>
>(new Map());
const [attributeErrorsMap, setAttributeErrorsMap] = useState<
Map<number, string>
>(new Map());
useEffect(() => {
const values = new Map<number, Value | null>();
const values = new Map<number, AttrInfo | null>();
for (const dealAttr of dealAttributes) {
values.set(dealAttr.attributeId, dealAttr?.value);
values.set(dealAttr.attributeId, {
...dealAttr,
value: dealAttr.value,
});
}
setAttributeValuesMap(values);
}, [dealAttributes]);
@ -65,10 +69,10 @@ const CustomTab: FC<Props> = ({ module, deal }) => {
attributeValuesMap
.entries()
.map(
([attributeId, value]) =>
([attributeId, info]) =>
({
attributeId,
value,
...info,
}) as UpdateDealModuleAttributeSchema
)
.toArray();
@ -83,7 +87,10 @@ const CustomTab: FC<Props> = ({ module, deal }) => {
attrInfo={attribute}
value={attributeValuesMap.get(attribute.attributeId)?.value}
onChange={value => {
attributeValuesMap.set(attribute.attributeId, { value });
attributeValuesMap.set(attribute.attributeId, {
...attribute,
value,
});
setAttributeValuesMap(new Map(attributeValuesMap));
attributeErrorsMap.delete(attribute.attributeId);
setAttributeErrorsMap(new Map(attributeErrorsMap));