Bug/gh issues fiz (#1103)
* refactor: optimize page loading and data fetching * fix: resolve recurring production runtime errors * feat: add MCP company and customer updates * fix: handle year-end tax adjustments * feat: harden annual report compliance * fix: expand invoice logo and font support * fix: sanitize API route error responses * fix: sanitize user-facing error messages * feat: persist onboarding and tax assessment notices * fix: reduce cloud backup audit churn * feat: refine invoice editor layout * fix: show saved tax adjustments in INK2 * fix: complete annual report API mappings * docs: record operational safeguards and decisions * fix: harden annual report review findings * fix: adjust column span for description based on VAT registration * New css class name
This commit is contained in:
@@ -19,6 +19,7 @@ import {
|
||||
import { RetentionNotice } from '@/components/ui/retention-notice'
|
||||
import { ExternalLink, Loader2 } from 'lucide-react'
|
||||
import { SupportLink } from '@/components/ui/support-link'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
interface Blocker {
|
||||
id: string
|
||||
@@ -92,7 +93,7 @@ export function AccountDangerZone() {
|
||||
|
||||
router.push('/login')
|
||||
} catch (err) {
|
||||
setError(err instanceof Error ? err.message : t('delete_failed_default'))
|
||||
setError(err instanceof Error ? getUserErrorMessage(err) : t('delete_failed_default'))
|
||||
setIsDeleting(false)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import { Cloud, Download, Info, Loader2 } from 'lucide-react'
|
||||
import { ENABLED_EXTENSION_IDS } from '@/lib/extensions/_generated/enabled-extensions'
|
||||
import { getSettingsPanel } from '@/lib/extensions/settings-panel-registry'
|
||||
import type { FiscalPeriod } from '@/types'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
const CloudBackupPanel = getSettingsPanel('cloud-backup')
|
||||
const hasCloudBackup = ENABLED_EXTENSION_IDS.has('cloud-backup')
|
||||
@@ -170,7 +171,7 @@ export function BackupDownloadForm() {
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: t('toast_backup_failed'),
|
||||
description: err instanceof Error ? err.message : t('toast_try_again'),
|
||||
description: err instanceof Error ? getUserErrorMessage(err) : t('toast_try_again'),
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { formatDateLong } from '@/lib/utils'
|
||||
import type { BillingPlan } from '@/lib/stripe/client'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
const PRICE: Record<BillingPlan, { amount: string; suffix: string; sub: string; cta: string }> = {
|
||||
monthly: {
|
||||
@@ -62,7 +63,7 @@ export function BillingActions({
|
||||
} catch (e) {
|
||||
toast({
|
||||
title: 'Kunde inte öppna betalningen',
|
||||
description: e instanceof Error ? e.message : undefined,
|
||||
description: e instanceof Error ? getUserErrorMessage(e) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
setLoading(false)
|
||||
|
||||
@@ -19,6 +19,7 @@ import { RetentionNotice } from '@/components/ui/retention-notice'
|
||||
import { Loader2 } from 'lucide-react'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { getBranding } from '@/lib/branding/service'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
const branding = getBranding()
|
||||
|
||||
@@ -72,7 +73,7 @@ export function CompanyDangerZone() {
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: t('danger_delete_failed_title'),
|
||||
description: err instanceof Error ? err.message : t('danger_try_again'),
|
||||
description: err instanceof Error ? getUserErrorMessage(err) : t('danger_try_again'),
|
||||
variant: 'destructive',
|
||||
})
|
||||
setIsDeleting(false)
|
||||
|
||||
@@ -18,6 +18,7 @@ import {
|
||||
validateFirstPeriod,
|
||||
} from '@/components/bookkeeping/FiscalPeriodDateFields'
|
||||
import type { FiscalPeriod } from '@/types'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
function formatSwedishDate(dateStr: string): string {
|
||||
const months = [
|
||||
@@ -84,7 +85,7 @@ export function FiscalPeriodEditor() {
|
||||
setEndDate(first.period_end)
|
||||
} catch (err) {
|
||||
if (!cancelled) {
|
||||
setLoadError(err instanceof Error ? err.message : t('fp_load_error_unknown'))
|
||||
setLoadError(err instanceof Error ? getUserErrorMessage(err) : t('fp_load_error_unknown'))
|
||||
}
|
||||
} finally {
|
||||
if (!cancelled) setIsLoading(false)
|
||||
@@ -158,7 +159,7 @@ export function FiscalPeriodEditor() {
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: t('fp_update_failed_title'),
|
||||
description: err instanceof Error ? err.message : t('fp_try_again'),
|
||||
description: err instanceof Error ? getUserErrorMessage(err) : t('fp_try_again'),
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
|
||||
@@ -16,6 +16,7 @@ import { formatDate } from '@/lib/utils'
|
||||
import type { FiscalPeriod } from '@/types'
|
||||
import CreatePeriodDialog from '@/components/bookkeeping/CreatePeriodDialog'
|
||||
import { suggestSeedDate } from '@/lib/bookkeeping/suggest-fiscal-period'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
/** Status of a fiscal period, in legal precedence: closed > locked > open. */
|
||||
function periodStatus(p: FiscalPeriod): 'closed' | 'locked' | 'open' {
|
||||
@@ -81,7 +82,7 @@ export function FiscalYearsManager() {
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: t('fy_action_error'),
|
||||
description: err instanceof Error ? err.message : undefined,
|
||||
description: err instanceof Error ? getUserErrorMessage(err) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
|
||||
@@ -6,6 +6,8 @@ import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { Loader2, Upload, Trash2 } from 'lucide-react'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
import { LOGO_UPLOAD_MAX_BYTES } from '@/lib/invoices/branding-constants'
|
||||
|
||||
interface LogoUploadProps {
|
||||
logoUrl: string | null
|
||||
@@ -28,7 +30,7 @@ export function LogoUpload({ logoUrl, onUpdate }: LogoUploadProps) {
|
||||
toast({ title: t('logo_disallowed_type_title'), description: t('logo_disallowed_type_description'), variant: 'destructive' })
|
||||
return
|
||||
}
|
||||
if (file.size > 2 * 1024 * 1024) {
|
||||
if (file.size > LOGO_UPLOAD_MAX_BYTES) {
|
||||
toast({ title: t('logo_too_large'), variant: 'destructive' })
|
||||
return
|
||||
}
|
||||
@@ -58,7 +60,7 @@ export function LogoUpload({ logoUrl, onUpdate }: LogoUploadProps) {
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: t('logo_upload_failed_title'),
|
||||
description: error instanceof Error ? error.message : t('logo_try_again'),
|
||||
description: error instanceof Error ? getUserErrorMessage(error) : t('logo_try_again'),
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -1,12 +1,17 @@
|
||||
'use client'
|
||||
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useState, useCallback } from 'react'
|
||||
import { useState, useCallback, useRef, type ChangeEvent } from 'react'
|
||||
import { Loader2, Trash2, Upload } from 'lucide-react'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
|
||||
import { Switch } from '@/components/ui/switch'
|
||||
import { Textarea } from '@/components/ui/textarea'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import type { CompanySettings } from '@/types'
|
||||
import { INVOICE_FONT_FAMILIES } from '@/lib/invoices/branding-constants'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
import type { CompanySettings, InvoiceFontFamily } from '@/types'
|
||||
|
||||
interface PdfPrintSettingsProps {
|
||||
settings: CompanySettings
|
||||
@@ -18,6 +23,10 @@ export function PdfPrintSettings({ settings, onUpdate }: PdfPrintSettingsProps)
|
||||
const { toast } = useToast()
|
||||
const [lateFeeText, setLateFeeText] = useState(settings.invoice_late_fee_text || '')
|
||||
const [creditTermsText, setCreditTermsText] = useState(settings.invoice_credit_terms_text || '')
|
||||
const [isSavingFont, setIsSavingFont] = useState(false)
|
||||
const [isUploadingFont, setIsUploadingFont] = useState(false)
|
||||
const [isDeletingFont, setIsDeletingFont] = useState(false)
|
||||
const fontInputRef = useRef<HTMLInputElement>(null)
|
||||
|
||||
const saveToggle = useCallback(async (field: string, value: boolean) => {
|
||||
try {
|
||||
@@ -61,12 +70,162 @@ export function PdfPrintSettings({ settings, onUpdate }: PdfPrintSettingsProps)
|
||||
}
|
||||
}, [onUpdate, toast, t])
|
||||
|
||||
const saveFont = useCallback(async (fontFamily: InvoiceFontFamily) => {
|
||||
setIsSavingFont(true)
|
||||
try {
|
||||
const response = await fetch('/api/settings', {
|
||||
method: 'PUT',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ invoice_font_family: fontFamily }),
|
||||
})
|
||||
const result = await response.json()
|
||||
if (!response.ok) throw new Error(result.error || t('toast_save_failed'))
|
||||
onUpdate({ invoice_font_family: fontFamily })
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: t('toast_save_failed'),
|
||||
description: error instanceof Error ? getUserErrorMessage(error) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
setIsSavingFont(false)
|
||||
}
|
||||
}, [onUpdate, toast, t])
|
||||
|
||||
async function uploadFont(file: File) {
|
||||
setIsUploadingFont(true)
|
||||
try {
|
||||
const formData = new FormData()
|
||||
formData.append('file', file)
|
||||
const response = await fetch('/api/settings/invoice-font', {
|
||||
method: 'POST',
|
||||
body: formData,
|
||||
})
|
||||
const result = await response.json()
|
||||
if (!response.ok) throw new Error(result.error || t('font_upload_failed'))
|
||||
onUpdate(result.data as Partial<CompanySettings>)
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: t('font_upload_failed'),
|
||||
description: error instanceof Error ? getUserErrorMessage(error) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
setIsUploadingFont(false)
|
||||
if (fontInputRef.current) fontInputRef.current.value = ''
|
||||
}
|
||||
}
|
||||
|
||||
async function deleteFont() {
|
||||
setIsDeletingFont(true)
|
||||
try {
|
||||
const response = await fetch('/api/settings/invoice-font', { method: 'DELETE' })
|
||||
const result = await response.json()
|
||||
if (!response.ok) throw new Error(result.error || t('font_delete_failed'))
|
||||
onUpdate(result.data as Partial<CompanySettings>)
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: t('font_delete_failed'),
|
||||
description: error instanceof Error ? getUserErrorMessage(error) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
setIsDeletingFont(false)
|
||||
}
|
||||
}
|
||||
|
||||
function handleFontChange(event: ChangeEvent<HTMLInputElement>) {
|
||||
const file = event.target.files?.[0]
|
||||
if (file) void uploadFont(file)
|
||||
}
|
||||
|
||||
const fontLabels: Record<InvoiceFontFamily, string> = {
|
||||
Helvetica: t('font_helvetica'),
|
||||
'Times-Roman': t('font_times'),
|
||||
Courier: t('font_courier'),
|
||||
'Source Sans 3': t('font_source_sans'),
|
||||
'Source Serif 4': t('font_source_serif'),
|
||||
Custom: t('font_custom'),
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="space-y-6">
|
||||
<h2 className="text-sm font-medium uppercase tracking-wider text-muted-foreground">
|
||||
{t('heading')}
|
||||
</h2>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div className="space-y-1">
|
||||
<Label htmlFor="invoice_font_family">{t('font_label')}</Label>
|
||||
<p className="text-xs text-muted-foreground">{t('font_help')}</p>
|
||||
</div>
|
||||
<Select
|
||||
value={settings.invoice_font_family ?? 'Helvetica'}
|
||||
onValueChange={(value) => {
|
||||
if (value) void saveFont(value as InvoiceFontFamily)
|
||||
}}
|
||||
disabled={isSavingFont || isUploadingFont || isDeletingFont}
|
||||
>
|
||||
<SelectTrigger id="invoice_font_family" className="max-w-sm">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
{INVOICE_FONT_FAMILIES
|
||||
.filter((family) => family !== 'Custom' || settings.invoice_custom_font_path)
|
||||
.map((family) => (
|
||||
<SelectItem key={family} value={family}>
|
||||
{fontLabels[family]}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<Button
|
||||
type="button"
|
||||
variant="outline"
|
||||
onClick={() => fontInputRef.current?.click()}
|
||||
disabled={isUploadingFont || isDeletingFont}
|
||||
>
|
||||
{isUploadingFont ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Upload className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{settings.invoice_custom_font_path ? t('font_replace') : t('font_upload')}
|
||||
</Button>
|
||||
{settings.invoice_custom_font_path && (
|
||||
<Button
|
||||
type="button"
|
||||
variant="ghost"
|
||||
onClick={() => void deleteFont()}
|
||||
disabled={isUploadingFont || isDeletingFont}
|
||||
className="text-muted-foreground hover:text-destructive"
|
||||
>
|
||||
{isDeletingFont ? (
|
||||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||||
) : (
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
)}
|
||||
{t('font_remove')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
{settings.invoice_custom_font_name && (
|
||||
<p className="text-xs text-muted-foreground">
|
||||
{t('font_uploaded_name', { name: settings.invoice_custom_font_name })}
|
||||
</p>
|
||||
)}
|
||||
<p className="text-xs text-muted-foreground">{t('font_file_help')}</p>
|
||||
<input
|
||||
ref={fontInputRef}
|
||||
type="file"
|
||||
accept=".ttf,.woff,font/ttf,font/woff"
|
||||
className="hidden"
|
||||
onChange={handleFontChange}
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="space-y-4">
|
||||
<div className="flex items-center justify-between">
|
||||
<div>
|
||||
|
||||
@@ -14,6 +14,7 @@ import { isMfaRequired } from '@/lib/auth/mfa'
|
||||
import { isBankIdEnabled } from '@/lib/auth/bankid'
|
||||
import { BankIdSettings } from '@/components/settings/BankIdSettings'
|
||||
import { userHasPassword } from '@/lib/auth/has-password'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
const isSelfHosted = process.env.NEXT_PUBLIC_SELF_HOSTED === 'true'
|
||||
const mfaRequired = isMfaRequired()
|
||||
@@ -141,7 +142,7 @@ export function SecuritySettings() {
|
||||
}
|
||||
toast({
|
||||
title: t('toast_unenroll_failed_title'),
|
||||
description: error.message,
|
||||
description: getUserErrorMessage(error),
|
||||
variant: 'destructive',
|
||||
})
|
||||
return
|
||||
|
||||
@@ -6,6 +6,7 @@ import { Button } from '@/components/ui/button'
|
||||
import { Loader2, Check, Lock } from 'lucide-react'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { useCanWrite } from '@/lib/hooks/use-can-write'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
type SaveResult =
|
||||
| Record<string, unknown>
|
||||
@@ -82,7 +83,7 @@ export function SettingsFormWrapper({ children, onSave, className }: SettingsFor
|
||||
} catch (error) {
|
||||
toast({
|
||||
title: t('wrapper_save_failed_title'),
|
||||
description: error instanceof Error ? error.message : t('wrapper_try_again'),
|
||||
description: error instanceof Error ? getUserErrorMessage(error) : t('wrapper_try_again'),
|
||||
variant: 'destructive',
|
||||
})
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ import { isAllowedSkvPopupOrigin } from '@/lib/skatteverket/popup-origin'
|
||||
import { CAPABILITY } from '@/lib/entitlements/keys'
|
||||
import { UpgradeNote } from '@/components/billing/UpgradeNote'
|
||||
import { CheckCircle2, ExternalLink, ShieldOff, FlaskConical, ShieldAlert } from 'lucide-react'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
type Environment = 'test' | 'prod'
|
||||
|
||||
@@ -227,7 +228,7 @@ function SkatteverketPersonalConnectionCard() {
|
||||
} catch (err) {
|
||||
toast({
|
||||
title: t('toast_disconnect_failed'),
|
||||
description: err instanceof Error ? err.message : undefined,
|
||||
description: err instanceof Error ? getUserErrorMessage(err) : undefined,
|
||||
variant: 'destructive',
|
||||
})
|
||||
} finally {
|
||||
|
||||
@@ -0,0 +1,243 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { CalendarClock, Pencil, Trash2 } from 'lucide-react'
|
||||
import { FiscalYearSelector } from '@/components/common/FiscalYearSelector'
|
||||
import { Button } from '@/components/ui/button'
|
||||
import { Input } from '@/components/ui/input'
|
||||
import { Label } from '@/components/ui/label'
|
||||
import {
|
||||
Select,
|
||||
SelectContent,
|
||||
SelectItem,
|
||||
SelectTrigger,
|
||||
SelectValue,
|
||||
} from '@/components/ui/select'
|
||||
import { useToast } from '@/components/ui/use-toast'
|
||||
import { useErrorToast } from '@/lib/hooks/use-error-toast'
|
||||
import type {
|
||||
TaxAssessmentDecisionType,
|
||||
TaxAssessmentNotice,
|
||||
} from '@/types'
|
||||
|
||||
function todayLocalIso(): string {
|
||||
const today = new Date()
|
||||
const year = today.getFullYear()
|
||||
const month = String(today.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(today.getDate()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}`
|
||||
}
|
||||
|
||||
export function TaxAssessmentNoticesPanel() {
|
||||
const t = useTranslations('tax_assessment_notices')
|
||||
const { toast } = useToast()
|
||||
const showError = useErrorToast()
|
||||
const [notices, setNotices] = useState<TaxAssessmentNotice[]>([])
|
||||
const [selectedPeriodId, setSelectedPeriodId] = useState<string | null>(null)
|
||||
const [decisionType, setDecisionType] = useState<TaxAssessmentDecisionType>('final')
|
||||
const [decisionDate, setDecisionDate] = useState(todayLocalIso)
|
||||
const [paymentDueDate, setPaymentDueDate] = useState('')
|
||||
const [editingId, setEditingId] = useState<string | null>(null)
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [saving, setSaving] = useState(false)
|
||||
|
||||
useEffect(() => {
|
||||
let cancelled = false
|
||||
void (async () => {
|
||||
try {
|
||||
const response = await fetch('/api/tax-assessment-notices')
|
||||
if (!response.ok) {
|
||||
if (!cancelled) await showError(response, { context: 'settings' })
|
||||
return
|
||||
}
|
||||
const payload = await response.json() as { data: TaxAssessmentNotice[] }
|
||||
if (!cancelled) setNotices(payload.data)
|
||||
} catch (error) {
|
||||
if (!cancelled) await showError(error, { context: 'settings' })
|
||||
} finally {
|
||||
if (!cancelled) setLoading(false)
|
||||
}
|
||||
})()
|
||||
return () => {
|
||||
cancelled = true
|
||||
}
|
||||
// The error helper is recreated with the toast hook. This load should run
|
||||
// once per panel mount, not after every render.
|
||||
// eslint-disable-next-line react-hooks/exhaustive-deps
|
||||
}, [])
|
||||
|
||||
const resetForm = () => {
|
||||
setEditingId(null)
|
||||
setDecisionType('final')
|
||||
setDecisionDate(todayLocalIso())
|
||||
setPaymentDueDate('')
|
||||
}
|
||||
|
||||
const saveNotice = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault()
|
||||
if (!selectedPeriodId || !paymentDueDate) return
|
||||
setSaving(true)
|
||||
try {
|
||||
const response = await fetch(
|
||||
editingId ? `/api/tax-assessment-notices/${editingId}` : '/api/tax-assessment-notices',
|
||||
{
|
||||
method: editingId ? 'PATCH' : 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({
|
||||
fiscal_period_id: selectedPeriodId,
|
||||
decision_type: decisionType,
|
||||
decision_date: decisionDate,
|
||||
payment_due_date: paymentDueDate,
|
||||
}),
|
||||
},
|
||||
)
|
||||
if (!response.ok) {
|
||||
await showError(response, { context: 'settings' })
|
||||
return
|
||||
}
|
||||
const payload = await response.json() as { data: TaxAssessmentNotice }
|
||||
setNotices((current) => {
|
||||
const withoutSaved = current.filter((notice) => notice.id !== payload.data.id)
|
||||
return [...withoutSaved, payload.data]
|
||||
.sort((a, b) => a.payment_due_date.localeCompare(b.payment_due_date))
|
||||
})
|
||||
toast({ title: t(editingId ? 'updated' : 'saved') })
|
||||
resetForm()
|
||||
} catch (error) {
|
||||
await showError(error, { context: 'settings' })
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
const editNotice = (notice: TaxAssessmentNotice) => {
|
||||
setEditingId(notice.id)
|
||||
setSelectedPeriodId(notice.fiscal_period_id)
|
||||
setDecisionType(notice.decision_type)
|
||||
setDecisionDate(notice.decision_date)
|
||||
setPaymentDueDate(notice.payment_due_date)
|
||||
}
|
||||
|
||||
const archiveNotice = async (notice: TaxAssessmentNotice) => {
|
||||
setSaving(true)
|
||||
try {
|
||||
const response = await fetch(`/api/tax-assessment-notices/${notice.id}`, {
|
||||
method: 'PATCH',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify({ archived: true }),
|
||||
})
|
||||
if (!response.ok) {
|
||||
await showError(response, { context: 'settings' })
|
||||
return
|
||||
}
|
||||
setNotices((current) => current.filter((item) => item.id !== notice.id))
|
||||
if (editingId === notice.id) resetForm()
|
||||
toast({ title: t('archived') })
|
||||
} catch (error) {
|
||||
await showError(error, { context: 'settings' })
|
||||
} finally {
|
||||
setSaving(false)
|
||||
}
|
||||
}
|
||||
|
||||
return (
|
||||
<section className="border-t border-border pt-8" aria-labelledby="tax-assessment-notices-title">
|
||||
<div className="max-w-3xl">
|
||||
<div className="flex items-start gap-3">
|
||||
<CalendarClock className="mt-0.5 h-5 w-5" />
|
||||
<div>
|
||||
<h2 id="tax-assessment-notices-title" className="font-display text-xl tracking-tight">
|
||||
{t('title')}
|
||||
</h2>
|
||||
<p className="mt-1 text-sm leading-relaxed text-muted-foreground">
|
||||
{t('description')}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<form onSubmit={saveNotice} className="mt-6 grid gap-4 rounded-lg border border-border p-4 sm:grid-cols-2 sm:p-6">
|
||||
<FiscalYearSelector
|
||||
value={selectedPeriodId}
|
||||
onChange={(periodId) => setSelectedPeriodId(periodId)}
|
||||
includeAllOption={false}
|
||||
label={t('fiscal_period')}
|
||||
className="sm:col-span-2"
|
||||
/>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="tax-assessment-decision-type">{t('decision_type')}</Label>
|
||||
<Select value={decisionType} onValueChange={(value) => setDecisionType(value as TaxAssessmentDecisionType)}>
|
||||
<SelectTrigger id="tax-assessment-decision-type">
|
||||
<SelectValue />
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="final">{t('decision_final')}</SelectItem>
|
||||
<SelectItem value="reassessment">{t('decision_reassessment')}</SelectItem>
|
||||
</SelectContent>
|
||||
</Select>
|
||||
</div>
|
||||
<div className="space-y-1.5">
|
||||
<Label htmlFor="tax-assessment-decision-date">{t('decision_date')}</Label>
|
||||
<Input
|
||||
id="tax-assessment-decision-date"
|
||||
type="date"
|
||||
required
|
||||
value={decisionDate}
|
||||
onChange={(event) => setDecisionDate(event.target.value)}
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-1.5 sm:col-span-2">
|
||||
<Label htmlFor="tax-assessment-payment-due-date">{t('payment_due_date')}</Label>
|
||||
<Input
|
||||
id="tax-assessment-payment-due-date"
|
||||
type="date"
|
||||
required
|
||||
min={decisionDate}
|
||||
value={paymentDueDate}
|
||||
onChange={(event) => setPaymentDueDate(event.target.value)}
|
||||
/>
|
||||
<p className="text-xs text-muted-foreground">{t('payment_due_date_help')}</p>
|
||||
</div>
|
||||
<div className="flex flex-wrap gap-2 sm:col-span-2">
|
||||
<Button type="submit" disabled={saving || !selectedPeriodId || !paymentDueDate}>
|
||||
{saving ? t('saving') : t(editingId ? 'update_action' : 'save_action')}
|
||||
</Button>
|
||||
{editingId && (
|
||||
<Button type="button" variant="ghost" onClick={resetForm} disabled={saving}>
|
||||
{t('cancel')}
|
||||
</Button>
|
||||
)}
|
||||
</div>
|
||||
</form>
|
||||
|
||||
{!loading && notices.length > 0 && (
|
||||
<div className="mt-6 divide-y divide-border border-y border-border">
|
||||
{notices.map((notice) => (
|
||||
<div key={notice.id} className="flex flex-col gap-3 py-4 sm:flex-row sm:items-center sm:justify-between">
|
||||
<div>
|
||||
<p className="text-sm font-medium">
|
||||
{notice.decision_type === 'final' ? t('decision_final') : t('decision_reassessment')}
|
||||
{notice.fiscal_period?.name ? `: ${notice.fiscal_period.name}` : ''}
|
||||
</p>
|
||||
<p className="mt-1 text-xs text-muted-foreground">
|
||||
{t('due_summary', { date: notice.payment_due_date })}
|
||||
</p>
|
||||
</div>
|
||||
<div className="flex gap-2">
|
||||
<Button type="button" variant="ghost" size="sm" onClick={() => editNotice(notice)} disabled={saving}>
|
||||
<Pencil className="mr-2 h-4 w-4" />
|
||||
{t('edit')}
|
||||
</Button>
|
||||
<Button type="button" variant="ghost" size="sm" onClick={() => void archiveNotice(notice)} disabled={saving}>
|
||||
<Trash2 className="mr-2 h-4 w-4" />
|
||||
{t('archive')}
|
||||
</Button>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</section>
|
||||
)
|
||||
}
|
||||
@@ -15,6 +15,7 @@ import { useToast } from '@/components/ui/use-toast'
|
||||
import { normaliseSwish } from '@/lib/payments/swish'
|
||||
import { formatPlusgiroNumber } from '@/lib/bankgiro/luhn'
|
||||
import type { CompanySettings } from '@/types'
|
||||
import { getErrorMessage as getUserErrorMessage } from '@/lib/errors/get-error-message'
|
||||
|
||||
export function InvoicingSettingsContent() {
|
||||
const t = useTranslations('settings_invoicing')
|
||||
@@ -29,7 +30,7 @@ export function InvoicingSettingsContent() {
|
||||
if (bankErrors.length > 0) {
|
||||
toast({
|
||||
title: t('bank_validation_title'),
|
||||
description: bankErrors.map(e => e.message).join(', '),
|
||||
description: bankErrors.map(e => getUserErrorMessage(e)).join(', '),
|
||||
variant: 'destructive',
|
||||
})
|
||||
return {}
|
||||
|
||||
@@ -4,6 +4,7 @@ import { useEffect, useState } from 'react'
|
||||
import { useTranslations } from 'next-intl'
|
||||
import { useSearchParams, useRouter } from 'next/navigation'
|
||||
import { TaxSettingsForm } from '@/components/settings/TaxSettingsForm'
|
||||
import { TaxAssessmentNoticesPanel } from '@/components/settings/TaxAssessmentNoticesPanel'
|
||||
import { SettingsFormWrapper } from '@/components/settings/SettingsFormWrapper'
|
||||
import { SettingsLoadError } from '@/components/settings/SettingsLoadError'
|
||||
import { SettingsLoadingSkeleton } from '@/components/settings/SettingsLoadingSkeleton'
|
||||
@@ -165,6 +166,8 @@ export function TaxSettingsContent() {
|
||||
rotRutSignalDetected={rotRutSignalDetected}
|
||||
/>
|
||||
</SettingsFormWrapper>
|
||||
|
||||
<TaxAssessmentNoticesPanel />
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -1,16 +1,55 @@
|
||||
import type { ComponentType } from 'react'
|
||||
import { AccountSettingsContent } from './AccountSettingsContent'
|
||||
import { CompanySettingsContent } from './CompanySettingsContent'
|
||||
import { BookkeepingSettingsContent } from './BookkeepingSettingsContent'
|
||||
import { TaxSettingsContent } from './TaxSettingsContent'
|
||||
import { SalarySettingsContent } from './SalarySettingsContent'
|
||||
import { InvoicingSettingsContent } from './InvoicingSettingsContent'
|
||||
import { TemplatesSettingsContent } from './TemplatesSettingsContent'
|
||||
import { PaymentsSettingsContent } from './PaymentsSettingsContent'
|
||||
import { BankingSettingsContent } from './BankingSettingsContent'
|
||||
import { AssistantSettingsContent } from './AssistantSettingsContent'
|
||||
import { ApiSettingsContent } from './ApiSettingsContent'
|
||||
import { BillingSettingsContent } from './BillingSettingsContent'
|
||||
import dynamic from 'next/dynamic'
|
||||
import { SettingsLoadingSkeleton } from '../SettingsLoadingSkeleton'
|
||||
|
||||
const AccountSettingsContent = dynamic(() =>
|
||||
import('./AccountSettingsContent').then((module) => ({ default: module.AccountSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const CompanySettingsContent = dynamic(() =>
|
||||
import('./CompanySettingsContent').then((module) => ({ default: module.CompanySettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const BookkeepingSettingsContent = dynamic(() =>
|
||||
import('./BookkeepingSettingsContent').then((module) => ({ default: module.BookkeepingSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const TaxSettingsContent = dynamic(() =>
|
||||
import('./TaxSettingsContent').then((module) => ({ default: module.TaxSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const SalarySettingsContent = dynamic(() =>
|
||||
import('./SalarySettingsContent').then((module) => ({ default: module.SalarySettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const InvoicingSettingsContent = dynamic(() =>
|
||||
import('./InvoicingSettingsContent').then((module) => ({ default: module.InvoicingSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const TemplatesSettingsContent = dynamic(() =>
|
||||
import('./TemplatesSettingsContent').then((module) => ({ default: module.TemplatesSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const PaymentsSettingsContent = dynamic(() =>
|
||||
import('./PaymentsSettingsContent').then((module) => ({ default: module.PaymentsSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const BankingSettingsContent = dynamic(() =>
|
||||
import('./BankingSettingsContent').then((module) => ({ default: module.BankingSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const AssistantSettingsContent = dynamic(() =>
|
||||
import('./AssistantSettingsContent').then((module) => ({ default: module.AssistantSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const ApiSettingsContent = dynamic(() =>
|
||||
import('./ApiSettingsContent').then((module) => ({ default: module.ApiSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
const BillingSettingsContent = dynamic(() =>
|
||||
import('./BillingSettingsContent').then((module) => ({ default: module.BillingSettingsContent })),
|
||||
{ loading: SettingsLoadingSkeleton },
|
||||
)
|
||||
|
||||
/**
|
||||
* Single source of truth mapping a settings section id to the component that
|
||||
|
||||
Reference in New Issue
Block a user