mirror of
https://github.com/documenso/documenso.git
synced 2025-11-14 08:42:12 +10:00
fix: update prop typo, extract truncate method
This commit is contained in:
@ -5,6 +5,7 @@ import prisma from "@documenso/prisma";
|
|||||||
import { Button, IconButton } from "@documenso/ui";
|
import { Button, IconButton } from "@documenso/ui";
|
||||||
import { NextPageWithLayout } from "../../_app";
|
import { NextPageWithLayout } from "../../_app";
|
||||||
import { ArrowDownTrayIcon, CheckBadgeIcon } from "@heroicons/react/24/outline";
|
import { ArrowDownTrayIcon, CheckBadgeIcon } from "@heroicons/react/24/outline";
|
||||||
|
import { truncate } from "@documenso/lib/helpers";
|
||||||
|
|
||||||
const Signed: NextPageWithLayout = (props: any) => {
|
const Signed: NextPageWithLayout = (props: any) => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
@ -21,7 +22,7 @@ const Signed: NextPageWithLayout = (props: any) => {
|
|||||||
<CheckBadgeIcon className="text-neon mr-1 inline w-10"></CheckBadgeIcon>
|
<CheckBadgeIcon className="text-neon mr-1 inline w-10"></CheckBadgeIcon>
|
||||||
<h1 className="text-neon inline align-middle text-base font-medium">It's done!</h1>
|
<h1 className="text-neon inline align-middle text-base font-medium">It's done!</h1>
|
||||||
<p className="mt-2 text-4xl font-bold tracking-tight">
|
<p className="mt-2 text-4xl font-bold tracking-tight">
|
||||||
You signed "{props.document.title}"
|
You signed "{truncate(props.document.title)}"
|
||||||
</p>
|
</p>
|
||||||
<p className="mt-2 max-w-sm text-base text-gray-500" hidden={allRecipientsSigned}>
|
<p className="mt-2 max-w-sm text-base text-gray-500" hidden={allRecipientsSigned}>
|
||||||
You will be notfied when all recipients have signed.
|
You will be notfied when all recipients have signed.
|
||||||
|
|||||||
1
packages/lib/helpers/index.ts
Normal file
1
packages/lib/helpers/index.ts
Normal file
@ -0,0 +1 @@
|
|||||||
|
export * from './strings';
|
||||||
13
packages/lib/helpers/strings.ts
Normal file
13
packages/lib/helpers/strings.ts
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
/**
|
||||||
|
* Truncates a title to a given max length substituting the middle with an ellipsis.
|
||||||
|
*/
|
||||||
|
export const truncate = (str: string, maxLength: number = 20) => {
|
||||||
|
if (str.length <= maxLength) {
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
const startLength = Math.ceil((maxLength - 3) / 2);
|
||||||
|
const endLength = Math.floor((maxLength - 3) / 2);
|
||||||
|
|
||||||
|
return `${str.slice(0, startLength)}...${str.slice(-endLength)}`;
|
||||||
|
};
|
||||||
@ -1,6 +1,7 @@
|
|||||||
import React from "react";
|
import React, { useMemo } from "react";
|
||||||
import { Fragment } from "react";
|
import { Fragment } from "react";
|
||||||
import { sendSigningRequests } from "@documenso/lib/api";
|
import { sendSigningRequests } from "@documenso/lib/api";
|
||||||
|
import { truncate } from "@documenso/lib/helpers";
|
||||||
import { Button } from "@documenso/ui";
|
import { Button } from "@documenso/ui";
|
||||||
import { Dialog as DialogComponent, Transition } from "@headlessui/react";
|
import { Dialog as DialogComponent, Transition } from "@headlessui/react";
|
||||||
import { Document as PrismaDocument } from "@prisma/client";
|
import { Document as PrismaDocument } from "@prisma/client";
|
||||||
@ -19,7 +20,7 @@ type DialogProps = {
|
|||||||
formValues: FormValue[];
|
formValues: FormValue[];
|
||||||
setLoading: (loading: boolean) => void;
|
setLoading: (loading: boolean) => void;
|
||||||
icon: React.ReactNode;
|
icon: React.ReactNode;
|
||||||
trunateTitle: boolean;
|
truncateTitle: boolean;
|
||||||
};
|
};
|
||||||
|
|
||||||
export function Dialog({
|
export function Dialog({
|
||||||
@ -30,16 +31,13 @@ export function Dialog({
|
|||||||
formValues,
|
formValues,
|
||||||
setLoading,
|
setLoading,
|
||||||
icon,
|
icon,
|
||||||
trunateTitle = true,
|
truncateTitle = true,
|
||||||
}: DialogProps) {
|
}: DialogProps) {
|
||||||
const unsentEmailsLength = formValues.filter(
|
const unsentEmailsLength = formValues.filter(
|
||||||
(s: any) => s.email && s.sendStatus != "SENT"
|
(s: any) => s.email && s.sendStatus != "SENT"
|
||||||
).length;
|
).length;
|
||||||
|
|
||||||
if (trunateTitle && document.title.length > 20) {
|
const documentTitle = truncate(document.title)
|
||||||
document.title = document.title.substring(0, 7) + "..." +
|
|
||||||
document.title.substring(document.title.length - 7);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Transition.Root show={open} as={Fragment}>
|
<Transition.Root show={open} as={Fragment}>
|
||||||
@ -78,7 +76,7 @@ export function Dialog({
|
|||||||
</DialogComponent.Title>
|
</DialogComponent.Title>
|
||||||
<div className="mt-2">
|
<div className="mt-2">
|
||||||
<p className="text-sm text-gray-500">
|
<p className="text-sm text-gray-500">
|
||||||
{`"${document.title}" will be sent to ${unsentEmailsLength} recipients.`}
|
{`"${documentTitle}" will be sent to ${unsentEmailsLength} recipients.`}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user