'use client'; import type { Relationship } from '@impuestos/contracts'; import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query'; import { useState } from 'react'; import { Button } from '@/components/ui/button'; import { Card } from '@/components/ui/card'; import { Input } from '@/components/ui/input'; import { Skeleton } from '@/components/ui/skeleton'; import { useT } from '@/i18n/t'; import { api } from '@/lib/api'; const RELATIONSHIPS: Relationship[] = ['conyuge', 'hijo', 'padre', 'otro']; export function DependentsSection() { const t = useT(); const queryClient = useQueryClient(); const [name, setName] = useState(''); const [relationship, setRelationship] = useState('hijo'); const dependents = useQuery({ queryKey: ['me', 'dependents'], queryFn: ({ signal }) => api.listDependents(signal), }); const invalidate = () => queryClient.invalidateQueries({ queryKey: ['me', 'dependents'] }); const add = useMutation({ mutationFn: () => api.createDependent({ displayName: name.trim(), relationship }), onSuccess: async () => { setName(''); await invalidate(); }, }); const remove = useMutation({ mutationFn: (id: string) => api.deleteDependent(id), onSuccess: invalidate, }); return (

{t('profile.dependents')}

{t('setup.dependents.help')}

{dependents.isPending ? : null} {dependents.isError ? (

{t('common.error.generic')}

) : null} {dependents.data?.length === 0 ? (

{t('profile.dependents.empty')}

) : null} {dependents.data && dependents.data.length > 0 ? (
    {dependents.data.map((dependent) => (
  • {dependent.displayName} ({t(`relationship.${dependent.relationship}` as const)})
  • ))}
) : null}
setName(event.target.value)} />
); }