chore: clean up test scripts and sync payload CRM collections
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 11s
Build & Deploy / 🧪 QA (push) Failing after 23s
Build & Deploy / 🏗️ Build (push) Failing after 27s
Build & Deploy / 🚀 Deploy (push) Has been skipped
Build & Deploy / 🩺 Health Check (push) Has been skipped
Build & Deploy / 🔔 Notify (push) Successful in 5s

This commit is contained in:
2026-02-27 18:41:48 +01:00
parent 8907963d57
commit 4b5609a75e
15 changed files with 4301 additions and 106 deletions

View File

@@ -0,0 +1,82 @@
"use client";
import React, { useState, useEffect } from "react";
import { useDocumentInfo } from "@payloadcms/ui";
import { toast } from "@payloadcms/ui";
import { useRouter } from "next/navigation";
export const AiAnalyzeButton: React.FC = () => {
const { id, title } = useDocumentInfo();
const router = useRouter();
const [isAnalyzing, setIsAnalyzing] = useState(false);
const [hasWebsite, setHasWebsite] = useState(false);
useEffect(() => {
// Basic check if a website URL is likely present - would ideally check true document state
// but the fields might not be fully available in this context depending on Payload version.
// For now we just enable the button and the backend will validate.
setHasWebsite(true);
}, []);
const handleAnalyze = async (e: React.MouseEvent) => {
e.preventDefault();
if (!id) return;
setIsAnalyzing(true);
toast.info(
"Starting AI analysis for this account. This may take a few minutes...",
);
try {
const response = await fetch(`/api/crm-accounts/${id}/analyze`, {
method: "POST",
headers: {
"Content-Type": "application/json",
},
});
const result = await response.json();
if (!response.ok) {
throw new Error(result.error || "Analysis failed");
}
toast.success(result.message || "AI analysis completed successfully!");
// Refresh the page to show the new media items in the relationship field
router.refresh();
} catch (error) {
console.error("Analysis error:", error);
toast.error(
error instanceof Error
? error.message
: "An error occurred during analysis",
);
} finally {
setIsAnalyzing(false);
}
};
if (!id) return null; // Only show on existing documents, not when creating new
return (
<div style={{ marginBottom: "1rem", marginTop: "1rem" }}>
<button
onClick={handleAnalyze}
disabled={isAnalyzing || !hasWebsite}
className="btn btn--style-primary btn--icon-style-none btn--size-medium"
type="button"
>
{isAnalyzing ? "Analyzing Website..." : "Trigger AI Website Analysis"}
</button>
<p
style={{
fontSize: "0.8rem",
color: "var(--theme-elevation-400)",
marginTop: "0.5rem",
}}
>
Requires a valid website URL saved on this account.
</p>
</div>
);
};