1 import { selectOrganization, selectUser } from '@proton/account';
2 import { useIsOrganizationBeforeBackfill } from '@proton/components/containers/payments/subscription/assistant/useIsOrganizationBeforeBackfill';
3 import useScribePaymentsEnabled from '@proton/components/containers/payments/subscription/assistant/useScribePaymentsEnabled';
4 import { isScribeSupported } from '@proton/components/helpers/assistant';
5 import { baseUseSelector } from '@proton/react-redux-store';
6 import { useFlag } from '@proton/unleash';
8 const useAssistantFeatureEnabled = () => {
9 const accessToAssistant = useFlag('ComposerAssistant');
10 const scribePaymentsEnabled = useScribePaymentsEnabled();
11 const isOrganizationBeforeBackfill = useIsOrganizationBeforeBackfill();
13 const user = baseUseSelector(selectUser)?.value;
14 const userHasScribeSeat = !!user?.NumAI;
16 const organization = baseUseSelector(selectOrganization)?.value;
17 const organizationScribeEnabled = !!organization?.Settings.ShowScribeWritingAssistant || !!user?.isAdmin;
18 const planSupportsScribe = isScribeSupported(organization, user);
20 const paymentsEnabled = accessToAssistant && !isOrganizationBeforeBackfill && scribePaymentsEnabled;
24 !isOrganizationBeforeBackfill &&
25 // you can't see anything Scribe related if the payments can't support you buying it
26 // but if you have a seat you can still use it
27 (scribePaymentsEnabled || userHasScribeSeat) &&
28 // user can't enter scribe trial if the organization plan doesn't support it
30 // If org admin disabled scribe to sub users, do not show the feature
31 organizationScribeEnabled;
35 * If Scribe can be purchased then it should be true. This flag doesn't take organization's plan into account
36 * because free users should be able to buy Scribe too.
40 * This flag controls if the configuration for scribe is available. Example: user management panel can
41 * have an upsell for scribe addon. In this case we need to check both things: payments are possible and
42 * scribe is supported by the organization's plan.
43 * Kill switch takes precedence
49 export default useAssistantFeatureEnabled;