diff --git a/web/bun.lock b/web/bun.lock index ee5c9bf7b..dc44aaad6 100644 --- a/web/bun.lock +++ b/web/bun.lock @@ -19,7 +19,6 @@ "cn": "^0.5.2", "es-module-shims": "^2.8.4", "es-toolkit": "^1.53.2", - "isbot": "^5", "ky": "^2.2.0", "lucide-react": "^1.73.0", "maplibre-gl": "^6", diff --git a/web/package.json b/web/package.json index 6049ecccf..c0ecb3b5a 100644 --- a/web/package.json +++ b/web/package.json @@ -38,7 +38,6 @@ "cn": "^0.5.2", "es-module-shims": "^2.8.4", "es-toolkit": "^1.53.2", - "isbot": "^5", "ky": "^2.2.0", "lucide-react": "^1.73.0", "maplibre-gl": "^6", diff --git a/web/src/components/longlink/display/image.tsx b/web/src/components/longlink/display/image.tsx index a8c55a63d..ece28b43b 100644 --- a/web/src/components/longlink/display/image.tsx +++ b/web/src/components/longlink/display/image.tsx @@ -1,9 +1,9 @@ import { cn } from 'cn'; import { useState, type ComponentProps } from 'react'; +import { useImageResource } from './use-image-resource'; import { Skeleton } from '@/components/shadcn/skeleton'; import { useMergedRefs } from '@base-ui/utils/useMergedRefs'; import { AspectRatio } from '@/components/shadcn/aspect-ratio'; -import { useImageBody, useImageResource } from './use-image-resource'; type ImageProps = Omit, 'src' | 'alt'> & { /** Scoped Solution image path, or an image data/blob URL. */ @@ -36,8 +36,7 @@ function ImageContent({ dangerouslySetInnerHTML: _html, ...props }: ImageProps) { - const { src: localSrc, body, unavailable } = useImageResource(src); - const image = useImageBody(body); + const { src: localSrc, body, image, unavailable } = useImageResource(src); const mergedRef = useMergedRefs(image, ref); const [broken, setBroken] = useState(); diff --git a/web/src/components/longlink/display/logo.tsx b/web/src/components/longlink/display/logo.tsx index c735ac985..051c3c07d 100644 --- a/web/src/components/longlink/display/logo.tsx +++ b/web/src/components/longlink/display/logo.tsx @@ -1,7 +1,7 @@ import { ImageOff } from 'lucide-react'; import { useEffect, useState } from 'react'; import { Spinner } from '@/components/shadcn/spinner'; -import { useImageBody, useImageResource } from './use-image-resource'; +import { useImageResource } from './use-image-resource'; /** Displays contained artwork in a fixed frame with a missing-image fallback. */ export function Logo({ @@ -38,8 +38,7 @@ function LogoContent({ detail: boolean; padded: boolean; }) { - const { src, body, unavailable } = useImageResource(path); - const image = useImageBody(body); + const { src, body, image, unavailable } = useImageResource(path); const [decoded, setDecoded] = useState<{ source: Blob | string; status: 'loaded' | 'error' }>(); const source = body ?? src; const status = decoded?.source === source ? decoded?.status : undefined; diff --git a/web/src/components/longlink/display/use-image-resource.ts b/web/src/components/longlink/display/use-image-resource.ts index 94cb02653..ff6a3f59b 100644 --- a/web/src/components/longlink/display/use-image-resource.ts +++ b/web/src/components/longlink/display/use-image-resource.ts @@ -4,13 +4,7 @@ import { useBinaryQuery } from '@/lib/hooks/use-binary-query'; export function useImageResource(src?: string) { const local = src?.startsWith('data:image/') || src?.startsWith('blob:'); const { data, isError } = useBinaryQuery(local ? undefined : src); - if (local || src === undefined) return { src, unavailable: src === undefined }; - - const body = data?.type.startsWith('image/') ? data : undefined; - return { body, unavailable: isError || !!(data && !body) }; -} - -export function useImageBody(body?: Blob) { + const body = !local && src !== undefined && data?.type.startsWith('image/') ? data : undefined; const image = useRef(null); useEffect(() => { @@ -25,5 +19,7 @@ export function useImageBody(body?: Blob) { }; }, [body]); - return image; + if (local || src === undefined) return { src, image, unavailable: src === undefined }; + + return { body, image, unavailable: isError || !!(data && !body) }; } diff --git a/web/src/components/longlink/maps/canvas.tsx b/web/src/components/longlink/maps/canvas.tsx index ad59df839..43058f40a 100644 --- a/web/src/components/longlink/maps/canvas.tsx +++ b/web/src/components/longlink/maps/canvas.tsx @@ -1,9 +1,9 @@ +import { ViewMap } from './map'; import { coordinateError } from './data'; import type { MapOptions } from './types'; import * as mapcn from '@/components/mapcn/map'; import { useEffect, type ReactNode } from 'react'; -import { Button } from '@/components/shadcn/button'; -import { ErrorBoundary, useErrorBoundary } from 'react-error-boundary'; +import { useErrorBoundary } from 'react-error-boundary'; /** Reports asynchronous map resource failures inside the map region. */ function MapStatus() { @@ -69,33 +69,22 @@ export function MapCanvas({ {message ?? 'No map data'} ) : ( - ( -
- Unable to load map - -
- )} + ({ url, credentials: 'same-origin' })} > - ({ url, credentials: 'same-origin' })} - > - - {controls && interactive && ( - - )} - {children} - -
+ + {controls && interactive && ( + + )} + {children} + )} ); diff --git a/web/src/components/longlink/maps/map.tsx b/web/src/components/longlink/maps/map.tsx index 30529de80..804aaea4e 100644 --- a/web/src/components/longlink/maps/map.tsx +++ b/web/src/components/longlink/maps/map.tsx @@ -13,7 +13,7 @@ export function ViewMap(props: PublicProps & RefAt return ( ( -
+
diff --git a/web/src/platform/hooks/use-action.ts b/web/src/platform/hooks/use-action.ts new file mode 100644 index 000000000..c49ec1855 --- /dev/null +++ b/web/src/platform/hooks/use-action.ts @@ -0,0 +1,19 @@ +import { useApiError } from '@/lib/errors'; +import { useConfirmAction } from '@/lib/hooks/use-confirm-action'; + +export function useAction() { + const reportError = useApiError(); + const { isPending, inFlight, run } = useConfirmAction(); + + function runAction(action: () => void | Promise) { + run(async () => { + try { + await action(); + } catch (cause) { + reportError(cause); + } + }); + } + + return { isPending, inFlight, run: runAction }; +} diff --git a/web/src/platform/routes/auth/reset-password.tsx b/web/src/platform/routes/auth/reset-password.tsx index 6c727cfb0..f6692082a 100644 --- a/web/src/platform/routes/auth/reset-password.tsx +++ b/web/src/platform/routes/auth/reset-password.tsx @@ -27,13 +27,6 @@ function isBadTokenError(cause: unknown): boolean { /** Accepts a password reset token and saves a new password. */ export default function ResetPassword() { - const form = useForm({ - defaultValues: { password: '' }, - resolver: zodResolver(resetPasswordSchema) - }); - - const confirmation = 'Your password has been reset. You can now sign in.'; - const { verification } = useVerification(PASSWORD_RESET_TOKEN_KEY, async ({ signal, token: resetToken }) => { if (resetToken) { await api('/api/v1/auth/reset-password/verify', { json: { token: resetToken }, method: 'POST', signal }); @@ -41,6 +34,41 @@ export default function ResetPassword() { await api('/api/v1/auth/reset-password/setup', { signal }); } }); + + if (verification?.status === 'verified') return ; + + return ( + + Set a New Password | LongLink + + {verification?.status === 'error' ? ( + + Request another reset link + + ) : ( + + )} + + ); +} + +function ResetPasswordForm() { + const form = useForm({ + defaultValues: { password: '' }, + resolver: zodResolver(resetPasswordSchema) + }); + + const confirmation = 'Your password has been reset. You can now sign in.'; + const save = useSubmit( async (payload: ResetPasswordValues) => { try { @@ -57,19 +85,13 @@ export default function ResetPassword() { let body: ReactNode; // Invalid and expired credentials require a replacement email. - if (verification?.status === 'error' || form.formState.errors.root?.credential) { + if (form.formState.errors.root?.credential) { description = 'This password reset link is invalid or expired. Request a new link to continue.'; body = ( Request another reset link ); - } else if (verification?.status !== 'verified') { - body = ( - - ); } else if (form.formState.isSubmitSuccessful) { body = ( diff --git a/web/src/platform/routes/auth/verify-email.tsx b/web/src/platform/routes/auth/verify-email.tsx index 2b9b26f9a..5aca4b841 100644 --- a/web/src/platform/routes/auth/verify-email.tsx +++ b/web/src/platform/routes/auth/verify-email.tsx @@ -30,15 +30,6 @@ type RegistrationCompleteValues = z.infer; /** Verifies an emailed registration link before collecting account credentials. */ export default function VerifyEmail() { - const navigate = useNavigate(); - const queryClient = useQueryClient(); - const { refetch } = useCurrentUser(); - - const form = useForm({ - defaultValues: { name: '', password: '' }, - resolver: zodResolver(registrationCompleteSchema) - }); - const { verification, startVerification } = useVerification( REGISTRATION_TOKEN_KEY, async ({ signal, token: registrationToken }) => @@ -48,7 +39,51 @@ export default function VerifyEmail() { ) : await api('/api/v1/auth/register/setup', { signal }).json(zEmailPayload) ); - const verifiedEmail = verification?.status === 'verified' ? verification.data.email : null; + + if (verification?.status === 'verified') { + return ( + { + void startVerification(''); + }} + /> + ); + } + + return ( + + Verify Your Email | LongLink + {verification?.status === 'error' ? ( + + + Request a new registration link + + + ) : ( + + )} + + ); +} + +function RegistrationForm({ email, onExpired }: { email: string; onExpired: () => void }) { + const navigate = useNavigate(); + const queryClient = useQueryClient(); + const { refetch } = useCurrentUser(); + const form = useForm({ + defaultValues: { name: '', password: '' }, + resolver: zodResolver(registrationCompleteSchema) + }); /** Creates the account and clears the previous session's cached data. */ async function handleComplete(payload: RegistrationCompleteValues) { @@ -61,7 +96,7 @@ export default function VerifyEmail() { if (cause.status === 409) form.setError('root.accountConflict', { type: 'conflict' }); // Expired setup cookies require recovering or replacing the registration link. - if (cause.status === 400) void startVerification(''); + if (cause.status === 400) onExpired(); return; } @@ -73,33 +108,14 @@ export default function VerifyEmail() { } const save = useSubmit(handleComplete, { onError: (error) => form.setError('root', { message: error.message }) }); - const recoveryRegisterHref = verifiedEmail - ? `/auth/register?${new URLSearchParams({ email: verifiedEmail })}` - : '/auth/register'; + const recoveryRegisterHref = `/auth/register?${new URLSearchParams({ email })}`; - let title: ReactNode = 'Verify your email'; + let title: ReactNode; let description: string | null = 'Request a new registration link to continue.'; let headingSize: 3 | undefined; let body: ReactNode; - // Invalid credentials require a replacement registration link. - if (verification?.status === 'error') { - body = ( - - - Request a new registration link - - - ); - } else if (verification?.status !== 'verified') { - // Wait for the server to authenticate the signed email claim. - description = 'Verifying your email...'; - body = ( - - ); - } else if (form.formState.errors.root?.accountConflict) { + if (form.formState.errors.root?.accountConflict) { // Account races cannot succeed by resubmitting the same form. title = 'Complete your account'; body = ( diff --git a/web/src/platform/routes/orgs/dialogs/deployment-review.tsx b/web/src/platform/routes/orgs/dialogs/deployment-review.tsx index fbe47474c..6a7732e7d 100644 --- a/web/src/platform/routes/orgs/dialogs/deployment-review.tsx +++ b/web/src/platform/routes/orgs/dialogs/deployment-review.tsx @@ -1,10 +1,10 @@ import type { z } from 'zod'; +import { useId } from 'react'; import { api } from '@/lib/api'; import { ArrowRight } from 'lucide-react'; import { useQuery } from '@tanstack/react-query'; import { Input } from '@/components/shadcn/input'; import { useSubmit } from '@/lib/hooks/use-submit'; -import { useEffect, useId, useState } from 'react'; import { Checkbox } from '@/components/shadcn/checkbox'; import { Text } from '@/components/longlink/display/text'; import { Stack } from '@/components/longlink/layout/stack'; @@ -37,7 +37,6 @@ function imageDigest(image: string) { /** Owns fresh inspection, the deployment draft, and submission for one review attempt. */ export default function DeploymentReview({ item, onSaved, onClose }: DeploymentReviewProps) { const formId = useId(); - const [step, setStep] = useState(0); // Keep inspection attempt-local, cancel on unmount, and never refresh beneath an edited draft. const path = `/api/v1/solutions/${item.id}/update`; @@ -86,23 +85,9 @@ export default function DeploymentReview({ item, onSaved, onClose }: DeploymentR } }); const envs = useWatch({ control: form.control, name: 'envs' }); - const requiredFieldPaths = (candidate?.metadata.environments ?? []) - .filter((environment) => environment.required) - .map((environment) => `envs.${environment.name}.value` as const); const missingRequired = (candidate?.metadata.environments ?? []).some((environment) => isMissingRequired(environment, envs[environment.name]) ); - const environments = (candidate?.metadata.environments ?? []).filter((environment) => - step === 1 ? environment.required : !environment.required - ); - - useEffect(() => { - if (step !== 1) return; - const invalid = candidate?.metadata.environments?.find( - (environment) => environment.required && form.getFieldState(`envs.${environment.name}.value`).error - ); - if (invalid) form.setFocus(`envs.${invalid.name}.value`); - }, [step, candidate, form]); const hasChanges = candidate?.metadata.image !== candidate?.current_image || Object.keys(environmentEdits(envs)).length > 0; @@ -118,13 +103,7 @@ export default function DeploymentReview({ item, onSaved, onClose }: DeploymentR const submit = useSubmit( async () => { - if (step === 0) { - setStep(1); - } else if (step === 1) { - if (await form.trigger(requiredFieldPaths, { shouldFocus: true })) setStep(2); - } else { - await form.handleSubmit(updateSolution, () => setStep(1))(); - } + await form.handleSubmit(updateSolution)(); }, { onError: () => form.setError('root', { message: 'Could not update the Solution. Please try again.' }) } ); @@ -160,27 +139,21 @@ export default function DeploymentReview({ item, onSaved, onClose }: DeploymentR noValidate aria-busy={form.formState.isSubmitting} > - {step === 0 ? ( - - - {candidate.current_version || imageDigest(candidate.current_image)} - - - ) : ( + + + {candidate.current_version || imageDigest(candidate.current_image)} + + + {!!candidate.metadata.environments?.length && (
- {environments.length === 0 && ( - - No {step === 1 ? 'required' : 'optional'} environments. - - )} - {environments.map((environment) => { + {candidate.metadata.environments?.map((environment) => { // Resolve the configured secret and its local draft without exposing its value. const configured = candidate.configured_envs.includes(environment.name); @@ -288,29 +261,17 @@ export default function DeploymentReview({ item, onSaved, onClose }: DeploymentR )} - {candidate ? ( - - - + ) : ( !isPending && (