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 bbca86c9a7
commit 6c481eaf7c
3 changed files with 11 additions and 7 deletions

View file

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

View file

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

View file

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