import { useState } from "react"; import { Link } from "react-router-dom"; import type { Opportunity, OpportunityRemovalReason } from "../../domain/types"; import { Badge, Button, Select, Textarea } from "../ui"; import { formatTimeAgo } from "../../lib/time"; const reasonLabels: Record, string> = { pain_mismatch: "不符合產品痛點", provider_or_ad: "供應商/廣告貼文", stale: "需求已過期", already_solved: "對方已解決", duplicate: "重複商機", other: "其他原因", }; type Props = { opportunity: Opportunity; onOpen: (opportunity: Opportunity) => void; onAccept: (opportunity: Opportunity) => void; onComplete: (opportunity: Opportunity) => void; onRemove: (opportunity: Opportunity, input: { reason: OpportunityRemovalReason; note?: string }) => void; onRestore: (opportunity: Opportunity) => void; busy?: boolean; }; export function OpportunityInboxCard({ opportunity, onOpen, onAccept, onComplete, onRemove, onRestore, busy = false }: Props) { const [removeOpen, setRemoveOpen] = useState(false); const [reason, setReason] = useState("pain_mismatch"); const [note, setNote] = useState(""); const reviewState = opportunity.review_state ?? (opportunity.status === "accepted" ? "completed" : opportunity.status === "dismissed" ? "removed" : "pending"); const pending = reviewState === "pending"; const score = opportunity.priority_score ?? opportunity.intent_score; const evidence = opportunity.demand_evidence?.[0] ?? opportunity.product_matches?.[0]?.reasons?.[0]?.reason; const accepted = opportunity.status === "accepted" || Boolean(opportunity.contact_id); const priorityLabel = opportunity.priority_band === "high" ? "優先跟進" : opportunity.priority_band === "review" ? "值得確認" : opportunity.priority_band === "low" ? "低順位" : opportunity.intent_band === "high" ? "高意向" : opportunity.intent_band === "mid" ? "中意向" : "低意向"; function submitRemove() { if (reason === "other" && !note.trim()) return; onRemove(opportunity, { reason, note: note.trim() || undefined }); setRemoveOpen(false); setNote(""); } return (
{priorityLabel} · {score} {opportunity.primary_product_label ? 適合產品 · {opportunity.primary_product_label} : 尚未配對產品} 需求意向 {opportunity.intent_score} · {formatTimeAgo(opportunity.posted_at)}

{opportunity.text}

{evidence ?

為什麼推薦:{evidence}

: null}
@{opportunity.author_handle || "未知作者"} 查看 Threads 原文
{(pending || reviewState === "completed") && !accepted ? ( ) : null} {pending ? : null} {pending ? : null} {reviewState === "removed" ? : null} {reviewState === "completed" && accepted && opportunity.contact_id ? ( 前往名單 ) : null} {reviewState === "completed" ? {accepted ? "已加入名單" : "已處理"} : null}
{removeOpen ? (
為什麼不適合?

選原因後,這筆會移到「已移除」且不會再次出現在待處理。這個動作不扣點。

{reason === "other" ?