| 1 |
import React from "react"; |
| 2 |
import { useState } from "@wordpress/element"; |
| 3 |
import { __ } from "@wordpress/i18n"; |
| 4 |
import { toast } from "react-toastify"; |
| 5 |
import { generateSampleData } from "./function"; |
| 6 |
import SampleDocsFlow from "../../sample-docs/SampleDocsFlow"; |
| 7 |
import { sampleDocsEnabled } from "../../sample-docs/api"; |
| 8 |
import { AiBadge, GenerateBtn } from "../../sample-docs/Pieces"; |
| 9 |
import { FaqIllustration } from "../../sample-docs/icons"; |
| 10 |
|
| 11 |
const EmptyDashboard = ({ |
| 12 |
reFetchCategories, |
| 13 |
setShowCategoryModal, |
| 14 |
showNewFaqText = true, |
| 15 |
showFaqActionButtons = true, |
| 16 |
showSampleFaqButton = true, |
| 17 |
contentType = "faq", |
| 18 |
}) => { |
| 19 |
const [flowOpen, setFlowOpen] = useState(false); |
| 20 |
const [text, setText] = useState(__("Generate Sample FAQs", "betterdocs")); |
| 21 |
const aiEnabled = sampleDocsEnabled(); |
| 22 |
const isProductFaq = contentType === "product_faq"; |
| 23 |
|
| 24 |
// The classic CSV/sample-data fallback seeds the General FAQ taxonomy, so it |
| 25 |
// is only valid for the General tab. On the WooCommerce (Product FAQ) tab we |
| 26 |
// only offer the AI/store-aware flow — never the CSV button. |
| 27 |
const showSampleButton = showSampleFaqButton && (aiEnabled || !isProductFaq); |
| 28 |
|
| 29 |
// Tier-3 fallback (AI disabled): the classic CSV/sample-data generator. |
| 30 |
const handleSampleDataCreate = () => { |
| 31 |
setText(__("Generating...", "betterdocs")); |
| 32 |
generateSampleData() |
| 33 |
.then(() => { |
| 34 |
toast.success(__("Sample data generated.", "betterdocs")); |
| 35 |
reFetchCategories(); |
| 36 |
}) |
| 37 |
.catch((err) => { |
| 38 |
setText(__("Generate Sample FAQs", "betterdocs")); |
| 39 |
err?.name |
| 40 |
? toast.error(`${err?.name} :${err?.message}`) |
| 41 |
: toast.error(`${err?.message}`); |
| 42 |
}); |
| 43 |
}; |
| 44 |
|
| 45 |
return ( |
| 46 |
<section className="betterdocs-dashboard-body"> |
| 47 |
<div className="betterdocs-no-docs-wrapper betterdocs-sd-empty-card"> |
| 48 |
<div className="betterdocs-no-docs-img-wrap"> |
| 49 |
<FaqIllustration /> |
| 50 |
</div> |
| 51 |
|
| 52 |
<div className="betterdocs-no-docs-content"> |
| 53 |
<h3 className="betterdocs-no-docs-title"> |
| 54 |
{isProductFaq |
| 55 |
? __("No Product FAQ Found!", "betterdocs") |
| 56 |
: __("No FAQ Found!", "betterdocs")} |
| 57 |
</h3> |
| 58 |
|
| 59 |
{showNewFaqText && ( |
| 60 |
<p className="betterdocs-no-docs-text"> |
| 61 |
{aiEnabled && showSampleButton |
| 62 |
? isProductFaq |
| 63 |
? __("Create a product FAQ group to get started — or let AI build a store-ready FAQ set from your store details.", "betterdocs") |
| 64 |
: __("Create a new FAQ group to get started — or let AI build a starter set of FAQs for you.", "betterdocs") |
| 65 |
: isProductFaq |
| 66 |
? __("Please create a product FAQ group to get started.", "betterdocs") |
| 67 |
: __("Please create a new FAQ group to get started.", "betterdocs")} |
| 68 |
</p> |
| 69 |
)} |
| 70 |
|
| 71 |
{showFaqActionButtons && ( |
| 72 |
<> |
| 73 |
<div className="betterdocs-sd-empty-actions"> |
| 74 |
<button |
| 75 |
type="button" |
| 76 |
className="betterdocs-sd-create-btn" |
| 77 |
onClick={() => setShowCategoryModal(true)} |
| 78 |
> |
| 79 |
{isProductFaq |
| 80 |
? __("Create a Product FAQ Group", "betterdocs") |
| 81 |
: __("Create a New FAQ Group", "betterdocs")} |
| 82 |
</button> |
| 83 |
|
| 84 |
{showSampleButton && ( |
| 85 |
aiEnabled ? ( |
| 86 |
<GenerateBtn block onClick={() => setFlowOpen(true)}> |
| 87 |
{isProductFaq |
| 88 |
? __("Generate Sample Product FAQs", "betterdocs") |
| 89 |
: __("Generate Sample FAQs", "betterdocs")} |
| 90 |
</GenerateBtn> |
| 91 |
) : ( |
| 92 |
<button type="button" className="betterdocs-dashboard-btn" onClick={handleSampleDataCreate}> |
| 93 |
{text} |
| 94 |
</button> |
| 95 |
) |
| 96 |
)} |
| 97 |
</div> |
| 98 |
|
| 99 |
{showSampleButton && aiEnabled && ( |
| 100 |
<div className="betterdocs-sd-empty-badge"> |
| 101 |
<AiBadge /> |
| 102 |
</div> |
| 103 |
)} |
| 104 |
</> |
| 105 |
)} |
| 106 |
</div> |
| 107 |
</div> |
| 108 |
|
| 109 |
{flowOpen && ( |
| 110 |
<SampleDocsFlow |
| 111 |
contentType={contentType} |
| 112 |
onClose={() => setFlowOpen(false)} |
| 113 |
onComplete={() => { |
| 114 |
setFlowOpen(false); |
| 115 |
reFetchCategories(); |
| 116 |
}} |
| 117 |
/> |
| 118 |
)} |
| 119 |
</section> |
| 120 |
); |
| 121 |
}; |
| 122 |
|
| 123 |
export default EmptyDashboard; |
| 124 |
|