1 import { useEffect, useState } from 'react';
3 import type { Action, ThunkDispatch } from '@reduxjs/toolkit';
4 import { c, msgid } from 'ttag';
6 import { Button } from '@proton/atoms';
15 } from '@proton/components';
16 import { useLoadingByKey } from '@proton/hooks/useLoading';
17 import { baseUseDispatch } from '@proton/react-redux-store';
18 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
19 import { BRAND_NAME } from '@proton/shared/lib/constants';
21 import ConfirmDenyMemberAuthDevice from './ConfirmDenyMemberAuthDevice';
22 import MemberAuthDevicesModal from './MemberAuthDevicesModal';
23 import MembersAuthDevicesList from './MembersAuthDevicesList';
24 import { rejectMemberAuthDevice } from './memberAuthDeviceActions';
25 import type { MemberAuthDevicesState, PendingAdminActivation, PendingAdminActivations } from './memberAuthDevices';
27 interface Props extends Omit<ModalProps<'div'>, 'children' | 'buttons'> {
28 pendingAdminActivationsWithMembers: PendingAdminActivations;
31 const MembersAuthDevicesModal = ({ pendingAdminActivationsWithMembers, ...rest }: Props) => {
32 const n = pendingAdminActivationsWithMembers.length;
33 const [pendingMemberAuthDevice, setPendingMemberAuthDevice] = useState<PendingAdminActivation | null>(null);
34 const [grantModalProps, setGrantModal, renderGrantModal] = useModalState();
35 const [denyModalProps, setDenyModal, renderDenyModal] = useModalState();
36 const errorHandler = useErrorHandler();
37 const dispatch = baseUseDispatch<ThunkDispatch<MemberAuthDevicesState, ProtonThunkArguments, Action>>();
38 const [loadingMap, , setLoading] = useLoadingByKey();
48 {renderGrantModal && pendingMemberAuthDevice && (
49 <MemberAuthDevicesModal
50 pendingMemberAuthDevice={pendingMemberAuthDevice}
53 setPendingMemberAuthDevice(null);
54 grantModalProps.onExit();
58 {renderDenyModal && pendingMemberAuthDevice && (
59 <ConfirmDenyMemberAuthDevice
60 pendingMemberAuthDevice={pendingMemberAuthDevice}
61 onConfirm={async () => {
62 if (!pendingMemberAuthDevice) {
65 const { member, memberAuthDevice } = pendingMemberAuthDevice;
67 setLoading(memberAuthDevice.ID, true);
69 rejectMemberAuthDevice({
78 setLoading(memberAuthDevice.ID, false);
83 setPendingMemberAuthDevice(null);
84 grantModalProps.onExit();
88 <ModalTwo {...rest} size="xlarge">
89 <ModalTwoHeader title={c('sso').t`Grant access to users?`} />
91 <p className="text-break">
93 msgid`${n} user is requesting your help to sign in to their ${BRAND_NAME} Account with single sign-on.`,
94 `${n} users are requesting your help to sign in to their ${BRAND_NAME} Account with single sign-on.`,
99 <MembersAuthDevicesList
100 pendingAdminActivationsWithMembers={pendingAdminActivationsWithMembers}
102 loadingMap={loadingMap}
103 onApprove={(pendingAdminActivation) => {
104 setPendingMemberAuthDevice(pendingAdminActivation);
107 onReject={(pendingAdminActivation) => {
108 setPendingMemberAuthDevice(pendingAdminActivation);
116 <Button color="norm" onClick={rest.onClose}>{c('sso').t`Cancel`}</Button>
123 export default MembersAuthDevicesModal;