Skip to content

Commit

Permalink
TUP-609 Improve feedback when users reply to tickets (#382)
Browse files Browse the repository at this point in the history
* TUP-609 Improve feedback when users reply to tickets

* Linting

* Create test for success message

* Linting test

* - Added timeout for error/success messages
- Removed disabled reply button on submit
- Added margin to button
- Centered reply response message with button
  • Loading branch information
sophia-massie authored Dec 12, 2023
1 parent b7c7566 commit 7e9f1a8
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
.ticket-reply-submission {
display: flex;
justify-content: right;
align-items: center;
}

.ticket-model-content {
Expand Down Expand Up @@ -130,4 +131,5 @@
.ticket-reply-submission button {
padding-left: 5rem;
padding-right: 5rem;
margin-left: 1rem;
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,24 @@ describe('Ticket Modal', () => {
);
});
});

it('should render an success message if an reply success is returned from the useMutation hook', async () => {
const user = userEvent.setup();
server.use(
rest.post('http://localhost:8001/tickets/85411/reply', (req, res, ctx) =>
res.once(ctx.status(200))
)
);
const { getByLabelText, getByText, getByRole } = testRender(
<TicketReplyForm ticketId="85411" />
);

const reply = getByLabelText(/Reply/);
const submit = getByRole('button', { name: 'Reply' });
await user.type(reply, 'success message?');
fireEvent.click(submit);

await waitFor(() =>
expect(getByText(/Your reply has been sent/)).toBeDefined()
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ export const TicketReplyForm: React.FC<{ ticketId: string }> = ({
ticketId,
}) => {
const mutation = useTicketReply(ticketId);
const { mutate, isLoading, isError } = mutation;
const { mutate, isSuccess, isLoading, isError } = mutation;

const defaultValues: TicketReplyFormValues = {
text: '',
Expand All @@ -44,6 +44,11 @@ export const TicketReplyForm: React.FC<{ ticketId: string }> = ({
if (values.status) formData.append('status', values.status);
mutate(formData, {
onSuccess: () => resetForm(),
onSettled: () => {
setTimeout(() => {
mutation.reset();
}, 5000);
},
});
};

Expand Down Expand Up @@ -77,7 +82,13 @@ export const TicketReplyForm: React.FC<{ ticketId: string }> = ({
maxSizeMessage="Max File Size: 3MB"
maxSize={3145728}
/>

<FormGroup className="ticket-reply-submission">
{isSuccess && (
<InlineMessage type="success">
Your reply has been sent.
</InlineMessage>
)}
{isError && (
<InlineMessage type="error">
Something went wrong.
Expand Down

0 comments on commit 7e9f1a8

Please sign in to comment.