-
Notifications
You must be signed in to change notification settings - Fork 86
feat: add obfx modules #4447
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add obfx modules #4447
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
210 changes: 210 additions & 0 deletions
210
assets/apps/dashboard/src/Components/Content/AvailableModule.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,210 @@ | ||
| /* global neveDash */ | ||
| import { __ } from '@wordpress/i18n'; | ||
| import { | ||
| NEVE_AVAIABLE_MODULES_ICON_MAP, | ||
| NEVE_STORE, | ||
| } from '../../utils/constants'; | ||
| import { ArrowRight, LoaderCircle, LucideSettings } from 'lucide-react'; | ||
| import Card from '../../Layout/Card'; | ||
| import { useState } from '@wordpress/element'; | ||
| import { useDispatch, useSelect } from '@wordpress/data'; | ||
| import Toggle from '../Common/Toggle'; | ||
| import { send } from '../../utils/rest'; | ||
|
|
||
| const Toast = ({ message }) => { | ||
| return ( | ||
| <div className="fixed flex items-center gap-2 z-[99999] top-10 right-5 bg-white text-black text-base font-medium px-4 py-2 rounded shadow border border-solid border-blue-600"> | ||
| {message} | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const ModuleToggle = ({ | ||
| slug, | ||
| moduleData, | ||
| setMessage, | ||
| isActive, | ||
| setIsActive, | ||
| isInstalled, | ||
| setIsInstalled, | ||
| }) => { | ||
| const [loading, setLoading] = useState(false); | ||
| const { changeModuleStatus, setObfxModuleStatus, setToast } = | ||
| useDispatch(NEVE_STORE); | ||
| const { moduleStatus } = useSelect((select) => { | ||
| const { getObfxModuleStatus } = select(NEVE_STORE); | ||
|
|
||
| return { | ||
| moduleStatus: getObfxModuleStatus(slug) || false, | ||
| }; | ||
| }); | ||
|
|
||
| const { api } = neveDash; | ||
| const { title } = moduleData; | ||
| const toastMessage = { | ||
| installing: __('Installing Orbix Fox Plugin', 'neve'), | ||
| activating: __('Activating Orbix Fox Plugin', 'neve'), | ||
girishpanchal30 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
girishpanchal30 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| }; | ||
|
|
||
| const handleToggle = async (value) => { | ||
| try { | ||
| setLoading(true); | ||
| changeModuleStatus(slug, value); | ||
|
|
||
| let isPluginActive = true; | ||
| // Handle plugin installation or activation | ||
| if (!isInstalled) { | ||
| setMessage(toastMessage.installing); | ||
| isPluginActive = false; | ||
| } else if (!isActive) { | ||
| setMessage(toastMessage.activating); | ||
| isPluginActive = false; | ||
| } | ||
|
|
||
| if (!isPluginActive) { | ||
| await send(api + 'activate-plugin', { | ||
| slug: 'themeisle-companion', | ||
| }).then((res) => { | ||
| if (res.success) { | ||
| setIsInstalled(true); | ||
| setIsActive(true); | ||
| } | ||
| }); | ||
| } | ||
|
|
||
| // Fire the send method after install/activate or immediately if both are done | ||
| const response = await send(api + 'activate-module', { | ||
| slug, | ||
| value, | ||
| }); | ||
|
|
||
| setObfxModuleStatus(slug, response.success ? value : !value); | ||
| setToast( | ||
| response.success | ||
| ? (value | ||
| ? __('Module Activated', 'neve') | ||
| : __('Module Deactivated.', 'neve')) + ` (${title})` | ||
| : response.data | ||
| ); | ||
| } catch (error) { | ||
| setToast( | ||
| __('Something went wrong while activating the module.', 'neve') | ||
| ); | ||
| } finally { | ||
| setLoading(false); | ||
| setMessage(''); | ||
| } | ||
| }; | ||
|
|
||
| return ( | ||
| <div className="flex gap-2 items-center"> | ||
| <Toggle | ||
| checked={moduleStatus} | ||
| onToggle={handleToggle} | ||
| disabled={loading} | ||
| /> | ||
| </div> | ||
| ); | ||
| }; | ||
|
|
||
| const AvailableModuleCard = ({ | ||
| moduleData, | ||
| slug, | ||
| setMessage, | ||
| isActive, | ||
| setIsActive, | ||
| isInstalled, | ||
| setIsInstalled, | ||
| }) => { | ||
| const { title, description } = moduleData; | ||
| const CardIcon = NEVE_AVAIABLE_MODULES_ICON_MAP[slug] || LucideSettings; | ||
girishpanchal30 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| return ( | ||
| <Card | ||
| icon={<CardIcon size={18} />} | ||
| title={title} | ||
| className="bg-white p-6 rounded-lg shadow-sm" | ||
| afterTitle={ | ||
| <ModuleToggle | ||
| slug={slug} | ||
| moduleData={moduleData} | ||
| setMessage={setMessage} | ||
| isActive={isActive} | ||
| setIsActive={setIsActive} | ||
| isInstalled={isInstalled} | ||
| setIsInstalled={setIsInstalled} | ||
| /> | ||
| } | ||
| id={`module-${slug}`} | ||
| > | ||
| <p className="text-gray-600 text-sm leading-relaxed"> | ||
| {description} | ||
| </p> | ||
| {!isActive ? ( | ||
| <p className="mt-2 italic text-sm text-gray-500"> | ||
| {__( | ||
| 'This feature is part of OrbitFox plugin, built by the Neve team. Enabling the toggle will automatically install and activate the plugin.', | ||
| 'neve' | ||
| )} | ||
| </p> | ||
| ) : ( | ||
| <a | ||
| className="flex mt-2 text-blue-600 gap-2 align-middle" | ||
| href="admin.php?page=obfx_companion" | ||
| > | ||
| {__('Go to Settings to Edit')} | ||
girishpanchal30 marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| <ArrowRight size={18} /> | ||
| </a> | ||
| )} | ||
| </Card> | ||
| ); | ||
| }; | ||
|
|
||
| export default () => { | ||
| const [message, setMessage] = useState(''); | ||
| const [isInstalled, setIsInstalled] = useState( | ||
| neveDash.orbitFox.isInstalled | ||
| ); | ||
| const [isActive, setIsActive] = useState(neveDash.orbitFox.isActive); | ||
|
|
||
| return ( | ||
| <> | ||
| <div className="mb-6"> | ||
| <div className="flex items-center justify-between"> | ||
| <h2 className="text-lg font-semibold"> | ||
| {__('Available Modules', 'neve')} | ||
| </h2> | ||
| </div> | ||
| <div className="grid xl:grid-cols-2 gap-6"> | ||
| {Object.entries(neveDash.availableModules).map( | ||
| ([slug, moduleData]) => ( | ||
| <AvailableModuleCard | ||
| key={slug} | ||
| slug={slug} | ||
| moduleData={moduleData} | ||
| setMessage={setMessage} | ||
| isActive={isActive} | ||
| setIsActive={setIsActive} | ||
| isInstalled={isInstalled} | ||
| setIsInstalled={setIsInstalled} | ||
| /> | ||
| ) | ||
| )} | ||
| </div> | ||
| </div> | ||
| {message && ( | ||
| <Toast | ||
| message={ | ||
| <> | ||
| <LoaderCircle | ||
| size={18} | ||
| className="animate-spin text-blue-800" | ||
| /> | ||
| {message} | ||
| </> | ||
| } | ||
| /> | ||
| )} | ||
| </> | ||
| ); | ||
| }; | ||
8 changes: 7 additions & 1 deletion
8
assets/apps/dashboard/src/Components/Content/Settings/ManageModulesTabContent.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,11 @@ | ||
| import AvailableModule from '../AvailableModule'; | ||
| import ModuleGrid from '../ModuleGrid'; | ||
|
|
||
| export default () => { | ||
| return <ModuleGrid />; | ||
| return ( | ||
| <> | ||
| <AvailableModule /> | ||
| <ModuleGrid /> | ||
| </> | ||
| ); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.