Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions api/src/api/errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,10 @@ errors!(
status: NOT_FOUND,
"The requested ticket was not found.",
},
TicketMessageEmpty {
status: BAD_REQUEST,
"The ticket message is empty.",
},
TicketMetaNotValid {
status: BAD_REQUEST,
"The metadata for the ticket is not in a valid format, should be a key-value of strings.",
Expand Down
4 changes: 4 additions & 0 deletions api/src/api/tickets.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,10 @@ pub async fn post_message_handler(
return Err(ApiError::TicketNotFound);
}

if new_message.message.is_empty() {
return Err(ApiError::TicketMessageEmpty);
}

let (message, message_author) = db
.ticket_add_message(id, current_user.id, new_message)
.await?;
Expand Down
26 changes: 25 additions & 1 deletion frontend/islands/TicketMessageInput.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// Copyright 2024 the JSR authors. All rights reserved. MIT license.
import { useEffect, useState } from "preact/hooks";
import { TbCheck, TbClock } from "tb-icons";
import {
AdminUpdateTicketRequest,
Expand All @@ -13,13 +14,29 @@ export function TicketMessageInput(
{ ticket, user }: { ticket: Ticket; user: FullUser },
) {
const message = useSignal("");
const [error, setError] = useState<string | null>(null);

useEffect(() => {
if (error) {
const timeout = setTimeout(() => {
setError(null);
}, 3000); // 3 seconds

return () => clearTimeout(timeout);
}
}, [error]);

return (
<form
class="space-y-5"
onSubmit={(e) => {
e.preventDefault();

if (message.value.trim() === "") {
setError("Message cannot be empty");
return;
}

api.post(
path`/tickets/${ticket.id}`,
{
Expand All @@ -42,7 +59,14 @@ export function TicketMessageInput(
placeholder="Type your message here..."
onChange={(e) => message.value = e.currentTarget!.value}
/>
<div class="flex justify-end gap-4">
<div class="flex justify-end gap-4 items-center">
{error && (
<div class="text-red-500 font-semibold">
<p>
{error}
</p>
</div>
)}
<button type="submit" class="button-primary">Send message</button>
{user.isStaff && (
<button
Expand Down
Loading