MCPcopy Create free account
hub / github.com/alanagoyal/docbase / Documents

Function Documents

components/documents.tsx:40–165  ·  view source on GitHub ↗
({ documents }: { documents: Document[] })

Source from the content-addressed store, hash-verified

38 created_at: string
39}
40export function Documents({ documents }: { documents: Document[] }) {
41 const router = useRouter()
42 const getEditLink = (document: Document) => {
43 const fileName = document.document_name.toLowerCase()
44 if (fileName.includes("safe") || fileName.includes("side letter")) {
45 return `/investments/${document.id}${
46 fileName.includes("side letter") ? "?step=3" : ""
47 }`
48 }
49 return `/links/edit/${document.id}`
50 }
51
52 const downloadDocument = (url: string) => {
53 window.open(url, "_blank")
54 toast({ description: "Document downloaded" })
55 }
56
57 const handleCopyLink = (documentId: string) => {
58 const link = `${process.env.NEXT_PUBLIC_SITE_URL}/links/view/${documentId}`
59 navigator.clipboard
60 .writeText(link)
61 .then(() => {
62 toast({
63 description: "Your link has been copied",
64 })
65 })
66 .catch((error) => {
67 toast({
68 description: "There was an error copying your link",
69 })
70 })
71 }
72
73 const linkUrl = (document: Document) => {
74 return `${process.env.NEXT_PUBLIC_SITE_URL}/links/view/${document.id}`
75 }
76
77 const formatDate = (dateString: string | null) => {
78 if (!dateString) return "n/a"
79 const date = new Date(dateString)
80 return date.toLocaleDateString("en-US", {
81 month: "2-digit",
82 day: "2-digit",
83 year: "2-digit",
84 timeZone: "UTC",
85 })
86 }
87
88 useEffect(() => {
89 const handleKeyDown = (e: KeyboardEvent) => {
90 if (e.key === "n" && !isTyping()) {
91 e.preventDefault()
92 router.push("/links/new")
93 }
94 }
95
96 document.addEventListener("keydown", handleKeyDown)
97 return () => document.removeEventListener("keydown", handleKeyDown)

Callers

nothing calls this directly

Calls 5

downloadDocumentFunction · 0.85
getEditLinkFunction · 0.85
handleCopyLinkFunction · 0.70
linkUrlFunction · 0.70
formatDateFunction · 0.70

Tested by

no test coverage detected