PluginProbe
Extendify / 3.0.6
Extendify v3.0.6
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / Shared / state / ai-consent.js

ai-consent.js in Extendify 3.0.6, at src/Shared/state/ai-consent.js

50 lines 1.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import apiFetch from '@wordpress/api-fetch';
2 import { __, sprintf } from '@wordpress/i18n';
3 import { create } from 'zustand';
4 import { devtools, persist } from 'zustand/middleware';
5
6 const storage = {
7 setItem: (_name, store) =>
8 apiFetch({
9 path: '/extendify/v1/shared/update-user-meta',
10 method: 'POST',
11 data: { option: 'ai_consent', value: store.state.userGaveConsent },
12 }),
13 };
14
15 const defaultConsentTerms = sprintf(
16 // translators: %1$s and %2$s are opening and closing anchor tags.
17 __(
18 'By using AI features, you agree with the %1$sTerms of Use and Privacy Policy%2$s.',
19 'extendify-local',
20 ),
21 '<a href="https://hosting-ai-terms.com/" target="_blank">',
22 '</a>',
23 );
24
25 const state = (set, get) => ({
26 showAIConsent: window.extSharedData?.showAIConsent ?? false,
27 consentTerms: window.extSharedData?.consentTermsCustom || defaultConsentTerms,
28 userGaveConsent: window.extSharedData?.userGaveConsent ?? false,
29 setUserGaveConsent: (userGaveConsent) => set({ userGaveConsent }),
30 // Context refers to the feature where the function is being used.
31 shouldShowAIConsent: (context) => {
32 const { showAIConsent, consentTerms, userGaveConsent } = get();
33 const enabled = showAIConsent && consentTerms;
34 const display = {
35 launch: enabled,
36 draft: enabled && !userGaveConsent,
37 'help-center': enabled && !userGaveConsent,
38 };
39 return display?.[context] ?? false;
40 },
41 });
42
43 export const useAIConsentStore = create(
44 persist(devtools(state, { name: 'Extendify AI Consent' }), {
45 name: 'extendify-ai-consent',
46 storage,
47 skipHydration: true,
48 }),
49 );
50