Skip to content

Commit

Permalink
Merge pull request stakwork#698 from saithsab877/update-ticket-error-…
Browse files Browse the repository at this point in the history
…handling

✨Implement Toast Notifications for Ticket Update Submission Feedback
  • Loading branch information
humansinstitute authored Dec 3, 2024
2 parents abe88b0 + b510776 commit 5803ab0
Showing 1 changed file with 29 additions and 1 deletion.
30 changes: 29 additions & 1 deletion src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
fetchTicketDetails();
}, [ticketData.uuid, main]);

const addUpdateSuccessToast = () => {
setToasts([
{
id: '3',
title: 'Hive',
color: 'success',
text: 'Updates Saved!'
}
]);
};

const addUpdateErrorToast = () => {
setToasts([
{
id: '4',
title: 'Hive',
color: 'danger',
text: 'We had an issue, try again!'
}
]);
};

const handleUpdate = async () => {
const updateTicketData = {
...ticketData,
Expand All @@ -59,9 +81,15 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
};

try {
await main.createUpdateTicket(updateTicketData);
const response = await main.createUpdateTicket(updateTicketData);

if (response === 406 || !response) {
throw new Error('Failed to update ticket');
}
addUpdateSuccessToast();
} catch (error) {
console.error('Error updating ticket:', error);
addUpdateErrorToast();
}
};

Expand Down

0 comments on commit 5803ab0

Please sign in to comment.