1 import { useState } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import Form from '@proton/components/components/form/Form';
7 import type { ModalProps } from '@proton/components/components/modalTwo/Modal';
8 import ModalTwo from '@proton/components/components/modalTwo/Modal';
9 import ModalTwoContent from '@proton/components/components/modalTwo/ModalContent';
10 import ModalTwoFooter from '@proton/components/components/modalTwo/ModalFooter';
11 import ModalTwoHeader from '@proton/components/components/modalTwo/ModalHeader';
13 import type { GatewayDto } from './GatewayDto';
14 import type { GatewayModel } from './GatewayModel';
15 import type { GatewayUser } from './GatewayUser';
16 import { GatewayUserSelection } from './GatewayUserSelection';
18 type PartialGateway = Pick<GatewayDto, 'features' | 'userIds'>;
20 interface Props extends ModalProps<typeof Form> {
21 model: PartialGateway;
22 users: readonly GatewayUser[];
23 showCancelButton?: boolean;
24 onSubmitDone: (gateway: Pick<GatewayModel, 'Features' | 'UserIds'>) => Promise<void>;
27 const GatewayUsersModal = ({ model: initialModel, users, showCancelButton = false, onSubmitDone, ...rest }: Props) => {
28 const [model, setModel] = useState<PartialGateway>({ ...initialModel });
29 const [loading, setLoading] = useState(false);
31 const changeModel = (diff: Partial<PartialGateway>) => setModel((model) => ({ ...model, ...diff }));
33 const handleSubmit = async () => {
35 Features: model.features,
36 UserIds: model.userIds,
41 await onSubmitDone(dtoBody);
49 <ModalTwo size="xlarge" {...rest} as={Form} onSubmit={handleSubmit}>
50 <ModalTwoHeader title={c('Title').t`Edit users`} />
52 <GatewayUserSelection loading={loading} users={users} model={model} changeModel={changeModel} />
56 <Button color="weak" onClick={rest.onClose}>
57 {c('Action').t`Cancel`}
62 <Button color="norm" type="submit" loading={loading}>
70 export default GatewayUsersModal;