fix(web): reuse project combobox in timeline popovers
This commit is contained in:
@@ -31,10 +31,7 @@ interface CommentItem {
|
||||
replies: CommentReply[];
|
||||
}
|
||||
|
||||
type CommentEntityType = "estimate";
|
||||
|
||||
interface CommentThreadProps {
|
||||
entityType: CommentEntityType;
|
||||
entityId: string;
|
||||
}
|
||||
|
||||
@@ -113,37 +110,36 @@ function CommentBody({ body }: { body: string }) {
|
||||
|
||||
function SingleComment({
|
||||
comment,
|
||||
entityType,
|
||||
entityId,
|
||||
isReply = false,
|
||||
}: {
|
||||
comment: CommentItem | CommentReply;
|
||||
entityType: CommentEntityType;
|
||||
entityId: string;
|
||||
isReply?: boolean;
|
||||
}) {
|
||||
const [showReplyInput, setShowReplyInput] = useState(false);
|
||||
const [confirmDelete, setConfirmDelete] = useState(false);
|
||||
const utils = trpc.useUtils();
|
||||
const commentTarget = { entityType: "estimate" as const, entityId };
|
||||
|
||||
const createMutation = trpc.comment.create.useMutation({
|
||||
onSuccess: () => {
|
||||
setShowReplyInput(false);
|
||||
void utils.comment.list.invalidate({ entityType, entityId });
|
||||
void utils.comment.count.invalidate({ entityType, entityId });
|
||||
void utils.comment.list.invalidate(commentTarget);
|
||||
void utils.comment.count.invalidate(commentTarget);
|
||||
},
|
||||
});
|
||||
|
||||
const resolveMutation = trpc.comment.resolve.useMutation({
|
||||
onSuccess: () => {
|
||||
void utils.comment.list.invalidate({ entityType, entityId });
|
||||
void utils.comment.list.invalidate(commentTarget);
|
||||
},
|
||||
});
|
||||
|
||||
const deleteMutation = trpc.comment.delete.useMutation({
|
||||
onSuccess: () => {
|
||||
void utils.comment.list.invalidate({ entityType, entityId });
|
||||
void utils.comment.count.invalidate({ entityType, entityId });
|
||||
void utils.comment.list.invalidate(commentTarget);
|
||||
void utils.comment.count.invalidate(commentTarget);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -217,12 +213,12 @@ function SingleComment({
|
||||
{showReplyInput && (
|
||||
<div className="mt-3">
|
||||
<CommentInput
|
||||
entityType={entityType}
|
||||
entityType={commentTarget.entityType}
|
||||
entityId={entityId}
|
||||
parentId={comment.id}
|
||||
onSubmit={(replyBody) => {
|
||||
createMutation.mutate({
|
||||
entityType,
|
||||
entityType: commentTarget.entityType,
|
||||
entityId,
|
||||
parentId: comment.id,
|
||||
body: replyBody,
|
||||
@@ -259,7 +255,6 @@ function SingleComment({
|
||||
<SingleComment
|
||||
key={reply.id}
|
||||
comment={reply}
|
||||
entityType={entityType}
|
||||
entityId={entityId}
|
||||
isReply
|
||||
/>
|
||||
@@ -270,18 +265,19 @@ function SingleComment({
|
||||
);
|
||||
}
|
||||
|
||||
export function CommentThread({ entityType, entityId }: CommentThreadProps) {
|
||||
export function CommentThread({ entityId }: CommentThreadProps) {
|
||||
const utils = trpc.useUtils();
|
||||
const commentTarget = { entityType: "estimate" as const, entityId };
|
||||
|
||||
const commentsQuery = trpc.comment.list.useQuery(
|
||||
{ entityType, entityId },
|
||||
commentTarget,
|
||||
{ staleTime: 10_000 },
|
||||
);
|
||||
|
||||
const createMutation = trpc.comment.create.useMutation({
|
||||
onSuccess: () => {
|
||||
void utils.comment.list.invalidate({ entityType, entityId });
|
||||
void utils.comment.count.invalidate({ entityType, entityId });
|
||||
void utils.comment.list.invalidate(commentTarget);
|
||||
void utils.comment.count.invalidate(commentTarget);
|
||||
},
|
||||
});
|
||||
|
||||
@@ -312,7 +308,6 @@ export function CommentThread({ entityType, entityId }: CommentThreadProps) {
|
||||
<SingleComment
|
||||
key={comment.id}
|
||||
comment={comment}
|
||||
entityType={entityType}
|
||||
entityId={entityId}
|
||||
/>
|
||||
))}
|
||||
@@ -322,11 +317,11 @@ export function CommentThread({ entityType, entityId }: CommentThreadProps) {
|
||||
{/* New comment input */}
|
||||
<div className="border-t border-gray-200 dark:border-gray-700 pt-4">
|
||||
<CommentInput
|
||||
entityType={entityType}
|
||||
entityType={commentTarget.entityType}
|
||||
entityId={entityId}
|
||||
onSubmit={(body) => {
|
||||
createMutation.mutate({
|
||||
entityType,
|
||||
entityType: commentTarget.entityType,
|
||||
entityId,
|
||||
body,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user