one-click-accessibility/modules/settings/assets/js/hooks/use-toggle-settings.js
Nirbhay Singh 83d2a9f641
[APP-1105] Add pro capabilities (#205)
* add: volume and solid crown icon

* add: volume and crown icons to export

* update: refactor menu item to a new component

* add: screen reader to the menu items and reorganize them

* add: pro item infotip content

* add: capabilities item and pro info tip to exports

* update: import ProInfoTip component and change disabled logic

* update: imports

* update: refactor pro item infotip into the separate component

* update: refactor infotip and add comments

* add: custom switch component

* add: logo settings layout

* update: switch component

* add: useToggleSetting hook to manage widget settings.

* update: move pro feature key to a separate constant

* fix: pro icon style

* update: remove branding key

* update: pro enable check structure

* update: pro enabled check structure

* update: key name

* update: update key before checking for it

* fix: null error

* add: update logic to get the tools settings based on plan

* update: exclude remove-elementor-label from the minimum option rule

* update: add formlabel and eventnames

* add: logic to deactivate the features which are disabled for the plan

* fix: PHP warning

* fix: keyword name

* add: GOLINKS

* add: open link function

* fix: PHP warning undefined key

* update: logic to show the icon and added golinks
2025-03-17 13:12:30 +02:00

40 lines
1,012 B
JavaScript

import { useSettings } from '@ea11y/hooks';
import { mixpanelService } from '@ea11y/services';
import { useCallback } from '@wordpress/element';
export const useToggleSetting = () => {
const { setWidgetMenuSettings, setHasChanges } = useSettings();
const toggleMenu = useCallback(
(category, option) => {
setWidgetMenuSettings((prevSettings) => {
const newSettings = {
...prevSettings,
[option]: {
...prevSettings[option],
enabled: !prevSettings[option]?.enabled,
},
};
setHasChanges(true);
if (window?.ea11yWidget?.toolsSettings && window?.ea11yWidget?.widget) {
window.ea11yWidget.toolsSettings = newSettings;
window.ea11yWidget.widget.updateState();
}
if (prevSettings[option]) {
mixpanelService.sendEvent('toggle_clicked', {
state: prevSettings[option]?.enabled ? 'off' : 'on',
type: option,
});
}
return newSettings;
});
},
[setWidgetMenuSettings, setHasChanges],
);
return { toggleMenu };
};