fix(work-orders): preserve comment draft until mutation succeeds

This commit is contained in:
Arthur Bassi 2026-07-21 10:53:30 -03:00 • committed by Arthur Bassi
parent 1b5b4014d1
commit 0682b47678
3 changed files with 11 additions and 7 deletions

View file

@ -141,7 +141,7 @@ type SlideOverCommentsTabProps = {
isPending: boolean;
currentUserId?: string | number;
isUpdatePending?: boolean;
onSubmit: (text: string) => void;
onSubmit: (text: string, options?: { onSuccess?: () => void }) => void;
onUpdateComment?: (
commentId: string | number,
text: string,
@ -165,8 +165,7 @@ export function SlideOverCommentsTab({
const handlePost = () => {
const text = commentText.trim();
if (!text || isReadOnly || isPending) return;
onSubmit(text);
setCommentText("");
onSubmit(text, { onSuccess: () => setCommentText("") });
};
const startEdit = (comment: WorkOrderComment) => {

View file

@ -34,7 +34,11 @@ type WorkOrderDetailsSectionProps = {
onAssign: (userId: string | number, userName: string) => void;
isAssignPending?: boolean;
onDispatchClick: (dispatchId: string | number) => void;
onCommentSubmit: (text: string, commentType: "customer" | "internal") => void;
onCommentSubmit: (
text: string,
commentType: "customer" | "internal",
options?: { onSuccess?: () => void },
) => void;
isCommentPending: boolean;
};
@ -65,8 +69,9 @@ export function WorkOrderDetailsSection({
if (!commentText.trim()) {
return;
}
onCommentSubmit(commentText.trim(), activeTab === "customer" ? "customer" : "internal");
setCommentText("");
onCommentSubmit(commentText.trim(), activeTab === "customer" ? "customer" : "internal", {
onSuccess: () => setCommentText(""),
});
};
return (

View file

@ -271,7 +271,7 @@ export function WorkOrderSlideOver({
isPending={commentMutation.isPending}
currentUserId={user?.id}
isUpdatePending={updateCommentMutation.isPending}
onSubmit={(text) => commentMutation.mutate({ text })}
onSubmit={(text, options) => commentMutation.mutate({ text }, options)}
onUpdateComment={(commentId, text, options) =>
updateCommentMutation.mutate({ commentId, text }, options)
}