-
Notifications
You must be signed in to change notification settings - Fork 619
thirdweb AI inside dashboard #8003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
45 changes: 45 additions & 0 deletions
45
apps/dashboard/src/@/components/ui/image-upload-button.tsx
This file contains hidden or 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,45 @@ | ||
| "use client"; | ||
|
|
||
| import type React from "react"; | ||
| import { useRef } from "react"; | ||
| import { Button } from "@/components/ui/button"; | ||
|
|
||
| interface ImageUploadProps { | ||
| value: File | undefined; | ||
| onChange?: (files: File[]) => void; | ||
| children?: React.ReactNode; | ||
| variant?: React.ComponentProps<typeof Button>["variant"]; | ||
| className?: string; | ||
| multiple?: boolean; | ||
| accept: string; | ||
| } | ||
|
|
||
| export function ImageUploadButton(props: ImageUploadProps) { | ||
| const fileInputRef = useRef<HTMLInputElement>(null); | ||
|
|
||
| const handleFileChange = (e: React.ChangeEvent<HTMLInputElement>) => { | ||
| const files = Array.from(e.target.files || []); | ||
| props.onChange?.(files); | ||
| }; | ||
|
|
||
| return ( | ||
| <div> | ||
| <Button | ||
| className={props.className} | ||
| onClick={() => fileInputRef.current?.click()} | ||
| variant={props.variant} | ||
| > | ||
| {props.children} | ||
| </Button> | ||
| <input | ||
| accept={props.accept} | ||
| aria-label="Upload image" | ||
| className="hidden" | ||
| multiple={props.multiple} | ||
| onChange={handleFileChange} | ||
| ref={fileInputRef} | ||
| type="file" | ||
| /> | ||
| </div> | ||
| ); | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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
102 changes: 102 additions & 0 deletions
102
apps/dashboard/src/app/(app)/team/[team_slug]/[project_slug]/(sidebar)/ai/analytics/page.tsx
This file contains hidden or 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,102 @@ | ||
| import { redirect } from "next/navigation"; | ||
| import { ResponsiveSearchParamsProvider } from "responsive-rsc"; | ||
| import { getAuthToken } from "@/api/auth-token"; | ||
| import { getProject } from "@/api/project/projects"; | ||
| import type { DurationId } from "@/components/analytics/date-range-selector"; | ||
| import { ResponsiveTimeFilters } from "@/components/analytics/responsive-time-filters"; | ||
| import { ProjectPage } from "@/components/blocks/project-page/project-page"; | ||
| import { getClientThirdwebClient } from "@/constants/thirdweb-client.client"; | ||
| import { NebulaIcon } from "@/icons/NebulaIcon"; | ||
| import { getFiltersFromSearchParams } from "@/lib/time"; | ||
| import { loginRedirect } from "@/utils/redirects"; | ||
| import { AiAnalytics } from "./chart"; | ||
| import { AiSummary } from "./chart/Summary"; | ||
|
|
||
| export default async function Page(props: { | ||
| params: Promise<{ team_slug: string; project_slug: string }>; | ||
| searchParams: Promise<{ | ||
| from?: string; | ||
| to?: string; | ||
| type?: string; | ||
| interval?: string; | ||
| }>; | ||
| }) { | ||
| const [searchParams, params] = await Promise.all([ | ||
| props.searchParams, | ||
| props.params, | ||
| ]); | ||
|
|
||
| const { team_slug, project_slug } = params; | ||
|
|
||
| const [project, authToken] = await Promise.all([ | ||
| getProject(team_slug, project_slug), | ||
| getAuthToken(), | ||
| ]); | ||
|
|
||
| if (!authToken) { | ||
| loginRedirect(`/team/${team_slug}/${project_slug}/ai`); | ||
| } | ||
joaquim-verges marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (!project) { | ||
| redirect(`/team/${team_slug}`); | ||
| } | ||
|
|
||
| const client = getClientThirdwebClient({ | ||
| jwt: authToken, | ||
| teamId: project.teamId, | ||
| }); | ||
|
|
||
| const defaultRange = "last-30" as DurationId; | ||
| const { range, interval } = getFiltersFromSearchParams({ | ||
| defaultRange, | ||
| from: searchParams.from, | ||
| interval: searchParams.interval, | ||
| to: searchParams.to, | ||
| }); | ||
|
|
||
| return ( | ||
| <ResponsiveSearchParamsProvider value={searchParams}> | ||
| <ProjectPage | ||
| header={{ | ||
| icon: NebulaIcon, | ||
| client, | ||
| title: "AI Analytics", | ||
| description: "Track your AI app usage and performance", | ||
| actions: null, | ||
| links: [ | ||
| { | ||
| href: "https://portal.thirdweb.com/ai/chat", | ||
| type: "docs", | ||
| }, | ||
| { | ||
| href: "https://api.thirdweb.com/reference#tag/ai/post/ai/chat", | ||
| type: "api", | ||
| }, | ||
| { | ||
| href: "https://playground.thirdweb.com/ai/chat", | ||
| type: "playground", | ||
| }, | ||
| ], | ||
| }} | ||
| > | ||
| <div className="flex flex-col gap-4 md:gap-6"> | ||
| <ResponsiveTimeFilters defaultRange={defaultRange} /> | ||
| <AiSummary | ||
| projectId={project.id} | ||
| teamId={project.teamId} | ||
| authToken={authToken} | ||
| range={range} | ||
| /> | ||
|
|
||
| <AiAnalytics | ||
| interval={interval} | ||
| projectId={project.id} | ||
| range={range} | ||
| teamId={project.teamId} | ||
| authToken={authToken} | ||
| /> | ||
| </div> | ||
| </ProjectPage> | ||
| </ResponsiveSearchParamsProvider> | ||
| ); | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.