-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feature/5 add delete endpoint to delete a ticket (#30)
Feature: * Add new endpoint DELETE and tests * Add Button to delete ticket and dialogue to confirm deletion of ticket Refactoring: * Renamed SidePanelStatus und SnackBarStatus to SidePanelConfig and SnackBarConfig * Combined SidePanelConfig and SnackbarConfig into one Config file * Refactoring: Removed classes to simply export functions (ApiUtils)
- Loading branch information
1 parent
b7b127d
commit 3cd1320
Showing
21 changed files
with
325 additions
and
126 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
import { Button } from "@mui/material"; | ||
|
||
type DeleteButtonProps = { | ||
onClick: () => void; | ||
}; | ||
|
||
export default function DeleteButton({ onClick }: Readonly<DeleteButtonProps>) { | ||
return ( | ||
<Button | ||
onClick={onClick} | ||
color={"error"} | ||
variant="contained" | ||
size={"small"} | ||
sx={{ | ||
fontWeight: "bold", | ||
}} | ||
> | ||
Delete | ||
</Button> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
86 changes: 86 additions & 0 deletions
86
frontend/src/components/dialogues/ConfirmDeletionDialogue.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
import { | ||
Dialog, | ||
DialogActions, | ||
DialogContent, | ||
DialogContentText, | ||
DialogTitle, | ||
} from "@mui/material"; | ||
import CancelButton from "../buttons/CancelButton.tsx"; | ||
import { Dispatch, SetStateAction } from "react"; | ||
import DeleteButton from "../buttons/DeleteButton.tsx"; | ||
import { SnackbarConfig, SidepanelConfig } from "../../types/Config.ts"; | ||
import { deleteTicket } from "../utils/ApiRequests.tsx"; | ||
import { Ticket } from "../../types/Ticket.ts"; | ||
|
||
type ConfirmDeletionDialogueProps = { | ||
confirmDeletion: boolean; | ||
setConfirmDeletion: Dispatch<SetStateAction<boolean>>; | ||
sidePanelConfig: SidepanelConfig; | ||
setSidepanelConfig: Dispatch<SetStateAction<SidepanelConfig>>; | ||
searchResults: Ticket[] | undefined; | ||
setSearchResults: Dispatch<SetStateAction<Ticket[] | undefined>>; | ||
setSnackbarConfig: Dispatch<SetStateAction<SnackbarConfig>>; | ||
}; | ||
|
||
export default function ConfirmDeletionDialogue({ | ||
confirmDeletion, | ||
setConfirmDeletion, | ||
sidePanelConfig, | ||
setSidepanelConfig, | ||
searchResults, | ||
setSearchResults, | ||
setSnackbarConfig, | ||
}: Readonly<ConfirmDeletionDialogueProps>) { | ||
if (sidePanelConfig.formType !== "UpdateTicket") { | ||
return; | ||
} | ||
|
||
const handleDelete = () => { | ||
deleteTicket(sidePanelConfig.ticket.id) | ||
.then(() => { | ||
setSearchResults( | ||
searchResults?.filter((ticket) => { | ||
return ticket.id !== sidePanelConfig.ticket.id; | ||
}), | ||
); | ||
setSnackbarConfig({ | ||
open: true, | ||
severity: "success", | ||
message: "Ticket successfully deleted!", | ||
}); | ||
setConfirmDeletion(false); | ||
setSidepanelConfig({ ...sidePanelConfig, open: false }); | ||
}) | ||
.catch((error) => { | ||
setSnackbarConfig({ | ||
open: true, | ||
severity: "error", | ||
message: error.response.data.error, | ||
}); | ||
}); | ||
}; | ||
|
||
const handleClose = () => { | ||
setConfirmDeletion(false); | ||
}; | ||
|
||
return ( | ||
<Dialog | ||
open={confirmDeletion} | ||
keepMounted | ||
onClose={handleClose} | ||
aria-describedby="alert-dialog-slide-description" | ||
> | ||
<DialogTitle>{"Confirm Deletion"}</DialogTitle> | ||
<DialogContent> | ||
<DialogContentText id="alert-dialog-slide-description"> | ||
Do you really want to delete this ticket? | ||
</DialogContentText> | ||
</DialogContent> | ||
<DialogActions> | ||
<CancelButton onClick={handleClose} /> | ||
<DeleteButton onClick={handleDelete} /> | ||
</DialogActions> | ||
</Dialog> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.