-
-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(web,ui): implements greeting feature for dashboard
- Loading branch information
Showing
10 changed files
with
335 additions
and
41 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,33 @@ | ||
import { ErrorPanel, Skeleton, Typography } from '@noodle/ui'; | ||
|
||
import { api } from '@/utils/api'; | ||
|
||
const Greeting = () => { | ||
const { data, isLoading, error } = api.greeting.get.useQuery(undefined, { | ||
refetchOnWindowFocus: false, | ||
refetchOnMount: false, | ||
}); | ||
|
||
if (isLoading) { | ||
return ( | ||
<div className="space-y-3"> | ||
<Skeleton className="h-11 w-72" /> | ||
<Skeleton className="h-5 w-96" /> | ||
<Skeleton className="h-5 w-96" /> | ||
</div> | ||
); | ||
} | ||
|
||
if (error) { | ||
return <ErrorPanel errorMessage={error.message} className="h-36" />; | ||
} | ||
|
||
return ( | ||
<div className="space-y-3"> | ||
<Typography.H3 as="h1">{data.greeting}</Typography.H3> | ||
<Typography.P className="max-w-[57ch]">{data.quote}</Typography.P> | ||
</div> | ||
); | ||
}; | ||
|
||
export { Greeting }; |
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 |
---|---|---|
@@ -1,10 +1,12 @@ | ||
import { feedbackRouter } from './routers/feedback'; | ||
import { greetingRouter } from './routers/greeting'; | ||
import { waitListRouter } from './routers/wait-list'; | ||
import { createRouter } from './setup/trpc'; | ||
|
||
export const appRouter = createRouter({ | ||
waitlist: waitListRouter, | ||
feedback: feedbackRouter, | ||
greeting: greetingRouter, | ||
}); | ||
|
||
export type AppRouter = typeof appRouter; |
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,44 @@ | ||
import { clerkClient, currentUser } from '@clerk/nextjs'; | ||
import fetch from 'node-fetch'; | ||
|
||
import { protectedProcedure } from '../middlewares/auth'; | ||
import { createRouter } from '../setup/trpc'; | ||
|
||
type QuoteType = { | ||
_id: string; | ||
content: string; | ||
author: string; | ||
tags: string[]; | ||
authorSlug: string; | ||
length: number; | ||
dateAdded: string; | ||
dateModified: string; | ||
}; | ||
|
||
export const greetingRouter = createRouter({ | ||
get: protectedProcedure.query(async ({ ctx }) => { | ||
const userId = ctx.auth.userId; | ||
const user = userId ? await clerkClient.users.getUser(userId) : null; | ||
|
||
const name = user?.firstName; | ||
|
||
const quote = await fetch( | ||
'https://api.quotable.io/random?minLength=100&maxLength=140', | ||
).then((res) => res.json() as Promise<QuoteType>); | ||
|
||
const date = new Date(); | ||
const currentHour = date.getHours(); | ||
let greeting = 'Good evening'; | ||
|
||
if (currentHour < 12) { | ||
greeting = 'Good morning'; | ||
} else if (currentHour < 18) { | ||
greeting = 'Good afternoon'; | ||
} | ||
|
||
return { | ||
greeting: `${greeting}${name ? `, ${name}` : ''}!`, | ||
quote: `"${quote.content}" - ${quote.author}`, | ||
}; | ||
}), | ||
}); |
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,35 @@ | ||
import { type FC } from 'react'; | ||
import { AlertTriangle } from 'lucide-react'; | ||
|
||
import { cn } from '@noodle/utils'; | ||
|
||
import { Typography } from './typography'; | ||
|
||
type ErrorPanelProps = { | ||
errorMessage: string; | ||
className?: string; | ||
}; | ||
|
||
const ErrorPanel: FC<ErrorPanelProps> = ({ errorMessage, className }) => { | ||
return ( | ||
<div | ||
className={cn( | ||
'relative flex h-36 w-full items-center justify-center', | ||
className, | ||
)} | ||
> | ||
<div className="bg-red-4 dark:bg-reddark-1 border-red-6 dark:border-reddark-6 absolute left-0 top-0 z-0 h-full w-full animate-pulse rounded-xl border" /> | ||
<div className="z-10 flex flex-col space-y-4"> | ||
<Typography.P | ||
as="h1" | ||
className="text-red-10 dark:text-reddark-10 flex items-center gap-4 text-lg" | ||
> | ||
<AlertTriangle size={20} strokeWidth={1.5} /> Error: {errorMessage} | ||
message | ||
</Typography.P> | ||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export { ErrorPanel }; |
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
Oops, something went wrong.