Skip to content

Commit

Permalink
enable ignore and deny merge request in react
Browse files Browse the repository at this point in the history
  • Loading branch information
erinz2020 committed Feb 3, 2025
1 parent 7548632 commit df944b0
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 29 deletions.
27 changes: 15 additions & 12 deletions frontend/src/components/navBar/MergeMessages.jsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import React, { useState } from "react";
import BrutalismButton from "../BrutalismButton";
import { FormattedMessage } from "react-intl";
import changeIndividualMergeState from "../../models/notifications/changeIndividualMergeState";

export default function MergeMessages({
mergeData,
getAllNotifications,
setModalOpen,
}) {
const handleClick = () => {
// const result = changeIndividualMergeState(action, taskId);
// setError('Error: ' + result);
getAllNotifications();
setModalOpen(false);
const [error, setError] = useState(false);
const handleClick = async (action, taskId) => {
const result = await changeIndividualMergeState(action, taskId);
if (result.status === 200) {
getAllNotifications();
setModalOpen(false);
} else {
setError(true);
}
};

// eslint-disable-next-line no-unused-vars
const [showError, setShowError] = useState(false);
// eslint-disable-next-line no-unused-vars
const [error, setError] = useState("");

const content = mergeData?.map((data) => {
const mergePending = data.notificationType === "mergePending";
const mergeComplete = data.notificationType === "mergeComplete";
Expand Down Expand Up @@ -103,7 +103,6 @@ export default function MergeMessages({
display: "flex",
marginTop: "10px",
marginBottom: "10px",
// width: 105
}}
>
<BrutalismButton onClick={() => handleClick("ignore", data.taskId)}>
Expand Down Expand Up @@ -167,7 +166,11 @@ export default function MergeMessages({
</h4>
)}
{content}
{showError && <h6>{error}</h6>}
{error && (
<h4>
<FormattedMessage id="BEERROR_UNKNOWN" />
</h4>
)}
</div>
);
}
31 changes: 14 additions & 17 deletions frontend/src/models/notifications/changeIndividualMergeState.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,18 @@
import axios from 'axios';
import axios from "axios";

export default async function changeIndividualMergeState(action, mergeId) {
let json = {};
json["mergeId"] = mergeId;
json["action"] = action;

let json = {};
json['mergeId'] = mergeId;
json['action'] = action;

console.log("Trying to change individual merge state on mergeId "+mergeId+" to "+action+".");

const response = await axios.post('/ScheduledIndividualMergeUpdate', json, {
headers: {
'Content-Type': 'application/json'
}
try {
const response = await axios.post("/ScheduledIndividualMergeUpdate", json, {
headers: {
"Content-Type": "application/json",
},
});

console.log('changeIndividualMergeState result:', response.json());

return response.json();

}
return response;
} catch (error) {
return error;
}
}

0 comments on commit df944b0

Please sign in to comment.