mirror of
https://github.com/documenso/documenso.git
synced 2025-11-11 21:12:48 +10:00
This PR is handles the changes required to support envelopes. The new envelope editor/signing page will be hidden during release. The core changes here is to migrate the documents and templates model to a centralized envelopes model. Even though Documents and Templates are removed, from the user perspective they will still exist as we remap envelopes to documents and templates.
108 lines
3.3 KiB
TypeScript
108 lines
3.3 KiB
TypeScript
import type { MessageDescriptor } from '@lingui/core';
|
|
import { msg } from '@lingui/core/macro';
|
|
import { useLingui } from '@lingui/react';
|
|
import { Trans } from '@lingui/react/macro';
|
|
import { Upload } from 'lucide-react';
|
|
import { useDropzone } from 'react-dropzone';
|
|
import { Link } from 'react-router';
|
|
|
|
import { useCurrentOrganisation } from '@documenso/lib/client-only/providers/organisation';
|
|
import { useSession } from '@documenso/lib/client-only/providers/session';
|
|
import { APP_DOCUMENT_UPLOAD_SIZE_LIMIT, IS_BILLING_ENABLED } from '@documenso/lib/constants/app';
|
|
import { megabytesToBytes } from '@documenso/lib/universal/unit-convertions';
|
|
import { isPersonalLayout } from '@documenso/lib/utils/organisations';
|
|
|
|
import { Button } from './button';
|
|
import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from './tooltip';
|
|
|
|
export type DocumentDropzoneProps = {
|
|
className?: string;
|
|
disabled?: boolean;
|
|
loading?: boolean;
|
|
disabledMessage?: MessageDescriptor;
|
|
onDrop?: (_files: File[]) => void | Promise<void>;
|
|
onDropRejected?: () => void | Promise<void>;
|
|
type?: 'document' | 'template' | 'envelope';
|
|
[key: string]: unknown;
|
|
};
|
|
|
|
export const DocumentDropzone = ({
|
|
className,
|
|
loading,
|
|
onDrop,
|
|
onDropRejected,
|
|
disabled,
|
|
disabledMessage = msg`You cannot upload documents at this time.`,
|
|
type = 'document',
|
|
...props
|
|
}: DocumentDropzoneProps) => {
|
|
const { _ } = useLingui();
|
|
|
|
const { organisations } = useSession();
|
|
|
|
const organisation = useCurrentOrganisation();
|
|
|
|
const isPersonalLayoutMode = isPersonalLayout(organisations);
|
|
|
|
const { getRootProps, getInputProps } = useDropzone({
|
|
accept: {
|
|
'application/pdf': ['.pdf'],
|
|
},
|
|
multiple: type === 'envelope',
|
|
disabled,
|
|
maxFiles: 10, // Todo: Envelopes - Use claims. And also update other places where this is used.
|
|
onDrop: (acceptedFiles) => {
|
|
if (acceptedFiles.length > 0 && onDrop) {
|
|
void onDrop(acceptedFiles);
|
|
}
|
|
},
|
|
onDropRejected: () => {
|
|
if (onDropRejected) {
|
|
void onDropRejected();
|
|
}
|
|
},
|
|
maxSize: megabytesToBytes(APP_DOCUMENT_UPLOAD_SIZE_LIMIT),
|
|
});
|
|
|
|
const heading = {
|
|
document: msg`Upload Document`,
|
|
template: msg`Upload Template Document`,
|
|
envelope: msg`Envelope (beta)`,
|
|
};
|
|
|
|
if (disabled && IS_BILLING_ENABLED()) {
|
|
return (
|
|
<TooltipProvider>
|
|
<Tooltip>
|
|
<TooltipTrigger asChild>
|
|
<Button className="hover:bg-warning/80 bg-warning" asChild>
|
|
<Link
|
|
to={
|
|
isPersonalLayoutMode
|
|
? `/settings/billing`
|
|
: `/o/${organisation.url}/settings/billing`
|
|
}
|
|
>
|
|
<Trans>Upgrade</Trans>
|
|
</Link>
|
|
</Button>
|
|
</TooltipTrigger>
|
|
<TooltipContent>
|
|
<p className="text-sm">{_(disabledMessage)}</p>
|
|
</TooltipContent>
|
|
</Tooltip>
|
|
</TooltipProvider>
|
|
);
|
|
}
|
|
|
|
return (
|
|
<Button loading={loading} aria-disabled={disabled} {...getRootProps()} {...props}>
|
|
<div className="flex items-center gap-2">
|
|
<input data-testid="document-upload-input" {...getInputProps()} />
|
|
{!loading && <Upload className="h-4 w-4" />}
|
|
{disabled ? _(disabledMessage) : _(heading[type])}
|
|
</div>
|
|
</Button>
|
|
);
|
|
};
|