'use client'; import { isApiError, type LookupDto } from '@impuestos/contracts'; import { formatDateLong, type Locale } from '@impuestos/i18n'; import { useMutation } from '@tanstack/react-query'; import { useLocale } from 'next-intl'; import { useState } from 'react'; import { Button, buttonClasses } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Label } from '@/components/ui/label'; import { Skeleton } from '@/components/ui/skeleton'; import { Link } from '@/i18n/navigation'; import { useT } from '@/i18n/t'; import { api } from '@/lib/api'; /** * Flow A2. Type a RUC or CI and see your own filing dates before signing up: the whole * point is that the first screen already knows something true about you. */ export function RucHook() { const t = useT(); const locale = useLocale() as Locale; const [value, setValue] = useState(''); const lookup = useMutation({ mutationFn: (input) => api.lookupRuc(input), }); const result = lookup.data; const invalid = result !== undefined && !result.valid; return (
{ event.preventDefault(); const trimmed = value.trim(); if (trimmed.length > 0) lookup.mutate(trimmed); }} > {/* Stacks at 390px so the call to action never wraps to two lines. */}
setValue(event.target.value)} />
{invalid ? ( ) : null} {lookup.isError ? (

{isApiError(lookup.error) ? lookup.error.message : t('common.error.generic')}

) : null}
{lookup.isPending ? ( ) : null} {result?.valid ? : null}
); } function Preview({ result, locale }: { result: LookupDto; locale: Locale }) { const t = useT(); const [d1, d2, d3] = result.nextDeadlines as [string, string, string]; return (

{t('landing.preview.title')}

{t('landing.preview.deadline', { day: result.deadlineDay })}

{t('landing.preview.next', { d1: formatDateLong(locale, d1), d2: formatDateLong(locale, d2), d3: formatDateLong(locale, d3), })}

{t('landing.preview.cta')}
); }