PluginProbe
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO / 1.4.22
Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO v1.4.22
1.4.22 1.4.21 1.4.20 1.4.19 1.4.18 1.4.17 1.4.16 1.4.15 1.4.14 1.4.13 1.4.12 1.4.11 1.4.10 1.4.9 1.4.8 1.4.7 1.4.6 1.4.5 1.4.4 1.4.3 1.4.2 1.4.1 1.4.0 1.3.54 1.3.53 All 185 releases
disco / backend / views / components / Docs / App.jsx

App.jsx in Discount Rules for WooCommerce – Disco | Dynamic Pricing, Conditions, Bulk, Bundle, BOGO 1.4.22, at backend/views/components/Docs/App.jsx

83 lines 2.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { useEffect, useState } from 'react';
2 import DiscoAccordion from './components/accordions/Accordions';
3 import HelpCenter from './components/help-center/HelpCenter';
4 import DiscoResources from './components/resources/AdditionalResources';
5 import DiscoSidebar from './components/sidebar/Sidebar';
6 import DiscoSupportSection from './components/support/SupportSection';
7 import initialData from './data/docsData';
8 import getDocs from './utils/fetchDocs';
9 import withUtm from './utils/withUtm';
10
11 export default function App() {
12 const [docsData, setDocsData] = useState(initialData);
13 const [searchQuery, setSearchQuery] = useState('');
14
15 useEffect(() => {
16 const fetchDocs = async () => {
17 try {
18 const data = await getDocs();
19 const updatedDocs = initialData.map((section) => {
20 const matchingDocs = data.filter(
21 (doc) => doc.doc_category[0] === section.doc_category_id
22 );
23 return { ...section, items: matchingDocs };
24 });
25 setDocsData(updatedDocs);
26 } catch (err) {
27 console.error('Failed to fetch docs:', err);
28 }
29 };
30 fetchDocs();
31 }, []);
32
33 const query = searchQuery.trim().toLowerCase();
34
35 const stripHtml = (html) =>
36 html
37 ? html
38 .replace(/<[^>]*>/g, ' ')
39 .replace(/\s+/g, ' ')
40 .trim()
41 : '';
42
43 const itemMatches = (item) => {
44 const title = (item.title?.rendered || item.title || '').toLowerCase();
45 const content = stripHtml(item.content?.rendered || '').toLowerCase();
46 return title.includes(query) || content.includes(query);
47 };
48
49 // Flat list of matching results for the search dropdown
50 const searchResults = query
51 ? docsData.flatMap((section) =>
52 section.items.filter(itemMatches).map((item) => ({
53 title: item.title?.rendered || item.title,
54 link: withUtm(item.link, 'help-docs', 'search-result'),
55 section: section.title,
56 excerpt: stripHtml(
57 item.excerpt?.rendered || item.content?.rendered || ''
58 ).slice(0, 100),
59 }))
60 )
61 : [];
62
63 return (
64 <div className="disco:py-4 disco:pr-4">
65 <HelpCenter
66 searchQuery={searchQuery}
67 setSearchQuery={setSearchQuery}
68 searchResults={searchResults}
69 />
70 {/* Accordions */}
71 <div className="disco:flex disco:justify-between disco:gap-5 disco:py-5">
72 <div className="disco:w-[70%]">
73 <DiscoAccordion docsData={docsData} />
74 {/* Contact Form */}
75 <DiscoSupportSection />
76 <DiscoResources />
77 </div>
78 <DiscoSidebar />
79 </div>
80 </div>
81 );
82 }
83