Skip to content

Commit

Permalink
fix duplicate modal send updates
Browse files Browse the repository at this point in the history
  • Loading branch information
githubering182 committed Oct 1, 2024
1 parent c3845d1 commit 392a4ce
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
11 changes: 9 additions & 2 deletions frontend-app/src/components/DuplicateModal/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,13 @@ export default function DuplicateModal({ pathID, fileID, onUpdate, onClose }) {
}
};

const hanleUpdate = async (file_id, status) => {
await onUpdate(file_id, status);

var data = await getDuplicates();
setDuplicates(data);
};

useEffect(() => {
getDuplicates().then((data) => setDuplicates(data));
window.addEventListener("keydown", handleKey);
Expand Down Expand Up @@ -109,12 +116,12 @@ export default function DuplicateModal({ pathID, fileID, onUpdate, onClose }) {
<div className="iss__fileInfo__buttonsWrap">
<button
type="button"
onClick={() => onUpdate("d")}
onClick={() => hanleUpdate(id, "d")}
className="button--reject"
>Decline</button>
<button
type="button"
onClick={() => onUpdate("a")}
onClick={() => hanleUpdate(id, "a")}
className="button--accept"
>Accept</button>
</div>
Expand Down
13 changes: 8 additions & 5 deletions frontend-app/src/components/common/FileModification/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,14 @@ export default function FileModification({ pathID, fileManager, slide, slideInc,
buttonMap[key]?.current.click();
};

const fetchUpdateFile = async (status, newAttributes) => {
await api.request(`/api/files/${file.id}/`,
const fetchUpdateFile = async (fileId, status, newAttributes) => {
var data = { status };
if (newAttributes) data.attribute = newAttributes;

await api.request(`/api/files/${fileId}/`,
{
method: 'patch',
data: { status, attribute: newAttributes },
data,
headers: {
'Content-Type': 'application/json',
"Authorization": "Bearer " + localStorage.getItem("dtcAccess")
Expand All @@ -57,7 +60,7 @@ export default function FileModification({ pathID, fileManager, slide, slideInc,

var preparedAtrs = prepareAttributes();

await fetchUpdateFile(status, preparedAtrs);
await fetchUpdateFile(file.id, status, preparedAtrs);

setFiles((prev) => {
var newFiles = [...prev];
Expand Down Expand Up @@ -96,7 +99,7 @@ export default function FileModification({ pathID, fileManager, slide, slideInc,
pathID={pathID}
fileID={duplicates}
onClose={() => setDuplicates(null)}
onUpdate={updateFile}
onUpdate={fetchUpdateFile}
/>
}
<div className='iss__fileInfo'>
Expand Down

0 comments on commit 392a4ce

Please sign in to comment.