Skip to content

Commit

Permalink
Add toast notifications for Ticket Builder success and failure
Browse files Browse the repository at this point in the history
  • Loading branch information
saithsab877 committed Dec 2, 2024
1 parent 39ef5ad commit d401041
Showing 1 changed file with 32 additions and 1 deletion.
33 changes: 32 additions & 1 deletion src/components/common/TicketEditor/TicketEditor.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import React, { useState, useEffect } from 'react';
import { useStores } from 'store';
import { EuiGlobalToastList } from '@elastic/eui';
import { ActionButton, TicketButtonGroup } from '../../../people/widgetViews/workspace/style';
import { TicketContainer, TicketHeader, TicketTextArea } from '../../../pages/tickets/style';
import { TicketStatus } from '../../../store/interface';
import { Toast } from '../../../people/widgetViews/workspace/interface';

interface TicketEditorProps {
ticketData: {
Expand All @@ -21,6 +23,7 @@ interface TicketEditorProps {

const TicketEditor = ({ ticketData }: TicketEditorProps) => {
const [description, setDescription] = useState('');
const [toasts, setToasts] = useState<Toast[]>([]);
const { main } = useStores();

useEffect(() => {
Expand Down Expand Up @@ -58,6 +61,28 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
}
};

const addSuccessToast = () => {
setToasts([
{
id: '1',
title: 'Ticket Builder',
color: 'success',
text: "Success, I'll rewrite your ticket now!"
}
]);
};

const addErrorToast = () => {
setToasts([
{
id: '2',
title: 'Ticket Builder',
color: 'danger',
text: 'Sorry, there appears to be a problem'
}
]);
};

const handleTicketBuilder = async () => {
try {
const ticketForReview = {
Expand All @@ -69,12 +94,13 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
const response = await main.sendTicketForReview(ticketForReview);

if (response) {
console.log('Ticket sent for review successfully');
addSuccessToast();
} else {
throw new Error('Failed to send ticket for review');
}
} catch (error) {
console.error('Error in ticket builder:', error);
addErrorToast();
}
};

Expand All @@ -99,6 +125,11 @@ const TicketEditor = ({ ticketData }: TicketEditorProps) => {
Ticket Builder
</ActionButton>
</TicketButtonGroup>
<EuiGlobalToastList
toasts={toasts}
dismissToast={() => setToasts([])}
toastLifeTimeMs={3000}
/>
</TicketContainer>
);
};
Expand Down

0 comments on commit d401041

Please sign in to comment.