Skip to content

Commit

Permalink
Merge pull request stakwork#690 from saithsab877/ticket-builder-toast…
Browse files Browse the repository at this point in the history
…-notifications

✨Implement Toast Notifications for Ticket Builder Submission Feedback
  • Loading branch information
humansinstitute authored Dec 3, 2024
2 parents 39ef5ad + d401041 commit a1594a7
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 a1594a7

Please sign in to comment.