forked from mfts/papermark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.tsx
162 lines (151 loc) · 6.45 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import Link from "next/link";
import { PlusIcon } from "lucide-react";
import { UpgradePlanModal } from "@/components/billing/upgrade-plan-modal";
import { AddDataroomModal } from "@/components/datarooms/add-dataroom-modal";
import { DataroomTrialModal } from "@/components/datarooms/dataroom-trial-modal";
import { EmptyDataroom } from "@/components/datarooms/empty-dataroom";
import AppLayout from "@/components/layouts/app";
import { Button } from "@/components/ui/button";
import {
Card,
CardContent,
CardDescription,
CardHeader,
CardTitle,
} from "@/components/ui/card";
import { Separator } from "@/components/ui/separator";
import { usePlan } from "@/lib/swr/use-billing";
import useDatarooms from "@/lib/swr/use-datarooms";
import useLimits from "@/lib/swr/use-limits";
import { daysLeft } from "@/lib/utils";
import { useEffect } from "react";
import { useRouter } from "next/navigation";
export default function DataroomsPage() {
const { datarooms } = useDatarooms();
const { plan, trial } = usePlan();
const { limits } = useLimits();
const router = useRouter()
const numDatarooms = datarooms?.length ?? 0;
const limitDatarooms = limits?.datarooms ?? 1;
const isBusiness = plan === "business";
const isDatarooms = plan === "datarooms";
const isTrialDatarooms = trial === "drtrial";
const canCreateUnlimitedDatarooms =
isDatarooms || (isBusiness && numDatarooms < limitDatarooms);
useEffect(()=>{
if(trial == null && plan == 'free') router.push('/documents')
},[trial,plan])
return (
<AppLayout>
<main className="p-4 sm:m-4 sm:px-4 sm:py-4">
<section className="mb-4 flex items-center justify-between md:mb-8 lg:mb-12">
<div className="space-y-1">
<h2 className="text-xl font-semibold tracking-tight text-foreground sm:text-2xl">
Datarooms
</h2>
<p className="text-xs text-muted-foreground sm:text-sm">
Manage your datarooms
</p>
</div>
<div className="flex items-center gap-x-1">
{isBusiness && !canCreateUnlimitedDatarooms ? (
<UpgradePlanModal clickedPlan="Data Rooms" trigger="datarooms">
<Button
className="group flex flex-1 items-center justify-start gap-x-3 px-3 text-left"
title="Add New Document"
>
<span>Upgrade to Add Data Room</span>
</Button>
</UpgradePlanModal>
) : isTrialDatarooms && datarooms && !isBusiness && !isDatarooms ? (
<div className="flex items-center gap-x-4">
<div className="text-sm text-destructive">
<span>Dataroom Trial: </span>
<span className="font-medium">
{daysLeft(new Date(datarooms[0].createdAt), 7)} days left
</span>
</div>
<UpgradePlanModal clickedPlan="Data Rooms" trigger="datarooms">
<Button
className="group flex flex-1 items-center justify-start gap-x-3 px-3 text-left"
title="Add New Document"
>
<span>Upgrade to Add Data Room</span>
</Button>
</UpgradePlanModal>
</div>
) : isBusiness || isDatarooms ? (
<AddDataroomModal>
<Button
className="group flex flex-1 items-center justify-start gap-x-3 px-3 text-left"
title="Add New Document"
>
<PlusIcon className="h-5 w-5 shrink-0" aria-hidden="true" />
<span>Create New Dataroom</span>
</Button>
</AddDataroomModal>
) : (
<DataroomTrialModal>
<Button
className="group flex flex-1 items-center justify-start gap-x-3 px-3 text-left"
title="Add New Document"
>
<span>Start Data Room Trial</span>
</Button>
</DataroomTrialModal>
)}
</div>
</section>
<Separator className="mb-5 bg-gray-200 dark:bg-gray-800" />
<div className="space-y-4">
<ul className="grid grid-cols-1 gap-x-6 gap-y-8 lg:grid-cols-2 xl:grid-cols-3">
{datarooms &&
datarooms.map((dataroom) => (
<Link key={dataroom.id} href={`/datarooms/${dataroom.id}`}>
<Card className="group relative overflow-hidden duration-500 hover:border-primary/50">
<CardHeader>
<div className="flex items-center justify-between">
<CardTitle className="truncate">
{dataroom.name}
</CardTitle>
</div>
{/* <CardDescription>{dataroom.pId}</CardDescription> */}
</CardHeader>
<CardContent>
<dl className="divide-y divide-gray-100 text-sm leading-6">
<div className="flex justify-between gap-x-4 py-3">
<dt className="text-gray-500 dark:text-gray-400">
Documents
</dt>
<dd className="flex items-start gap-x-2">
<div className="font-medium text-gray-900 dark:text-gray-200">
{dataroom._count.documents ?? 0}
</div>
</dd>
</div>
<div className="flex justify-between gap-x-4 py-3">
<dt className="text-gray-500 dark:text-gray-400">
Views
</dt>
<dd className="flex items-start gap-x-2">
<div className="font-medium text-gray-900 dark:text-gray-200">
{dataroom._count.views ?? 0}
</div>
</dd>
</div>
</dl>
</CardContent>
</Card>
</Link>
))}
</ul>
{datarooms && datarooms.length === 0 && (
<div className="flex items-center justify-center">
<EmptyDataroom />
</div>
)}
</div>
</main>
</AppLayout>
);
}