Skip to content

Commit

Permalink
add 403 and 500 pages in App Router
Browse files Browse the repository at this point in the history
  • Loading branch information
hbjORbj committed Dec 31, 2024
1 parent a5994c5 commit e5ae554
Show file tree
Hide file tree
Showing 3 changed files with 98 additions and 0 deletions.
30 changes: 30 additions & 0 deletions apps/web/app/403/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { _generateMetadata, getTranslate } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

import { APP_NAME, WEBAPP_URL } from "@calcom/lib/constants";
import { Button } from "@calcom/ui";

export const generateMetadata = () =>
_generateMetadata(
(t) => `${t("access_denied")} | ${APP_NAME}`,
() => ""
);

async function Error403() {
const t = await getTranslate();

return (
<div className="bg-subtle flex h-screen">
<div className="rtl: bg-default m-auto rounded-md p-10 text-right ltr:text-left">
<h1 className="font-cal text-emphasis text-6xl">403</h1>
<h2 className="text-emphasis mt-6 text-2xl font-medium">{t("dont_have_access_this_page")}</h2>
<p className="text-default mb-6 mt-4 max-w-2xl text-sm">
{t("you_need_admin_or_owner_privileges_to_access")}
</p>
<Button href={WEBAPP_URL}>{t("go_back_home")}</Button>
</div>
</div>
);
}

export default WithLayout({ ServerPage: Error403 });
21 changes: 21 additions & 0 deletions apps/web/app/500/copy-button.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
"use client";

import { useLocale } from "@calcom/lib/hooks/useLocale";
import { Button, showToast } from "@calcom/ui";

export default function CopyButton({ error }: { error: string }) {
const { t } = useLocale();

return (
<Button
color="secondary"
className="mt-2 border-0 font-sans font-normal hover:bg-gray-300"
StartIcon="copy"
onClick={() => {
navigator.clipboard.writeText(error);
showToast("Link copied!", "success");
}}>
{t("copy")}
</Button>
);
}
47 changes: 47 additions & 0 deletions apps/web/app/500/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { _generateMetadata, getTranslate } from "app/_utils";
import { WithLayout } from "app/layoutHOC";

import { APP_NAME } from "@calcom/lib/constants";
import { Button } from "@calcom/ui";

import CopyButton from "./copy-button";

export const generateMetadata = () =>
_generateMetadata(
(t) => `${t("something_unexpected_occurred")} | ${APP_NAME}`,
() => ""
);

async function Error500({ searchParams }: { searchParams: { error?: string } }) {
const t = await getTranslate();

return (
<div className="bg-subtle flex h-screen">
<div className="rtl: bg-default m-auto rounded-md p-10 text-right ltr:text-left">
<h1 className="font-cal text-emphasis text-6xl">500</h1>
<h2 className="text-emphasis mt-6 text-2xl font-medium">{t("500_error_message")}</h2>
<p className="text-default mb-6 mt-4 max-w-2xl text-sm">{t("something_went_wrong_on_our_end")}</p>
{searchParams?.error && (
<div className="mb-8 flex flex-col">
<p className="text-default mb-4 max-w-2xl text-sm">
{t("please_provide_following_text_to_suppport")}:
</p>
<pre className="bg-emphasis text-emphasis w-full max-w-2xl whitespace-normal break-words rounded-md p-4">
{searchParams.error}
<br />
<CopyButton error={searchParams.error} />
</pre>
</div>
)}
<Button href="mailto:[email protected]">{t("contact_support")}</Button>
<Button color="secondary" href="javascript:history.back()" className="ml-2">
{t("go_back")}
</Button>
</div>
</div>
);
}

export default WithLayout({
ServerPage: Error500,
});

0 comments on commit e5ae554

Please sign in to comment.