Skip to content

Commit

Permalink
Merge pull request #155 from kasundie30/main
Browse files Browse the repository at this point in the history
Alerts Updated
  • Loading branch information
kasundie30 authored Oct 16, 2024
2 parents 8b83d17 + 983799d commit 7d3bb82
Show file tree
Hide file tree
Showing 5 changed files with 52 additions and 19 deletions.
24 changes: 17 additions & 7 deletions front-end/src/Pages/Deliverables.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ const onInputChange=(e)=>{
//When 'Update' button is clicked in the interface : Only Edit
const onUpdateSubmit = async (e) => {
e.preventDefault(); // Prevent default form submission
const confirmUpdate = window.confirm('Are you sure you want to update this deliverable?');
if (!confirmUpdate) return;
try {
await axios.put(`http://localhost:8080/deliverable/update/${deliverable.deliverableId}`, deliverable);
// Optionally, reload the data after successful submission
Expand Down Expand Up @@ -143,13 +145,21 @@ const onInputChange=(e)=>{
const onDeleteClick = async (deliverableId) => {
console.log("Delete button clicked");
console.log(deliverableId);
try {
await axios.delete(`http://localhost:8080/deliverable/delete/${deliverableId}`);
loadData();
alert("Deliverable Deleted!");
} catch (error) {
console.error("Error deleting deliverable:", error);
}
const confirmDelete = window.confirm('Are you sure you want to delete this deliverable?');
if (!confirmDelete) return;
try {
await axios.delete(`http://localhost:8080/deliverable/delete/${deliverableId}`);
loadData();
if (response.status === 200) {
alert('Deliverable deleted successfully');
loadData();
} else {
alert('Failed to delete deliverable');
}
} catch (error) {
console.error("Error deleting deliverable:", error);
alert("Failed to delete deliverable!");
}
}

/************************** View a specific entry *************************************/
Expand Down
4 changes: 4 additions & 0 deletions front-end/src/Pages/Gallery.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,16 @@ const Gallery = () => {
* Sends a DELETE request to remove the item from the backend.
*/
const onDeleteClick = async (albumID) => {
const confirmDelete = window.confirm('Are you sure you want to delete this album?');
if (!confirmDelete) return;
try {
await axios.delete(`http://localhost:8080/api/v1/gallery/${albumID}`);
const latestGallery = await fetchGallery();
setGallery(latestGallery);
alert('Album deleted successfully');
} catch (error) {
console.error("Error deleting gallery item:", error);
alert("Failed to delete album!");
}
}
// When 'Close' button is clicked: for Edit, and Add New
Expand Down
5 changes: 4 additions & 1 deletion front-end/src/Pages/News.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,14 +77,17 @@ const News = () => {
const onDeleteClick = async (newsID) => {
console.log("Delete button clicked");
console.log(newsID); // Log the newsID for debugging
const confirmDelete = window.confirm('Are you sure you want to delete this news?');
if (!confirmDelete) return;
try {
await axios.delete(`http://localhost:8080/api/v1/news/${newsID}`); // Send DELETE request

// Fetch the updated list of news and update the state
const latestNews = await fetchNews();
setNews(latestNews);
alert('News deleted successfully');
} catch (error) {
console.error("Error deleting news:", error); // Log any errors
alert("Failed to delete news!");
}
}
// When 'Close' button is clicked: for Edit, and Add New
Expand Down
26 changes: 16 additions & 10 deletions front-end/src/Pages/ProjectManagement.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ try {
headers: {
'Content-Type': 'multipart/form-data'
}});
alert("task added");
alert("Task added successfully!");
// reload the data after successful submission
setTasks([...tasks,task])
// Clear the form fields after successful submission if needed
Expand All @@ -192,26 +192,30 @@ try {
//When 'Update' button is clicked in the interface : Only Edit
const onUpdateSubmit = async (e) => {
e.preventDefault(); // Prevent default form submission
setIsLoading(true); // Show loading indicator
const confirmUpdate = window.confirm('Are you sure you want to update this task?');
if (!confirmUpdate) return;

const {assignedUsers, ...newtaskFormat } = task;
const formData = new FormData();
for (const key in newtaskFormat) {
formData.append(key, newtaskFormat[key]);
}
formData.append("assignedUsers",JSON.stringify(assignedUsers.map(({ admin, ...assignedUsersDetails }) => assignedUsersDetails)))
console.log("task",task)
try {
console.log("task.... ",formData)
await axios.put(`http://localhost:8080/api/v1/tasks/updateWithUsers`, formData, {
headers: {
'Content-Type': 'multipart/form-data'
}});;

// Optionally, change the tasks list after successful submission
setTasks([...tasks,task])
setEditRow(false);
setShowInterface()
// Optionally, change the tasks list after successful submission
setTasks([...tasks,task])
setEditRow(false);
setShowInterface(false)
alert("Task updated successfully!");
} catch (error) {
console.error("Error editing tasks:", error);
} finally {
setIsLoading(false); // Hide loading indicator
}
};

Expand Down Expand Up @@ -463,8 +467,10 @@ if(loggedInUser){
</div>
</div>
}

{addRow? <div className="buttonsBlock"><button type = "submit">Add</button><button onClick={closePopUp} endIcon={<CloseIcon></CloseIcon>} >Close</button></div> : <div className="buttonsBlock"><button type = "submit">Update</button><button onClick={closePopUp} endIcon={<CloseIcon></CloseIcon>} >Close</button></div> }
<div className = "buttonsBlock">
{addRow? <button type = "submit">Add</button> : <button type = "submit">Update</button> }
<button type="button" onClick={closePopUp} endIcon={<CloseIcon></CloseIcon>}>Discard</button>
</div>
</form>
</div>
</DialogContent>
Expand Down
12 changes: 11 additions & 1 deletion front-end/src/Pages/Workplan.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ function Workplan() {

//When 'Update' button is clicked in the dialog : Only Edit
const onUpdateSubmit = async (e) => {
e.preventDefault(); // Prevent default form submission
e.preventDefault();
const confirmUpdate = window.confirm('Are you sure you want to update this activity?');
if (!confirmUpdate) return;
try {
await axios.put(`http://localhost:8080/workplan/update/${activity.activityId}`, activity);
// Optionally, reload the data after successful submission
Expand All @@ -161,9 +163,17 @@ function Workplan() {
const onDeleteClick = async (activityId) => {
console.log("Delete button clicked");
console.log(activityId);
const confirmDelete = window.confirm('Are you sure you want to delete this activity?');
if (!confirmDelete) return;
try {
await axios.delete(`http://localhost:8080/workplan/delete/${activityId}`);
loadData();
if (response.status === 200) {
alert('Activity deleted successfully');
loadData();
} else {
alert('Failed to delete Activity');
}
} catch (error) {
console.error("Error deleting workplan activity:", error);
}
Expand Down

0 comments on commit 7d3bb82

Please sign in to comment.