Skip to content

Commit

Permalink
Merge pull request #1136 from akvo/bug/1134-save-button-bugs-on-datap…
Browse files Browse the repository at this point in the history
…oint-editing

[#1134] Save Button Bugs on Datapoint Editing
  • Loading branch information
ifirmawan authored Feb 6, 2024
2 parents 2fa8533 + 72997da commit 41cb361
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
8 changes: 8 additions & 0 deletions frontend/src/pages/approvals/ApprovalDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const ApprovalDetail = ({
const [checkedState, setCheckedState] = useState(
new Array(record.form?.approval_instructions?.action.length).fill(false)
);
const [resetButton, setresetButton] = useState({});

const { user: authUser } = store.useState((s) => s);
const { approvalsLiteral } = config;
Expand Down Expand Up @@ -152,6 +153,11 @@ const ApprovalDetail = ({
type: "success",
message: "Data updated",
});
const resetObj = {};
formData.map((d) => {
resetObj[d.question] = false;
});
setresetButton({ ...resetButton, ...resetObj });
})
.catch((e) => {
console.error(e);
Expand Down Expand Up @@ -246,6 +252,7 @@ const ApprovalDetail = ({
}, [selectedTab, record]);

const updateCell = (key, parentId, value) => {
setresetButton({ ...resetButton, [key]: true });
let prev = JSON.parse(JSON.stringify(rawValues));
prev = prev.map((rI) => {
let hasEdits = false;
Expand Down Expand Up @@ -457,6 +464,7 @@ const ApprovalDetail = ({
resetCell={resetCell}
disabled={!!dataLoading}
readonly={!approve}
resetButton={resetButton}
/>
),
},
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/manage-data/DataDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@ const DataDetail = ({
const [dataset, setDataset] = useState([]);
const [loading, setLoading] = useState(false);
const [saving, setSaving] = useState(false);
const [resetButton, setresetButton] = useState({});
const pendingData = record?.pending_data?.created_by || false;
const { user: authUser, forms } = store.useState((state) => state);
const { notify } = useNotification();

const updateCell = (key, parentId, value) => {
setresetButton({ ...resetButton, [key]: true });
let prev = JSON.parse(JSON.stringify(dataset));
prev = prev.map((qg) =>
qg.id === parentId
Expand Down Expand Up @@ -105,6 +107,11 @@ const DataDetail = ({
: record.id
);
fetchData(record.id);
const resetObj = {};
data.map((d) => {
resetObj[d.question] = false;
});
setresetButton({ ...resetButton, ...resetObj });
})
.catch((e) => {
console.error(e);
Expand Down Expand Up @@ -218,6 +225,7 @@ const DataDetail = ({
resetCell={resetCell}
pendingData={pendingData}
isPublic={isPublic}
resetButton={resetButton}
/>
),
},
Expand Down
8 changes: 8 additions & 0 deletions frontend/src/pages/submissions/UploadDetail.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ const UploadDetail = ({ record, setReload }) => {
const [expandedRowKeys, setExpandedRowKeys] = useState([]);
const [comments, setComments] = useState([]);
const [questionGroups, setQuestionGroups] = useState([]);
const [resetButton, setresetButton] = useState({});
const { notify } = useNotification();
const { user } = store.useState((state) => state);
const { language } = store.useState((s) => s);
Expand Down Expand Up @@ -127,6 +128,11 @@ const UploadDetail = ({ record, setReload }) => {
type: "success",
message: "Data updated",
});
const resetObj = {};
formData.map((d) => {
resetObj[d.question] = false;
});
setresetButton({ ...resetButton, ...resetObj });
})
.catch((e) => {
console.error(e);
Expand Down Expand Up @@ -197,6 +203,7 @@ const UploadDetail = ({ record, setReload }) => {
}, [selectedTab, record]);

const updateCell = (key, parentId, value) => {
setresetButton({ ...resetButton, [key]: true });
let prev = JSON.parse(JSON.stringify(rawValues));
prev = prev.map((rI) => {
let hasEdits = false;
Expand Down Expand Up @@ -415,6 +422,7 @@ const UploadDetail = ({ record, setReload }) => {
resetCell={resetCell}
disabled={!!dataLoading}
readonly={!isEditable}
resetButton={resetButton}
/>
),
},
Expand Down

0 comments on commit 41cb361

Please sign in to comment.