Skip to content

Commit

Permalink
[#385] Init set income target page layout
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 8, 2025
1 parent bf4919d commit 4e15fb2
Show file tree
Hide file tree
Showing 4 changed files with 267 additions and 4 deletions.
4 changes: 2 additions & 2 deletions frontend/src/components/layout/ContentLayout.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const ContentLayout = ({
justify="start"
className="title-wrapper"
>
<Col span={titleRighContent ? 6 : 24}>
<Col span={titleRighContent ? 12 : 24}>
{title ? (
<div data-testid="title" className="title">
{title}
Expand All @@ -111,7 +111,7 @@ const ContentLayout = ({
)}
</Col>
{titleRighContent && (
<Col span={18}>
<Col span={12}>
<Row justify="end">
<Col>{titleRighContent}</Col>
</Row>
Expand Down
1 change: 1 addition & 0 deletions frontend/src/pages/cases/Case.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
AssessImpactMitigationStrategies,
ClosingGap,
} from "./steps";
import "./steps/steps.scss";

const Case = () => {
const navigate = useNavigate();
Expand Down
186 changes: 184 additions & 2 deletions frontend/src/pages/cases/steps/SetIncomeTarget.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,189 @@
import React from "react";
import React, { useMemo } from "react";
import {
Tabs,
Form,
Radio,
Row,
Col,
InputNumber,
Select,
Card,
Space,
} from "antd";
import { CurrentCaseState } from "../store";
import { yesNoOptions } from "../../../store/static";
import { InputNumberThousandFormatter } from "../../../lib";

const formStyle = { width: "100%" };

const IncomeTargetForm = ({ segmentId }) => {
const [form] = Form.useForm();

const setTargetYourself = Form.useWatch("set_target_yourself", form);

const currentCase = CurrentCaseState.useState((s) => s);

const preventNegativeValue = (fieldName) => [
() => ({
validator(_, value) {
if (value >= 0) {
return Promise.resolve();
}
form.setFieldValue(fieldName, null);
return Promise.reject(new Error("Negative value not allowed"));
},
}),
];

const renderTargetInput = (key) => {
switch (key) {
case 1:
return (
<Col span={24}>
<Form.Item
name="target"
label="Target"
rules={[
{
required: true,
message: "Income target required.",
},
]}
>
<InputNumber
style={{ width: "40%" }}
controls={false}
addonAfter={currentCase.currency}
{...InputNumberThousandFormatter}
// disabled={!disableTarget || !enableEditCase}
/>
</Form.Item>
</Col>
);
case 0:
return (
<Col span={24}>
<Row gutter={[12, 12]}>
<Col span={8}>
<Form.Item label="Region" name="region">
<Select
style={formStyle}
// options={regionOptions}
// disabled={!disableTarget || !enableEditCase}
// loading={loadingRegionOptions}
// placeholder={
// regionOptionStatus === 404
// ? "Region not available"
// : "Select or Type Region"
// }
// {...selectProps}
/>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item
label="Average number of adults in the household"
name="household_adult"
rules={preventNegativeValue("household_adult")}
>
<InputNumber
style={formStyle}
// onChange={handleOnChangeHouseholdAdult}
// disabled={!enableEditCase}
controls={false}
/>
</Form.Item>
</Col>
<Col span={8}>
<Form.Item
label="Average number of children in the household"
name="household_children"
rules={preventNegativeValue("household_children")}
>
<InputNumber
style={formStyle}
// onChange={handleOnChangeHouseholdChild}
// disabled={!enableEditCase}
controls={false}
/>
</Form.Item>
</Col>
<Col span={24}>
<Card className="card-income-target-wrapper">
<Space size={50}>
<div className="income-target-value">
4486.00 {currentCase.currency}
</div>
<div className="income-target-text">
Living income benchmark value for a household per year
</div>
</Space>
</Card>
</Col>
<Col span={24}>
<Card className="card-lib-wrapper">
<Row align="middle">
<Col span={12} className="lib-text">
Information about Living Income Benchmark
</Col>
<Col span={12} align="end" className="lib-source">
Source: Living Income Benchmark
</Col>
</Row>
</Card>
</Col>
</Row>
</Col>
);
default:
return "";
}
};

return (
<Form form={form} layout="vertical" autoComplete="off">
<Row gutter={[12, 12]}>
<Col span={24}>
<Form.Item
name="set_target_yourself"
label="Do you want to set an income target yourself?"
rules={[
{
required: true,
message: "Please select yes or no",
},
]}
>
<Radio.Group options={yesNoOptions} />
</Form.Item>
</Col>
{renderTargetInput(setTargetYourself)}
</Row>
</Form>
);
};

const SetIncomeTarget = () => {
return <div>SetIncomeTarget</div>;
const currentCase = CurrentCaseState.useState((s) => s);

const segmentTabItems = useMemo(() => {
return currentCase.segments.map((segment) => ({
label: segment.name,
key: segment.id,
children: <IncomeTargetForm segmentId={segment.id} />,
}));
}, [currentCase]);

return (
<div id="step1">
<Tabs
className="step-segment-tabs-container"
type="card"
items={segmentTabItems}
tabBarGutter={5}
/>
</div>
);
};

export default SetIncomeTarget;
80 changes: 80 additions & 0 deletions frontend/src/pages/cases/steps/steps.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
@import "../../../variables.scss";

.step-segment-tabs-container {
&.ant-tabs {
.ant-tabs-nav {
margin: 0;

.ant-tabs-nav-wrap {
.ant-tabs-nav-list {
.ant-tabs-tab {
border-radius: 15px 15px 0 0 !important;
background: #e1e0e0;

&.ant-tabs-tab-active {
background: #fff;
}
}
}
}
}

.ant-tabs-content {
background: #fff;
padding: 20px 24px;
border-radius: 0 20px 20px 20px;
}
}
}

.card-income-target-wrapper {
font-family: "TabletGothic";
background: $primary-color;
color: #fff;
border-radius: 20px;

.ant-card-body {
padding: 20px;

.income-target-value {
font-family: "RocGrotesk";
font-weight: bold;
font-size: 22px;
}

.income-target-text {
max-width: 225px;
}
}
}

.card-lib-wrapper {
background: #f2f2f2;
border: 1px solid #e5e5e5;
border-radius: 8px;

.ant-card-body {
padding: 20px;

.lib-text,
.lib-source {
font-family: "TabletGothic" !important;
}

.lib-text {
font-size: 16px;
font-weight: 700;
}

.lib-source {
font-size: 14px;
font-weight: 400;
text-decoration-line: underline;
text-decoration-style: solid;
text-decoration-skip-ink: none;
text-decoration-thickness: auto;
text-underline-offset: auto;
text-underline-position: from-font;
}
}
}

0 comments on commit 4e15fb2

Please # to comment.