1 import type { Action, ThunkDispatch } from '@reduxjs/toolkit';
2 import { c } from 'ttag';
4 import { useErrorHandler, useNotifications } from '@proton/components';
5 import { useLoading } from '@proton/hooks';
6 import { baseUseDispatch } from '@proton/react-redux-store';
7 import type { ProtonThunkArguments } from '@proton/redux-shared-store-types';
8 import noop from '@proton/utils/noop';
11 AbstractAuthDevicesModal,
12 type AbstractAuthDevicesModalProps,
13 type BaseAbstractAuthDevicesModalProps,
14 } from './AbstractAuthDeviceModal';
15 import { confirmPendingAuthDevice, rejectAuthDevice } from './authDeviceActions';
16 import type { AuthDevicesState } from './authDevices';
18 export const AuthDevicesModal = (props: BaseAbstractAuthDevicesModalProps) => {
19 const [loading, withLoading] = useLoading();
20 const dispatch = baseUseDispatch<ThunkDispatch<AuthDevicesState, ProtonThunkArguments, Action>>();
21 const { createNotification } = useNotifications();
22 const errorHandler = useErrorHandler();
24 const handleConfirm: AbstractAuthDevicesModalProps['onConfirm'] = async ({
33 confirmPendingAuthDevice({
38 createNotification({ text: c('sso').t`Sign-in confirmed` });
45 const handleReject: AbstractAuthDevicesModalProps['onReject'] = async (pendingAuthDevice) => {
46 dispatch(rejectAuthDevice({ pendingAuthDevice, type: 'reject' })).catch(noop);
47 createNotification({ text: c('sso').t`Sign-in rejected` });
52 <AbstractAuthDevicesModal
55 onReject={handleReject}
56 onConfirm={(data) => withLoading(handleConfirm(data))}