PluginProbe
Code Snippets / 4.0.0-beta.1
Code Snippets v4.0.0-beta.1
4.0.0-beta.2 3.10.2 3.10.1 3.10.0 3.10.0-beta.2 3.10.0-beta.1 4.0.0-beta.1 3.9.6 trunk 2.10.0 2.10.1 2.12.0 2.12.1 2.13.0 2.13.1 2.13.2 2.13.3 2.14.0 2.14.1 2.14.2 2.14.3 2.14.4 2.14.5 2.14.6 3.0.0 All 65 releases
code-snippets / js / components / ManageMenu / CommunityCloud / CommunityCloud.tsx

CommunityCloud.tsx in Code Snippets 4.0.0-beta.1, at js/components/ManageMenu/CommunityCloud/CommunityCloud.tsx

68 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import React, { useState } from 'react'
2 import { __ } from '@wordpress/i18n'
3 import classnames from 'classnames'
4 import { WithRestAPIContext } from '../../../hooks/useRestAPI'
5 import { isLicensed } from '../../../utils/screen'
6 import { buildUrl, fetchQueryParam, updateQueryParams } from '../../../utils/urls'
7 import { UpsellDialog } from '../../common/UpsellDialog'
8 import { WithCloudSearchContext } from './WithCloudSearchContext'
9 import { CloudSearch } from './CloudSearch'
10
11 const TABS = ['snippets', 'bundles'] as const
12 type TabName = typeof TABS[number]
13
14 const TAB_LABELS: Record<TabName, string> = {
15 snippets: __('Code Snippets', 'code-snippets'),
16 bundles: __('Bundles', 'code-snippets')
17 }
18
19 const PRO_TABS: TabName[] = ['bundles']
20
21 export const CommunityCloud = () => {
22 const [currentTab, setCurrentTab] = useState(() => fetchQueryParam('tab') as TabName | null ?? TABS[0])
23 const [isUpsellDialogOpen, setIsUpsellDialogOpen] = useState(false)
24
25 return (
26 <>
27 <h2>{__('Community Cloud', 'code-snippets')}</h2>
28
29 <hr className="wp-header-end" />
30
31 <nav
32 className="nav-tab-wrapper community-cloud-tabs"
33 aria-label={__('Community Cloud types', 'code-snippets')}
34 >
35 {TABS.map(tab =>
36 <a
37 key={tab}
38 href={buildUrl(window.location.href, { type: tab })}
39 className={classnames('nav-tab', `${tab}-tab`, { 'nav-tab-active': tab === currentTab })}
40 aria-current={tab === currentTab ? 'page' : undefined}
41 onClick={event => {
42 event.preventDefault()
43
44 if (PRO_TABS.includes(tab) && !isLicensed()) {
45 setIsUpsellDialogOpen(true)
46 } else {
47 updateQueryParams({ tab })
48 setCurrentTab(tab)
49 }
50 }}
51 >
52 {TAB_LABELS[tab]}
53 {PRO_TABS.includes(tab) && !isLicensed() && <span className="pro-chip">{__('Pro', 'code-snippets')}</span>}
54 </a>)}
55 </nav>
56
57 {'snippets' === currentTab && (
58 <WithRestAPIContext>
59 <WithCloudSearchContext>
60 <CloudSearch />
61 </WithCloudSearchContext>
62 </WithRestAPIContext>)}
63
64 <UpsellDialog isOpen={isUpsellDialogOpen} setIsOpen={setIsUpsellDialogOpen} />
65 </>
66 )
67 }
68