| 1 |
import React, { useState } from 'react'; |
| 2 |
import { __ } from "@wordpress/i18n"; |
| 3 |
import { useSearchParams } from "react-router-dom"; |
| 4 |
import CategoryModal from '../faq-builder/components/CategoryModal'; |
| 5 |
import { IconPlus } from "~betterdocs/icons"; |
| 6 |
import { useFAQ } from "./FAQContext"; |
| 7 |
|
| 8 |
export default function CreateFAQGroup() { |
| 9 |
const context = useFAQ(); |
| 10 |
const [searchParams] = useSearchParams(); |
| 11 |
const [showCategoryModal, setShowCategoryModal] = useState(false); |
| 12 |
const [updateCategory, setUpdateCategory] = useState(null); |
| 13 |
|
| 14 |
// This header action creates a General FAQ Group; only show it on the FAQ Builder sub-tab. |
| 15 |
if ((searchParams.get("faq_tab") || "builder") !== "builder") { |
| 16 |
return null; |
| 17 |
} |
| 18 |
|
| 19 |
// Check if context is undefined |
| 20 |
if (!context) { |
| 21 |
console.error("useFAQ context is undefined. Ensure FAQProvider is set up correctly."); |
| 22 |
return null; // or handle the error as needed |
| 23 |
} |
| 24 |
|
| 25 |
const { reFetchCategories } = context; |
| 26 |
|
| 27 |
return ( |
| 28 |
<> |
| 29 |
<button |
| 30 |
type="button" |
| 31 |
className="admin-action-button" |
| 32 |
onClick={() => setShowCategoryModal(true)} |
| 33 |
> |
| 34 |
<span className="action-button-icon"> |
| 35 |
<IconPlus /> |
| 36 |
</span> |
| 37 |
<span className="action-button-icon-text"> |
| 38 |
{__("Create a New FAQ Group", "betterdocs")} |
| 39 |
</span> |
| 40 |
</button> |
| 41 |
{showCategoryModal || updateCategory !== null ? ( |
| 42 |
<CategoryModal |
| 43 |
open={true} |
| 44 |
reFetchCategories={reFetchCategories} |
| 45 |
setShowCategoryModal={setShowCategoryModal} |
| 46 |
updateCategory={updateCategory} |
| 47 |
setUpdateCategory={setUpdateCategory} |
| 48 |
/> |
| 49 |
) : null} |
| 50 |
</> |
| 51 |
); |
| 52 |
} |
| 53 |
|