hezarfen_frontend
Clone
https://git.tahinli.com/archive/hezarfen_frontend.git
0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits
| 1 | import { Navigate } from "@tanstack/solid-router"; |
| 2 | import { type ParentProps, Show } from "solid-js"; |
| 3 | import { formatApiError } from "@/api/client"; |
| 4 | import { ErrorAlert } from "@/components/ui/error-alert"; |
| 5 | import { PageSpinner } from "@/components/ui/page-spinner"; |
| 6 | import { useBuilder } from "@/stores/builder-context"; |
| 7 | |
| 8 | /** Renders its children only for a live builder session; otherwise sends the visitor to /builder/login. */ |
| 9 | export function BuilderGuard(props: ParentProps) { |
| 10 | const session = useBuilder(); |
| 11 | |
| 12 | return ( |
| 13 | <Show when={!session.loading()} fallback={<PageSpinner />}> |
| 14 | <Show |
| 15 | when={session.builder()} |
| 16 | fallback={ |
| 17 | <Show when={session.error()} fallback={<Navigate to="/builder/login" />}> |
| 18 | <ErrorAlert message={formatApiError(session.error())} onRetry={session.refresh} /> |
| 19 | </Show> |
| 20 | } |
| 21 | > |
| 22 | {props.children} |
| 23 | </Show> |
| 24 | </Show> |
| 25 | ); |
| 26 | } |