Files
sign/apps/remix/app/components/general/document/document-page-view-information.tsx

70 lines
2.0 KiB
TypeScript
Raw Normal View History

2024-02-12 17:30:23 +11:00
import { useMemo } from 'react';
2025-01-02 15:33:37 +11:00
import { msg } from '@lingui/core/macro';
2024-08-27 20:34:39 +09:00
import { useLingui } from '@lingui/react';
2025-01-02 15:33:37 +11:00
import { Trans } from '@lingui/react/macro';
import type { Document, Recipient, User } from '@prisma/client';
2024-02-12 17:30:23 +11:00
import { DateTime } from 'luxon';
import { useIsMounted } from '@documenso/lib/client-only/hooks/use-is-mounted';
export type DocumentPageViewInformationProps = {
userId: number;
document: Document & {
2025-01-13 13:41:53 +11:00
user: Pick<User, 'id' | 'name' | 'email'>;
recipients: Recipient[];
2024-02-12 17:30:23 +11:00
};
};
export const DocumentPageViewInformation = ({
document,
userId,
}: DocumentPageViewInformationProps) => {
const isMounted = useIsMounted();
2024-02-22 19:13:35 +11:00
const { _, i18n } = useLingui();
2024-02-12 17:30:23 +11:00
const documentInformation = useMemo(() => {
return [
{
2024-08-27 20:34:39 +09:00
description: msg`Uploaded by`,
2025-01-13 13:41:53 +11:00
value:
userId === document.userId ? _(msg`You`) : (document.user.name ?? document.user.email),
2024-02-12 17:30:23 +11:00
},
{
2024-08-27 20:34:39 +09:00
description: msg`Created`,
value: DateTime.fromJSDate(document.createdAt)
.setLocale(i18n.locales?.[0] || i18n.locale)
.toFormat('MMMM d, yyyy'),
2024-02-12 17:30:23 +11:00
},
{
2024-08-27 20:34:39 +09:00
description: msg`Last modified`,
value: DateTime.fromJSDate(document.updatedAt)
.setLocale(i18n.locales?.[0] || i18n.locale)
.toRelative(),
2024-02-12 17:30:23 +11:00
},
];
2024-08-27 20:34:39 +09:00
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [isMounted, document, userId]);
2024-02-12 17:30:23 +11:00
return (
2024-02-15 18:20:10 +11:00
<section className="dark:bg-background text-foreground border-border bg-widget flex flex-col rounded-xl border">
2024-08-27 20:34:39 +09:00
<h1 className="px-4 py-3 font-medium">
<Trans>Information</Trans>
</h1>
2024-02-12 17:30:23 +11:00
<ul className="divide-y border-t">
2024-08-27 20:34:39 +09:00
{documentInformation.map((item, i) => (
2024-02-12 17:30:23 +11:00
<li
2024-08-27 20:34:39 +09:00
key={i}
2024-02-12 17:30:23 +11:00
className="flex items-center justify-between px-4 py-2.5 text-sm last:border-b"
>
2024-08-27 20:34:39 +09:00
<span className="text-muted-foreground">{_(item.description)}</span>
2024-02-12 17:30:23 +11:00
<span>{item.value}</span>
</li>
))}
</ul>
</section>
);
};