-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathReviewNode.tsx
120 lines (112 loc) · 4.22 KB
/
ReviewNode.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
"use client";
import React, { useTransition } from "react";
import { Handle, Position, NodeProps, Node } from "@xyflow/react";
import { Split, Check, X, Clock } from "lucide-react";
import { approveArticleSummary, rejectArticleSummary } from "@/app/actions";
import type { ReviewStatus } from "@/trigger/reviewSummary";
import type { RealtimeRun, AnyTask } from "@trigger.dev/sdk";
export type ReviewNodeData = Node<
{
trigger: {
taskIdentifier: string;
currentRun?: RealtimeRun<AnyTask>;
};
},
"review"
>;
export const isReviewNode = (node: Node): node is ReviewNodeData => {
return node.type === "review";
};
function ReviewNode({ data }: NodeProps<ReviewNodeData>) {
const { currentRun } = data.trigger;
const waitpointTokenId = currentRun?.metadata?.waitpointTokenId as
| string
| undefined;
const audioSummaryUrl = currentRun?.metadata?.audioSummaryUrl as
| string
| undefined;
const reviewStatus = currentRun?.metadata?.reviewStatus as
| ReviewStatus
| undefined;
const [isReviewActionPending, startReviewActionTransition] = useTransition();
return (
<div className="p-2 shadow-md bg-white border-1 border-zinc-200 text-sm relative rounded-lg">
{reviewStatus === "pending" && (
<div className="absolute -top-1.5 -right-1.5 flex items-center justify-center w-4 h-4 rounded-full bg-indigo-600">
<span className="relative flex size-4">
<span className="absolute inline-flex h-full w-full animate-ping rounded-full bg-indigo-600 opacity-75"></span>
<span className="relative size-4 rounded-full bg-indigo-600 flex items-center justify-center">
<Split className="text-white size-2.5" />
</span>
</span>
</div>
)}
<div className="flex flex-col items-start gap-2">
<span>Review summary</span>
<audio controls className="h-[30px] w-[170px] mb-1">
{audioSummaryUrl && <source src={audioSummaryUrl} />}
</audio>
{reviewStatus === "approved" && (
<div className="bg-green-200 text-green-800 px-2 py-1 rounded-sm text-xs font-semibold">
<Check className="size-4 inline-block" /> Approved
</div>
)}
{reviewStatus === "rejected" && (
<div className="bg-red-200 text-red-800 px-2 py-1 rounded-sm text-xs font-semibold">
<X className="size-4 inline-block" /> Rejected
</div>
)}
{reviewStatus === "timeout" && (
<div className="bg-yellow-200 text-yellow-800 px-2 py-1 rounded-sm text-xs font-semibold">
<Clock className="size-4 inline-block" /> Timed out
</div>
)}
{(reviewStatus === undefined || reviewStatus === "pending") && (
<div className="flex items-center gap-2">
<button
className="bg-green-700 hover:bg-green-600 disabled:opacity-50 transition-colors text-white px-2 py-1 rounded-sm text-xs font-semibold"
onClick={() =>
startReviewActionTransition(() => {
waitpointTokenId && approveArticleSummary(waitpointTokenId);
})
}
disabled={
!waitpointTokenId ||
reviewStatus !== "pending" ||
isReviewActionPending
}
>
Approve
</button>
<button
className="bg-red-700 hover:bg-red-600 disabled:opacity-50 transition-colors text-white px-2 py-1 rounded-sm text-xs font-semibold"
onClick={() => {
startReviewActionTransition(() => {
waitpointTokenId && rejectArticleSummary(waitpointTokenId);
});
}}
disabled={
!waitpointTokenId ||
reviewStatus !== "pending" ||
isReviewActionPending
}
>
Reject
</button>
</div>
)}
</div>
<Handle
type="target"
position={Position.Left}
className="!bg-indigo-500"
/>
<Handle
type="source"
position={Position.Right}
className="!bg-indigo-500"
/>
</div>
);
}
export default ReviewNode;