-
-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: 🚀 added recent responses and usage card in dashboard page
- Loading branch information
1 parent
2b21f28
commit 0adb281
Showing
17 changed files
with
316 additions
and
116 deletions.
There are no files selected for viewing
68 changes: 68 additions & 0 deletions
68
apps/web/src/app/(protectedPage)/(mainPage)/dashboard/_components/recentResponseList.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
"use client"; | ||
|
||
import Link from "next/link"; | ||
import { Skeleton } from "@convoform/ui/components/ui/skeleton"; | ||
|
||
import { ListCard } from "@/components/common/list"; | ||
import { ListItem } from "@/components/common/listItem"; | ||
import { timeAgo } from "@/lib/utils"; | ||
import { api } from "@/trpc/react"; | ||
|
||
export function RecentResponseList({ | ||
organizationId, | ||
}: Readonly<{ organizationId: string }>) { | ||
const { data, isFetching } = api.conversation.getRecentResponses.useQuery({ | ||
organizationId, | ||
take: 10, | ||
}); | ||
|
||
if (isFetching) { | ||
return <RecentResponseListLoading />; | ||
} | ||
|
||
if (data) { | ||
return ( | ||
<ListCard> | ||
{data.map((response) => ( | ||
<ListItem key={response.id}> | ||
<Link | ||
href={`/forms/${response.formId}/conversations/${response.id}`} | ||
> | ||
<div className="flex items-center justify-between py-2"> | ||
<div className="grid"> | ||
<span>{response.name}</span> | ||
<span className="text-muted-foreground text-xs"> | ||
{response.form.name} | ||
</span> | ||
</div> | ||
<span className="text-muted-foreground text-sm"> | ||
{timeAgo(response.createdAt)} | ||
</span> | ||
</div> | ||
</Link> | ||
</ListItem> | ||
))} | ||
</ListCard> | ||
); | ||
} | ||
|
||
return null; | ||
} | ||
|
||
function RecentResponseListLoading() { | ||
return ( | ||
<ListCard> | ||
{[...Array(3)].map((_, i) => ( | ||
<ListItem key={i}> | ||
<div className="flex items-center justify-between py-2"> | ||
<div className="grid gap-1"> | ||
<Skeleton className="h-[10px] w-[150px]" /> | ||
<Skeleton className="h-[8px] w-[100px]" /> | ||
</div> | ||
<Skeleton className="h-[10px] w-[50px]" /> | ||
</div> | ||
</ListItem> | ||
))} | ||
</ListCard> | ||
); | ||
} |
File renamed without changes.
77 changes: 77 additions & 0 deletions
77
apps/web/src/app/(protectedPage)/(mainPage)/dashboard/_components/responseUsageCard.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
"use client"; | ||
|
||
import { Card, CardContent } from "@convoform/ui/components/ui/card"; | ||
import { Skeleton } from "@convoform/ui/components/ui/skeleton"; | ||
import { ProgressCircle } from "@tremor/react"; | ||
|
||
import { formSubmissionLimit } from "@/lib/config/pricing"; | ||
import { api } from "@/trpc/react"; | ||
|
||
type Props = { | ||
organizationId: string; | ||
}; | ||
|
||
export function ResponseUsageCard({ organizationId }: Readonly<Props>) { | ||
const { data, isFetching } = api.metrics.getResponsesCount.useQuery({ | ||
organizationId, | ||
}); | ||
|
||
if (isFetching) { | ||
return ( | ||
<Card> | ||
<CardContent className="pt-6"> | ||
<div className="grid grid-cols-2"> | ||
<div> | ||
<p className="text-tremor-default text-tremor-content dark:text-dark-tremor-content"> | ||
<span>Response usage</span> | ||
</p> | ||
<div className="mt-3 flex items-center gap-2"> | ||
<Skeleton className="h-[20px] w-[40px]" /> | ||
</div> | ||
</div> | ||
<div className="flex justify-end"> | ||
<Skeleton className="h-[58px] w-[58px] rounded-full" /> | ||
</div> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
if (data) { | ||
const usage = 200; | ||
const maximum = formSubmissionLimit; | ||
const usagePercentage = (usage / maximum) * 100; | ||
|
||
return ( | ||
<Card> | ||
<CardContent className="pt-6"> | ||
<div className="grid grid-cols-2"> | ||
<div> | ||
<p className="text-tremor-default text-tremor-content dark:text-dark-tremor-content"> | ||
<span>Response usage</span> | ||
</p> | ||
<p className="mt-3 flex items-end"> | ||
<span className="text-tremor-metric text-tremor-content-strong dark:text-dark-tremor-content-strong font-semibold"> | ||
{usage} | ||
</span> | ||
<span className="text-tremor-content-subtle dark:text-dark-tremor-content-subtle font-semibold"> | ||
/{maximum} | ||
</span> | ||
</p> | ||
</div> | ||
<div className="flex justify-end"> | ||
<ProgressCircle value={usagePercentage}> | ||
<span className="text-muted-foreground font-medium"> | ||
{usagePercentage}% | ||
</span> | ||
</ProgressCircle> | ||
</div> | ||
</div> | ||
</CardContent> | ||
</Card> | ||
); | ||
} | ||
|
||
return null; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
export function ListCard({ | ||
children, | ||
}: Readonly<{ children: React.ReactNode }>) { | ||
return <div className="divide-border grid divide-y border-b">{children}</div>; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
export function ListItem({ | ||
children, | ||
}: Readonly<{ children: React.ReactNode }>) { | ||
return ( | ||
<div className=" py-1 ps-1 align-middle transition-all hover:bg-gray-50 hover:ps-2"> | ||
{children} | ||
</div> | ||
); | ||
} |
13 changes: 0 additions & 13 deletions
13
apps/web/src/components/mainPage/dashboard/dataCardLoading.tsx
This file was deleted.
Oops, something went wrong.
12 changes: 0 additions & 12 deletions
12
apps/web/src/components/mainPage/dashboard/formDataCard.tsx
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.