-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FEAT] Dashboard UI on the web app (#3)
- Loading branch information
1 parent
ea2af69
commit cc275c9
Showing
42 changed files
with
611 additions
and
22 deletions.
There are no files selected for viewing
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 @@ | ||
# Active Users Widget | ||
|
||
## Todo's | ||
|
||
- [ ] Allowedorigins filter |
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
11 changes: 11 additions & 0 deletions
11
.../web/prisma/migrations/20230303200418_add_a_key_column_to_the_project_model/migration.sql
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,11 @@ | ||
/* | ||
Warnings: | ||
- A unique constraint covering the columns `[key]` on the table `Project` will be added. If there are existing duplicate values, this will fail. | ||
*/ | ||
-- AlterTable | ||
ALTER TABLE "Project" ADD COLUMN "key" TEXT; | ||
|
||
-- CreateIndex | ||
CREATE UNIQUE INDEX "Project_key_key" ON "Project"("key"); |
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
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
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,15 @@ | ||
import Link from "next/link"; | ||
import React from "react"; | ||
import PackagePlusIcon from "../svgx/PackagePlusIcon"; | ||
|
||
export default function NewProjectCard() { | ||
return ( | ||
<Link | ||
href="/dashboard/new-project" | ||
className="flex w-full items-center justify-center space-x-2 rounded-md border border-slate-100 bg-slate-50/40 p-4 py-14 text-slate-800 hover:bg-slate-100" | ||
> | ||
<PackagePlusIcon /> | ||
<span>Create new project</span> | ||
</Link> | ||
); | ||
} |
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,85 @@ | ||
import { Project } from "@prisma/client"; | ||
import { useClipboard } from "../../hooks/useClipboard"; | ||
import CopyIcon from "../svgx/CopyIcon"; | ||
|
||
type Props = { | ||
codeSnippet?: { | ||
highlighted: string; | ||
raw: string; | ||
}; | ||
project: Project; | ||
}; | ||
|
||
export default function ProjectCard({ codeSnippet, project }: Props) { | ||
const clipboard = useClipboard(); | ||
|
||
const cleanedHighlightedCode = | ||
project.key && | ||
codeSnippet?.highlighted?.replace("%PROJECT_ID%", project.key); | ||
const cleanedRawCode = | ||
project.key && codeSnippet?.raw?.replace("%PROJECT_ID%", project.key); | ||
|
||
const copy = () => { | ||
clipboard.copy(cleanedRawCode); | ||
}; | ||
|
||
return ( | ||
<article className="grid grid-cols-6 gap-4 rounded-md border border-slate-100 p-4"> | ||
<div className="col-span-2"> | ||
<div className="flex items-center justify-between space-x-2"> | ||
<div className="flex flex-col items-start"> | ||
<span className="rounded-lg font-sans font-medium"> | ||
{project.name} | ||
</span> | ||
<span className="py-.5 mt-1 rounded-sm bg-slate-200 px-1 font-mono text-xs font-medium"> | ||
{project.key} | ||
</span> | ||
</div> | ||
|
||
<div className="inline-flex items-center space-x-1 rounded-sm border border-gray-200 px-2 py-1"> | ||
<span className="text-xs text-gray-800">Active</span> | ||
<div className="h-1.5 w-1.5 animate-pulse rounded-full bg-green-500"></div> | ||
</div> | ||
</div> | ||
<div className="mt-4"> | ||
<div> | ||
<span className="text-sm text-slate-600"> | ||
Visits in the last 30 minutes :{" "} | ||
<span className="font-bold">0</span> | ||
</span> | ||
</div> | ||
<div> | ||
<span className="text-sm text-slate-600"> | ||
Total visits : <span className="font-bold">0</span> | ||
</span> | ||
</div> | ||
</div>{" "} | ||
</div> | ||
{cleanedHighlightedCode && ( | ||
<div className="col-span-4"> | ||
<div className=" rounded-md bg-gradient-to-br from-slate-50 to-slate-200 px-3 py-3"> | ||
<h3 className="mb-2 text-lg font-medium leading-none text-slate-700"> | ||
Integrate the widget | ||
</h3> | ||
<p> | ||
Add the following code to the <code><head></code> tag | ||
</p> | ||
<div className="mt-2 flex space-x-2"> | ||
<div | ||
className="code-block" | ||
dangerouslySetInnerHTML={{ __html: cleanedHighlightedCode }} | ||
></div> | ||
<button | ||
onClick={copy} | ||
className="flex items-center space-x-1 rounded-lg bg-slate-800 px-2 py-1 text-white" | ||
> | ||
<span>Copy</span> | ||
<CopyIcon /> | ||
</button> | ||
</div> | ||
</div> | ||
</div> | ||
)} | ||
</article> | ||
); | ||
} |
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,24 @@ | ||
import React, { SVGProps } from "react"; | ||
|
||
export default function CopyIcon(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 24 24" | ||
{...props} | ||
> | ||
<g | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
> | ||
<rect width="13" height="13" x="9" y="9" rx="2" ry="2"></rect> | ||
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"></path> | ||
</g> | ||
</svg> | ||
); | ||
} |
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,24 @@ | ||
import { SVGProps } from "react"; | ||
|
||
export default function PackagePlusIcon(props: SVGProps<SVGSVGElement>) { | ||
return ( | ||
<svg | ||
xmlns="http://www.w3.org/2000/svg" | ||
width="1em" | ||
height="1em" | ||
viewBox="0 0 24 24" | ||
{...props} | ||
> | ||
<g | ||
fill="none" | ||
stroke="currentColor" | ||
strokeLinecap="round" | ||
strokeLinejoin="round" | ||
strokeWidth="2" | ||
> | ||
<path d="M16 16h6m-3-3v6m2-9V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l2-1.14M16.5 9.4L7.55 4.24"></path> | ||
<path d="M3.29 7L12 12l8.71-5M12 22V12"></path> | ||
</g> | ||
</svg> | ||
); | ||
} |
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,34 @@ | ||
import { useState } from "react"; | ||
|
||
export function useClipboard({ timeout = 2000 } = {}) { | ||
const [error, setError] = useState<Error | null>(null); | ||
const [copied, setCopied] = useState(false); | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const [copyTimeout, setCopyTimeout] = useState<any>(null); | ||
|
||
const handleCopyResult = (value: boolean) => { | ||
clearTimeout(copyTimeout); | ||
setCopyTimeout(setTimeout(() => setCopied(false), timeout)); | ||
setCopied(value); | ||
}; | ||
|
||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
const copy = (valueToCopy: any) => { | ||
if ("clipboard" in navigator) { | ||
navigator.clipboard | ||
.writeText(valueToCopy) | ||
.then(() => handleCopyResult(true)) | ||
.catch((err) => setError(err)); | ||
} else { | ||
setError(new Error("useClipboard: navigator.clipboard is not supported")); | ||
} | ||
}; | ||
|
||
const reset = () => { | ||
setCopied(false); | ||
setError(null); | ||
clearTimeout(copyTimeout); | ||
}; | ||
|
||
return { copy, reset, error, copied }; | ||
} |
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,65 @@ | ||
import { | ||
GetStaticPaths, | ||
GetStaticPropsContext, | ||
InferGetStaticPropsType, | ||
} from "next"; | ||
import { prisma } from "../../server/db"; | ||
|
||
import { serialize } from "superjson"; | ||
import { Project } from "@prisma/client"; | ||
|
||
export const getStaticProps = async ( | ||
context: GetStaticPropsContext<{ id: string }> | ||
) => { | ||
const { id } = context.params!; | ||
|
||
const project = await prisma.project.findUnique({ | ||
where: { | ||
id, | ||
}, | ||
}); | ||
|
||
return { | ||
props: { | ||
project: serialize(project).json as unknown as Project, | ||
id, | ||
}, | ||
revalidate: 60, | ||
}; | ||
}; | ||
|
||
export const getStaticPaths: GetStaticPaths = async () => { | ||
const posts = await prisma.project.findMany({ | ||
select: { | ||
id: true, | ||
}, | ||
}); | ||
|
||
return { | ||
paths: posts.map((post) => ({ | ||
params: { | ||
id: post.id, | ||
}, | ||
})), | ||
fallback: "blocking", | ||
}; | ||
}; | ||
|
||
export default function PostViewPage( | ||
props: InferGetStaticPropsType<typeof getStaticProps> | ||
) { | ||
const { project, id } = props; | ||
|
||
if (!project) { | ||
return <div>Project not found</div>; | ||
} | ||
|
||
return ( | ||
<> | ||
<h1>{project.name}</h1> | ||
<em>Created {new Date(project.createdAt).toLocaleDateString()}</em> | ||
|
||
<pre>{JSON.stringify(project, null, 4)}</pre> | ||
</> | ||
); | ||
} |
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,31 @@ | ||
import { GetServerSideProps, InferGetServerSidePropsType } from "next"; | ||
import shiki from "shiki"; | ||
import NewProjectCard from "../../components/dashboard/NewProjectCard"; | ||
import ProjectCard from "../../components/dashboard/ProjectCard"; | ||
import { prisma } from "../../server/db"; | ||
import { api } from "../../utils/api"; | ||
|
||
export default function DashboardPage() { | ||
const dashboardProjects = api.project.getUserDashboardProjects.useQuery(); | ||
|
||
const projects = dashboardProjects.data?.projects; | ||
const code = dashboardProjects.data?.code; | ||
|
||
return ( | ||
<div className="mx-auto max-w-screen-lg"> | ||
<h1>Dashboard</h1> | ||
|
||
<div className="grid grid-cols-1"> | ||
<div> | ||
<h2>Projects</h2> | ||
<div className="flex flex-col space-y-3"> | ||
{projects?.map((project) => ( | ||
<ProjectCard project={project} key={"dashboard-" + project.id} codeSnippet={code}/> | ||
))} | ||
<NewProjectCard /> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
Oops, something went wrong.