fix: applied timezone to default values, removed value nesting
This commit is contained in:
@ -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));
|
||||
|
||||
Reference in New Issue
Block a user