-
Notifications
You must be signed in to change notification settings - Fork 92
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
930dcbb
commit 0e76d2c
Showing
15 changed files
with
919 additions
and
168 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
169 changes: 117 additions & 52 deletions
169
packages/react/src/components/common/ErrorFallback.tsx
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,64 +1,129 @@ | ||
import { FallbackProps } from "react-error-boundary"; | ||
import { Trans, useTranslation } from "react-i18next"; | ||
import { TwitterFeed } from "./TwitterFeed"; | ||
import { StatusTweetEmbed } from "./TwitterFeed"; | ||
import { Button } from "@/shadcn/ui/button"; | ||
import { useAuth } from "@/hooks/useAuth"; | ||
import { | ||
Card, | ||
CardContent, | ||
CardFooter, | ||
CardHeader, | ||
CardTitle, | ||
} from "@/shadcn/ui/card"; | ||
import { Alert, AlertDescription } from "@/shadcn/ui/alert"; | ||
import { userAtom, tokenAtom } from "@/store/auth"; | ||
import { | ||
Collapsible, | ||
CollapsibleTrigger, | ||
CollapsibleContent, | ||
} from "@/shadcn/ui/collapsible"; | ||
import { useSetAtom, useAtom } from "jotai"; | ||
import { useState, useCallback } from "react"; | ||
|
||
export function ErrorFallback({ error }: Partial<FallbackProps>) { | ||
const { t } = useTranslation(); | ||
const { logout } = useAuth(); | ||
const setUser = useSetAtom(userAtom); | ||
const [token, setToken] = useAtom(tokenAtom); | ||
const [isDebugOpen, setIsDebugOpen] = useState(false); | ||
|
||
const logout = useCallback(() => { | ||
setToken(null); | ||
setUser(null); | ||
}, [setToken, setUser]); | ||
|
||
return ( | ||
<div className="h-full w-full overflow-y-auto p-8"> | ||
<div className="mx-auto flex h-full w-full max-w-screen-lg flex-col items-center gap-4"> | ||
<h2 className="text-3xl font-bold">{t("component.apiError.title")}</h2> | ||
<p> | ||
<Trans | ||
i18nKey="component.apiError.text" | ||
components={{ | ||
twitter: ( | ||
<a | ||
className="text-blue-500 underline" | ||
href="https://x.com/holodex" | ||
> | ||
</a> | ||
), | ||
discord: ( | ||
<a | ||
className="text-blue-500 underline" | ||
href="https://discord.gg/jctkgHBt4b" | ||
> | ||
Discord | ||
</a> | ||
), | ||
}} | ||
/> | ||
</p> | ||
<div className="flex flex-wrap justify-center gap-4"> | ||
<Button size="lg" onClick={() => window.location.reload()}> | ||
{t("component.apiError.reload")} | ||
</Button> | ||
<Button | ||
size="lg" | ||
variant="secondary" | ||
onClick={() => { | ||
logout(); | ||
window.localStorage.clear(); | ||
window.location.assign("/"); | ||
}} | ||
<div className="p-4 sm:p-8"> | ||
<Card className="mx-auto max-w-2xl bg-base-4"> | ||
<CardHeader className="text-center"> | ||
<CardTitle className="text-3xl font-bold text-secondary"> | ||
{t("component.apiError.title")} | ||
</CardTitle> | ||
</CardHeader> | ||
|
||
<CardContent className="space-y-4"> | ||
<Alert> | ||
<AlertDescription className="text-center text-base"> | ||
<Trans | ||
i18nKey="component.apiError.text" | ||
components={{ | ||
twitter: ( | ||
<a | ||
key="twitterlink" | ||
className="font-medium text-primary hover:underline" | ||
href="https://x.com/holodex" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
></a> | ||
), | ||
discord: ( | ||
<a | ||
className="font-medium text-primary hover:underline" | ||
href="https://discord.gg/jctkgHBt4b" | ||
target="_blank" | ||
rel="noopener noreferrer" | ||
></a> | ||
), | ||
}} | ||
/> | ||
</AlertDescription> | ||
</Alert> | ||
|
||
<div className="flex flex-col gap-4 sm:flex-row sm:justify-center"> | ||
<Button | ||
size="lg" | ||
variant="primary" | ||
onClick={() => window.location.reload()} | ||
className="gap-2" | ||
> | ||
<div className="i-lucide:refresh-ccw h-4 w-4" /> | ||
{t("component.apiError.reload")} | ||
</Button> | ||
<Button | ||
size="lg" | ||
variant="ghost-secondary" | ||
onClick={() => { | ||
logout(); | ||
window.localStorage.clear(); | ||
window.location.assign("/"); | ||
}} | ||
className="gap-2" | ||
> | ||
<div className="i-lucide:log-out h-4 w-4" /> | ||
{t("component.apiError.logoutAndClearCache")} | ||
</Button> | ||
</div> | ||
|
||
<Collapsible | ||
open={isDebugOpen} | ||
onOpenChange={setIsDebugOpen} | ||
className="" | ||
> | ||
{t("component.apiError.logoutAndClearCache")} | ||
</Button> | ||
</div> | ||
<code className="max-w-full shrink-0 overflow-x-auto whitespace-pre-wrap rounded-md bg-black/10 px-2 py-0 text-sm"> | ||
{error?.message} | ||
</code> | ||
<code className="max-w-full shrink-0 overflow-x-auto whitespace-pre-wrap rounded-md bg-black/10 p-2 text-xs"> | ||
{error?.stack} | ||
</code> | ||
<TwitterFeed className="flex h-[400px] w-[min(800px,calc(100vw-40px))] justify-center" /> | ||
</div> | ||
<CollapsibleTrigger className="flex w-full items-center justify-between rounded-lg border border-base-6 p-4 font-medium hover:bg-muted"> | ||
Debug Information | ||
<div | ||
className={`i-lucide:chevron-down h-4 w-4 transition-transform duration-200 ${ | ||
isDebugOpen ? "rotate-180" : "" | ||
}`} | ||
/> | ||
</CollapsibleTrigger> | ||
<CollapsibleContent className=""> | ||
<code className="bg-muted/50 my-2 block w-full overflow-x-auto rounded-lg px-4"> | ||
{error?.message} | ||
</code> | ||
<code className="bg-muted/50 block w-full overflow-x-auto rounded-lg px-4 text-xs"> | ||
{error?.stack} | ||
</code> | ||
</CollapsibleContent> | ||
</Collapsible> | ||
|
||
<div className="mx-auto max-w-md"> | ||
<StatusTweetEmbed /> | ||
</div> | ||
</CardContent> | ||
|
||
<CardFooter className="justify-center text-sm text-base-8"> | ||
© Holodex | ||
</CardFooter> | ||
</Card> | ||
</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
Oops, something went wrong.