one-click-accessibility/modules/settings/assets/js/components/analytics/analytics-toggle.js
VasylD 38bdaef8b6
[APP-1107] Add dashboard for analytics (#204)
* [APP-1108][APP-1109][APP-1110] Add analytics backend logic

* [APP-1108][APP-1109][APP-1110] Add analytics backend logic

* Add nonce to the widget settings

* Update routes and DB table

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* Fix comments

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1107] Add dashboard for analytics

* [APP-1201] add accessibility rules

* [APP-1107] fixed API endpoint

* [APP-1107] fixed API endpoint

* [APP-1107] fixed API endpoint

* [APP-1107] add check for is_active

* update to the latest

* update to the latest

* update to the latest

* fix bugs, add changes

* fix bugs, add changes

* fix bugs, add changes

* fix bugs, add changes
2025-03-17 12:26:52 +02:00

124 lines
3.5 KiB
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import InfoCircleIcon from '@elementor/icons/InfoCircleIcon';
import Box from '@elementor/ui/Box';
import Button from '@elementor/ui/Button';
import Dialog from '@elementor/ui/Dialog';
import DialogActions from '@elementor/ui/DialogActions';
import DialogContent from '@elementor/ui/DialogContent';
import DialogContentText from '@elementor/ui/DialogContentText';
import FormControlLabel from '@elementor/ui/FormControlLabel';
import Infotip from '@elementor/ui/Infotip';
import Switch from '@elementor/ui/Switch';
import Typography from '@elementor/ui/Typography';
import { eventNames, mixpanelService } from '@ea11y/services';
import { useState } from '@wordpress/element';
import { __ } from '@wordpress/i18n';
import { useAnalyticsContext } from '../../contexts/analytics-context';
export const AnalyticsToggle = () => {
const { isAnalyticsEnabled, updateIsAnalyticsEnabled } =
useAnalyticsContext();
const [showConfirm, setShowConfirm] = useState(false);
const handleToggle = () => {
if (isAnalyticsEnabled) {
updateIsAnalyticsEnabled();
} else {
setShowConfirm(true);
}
mixpanelService.sendEvent(eventNames.toggleClicked, {
state: isAnalyticsEnabled ? 'off' : 'on',
type: 'Enable analytics',
});
};
const handleClose = () => {
setShowConfirm(false);
mixpanelService.sendEvent(eventNames.popupButtonClicked, {
data: {
popupType: 'analytics_confirm',
buttonName: 'Not now',
},
});
};
const handleConfirm = () => {
updateIsAnalyticsEnabled();
setShowConfirm(false);
mixpanelService.sendEvent(eventNames.popupButtonClicked, {
data: {
popupType: 'analytics_confirm',
buttonName: 'Confirm',
},
});
};
return (
<>
<FormControlLabel
control={
<Switch
color="info"
checked={isAnalyticsEnabled}
onChange={handleToggle}
sx={{ ml: 2 }}
/>
}
label={
<Box display="flex" alignItems="center" gap={1}>
<Typography variant="body1">
{__('Track widget data', 'pojo-accessibility')}
</Typography>
<Infotip
content={
<Typography variant="body1" sx={{ p: 2, maxWidth: '300px' }}>
{__(
"Enable to track widget data, feature usage, user insights and more to improve your website's accessibility.",
'pojo-accessibility',
)}
</Typography>
}
>
<InfoCircleIcon fontSize="small" />
</Infotip>
</Box>
}
labelPlacement="start"
sx={{ ml: 0 }}
/>
<Dialog
open={showConfirm}
onClose={handleClose}
aria-labelledby="confirm-enable-analytics-title"
aria-describedby="confirm-enable-analytics-description"
>
<DialogContent>
<Typography variant="h5" align="center" sx={{ mb: 3 }}>
{__('Confirm widget data tracking', 'pojo-accessibility')}
</Typography>
<DialogContentText
id="confirm-enable-analytics-description"
align="center"
>
{__(
'Enabling data tracking lets you see how users interact with your widget and features. Keep in mind: Real-time data processing may slightly impact a sites performance, especially on high-traffic websites.',
'pojo-accessibility',
)}
</DialogContentText>
</DialogContent>
<DialogActions>
<Button onClick={handleClose} color="secondary">
{__('Not now', 'pojo-accessibility')}
</Button>
<Button onClick={handleConfirm} variant="contained" color="info">
{__('Confirm & enable', 'pojo-accessibility')}
</Button>
</DialogActions>
</Dialog>
</>
);
};