Files
accounted/components/settings/InvoicePaymentLinkSettings.tsx
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i
server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma
strängvärde byggs med konkatenering i stället för att matcha mönstret.
2026-11-10 09:37:22 +01:00

61 lines
1.9 KiB
TypeScript

'use client'
import { useTranslations } from 'next-intl'
import { useCallback, useState } from 'react'
import { Switch } from '@/components/ui/switch'
import { useToast } from '@/components/ui/use-toast'
import {
SettingsGroup,
SettingsRow,
SettingsRowEnd,
} from '@/components/settings/SettingsRows'
import type { CompanySettings } from '@/types'
interface InvoicePaymentLinkSettingsProps {
settings: CompanySettings
onUpdate: (updates: Partial<CompanySettings>) => void
}
/**
* Opt-in for the invoice payment-link feature. Off (the default) hides the
* payment-link field in the invoice editor and stops automatic Stripe link
* creation on send; the send routes enforce the same setting server-side.
*/
export function InvoicePaymentLinkSettings({ settings, onUpdate }: InvoicePaymentLinkSettingsProps) {
const t = useTranslations('settings_payment_links')
const { toast } = useToast()
const [isSaving, setIsSaving] = useState(false)
const saveToggle = useCallback(async (value: boolean) => {
setIsSaving(true)
try {
const response = await fetch('/api/settings', {
method: 'PUT',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ invoice_payment_links_enabled: value }),
})
if (!response.ok) throw new Error()
onUpdate({ invoice_payment_links_enabled: value })
} catch {
toast({ title: t('toast_save_failed'), variant: 'destructive' })
} finally {
setIsSaving(false)
}
}, [onUpdate, toast, t])
return (
<SettingsGroup label={t('heading')}>
<SettingsRow label={t('enable_label')} help={t('enable_help')}>
<SettingsRowEnd>
<Switch
checked={settings.invoice_payment_links_enabled ?? false}
onCheckedChange={saveToggle}
disabled={isSaving}
aria-label={t('enable_label')}
/>
</SettingsRowEnd>
</SettingsRow>
</SettingsGroup>
)
}