Update frontend/src/components/ExportButtons.jsx
Browse files
frontend/src/components/ExportButtons.jsx
CHANGED
|
@@ -20,7 +20,8 @@ import {
|
|
| 20 |
} from "@/components/ui/dropdown-menu";
|
| 21 |
import { cn } from "@/lib/utils";
|
| 22 |
import ShareModal from "@/components/ShareModal";
|
| 23 |
-
import
|
|
|
|
| 24 |
|
| 25 |
// Helper functions from ExtractionOutput
|
| 26 |
function prepareFieldsForOutput(fields, format = "json") {
|
|
@@ -177,6 +178,9 @@ export default function ExportButtons({ isComplete, extractionResult }) {
|
|
| 177 |
const [downloading, setDownloading] = useState(null);
|
| 178 |
const [copied, setCopied] = useState(false);
|
| 179 |
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
|
|
|
|
|
|
|
|
|
|
| 180 |
|
| 181 |
// Helper function to extract text from fields (same as in ExtractionOutput)
|
| 182 |
const extractTextFromFields = (fields) => {
|
|
@@ -537,9 +541,27 @@ ${htmlContent}
|
|
| 537 |
}
|
| 538 |
};
|
| 539 |
|
| 540 |
-
const handleCopyLink = () => {
|
| 541 |
-
|
| 542 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 543 |
};
|
| 544 |
|
| 545 |
const handleShare = async (extractionId, recipientEmail) => {
|
|
@@ -587,12 +609,8 @@ ${htmlContent}
|
|
| 587 |
className="rounded-lg cursor-pointer"
|
| 588 |
onClick={handleCopyLink}
|
| 589 |
>
|
| 590 |
-
|
| 591 |
-
|
| 592 |
-
) : (
|
| 593 |
-
<Link2 className="h-4 w-4 mr-2" />
|
| 594 |
-
)}
|
| 595 |
-
{copied ? "Link copied!" : "Copy share link"}
|
| 596 |
</DropdownMenuItem>
|
| 597 |
<DropdownMenuSeparator />
|
| 598 |
<DropdownMenuItem
|
|
@@ -659,6 +677,17 @@ ${htmlContent}
|
|
| 659 |
onShare={handleShare}
|
| 660 |
extractionId={extractionResult?.id}
|
| 661 |
/>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 662 |
</motion.div>
|
| 663 |
);
|
| 664 |
}
|
|
|
|
| 20 |
} from "@/components/ui/dropdown-menu";
|
| 21 |
import { cn } from "@/lib/utils";
|
| 22 |
import ShareModal from "@/components/ShareModal";
|
| 23 |
+
import ShareLinkModal from "@/components/ShareLinkModal";
|
| 24 |
+
import { shareExtraction, createShareLink } from "@/services/api";
|
| 25 |
|
| 26 |
// Helper functions from ExtractionOutput
|
| 27 |
function prepareFieldsForOutput(fields, format = "json") {
|
|
|
|
| 178 |
const [downloading, setDownloading] = useState(null);
|
| 179 |
const [copied, setCopied] = useState(false);
|
| 180 |
const [isShareModalOpen, setIsShareModalOpen] = useState(false);
|
| 181 |
+
const [isShareLinkModalOpen, setIsShareLinkModalOpen] = useState(false);
|
| 182 |
+
const [shareLink, setShareLink] = useState("");
|
| 183 |
+
const [isGeneratingLink, setIsGeneratingLink] = useState(false);
|
| 184 |
|
| 185 |
// Helper function to extract text from fields (same as in ExtractionOutput)
|
| 186 |
const extractTextFromFields = (fields) => {
|
|
|
|
| 541 |
}
|
| 542 |
};
|
| 543 |
|
| 544 |
+
const handleCopyLink = async () => {
|
| 545 |
+
if (!extractionResult?.id) return;
|
| 546 |
+
|
| 547 |
+
setIsGeneratingLink(true);
|
| 548 |
+
setIsShareLinkModalOpen(true);
|
| 549 |
+
setShareLink("");
|
| 550 |
+
|
| 551 |
+
try {
|
| 552 |
+
const result = await createShareLink(extractionResult.id);
|
| 553 |
+
if (result.success && result.share_link) {
|
| 554 |
+
setShareLink(result.share_link);
|
| 555 |
+
} else {
|
| 556 |
+
throw new Error("Failed to generate share link");
|
| 557 |
+
}
|
| 558 |
+
} catch (err) {
|
| 559 |
+
console.error("Failed to create share link:", err);
|
| 560 |
+
setShareLink("");
|
| 561 |
+
// Still show modal but with error state
|
| 562 |
+
} finally {
|
| 563 |
+
setIsGeneratingLink(false);
|
| 564 |
+
}
|
| 565 |
};
|
| 566 |
|
| 567 |
const handleShare = async (extractionId, recipientEmail) => {
|
|
|
|
| 609 |
className="rounded-lg cursor-pointer"
|
| 610 |
onClick={handleCopyLink}
|
| 611 |
>
|
| 612 |
+
<Link2 className="h-4 w-4 mr-2 text-indigo-600" />
|
| 613 |
+
Copy share link
|
|
|
|
|
|
|
|
|
|
|
|
|
| 614 |
</DropdownMenuItem>
|
| 615 |
<DropdownMenuSeparator />
|
| 616 |
<DropdownMenuItem
|
|
|
|
| 677 |
onShare={handleShare}
|
| 678 |
extractionId={extractionResult?.id}
|
| 679 |
/>
|
| 680 |
+
|
| 681 |
+
{/* Share Link Modal */}
|
| 682 |
+
<ShareLinkModal
|
| 683 |
+
isOpen={isShareLinkModalOpen}
|
| 684 |
+
onClose={() => {
|
| 685 |
+
setIsShareLinkModalOpen(false);
|
| 686 |
+
setShareLink("");
|
| 687 |
+
}}
|
| 688 |
+
shareLink={shareLink}
|
| 689 |
+
isLoading={isGeneratingLink}
|
| 690 |
+
/>
|
| 691 |
</motion.div>
|
| 692 |
);
|
| 693 |
}
|