fix(presentation): draw query access failures with the access surfaces (08-11)

AsyncSurface drew auth-required, forbidden and not-found query failures with
its own copy while the gallery used AccessSurface. Both now use one set, and
a state surface without a handler shows no dead button.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
donghyeon-ka
2026-09-27 13:03:27 +09:00
co-authored by Claude Opus 5.5
parent ee9b09563a
commit a5fff8f4b7
5 changed files with 79 additions and 6 deletions
@@ -4,6 +4,11 @@ import type { AsyncState } from "../../application/view-models/async-state.ts";
import type { AppFailure } from "../../contracts/errors.ts";
import { useLocale } from "../i18n/index.ts";
import { errorMessage } from "./error-copy.ts";
import {
AuthRequiredSurface,
ForbiddenSurface,
NotFoundSurface,
} from "./state-surfaces.tsx";
import { Button } from "./ui/button.ts";
export function LoadingSurface({
@@ -131,6 +136,23 @@ export function AsyncSurface({
if (state.base === "initial-loading") return <LoadingSurface />;
if (state.base === "empty") return <EmptySurface />;
if (state.base === "terminal-error" && state.failure) {
const AccessState = ACCESS_SURFACES[state.failure.kind];
if (AccessState) {
// 08-11. Access failures use the same surfaces as the design system's
// AccessSurface, so a query and the gallery show one copy.
return (
<div role="alert" data-message-key={state.failure.userMessageKey}>
<AccessState onAction={onAction} />
{state.failure.requestId ? (
<p>
{message("template.supportReference", {
reference: state.failure.requestId,
})}
</p>
) : null}
</div>
);
}
return (
<TerminalErrorSurface
userMessageKey={state.failure.userMessageKey}
@@ -188,3 +210,16 @@ export function AsyncSurface({
</section>
);
}
const ACCESS_SURFACES: Readonly<
Partial<
Record<
AppFailure["kind"],
(props: Readonly<{ onAction?: () => void }>) => ReactNode
>
>
> = Object.freeze({
AUTH_REQUIRED: ({ onAction }) => <AuthRequiredSurface onSignIn={onAction} />,
FORBIDDEN: ({ onAction }) => <ForbiddenSurface onNavigate={onAction} />,
NOT_FOUND: ({ onAction }) => <NotFoundSurface onNavigate={onAction} />,
});
@@ -23,7 +23,9 @@ function StateSurface({
<p className="state-surface__eyebrow">{eyebrow}</p>
<h2>{title}</h2>
<p>{description}</p>
{actionLabel ? <Button onClick={onAction}>{actionLabel}</Button> : null}
{actionLabel && onAction ? (
<Button onClick={onAction}>{actionLabel}</Button>
) : null}
</section>
);
}