Skip to content

Commit

Permalink
Merge branch 'develop' into feature/44-handle-onfinish-save-case-profile
Browse files Browse the repository at this point in the history
  • Loading branch information
dedenbangkit committed Oct 23, 2023
2 parents e75eff7 + 11fdd8b commit b3dba5a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
6 changes: 6 additions & 0 deletions frontend/src/pages/cases/cases.scss
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,12 @@
}
}
}
.ceret-up {
color: green;
}
.ceret-down {
color: red;
}
}
}
}
Expand Down
43 changes: 39 additions & 4 deletions frontend/src/pages/cases/components/IncomeDriverDataEntry.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import {
InfoCircleFilled,
CaretRightOutlined,
CaretDownOutlined,
CaretUpFilled,
CaretDownFilled,
} from "@ant-design/icons";
import { api } from "../../../lib";

Expand All @@ -28,6 +30,9 @@ const Questions = ({
childrens,
indent = 0,
}) => {
const [currentValue, setCurrentValue] = useState(0);
const [feasibleValue, setFeasibleValue] = useState(0);
const [percentage, setPercentage] = useState(0);
const [collapsed, setCollapsed] = useState(question_type !== "aggregator");
const [disabled, setDisabled] = useState(childrens.length > 0);
const unitName = unit
Expand All @@ -36,6 +41,13 @@ const Questions = ({
.map((u) => units?.[u])
.join(" / ");

useEffect(() => {
if (currentValue && feasibleValue) {
const percent = (feasibleValue / currentValue - 1) * 100;
setPercentage(percent);
}
}, [currentValue, feasibleValue, setPercentage]);

return (
<>
<Row
Expand Down Expand Up @@ -72,16 +84,39 @@ const Questions = ({
<Switch size="small" onChange={() => setDisabled(!disabled)} />
) : null}
</Col>
<Col span={5}>
<Col span={4}>
<Form.Item name={`current-${id}`} className="current-feasible-field">
<InputNumber style={{ width: "100%" }} disabled={disabled} />
<InputNumber
style={{ width: "100%" }}
disabled={disabled}
onChange={setCurrentValue}
/>
</Form.Item>
</Col>
<Col span={5}>
<Col span={4}>
<Form.Item name={`feasible-${id}`} className="current-feasible-field">
<InputNumber style={{ width: "100%" }} disabled={disabled} />
<InputNumber
style={{ width: "100%" }}
disabled={disabled}
onChange={setFeasibleValue}
/>
</Form.Item>
</Col>
<Col span={2}>
<Space>
{percentage > 0 ? (
<CaretUpFilled className="ceret-up" />
) : (
<CaretDownFilled className="ceret-down" />
)}
<div className={percentage > 0 ? "ceret-up" : "ceret-down"}>
{feasibleValue < currentValue
? -percentage.toFixed(0)
: percentage.toFixed(0)}
%
</div>
</Space>
</Col>
</Row>
{!collapsed
? childrens.map((child) => (
Expand Down

0 comments on commit b3dba5a

Please # to comment.