1 import { c } from 'ttag';
3 import { useCustomDomains } from '@proton/account/domains/hooks';
4 import { Button } from '@proton/atoms';
5 import type { ModalStateProps } from '@proton/components/components/modalTwo/useModalState';
6 import useModalState from '@proton/components/components/modalTwo/useModalState';
7 import Prompt from '@proton/components/components/prompt/Prompt';
8 import Tooltip from '@proton/components/components/tooltip/Tooltip';
9 import { getInviteLimit } from '@proton/components/containers/members/UsersAndAddressesSection/helper';
10 import { PLAN_NAMES } from '@proton/payments';
11 import type { APP_NAMES } from '@proton/shared/lib/constants';
12 import { BRAND_NAME } from '@proton/shared/lib/constants';
13 import type { Domain, EnhancedMember, Organization } from '@proton/shared/lib/interfaces';
14 import { isOrganizationFamily, isOrganizationPassFamily } from '@proton/shared/lib/organization/helper';
16 import SubUserCreateModal from './SubUserCreateModal';
18 interface Props extends ModalStateProps {
19 members: EnhancedMember[] | undefined;
20 organization?: Organization;
21 verifiedDomains: Domain[];
22 onInviteUser: () => void;
23 allowAIAssistantConfiguration: boolean;
24 aiSeatsRemaining: boolean;
28 interface ButtonProps {
32 const AddUserButton = ({ onClick }: ButtonProps) => {
33 const [customDomains = []] = useCustomDomains();
35 if (customDomains.length === 0) {
38 title={c('familyOffer_2023:Family plan')
39 .t`You need to configure a custom domain before creating a new user.`}
41 <div className="w-full">
42 <Button disabled fullWidth>{c('familyOffer_2023:Action').t`Create a new user`}</Button>
48 return <Button onClick={onClick} fullWidth>{c('familyOffer_2023:Action').t`Create a new user`}</Button>;
51 interface InviteButtonProps {
52 organization?: Organization;
55 const InviteProtonUserButton = ({ onClick, organization }: ButtonProps & InviteButtonProps) => {
56 if (organization && organization.InvitationsRemaining === 0) {
58 isOrganizationFamily(organization) || isOrganizationPassFamily(organization)
63 <Tooltip title={tooltip}>
64 <div className="w-full">
65 <Button disabled fullWidth>{c('familyOffer_2023:Action')
66 .t`Invite an existing ${BRAND_NAME} user`}</Button>
73 <Button fullWidth onClick={onClick} color="norm">{c('familyOffer_2023:Action')
74 .t`Invite an existing ${BRAND_NAME} user`}</Button>
78 const InviteUserCreateSubUserModal = ({
84 allowAIAssistantConfiguration,
88 const [subUserCreateModalProps, setSubUserCreateModalOpen, renderSubUserCreateModal] = useModalState();
90 const handleAddUser = () => {
91 setSubUserCreateModalOpen(true);
94 const handleInviteUser = () => {
102 title={c('familyOffer_2023:Title').t`Add a user to your ${PLAN_NAMES.visionary2022} account`}
104 <InviteProtonUserButton onClick={handleInviteUser} organization={organization} />,
105 <AddUserButton onClick={handleAddUser} />,
106 <Button fullWidth onClick={modalState.onClose} shape="ghost">{c('Action').t`Cancel`}</Button>,
110 <p>{c('familyOffer_2023:Info').t`To create a new user, a configured custom domain is required.`}</p>
112 {renderSubUserCreateModal && organization && verifiedDomains?.length > 0 && (
115 aiSeatsRemaining={aiSeatsRemaining}
116 organization={organization}
117 verifiedDomains={verifiedDomains}
118 {...subUserCreateModalProps}
119 onClose={() => modalState.onClose()}
120 allowStorageConfiguration
121 allowVpnAccessConfiguration
122 allowPrivateMemberConfiguration
123 allowAIAssistantConfiguration={allowAIAssistantConfiguration}
131 export default InviteUserCreateSubUserModal;