Skip to content

Commit

Permalink
[#391] Move enableEditCase state into general CaseUIState
Browse files Browse the repository at this point in the history
  • Loading branch information
wayangalihpratama committed Jan 16, 2025
1 parent 92840c9 commit 2282fcc
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 22 deletions.
1 change: 0 additions & 1 deletion frontend/src/pages/cases/Cases.js
Original file line number Diff line number Diff line change
Expand Up @@ -437,7 +437,6 @@ const Cases = () => {
<CaseSettings
open={caseSettingModalVisible}
handleCancel={() => setCaseSettingModalVisible(false)}
enableEditCase={true}
/>
</ContentLayout>
);
Expand Down
5 changes: 3 additions & 2 deletions frontend/src/pages/cases/components/CaseForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,13 @@ const SecondaryForm = ({
);
};

const CaseForm = ({ enableEditCase, updateCurrentCase = () => {} }) => {
const CaseForm = ({ updateCurrentCase = () => {} }) => {
const form = Form.useFormInstance();
const tagOptions = UIState.useState((s) => s.tagOptions);
const companyOptions = UIState.useState((s) => s.companyOptions);
const currentCase = CurrentCaseState.useState((s) => s);
const { secondary, tertiary } = CaseUIState.useState((s) => s);
const { secondary, tertiary, general } = CaseUIState.useState((s) => s);
const { enableEditCase } = general;

const updateCaseUI = (key, value) => {
CaseUIState.update((s) => ({
Expand Down
9 changes: 3 additions & 6 deletions frontend/src/pages/cases/components/CaseSettings.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,13 @@ import {
} from "../store";
import { isEqual } from "lodash";

const CaseSettings = ({
enableEditCase = true,
open = false,
handleCancel = () => {},
}) => {
const CaseSettings = ({ open = false, handleCancel = () => {} }) => {
const [form] = Form.useForm();
const navigate = useNavigate();

const currentCase = CurrentCaseState.useState((s) => s);
const { secondary, tertiary } = CaseUIState.useState((s) => s);
const { secondary, tertiary, general } = CaseUIState.useState((s) => s);
const { enableEditCase } = general;

const [prevCaseSettingValue, setPrevCaseSettingValue] = useState({});
const [formData, setFormData] = useState({ segments: [""] });
Expand Down
12 changes: 3 additions & 9 deletions frontend/src/pages/cases/components/EnterIncomeDataForm.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
calculateIncomePercentage,
} from "../../../lib";
import { commodities } from "../../../store/static";
import { CurrentCaseState } from "../store";
import { CaseUIState, CurrentCaseState } from "../store";
import { thousandFormatter } from "../../../components/chart/options/common";

const indentSize = 32;
Expand All @@ -37,6 +37,7 @@ const EnterIncomeDataQuestions = ({
question,
rowColSpanSize,
}) => {
const { enableEditCase } = CaseUIState.useState((s) => s.general);
const [collapsed, setCollapsed] = useState(
question.question_type !== "aggregator"
);
Expand Down Expand Up @@ -65,14 +66,7 @@ const EnterIncomeDataQuestions = ({
const isCollapsible =
question.question_type === "question" && question.childrens.length > 0;

const disableInput = isCollapsible && !collapsed;
// const disableInput = !enableEditCase
// ? true
// : checkFocus
// ? disabled
// : checkBreakdownValue
// ? disabled
// : checkBreakdownValue;
const disableInput = !enableEditCase ? true : isCollapsible && !collapsed;

const unitName = useMemo(
() =>
Expand Down
9 changes: 5 additions & 4 deletions frontend/src/pages/cases/steps/SetIncomeTarget.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ const calculateHouseholdSize = ({ adult = 0, child = 0 }) => {
const SetIncomeTarget = ({ segment, setbackfunction, setnextfunction }) => {
const navigate = useNavigate();
const [form] = Form.useForm();
const { enableEditCase } = CaseUIState.useState((s) => s.general);
const currentCase = CurrentCaseState.useState((s) => s);
const prevCaseSegments = PrevCaseState.useState((s) => s?.segments || []);
const stepSetIncomeTargetState = CaseUIState.useState(
Expand Down Expand Up @@ -420,7 +421,7 @@ const SetIncomeTarget = ({ segment, setbackfunction, setnextfunction }) => {
controls={false}
addonAfter={currentCase.currency}
{...InputNumberThousandFormatter}
// disabled={!disableTarget || !enableEditCase}
disabled={!enableEditCase}
onChange={handleChangeManualTarget}
/>
</Form.Item>
Expand All @@ -438,7 +439,7 @@ const SetIncomeTarget = ({ segment, setbackfunction, setnextfunction }) => {
<Select
style={formStyle}
options={stepSetIncomeTargetState.regionOptions}
// disabled={!enableEditCase}
disabled={!enableEditCase}
loading={stepSetIncomeTargetState.regionOptionLoading}
placeholder={
stepSetIncomeTargetState.regionOptionStatus === 404
Expand All @@ -461,7 +462,7 @@ const SetIncomeTarget = ({ segment, setbackfunction, setnextfunction }) => {
onChange={(value) =>
handleChangeAdultChildField("adult", value)
}
// disabled={!disableTarget || !enableEditCase}
disabled={!enableEditCase}
controls={false}
/>
</Form.Item>
Expand All @@ -477,7 +478,7 @@ const SetIncomeTarget = ({ segment, setbackfunction, setnextfunction }) => {
onChange={(value) =>
handleChangeAdultChildField("child", value)
}
// disabled={!enableEditCase}
disabled={!enableEditCase}
controls={false}
/>
</Form.Item>
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/pages/cases/store/case_ui.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { Store } from "pullstate";

const defaultCaseUIState = {
general: {
enableEditCase: true,
},
caseButton: {
loading: false,
},
Expand Down

0 comments on commit 2282fcc

Please sign in to comment.