-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
validate monthName route param, add 404 and 500 pages
- Loading branch information
Showing
13 changed files
with
136 additions
and
30 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
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,57 @@ | ||
'use client'; | ||
|
||
import { FC } from 'react'; | ||
import Link from 'next/link'; | ||
|
||
import { RefreshCcw, Settings } from 'lucide-react'; | ||
|
||
import { Button } from '@/components/ui/button'; | ||
|
||
import { fontSans } from '@/libs/fonts'; | ||
import { cn } from '@/utils/styles'; | ||
|
||
import '@/styles/globals.css'; | ||
|
||
interface Props { | ||
error: Error & { digest?: string }; | ||
reset: () => void; | ||
} | ||
|
||
const GlobalError: FC<Props> = ({ error, reset }) => ( | ||
<html> | ||
<body | ||
className={cn( | ||
'relative min-h-screen min-w-80 flex flex-col bg-background font-sans antialiased', | ||
fontSans.variable | ||
)} | ||
> | ||
<main className="flex-1 flex flex-col justify-center items-center p-4"> | ||
<div className="w-full max-w-md space-y-4 text-center"> | ||
<div className="flex justify-center"> | ||
<Settings className="size-24 text-muted-foreground" /> | ||
</div> | ||
|
||
<h1 className="text-3xl font-extrabold tracking-tight">500 - Server Error</h1> | ||
<p className="text-muted-foreground"> | ||
We are sorry, but something went wrong on our end. Please try again later. | ||
</p> | ||
|
||
<div className="flex flex-col sm:flex-row gap-4 justify-center"> | ||
<Button onClick={() => reset()} variant="outline"> | ||
<RefreshCcw className="mr-2 size-4" /> Try Again | ||
</Button> | ||
<Button asChild> | ||
<Link href="/">Return to Home</Link> | ||
</Button> | ||
</div> | ||
|
||
{error.digest && ( | ||
<p className="text-sm text-muted-foreground">Error ID: {error.digest}</p> | ||
)} | ||
</div> | ||
</main> | ||
</body> | ||
</html> | ||
); | ||
|
||
export default GlobalError; |
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,27 @@ | ||
import { FC } from 'react'; | ||
import Link from 'next/link'; | ||
|
||
import { Cat } from 'lucide-react'; | ||
|
||
import { Button } from '@/components/ui/button'; | ||
|
||
const NotFound: FC = () => ( | ||
<div className="flex-1 flex flex-col justify-center items-center"> | ||
<div className="space-y-4 text-center"> | ||
<div className="flex justify-center"> | ||
<Cat className="size-24 text-muted-foreground" /> | ||
</div> | ||
|
||
<h1 className="text-3xl font-extrabold tracking-tight">404 - Page Not Found</h1> | ||
<p className="text-muted-foreground">Oops! The page you are looking for does not exist.</p> | ||
|
||
<div className="flex flex-col sm:flex-row gap-4 justify-center"> | ||
<Button asChild variant="outline"> | ||
<Link href="/">Return to Home</Link> | ||
</Button> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
|
||
export default NotFound; |
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 const VALIDATION = { | ||
monthNameRegex: /^\d{4}-\d{2}$/, | ||
} as const; |
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,11 @@ | ||
import { getMonthByName } from '@/modules/database/select/month'; | ||
import { VALIDATION } from '@/constants/validation'; | ||
|
||
const { monthNameRegex } = VALIDATION; | ||
|
||
/** Used only in db to validate for delete. */ | ||
export const isValidMonthName = (monthName: string): boolean => monthNameRegex.test(monthName); | ||
|
||
/** In pages, validate month slug. */ | ||
export const isValidMonthNameWithDb = (monthName: string): boolean => | ||
isValidMonthName(monthName) && Boolean(getMonthByName(monthName)); |