'use client' import { useTranslations } from 'next-intl' import { Copy, Link2, Loader2 } from 'lucide-react' import { Dialog, DialogContent, DialogHeader, DialogTitle, } from '@/components/ui/dialog' import JournalEntryForm, { type FormLine } from '@/components/bookkeeping/JournalEntryForm' export interface CopyPrefill { sourceId: string sourceVoucherLabel: string lines: FormLine[] description: string notes: string } /** Prefill for the skattekonto "Skapa verifikat manuellt" deep link. */ export interface SkvLinkPrefill { transactionId: string /** Row summary for the banner: date, text and amount, built by the caller. */ bannerLabel: string lines: FormLine[] description: string date: string } interface Props { open: boolean onOpenChange: (open: boolean) => void /** Fired after a verifikat is created/saved as draft. */ onCreated: () => void /** Fired with the created entry's id (both posted and draft saves). */ onEntryCreated?: (entryId: string) => void /** When set, the form is pre-filled from a copied verifikat. */ copyPrefill?: CopyPrefill | null /** When set, the form is pre-filled from a skattekonto row and the caller * links the created entry back to it. copyPrefill wins if both are set. */ skvPrefill?: SkvLinkPrefill | null /** True while the copy source is being fetched. */ isLoading?: boolean } /** * "Ny verifikat" as a modal: the dialog you type a manual voucher into, * instead of an inline tab. Wraps the standalone JournalEntryForm; the form's * own review/confirm dialogs stack on top of this one. */ export default function NewJournalEntryDialog({ open, onOpenChange, onCreated, onEntryCreated, copyPrefill, skvPrefill, isLoading, }: Props) { const t = useTranslations('bookkeeping') const activeSkvPrefill = copyPrefill ? null : (skvPrefill ?? null) return ( e.preventDefault()} onPointerDownOutside={(e) => e.preventDefault()} onInteractOutside={(e) => e.preventDefault()} > {t('new_entry_dialog_title')} {isLoading ? (
{t('loading_source_voucher')}
) : ( <> {copyPrefill && (

{t('copy_banner_title', { label: copyPrefill.sourceVoucherLabel || t('copy_banner_unknown_label'), })}

{t('copy_banner_body')}

)} {activeSkvPrefill && (

{t('skv_link_banner_title', { label: activeSkvPrefill.bannerLabel })}

{t('skv_link_banner_body')}

)} )}
) }