1 import { type FC, useState } from 'react';
3 import { c } from 'ttag';
5 import { Button } from '@proton/atoms';
6 import { ModalTwoContent, ModalTwoFooter } from '@proton/components';
7 import { ExpirationTimeSelect, ExpireTime } from '@proton/pass/components/Form/Field/Custom/ExpirationTimeSelect';
8 import { MaxReadsToggleInput } from '@proton/pass/components/Form/Field/Custom/MaxReadsToggleInput';
9 import { useRequest } from '@proton/pass/hooks/useActionRequest';
10 import { secureLinkCreate } from '@proton/pass/store/actions';
11 import type { SecureLink, SecureLinkOptions, UniqueItem } from '@proton/pass/types';
13 type Props = UniqueItem & { onLinkGenerated: (data: SecureLink) => void };
15 export const SecureLinkGenerate: FC<Props> = ({ shareId, itemId, onLinkGenerated }) => {
16 const [{ expirationTime, maxReadCount }, setOptions] = useState<SecureLinkOptions>({
17 expirationTime: ExpireTime.OneWeek,
21 const { dispatch, loading } = useRequest(secureLinkCreate, {
22 initial: { shareId, itemId },
23 onSuccess: ({ data }) => onLinkGenerated(data),
26 const generateSecureLink = () => dispatch({ itemId, shareId, expirationTime, maxReadCount });
32 onChange={(expirationTime) => setOptions((options) => ({ ...options, expirationTime }))}
34 value={expirationTime}
36 <hr className="mt-4" />
40 onChange={(maxReadCount) => setOptions((options) => ({ ...options, maxReadCount }))}
41 onPressEnter={generateSecureLink}
45 <ModalTwoFooter className="flex flex-column items-stretch text-center">
47 className="max-w-full"
54 onClick={generateSecureLink}
56 <span className="text-ellipsis">
57 {loading ? c('Action').t`Generating secure link...` : c('Action').t`Generate secure link`}