1 import { useRef } from 'react';
3 import { c } from 'ttag';
5 import { Avatar, Button, Input } from '@proton/atoms';
6 import { Icon, Toggle, useNotifications } from '@proton/components';
7 import useLoading from '@proton/hooks/useLoading';
8 import type { SHARE_URL_PERMISSIONS } from '@proton/shared/lib/drive/permissions';
9 import { textToClipboard } from '@proton/shared/lib/helpers/browser';
10 import clsx from '@proton/utils/clsx';
12 import { PermissionsDropdownMenu } from '../PermissionsDropdownMenu';
15 publicSharedLink: string;
16 publicSharedLinkPermissions: SHARE_URL_PERMISSIONS;
17 onChangePermissions: (permissions: number) => Promise<void>;
18 createSharedLink: () => void;
19 deleteSharedLink: () => void;
23 export const PublicSharing = ({
25 publicSharedLinkPermissions,
32 const contentRef = useRef<HTMLDivElement>(null);
33 const [isPermissionsLoading, withPermissionsLoading] = useLoading(false);
34 const { createNotification } = useNotifications();
35 const handleCopyURLClick = () => {
36 if (contentRef.current) {
37 textToClipboard(publicSharedLink, contentRef.current);
39 text: c('Success').t`Secure link copied`,
44 const handleUpdatePermissions = (permissions: SHARE_URL_PERMISSIONS) => {
45 return withPermissionsLoading(() => onChangePermissions(permissions));
48 const handleToggle = () => {
49 if (publicSharedLink) {
57 <div className="w-full" ref={contentRef} data-testid="share-modal-shareWithAnyoneSection">
58 <div className="flex justify-space-between items-center mb-6">
59 <h2 className="text-lg text-semibold mr">{c('Info').t`Create public link`}</h2>
60 <Toggle checked={!!publicSharedLink} loading={isLoading} onChange={handleToggle} />
62 <div className={clsx('flex items-center justify-space-between mb-4', !publicSharedLink && 'opacity-30')}>
63 <div className="flex items-center">
64 <Avatar color="weak" className="mr-2 shrink-0">
67 <p className="flex-1 flex flex-column p-0 m-0">
68 <span className="text-semibold">{c('Label').t`Anyone with the link`}</span>
69 <span className="color-weak">{c('Label')
70 .t`Anyone on the Internet with the link can view`}</span>
74 <div className="hidden sm:block shrink-0">{c('Label').t`Viewer`}</div>
76 <PermissionsDropdownMenu
77 disabled={!publicSharedLink || isLoading}
78 isLoading={isPermissionsLoading}
79 selectedPermissions={publicSharedLinkPermissions}
80 onChangePermissions={handleUpdatePermissions}
85 {!!publicSharedLink ? (
86 <div className="w-full flex justify-space-between">
89 value={publicSharedLink}
90 className="overflow-hidden text-ellipsis bg-weak border-weak color-weak"
91 data-testid="share-anyone-url"
92 disabled={!publicSharedLink}
99 onClick={handleCopyURLClick}
101 disabled={!publicSharedLink}
102 data-testid="share-anyone-copyUrlButton"
104 <Icon name="squares" />