mirror of
https://github.com/documenso/documenso.git
synced 2025-11-10 04:22:32 +10:00
feat: update disabled dropzone text (#787)
Update the dropzone so it will display the relevant disabled text based on the reason it is disabled.
This commit is contained in:
@ -1,6 +1,6 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { useState } from 'react';
|
import { useMemo, useState } from 'react';
|
||||||
|
|
||||||
import Link from 'next/link';
|
import Link from 'next/link';
|
||||||
import { useRouter } from 'next/navigation';
|
import { useRouter } from 'next/navigation';
|
||||||
@ -36,6 +36,16 @@ export const UploadDocument = ({ className }: UploadDocumentProps) => {
|
|||||||
|
|
||||||
const { mutateAsync: createDocument } = trpc.document.createDocument.useMutation();
|
const { mutateAsync: createDocument } = trpc.document.createDocument.useMutation();
|
||||||
|
|
||||||
|
const disabledMessage = useMemo(() => {
|
||||||
|
if (remaining.documents === 0) {
|
||||||
|
return 'You have reached your document limit.';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!session?.user.emailVerified) {
|
||||||
|
return 'Verify your email to upload documents.';
|
||||||
|
}
|
||||||
|
}, [remaining.documents, session?.user.emailVerified]);
|
||||||
|
|
||||||
const onFileDrop = async (file: File) => {
|
const onFileDrop = async (file: File) => {
|
||||||
try {
|
try {
|
||||||
setIsLoading(true);
|
setIsLoading(true);
|
||||||
@ -91,6 +101,7 @@ export const UploadDocument = ({ className }: UploadDocumentProps) => {
|
|||||||
<DocumentDropzone
|
<DocumentDropzone
|
||||||
className="min-h-[40vh]"
|
className="min-h-[40vh]"
|
||||||
disabled={remaining.documents === 0 || !session?.user.emailVerified}
|
disabled={remaining.documents === 0 || !session?.user.emailVerified}
|
||||||
|
disabledMessage={disabledMessage}
|
||||||
onDrop={onFileDrop}
|
onDrop={onFileDrop}
|
||||||
/>
|
/>
|
||||||
|
|
||||||
|
|||||||
@ -87,6 +87,7 @@ const DocumentDescription = {
|
|||||||
export type DocumentDropzoneProps = {
|
export type DocumentDropzoneProps = {
|
||||||
className?: string;
|
className?: string;
|
||||||
disabled?: boolean;
|
disabled?: boolean;
|
||||||
|
disabledMessage?: string;
|
||||||
onDrop?: (_file: File) => void | Promise<void>;
|
onDrop?: (_file: File) => void | Promise<void>;
|
||||||
type?: 'document' | 'template';
|
type?: 'document' | 'template';
|
||||||
[key: string]: unknown;
|
[key: string]: unknown;
|
||||||
@ -96,6 +97,7 @@ export const DocumentDropzone = ({
|
|||||||
className,
|
className,
|
||||||
onDrop,
|
onDrop,
|
||||||
disabled,
|
disabled,
|
||||||
|
disabledMessage = 'You cannot upload documents at this time.',
|
||||||
type = 'document',
|
type = 'document',
|
||||||
...props
|
...props
|
||||||
}: DocumentDropzoneProps) => {
|
}: DocumentDropzoneProps) => {
|
||||||
@ -172,7 +174,9 @@ export const DocumentDropzone = ({
|
|||||||
{DocumentDescription[type].headline}
|
{DocumentDescription[type].headline}
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
<p className="text-muted-foreground/80 mt-1 text-sm ">Drag & drop your document here.</p>
|
<p className="text-muted-foreground/80 mt-1 text-sm">
|
||||||
|
{disabled ? disabledMessage : 'Drag & drop your document here.'}
|
||||||
|
</p>
|
||||||
</CardContent>
|
</CardContent>
|
||||||
</Card>
|
</Card>
|
||||||
</motion.div>
|
</motion.div>
|
||||||
|
|||||||
Reference in New Issue
Block a user