generated from Real-Dev-Squad/website-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
move the dashboard route to app dir (#54)
* make the dashboard route in app dir * move dashboard route to app dir * remove flaky test * remove comment
- Loading branch information
Showing
12 changed files
with
180 additions
and
156 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,24 @@ | ||
"use client" | ||
|
||
import { useEffect } from "react" | ||
|
||
export default function Error({ error, reset }: { error: Error & { digest?: string }; reset: () => void }) { | ||
useEffect(() => { | ||
// Log the error to an error reporting service | ||
console.error(error) | ||
}, [error]) | ||
|
||
return ( | ||
<div> | ||
<h2>Something went wrong!</h2> | ||
<button | ||
onClick={ | ||
// Attempt to recover by trying to re-render the segment | ||
() => reset() | ||
} | ||
> | ||
Try again | ||
</button> | ||
</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,20 @@ | ||
import type { Metadata } from "next" | ||
|
||
import { Navbar } from "@/components/navbar" | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
} | ||
|
||
export const metadata: Metadata = { | ||
title: "Dashboard", | ||
} | ||
|
||
export default function DashboardLayout({ children }: Props) { | ||
return ( | ||
<div> | ||
<Navbar /> | ||
<main className="ml-56 p-6">{children}</main> | ||
</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,3 @@ | ||
export default function Loading() { | ||
return <p>Loading...</p> | ||
} |
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,19 @@ | ||
import { HydrationBoundary, QueryClient, dehydrate } from "@tanstack/react-query" | ||
|
||
import { FormBuilderApi } from "@/api/form-builder/form-builder.api" | ||
import { Dashboard } from "@/modules/dashboard" | ||
|
||
export default async function DashboardPage() { | ||
const queryClient = new QueryClient() | ||
|
||
await queryClient.fetchQuery({ | ||
queryKey: ["FormBuilderApi.getAllForms"], | ||
queryFn: FormBuilderApi.getAllForms, | ||
}) | ||
|
||
return ( | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<Dashboard /> | ||
</HydrationBoundary> | ||
) | ||
} |
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,22 @@ | ||
import { Inter } from "next/font/google" | ||
|
||
import { cn } from "@/utils/classname" | ||
|
||
import "@/styles/globals.css" | ||
import Providers from "./providers" | ||
|
||
export const inter = Inter({ subsets: ["latin"], variable: "--font-inter" }) | ||
|
||
type Props = { | ||
children: React.ReactNode | ||
} | ||
|
||
export default function RootLayout({ children }: Props) { | ||
return ( | ||
<html lang="en"> | ||
<body className={cn("font-sans", inter.className, inter.variable)}> | ||
<Providers>{children}</Providers> | ||
</body> | ||
</html> | ||
) | ||
} |
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,48 @@ | ||
// In Next.js, this file would be called: app/providers.jsx | ||
"use client" | ||
|
||
// We can not useState or useRef in a server component, which is why we are | ||
// extracting this part out into it's own file with 'use client' on top | ||
import { QueryClient, QueryClientProvider } from "@tanstack/react-query" | ||
|
||
function makeQueryClient() { | ||
return new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
// With SSR, we usually want to set some default staleTime | ||
// above 0 to avoid refetching immediately on the client | ||
staleTime: 60 * 1000, | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
let browserQueryClient: QueryClient | undefined = undefined | ||
|
||
function getQueryClient() { | ||
if (typeof window === "undefined") { | ||
// Server: always make a new query client | ||
return makeQueryClient() | ||
} else { | ||
// Browser: make a new query client if we don't already have one | ||
// This is very important so we don't re-make a new client if React | ||
// suspends during the initial render. This may not be needed if we | ||
// have a suspense boundary BELOW the creation of the query client | ||
if (!browserQueryClient) browserQueryClient = makeQueryClient() | ||
return browserQueryClient | ||
} | ||
} | ||
|
||
type ProviderProps = { | ||
children: React.ReactNode | ||
} | ||
|
||
export default function Providers({ children }: ProviderProps) { | ||
// NOTE: Avoid useState when initializing the query client if you don't | ||
// have a suspense boundary between this and the code that may | ||
// suspend because React will throw away the client on the initial | ||
// render if it suspends and there is no boundary | ||
const queryClient = getQueryClient() | ||
|
||
return <QueryClientProvider client={queryClient}>{children}</QueryClientProvider> | ||
} |
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 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
"use client" | ||
|
||
import { useQuery } from "@tanstack/react-query" | ||
|
||
import { FormBuilderApi } from "@/api/form-builder/form-builder.api" | ||
|
||
import { FormCard } from "./form-card" | ||
|
||
export const FormsList = () => { | ||
const { data } = useQuery({ | ||
queryKey: ["FormBuilderApi.getAllForms"], | ||
queryFn: FormBuilderApi.getAllForms, | ||
}) | ||
|
||
return ( | ||
<div> | ||
{data?.data.map((form) => ( | ||
<FormCard | ||
key={form.id} | ||
id={form.id} | ||
status={form.status} | ||
title={form.content.blocks.find((block) => block.type === "FORM_TITLE")?.content ?? "Untitled Form"} | ||
updated_at={form.updated_at} | ||
/> | ||
))} | ||
</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 |
---|---|---|
@@ -1,117 +1,11 @@ | ||
import { useQuery } from "@tanstack/react-query" | ||
import { FilePlus, Plus, PlusIcon } from "lucide-react" | ||
import Link from "next/link" | ||
|
||
import { FormBuilderApi } from "@/api/form-builder/form-builder.api" | ||
import { Button } from "@/components" | ||
import { GenericError } from "@/components/generic-error/generic-error" | ||
import { Shimmer } from "@/components/shimmer" | ||
|
||
import { DashboardTemplate } from "../common/tempaltes/dashboard-template" | ||
|
||
import { DashboardHeader, FormCard } from "./components" | ||
|
||
const EmptyState = () => { | ||
return ( | ||
<div className="flex flex-col items-center justify-center"> | ||
<div className="mb-4 w-max rounded-lg bg-stone-100 p-2 text-stone-700"> | ||
<FilePlus className="h-10 w-10" strokeWidth={1.5} /> | ||
</div> | ||
|
||
<h3 className="pb-1 text-lg font-semibold text-stone-800">No forms yet</h3> | ||
<p className="pb-5 text-center text-sm text-stone-500">Looks empty here, let's create a new form.</p> | ||
<Button size="sm"> | ||
<PlusIcon /> | ||
Create form | ||
</Button> | ||
</div> | ||
) | ||
} | ||
import { DashboardHeader } from "./components" | ||
import { FormsList } from "./components/forms-list" | ||
|
||
export const Dashboard = () => { | ||
const { data, isLoading, isError } = useQuery({ | ||
queryKey: ["FormBuilderApi.getAllForms"], | ||
queryFn: FormBuilderApi.getAllForms, | ||
}) | ||
|
||
const appName = process.env.NEXT_PUBLIC_APP_NAME | ||
const pageTitle = `Dashboard - ${appName}` | ||
|
||
if (isLoading) { | ||
return ( | ||
<DashboardTemplate title={pageTitle}> | ||
<section className="w-full p-6"> | ||
<div className="flex items-center gap-2 pb-8"> | ||
<Shimmer className="h-8 w-24 lg:hidden" /> | ||
<Shimmer className="ml-auto h-8 w-full lg:h-9 lg:w-72" /> | ||
<Shimmer className="h-8 w-11 shrink-0 lg:h-9 lg:w-32" /> | ||
</div> | ||
|
||
<div className="space-y-2"> | ||
{new Array(5).fill(0).map((_, index) => ( | ||
<Shimmer key={index} className="h-20" /> | ||
))} | ||
</div> | ||
</section> | ||
</DashboardTemplate> | ||
) | ||
} | ||
|
||
if (isError) { | ||
return ( | ||
<DashboardTemplate title={pageTitle}> | ||
<h1 className="p-6 text-xl font-semibold">{appName}</h1> | ||
<section className="grid w-full flex-1 place-items-center p-6"> | ||
<GenericError /> | ||
</section> | ||
</DashboardTemplate> | ||
) | ||
} | ||
|
||
if (!data?.data.length) { | ||
return ( | ||
<DashboardTemplate title={pageTitle}> | ||
<h1 className="p-6 text-xl font-semibold">{appName}</h1> | ||
|
||
<section className="grid w-full flex-1 place-items-center p-6"> | ||
<EmptyState /> | ||
</section> | ||
</DashboardTemplate> | ||
) | ||
} | ||
|
||
return ( | ||
<DashboardTemplate title={pageTitle}> | ||
<section className="h-full w-full flex-1 overflow-auto bg-white px-6 pb-24"> | ||
<DashboardHeader className="pb-8 pt-4" /> | ||
|
||
<div className="space-y-2 pb-8 lg:space-y-1 lg:px-4 lg:pb-12"> | ||
{data?.data.map((form) => ( | ||
<FormCard | ||
key={form.id} | ||
id={form.id} | ||
status={form.status} | ||
title={ | ||
form.content.blocks.find((block) => block.type === "FORM_TITLE")?.content ?? | ||
"Untitled Form" | ||
} | ||
updated_at={form.updated_at} | ||
/> | ||
))} | ||
</div> | ||
|
||
<div className="-mx-4 lg:mx-0 lg:px-6"> | ||
<Button asChild variant="ghost" size="lg" className="px-4 text-2xl [&>svg]:h-7 [&>svg]:w-7"> | ||
<Link | ||
href="/create" | ||
className="flex w-max items-center gap-2 rounded-lg px-3 py-2 text-stone-300 transition hover:bg-stone-100 hover:text-stone-400" | ||
> | ||
<Plus /> | ||
<span className="font-medium">Create Form</span> | ||
</Link> | ||
</Button> | ||
</div> | ||
</section> | ||
</DashboardTemplate> | ||
<> | ||
<DashboardHeader className="pb-8" /> | ||
<FormsList /> | ||
</> | ||
) | ||
} |
This file was deleted.
Oops, something went wrong.