1 import { useMemo } from 'react';
3 import { c } from 'ttag';
5 import { useUser } from '@proton/account/user/hooks';
6 import { ButtonLike, CircleLoader } from '@proton/atoms';
7 import type { ModalStateProps } from '@proton/components';
16 } from '@proton/components';
17 import { APPS } from '@proton/shared/lib/constants';
18 import { getIsOwner } from '@proton/shared/lib/drive/permissions';
19 import type { RevisionRetentionDaysSetting } from '@proton/shared/lib/interfaces/drive/userSettings';
21 import type { DecryptedLink } from '../../../store';
22 import { useUserSettings } from '../../../store';
23 import { RevisionList, RevisionsProvider, useRevisionsProvider } from '../../revisions';
25 import './RevisionsModal.scss';
31 const RevisionsSettingsBanner = ({
32 revisionRetentionDays,
34 revisionRetentionDays: RevisionRetentionDaysSetting;
36 const retentionLabel = getRetentionLabel(revisionRetentionDays);
38 <div className="flex items-center justify-space-between">
39 <p className="m-0 color-weak">
40 {revisionRetentionDays === 0
41 ? c('Info').t`Previous versions are not saved`
42 : c('Info').t`Previous versions are kept for ${retentionLabel}`}
46 to="/drive/version-history"
47 toApp={APPS.PROTONACCOUNT}
50 >{c('Action').t`Change`}</ButtonLike>
55 const RevisionsModalContent = () => {
56 const [{ hasPaidDrive }] = useUser();
57 const { revisionRetentionDays } = useUserSettings();
58 const { isLoading, currentRevision, permissions, categorizedRevisions } = useRevisionsProvider();
59 const isOwner = useMemo(() => getIsOwner(permissions), [permissions]);
64 <RevisionsSettingsBanner revisionRetentionDays={revisionRetentionDays} />
68 {isLoading && <CircleLoader className="w-full m-auto mt-5" size="large" />}
69 {!isLoading && currentRevision ? (
70 <RevisionList currentRevision={currentRevision} categorizedRevisions={categorizedRevisions} />
76 const RevisionsModal = ({ link, ...modalProps }: Props & ModalStateProps) => {
78 <ModalTwo size="large" {...modalProps}>
79 <ModalTwoHeader title={c('Title').t`Version history`} />
80 <ModalTwoContent className="mb-8">
81 <RevisionsProvider link={link}>
82 <RevisionsModalContent />
89 export default RevisionsModal;
91 export const useRevisionsModal = () => {
92 return useModalTwoStatic(RevisionsModal);