fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s

Å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.
This commit is contained in:
2026-11-10 09:37:22 +01:00
parent 077251ac94
commit e7f0070e84
6135 changed files with 1718997 additions and 4 deletions
+319
View File
@@ -0,0 +1,319 @@
'use client'
import { useState, useEffect } from 'react'
import {
Dialog,
DialogContent,
DialogHeader,
DialogTitle,
DialogFooter,
} from '@/components/ui/dialog'
import { Button } from '@/components/ui/button'
import { Input } from '@/components/ui/input'
import { Label } from '@/components/ui/label'
import { Textarea } from '@/components/ui/textarea'
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from '@/components/ui/select'
import { Deadline, DeadlineType, DeadlinePriority } from '@/types'
import { formatDateISO, DEADLINE_TYPE_LABELS, PRIORITY_LABELS } from '@/lib/calendar/utils'
import { useCanWrite } from '@/lib/hooks/use-can-write'
import { Lock } from 'lucide-react'
/**
* Only the fields the form actually manages. Both API routes whitelist to
* this set; the form must never fabricate values for system fields (source,
* status, reminder_offsets, tax_*), or editing a system-generated tax
* deadline would depend on the server whitelist alone to avoid data loss.
*/
export type DeadlineFormValues = Pick<
Deadline,
'title' | 'due_date' | 'due_time' | 'deadline_type' | 'priority' | 'customer_id' | 'notes'
>
interface DeadlineFormProps {
open: boolean
onOpenChange: (open: boolean) => void
onSubmit: (data: DeadlineFormValues) => Promise<void>
onDelete?: (deadline: Partial<Deadline>) => void
initialData?: Partial<Deadline>
initialDate?: Date | null
customers: { id: string; name: string }[]
}
export function DeadlineForm({
open,
onOpenChange,
onSubmit,
onDelete,
initialData,
initialDate,
customers,
}: DeadlineFormProps) {
const { canWrite } = useCanWrite()
const [confirmDelete, setConfirmDelete] = useState(false)
const [isLoading, setIsLoading] = useState(false)
const [formData, setFormData] = useState({
title: '',
due_date: '',
due_time: '',
deadline_type: 'other' as DeadlineType,
priority: 'normal' as DeadlinePriority,
customer_id: '',
notes: '',
})
// Reset form when dialog opens with new data
useEffect(() => {
if (open) {
setConfirmDelete(false)
if (initialData) {
setFormData({
title: initialData.title || '',
due_date: initialData.due_date || formatDateISO(new Date()),
due_time: initialData.due_time || '',
deadline_type: initialData.deadline_type || 'other',
priority: initialData.priority || 'normal',
customer_id: initialData.customer_id || '',
notes: initialData.notes || '',
})
} else if (initialDate) {
setFormData({
title: '',
due_date: formatDateISO(initialDate),
due_time: '',
deadline_type: 'other',
priority: 'normal',
customer_id: '',
notes: '',
})
} else {
setFormData({
title: '',
due_date: formatDateISO(new Date()),
due_time: '',
deadline_type: 'other',
priority: 'normal',
customer_id: '',
notes: '',
})
}
}
}, [open, initialData, initialDate])
const handleSubmit = async (e: React.FormEvent) => {
e.preventDefault()
setIsLoading(true)
try {
await onSubmit({
title: formData.title,
due_date: formData.due_date,
due_time: formData.due_time || null,
deadline_type: formData.deadline_type,
priority: formData.priority,
customer_id: formData.customer_id || null,
notes: formData.notes || null,
})
} finally {
setIsLoading(false)
}
}
const updateField = <K extends keyof typeof formData>(
field: K,
value: (typeof formData)[K]
) => {
setFormData((prev) => ({ ...prev, [field]: value }))
}
return (
<Dialog open={open} onOpenChange={onOpenChange}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle>
{initialData?.id ? 'Redigera deadline' : 'Ny deadline'}
</DialogTitle>
</DialogHeader>
<form onSubmit={handleSubmit} className="space-y-4">
{/* Title */}
<div className="space-y-2">
<Label htmlFor="title">Titel *</Label>
<Input
id="title"
placeholder="t.ex. Leverera video till Företag AB"
value={formData.title}
onChange={(e) => updateField('title', e.target.value)}
required
/>
</div>
{/* Date and Time */}
<div className="grid gap-4 grid-cols-1 sm:grid-cols-2">
<div className="space-y-2">
<Label htmlFor="due_date">Datum *</Label>
<Input
id="due_date"
type="date"
value={formData.due_date}
onChange={(e) => updateField('due_date', e.target.value)}
required
/>
</div>
<div className="space-y-2">
<Label htmlFor="due_time">Tid (valfritt)</Label>
<Input
id="due_time"
type="time"
value={formData.due_time}
onChange={(e) => updateField('due_time', e.target.value)}
/>
</div>
</div>
{/* Type and Priority */}
<div className="grid gap-4 grid-cols-1 sm:grid-cols-2">
<div className="space-y-2">
<Label>Typ *</Label>
<Select
value={formData.deadline_type}
onValueChange={(v) => { if (v) updateField('deadline_type', v as DeadlineType) }}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.entries(DEADLINE_TYPE_LABELS).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
<div className="space-y-2">
<Label>Prioritet</Label>
<Select
value={formData.priority}
onValueChange={(v) => { if (v) updateField('priority', v as DeadlinePriority) }}
>
<SelectTrigger>
<SelectValue />
</SelectTrigger>
<SelectContent>
{Object.entries(PRIORITY_LABELS).map(([value, label]) => (
<SelectItem key={value} value={value}>
{label}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
</div>
{/* Customer */}
{customers.length > 0 && (
<div className="space-y-2">
<Label>Kund (valfritt)</Label>
<Select
value={formData.customer_id || 'none'}
onValueChange={(v) => { if (v) updateField('customer_id', v === 'none' ? '' : v) }}
>
<SelectTrigger>
<SelectValue placeholder="Välj kund..." />
</SelectTrigger>
<SelectContent>
<SelectItem value="none">Ingen kund</SelectItem>
{customers.map((customer) => (
<SelectItem key={customer.id} value={customer.id}>
{customer.name}
</SelectItem>
))}
</SelectContent>
</Select>
</div>
)}
{/* Notes */}
<div className="space-y-2">
<Label htmlFor="notes">Anteckningar (valfritt)</Label>
<Textarea
id="notes"
placeholder="Lägg till anteckningar..."
value={formData.notes}
onChange={(e) => updateField('notes', e.target.value)}
rows={3}
/>
</div>
<DialogFooter className="flex-row justify-between sm:justify-between gap-2">
{/* Delete (only when editing an existing deadline) */}
{initialData?.id && onDelete ? (
<div className="flex items-center gap-2">
{confirmDelete ? (
<>
<span className="text-sm text-muted-foreground mr-1">Ta bort?</span>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setConfirmDelete(false)}
>
Avbryt
</Button>
<Button
type="button"
variant="destructive"
size="sm"
onClick={() => {
onDelete(initialData)
onOpenChange(false)
}}
>
Ta bort
</Button>
</>
) : (
<Button
type="button"
variant="ghost"
size="sm"
className="text-destructive hover:text-destructive hover:bg-destructive/10"
onClick={() => setConfirmDelete(true)}
>
Ta bort
</Button>
)}
</div>
) : (
<div />
)}
<div className="flex items-center gap-2">
<Button
type="button"
variant="outline"
onClick={() => onOpenChange(false)}
>
Avbryt
</Button>
<Button
type="submit"
disabled={isLoading || !formData.title || !canWrite}
title={!canWrite ? 'Du har endast läsbehörighet i detta företag' : undefined}
>
{!canWrite && <Lock className="mr-2 h-4 w-4" />}
{isLoading ? 'Sparar...' : initialData?.id ? 'Spara' : 'Skapa'}
</Button>
</div>
</DialogFooter>
</form>
</DialogContent>
</Dialog>
)
}
+111
View File
@@ -0,0 +1,111 @@
'use client'
import { useTranslations } from 'next-intl'
import { Deadline } from '@/types'
import { cn } from '@/lib/utils'
import { isDeadlineOverdue } from '@/lib/calendar/utils'
import { HOVER_REVEAL_CLASS, QUIET_LINK_CLASS } from '@/components/ui/dry-table'
import { deadlineDateLabel } from './DeadlineRow'
import { Pencil } from 'lucide-react'
/**
* System tax deadlines that legally share the skattekonto date ("den 12:e"):
* for a small monthly-moms employer, moms + AGI (+ debiterad preliminärskatt)
* all fall due the same day. Rendering them as one grouped row instead of
* 2-3 identical-date rows keeps the list scannable.
*/
export const SKATTEKONTO_GROUP_TYPES = new Set([
'moms_monthly',
'moms_quarterly',
'moms_yearly',
'f_skatt',
'arbetsgivardeklaration',
'skatteinbetalning',
])
export function isSkattekontoDeadline(d: Deadline): boolean {
return (
!d.is_completed &&
d.source === 'system' &&
d.tax_deadline_type !== null &&
SKATTEKONTO_GROUP_TYPES.has(d.tax_deadline_type)
)
}
interface DeadlineGroupRowProps {
/** Two or more skattekonto deadlines sharing the same due_date. */
deadlines: Deadline[]
onEdit?: (deadline: Deadline) => void
/** "Markera klar": the list confirms before toggling. */
onRequestToggle: (deadline: Deadline) => void
}
/**
* One thread row for all skattekonto obligations on a shared due date
* (concept scene 17 row language): the date renders once, each obligation is
* a sub-row with its own quiet "Markera klar".
*/
export function DeadlineGroupCard({ deadlines, onEdit, onRequestToggle }: DeadlineGroupRowProps) {
const t = useTranslations('deadlines')
const first = deadlines[0]
const overdue = deadlines.some(isDeadlineOverdue)
return (
<div className="flex items-start gap-3 py-3 -mx-2 px-2">
{/* Shared skattekonto date: always Skatteverket's mark (white ground,
badge not chrome). */}
<span className="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-white">
<img src="/logos/skatteverket_color.svg" alt="Skatteverket" className="h-4 w-4 object-contain" />
</span>
<div className="min-w-0 flex-1">
<p className="text-sm leading-6">
<span className="tabular-nums text-muted-foreground">
{deadlineDateLabel(first.due_date)}
</span>
<span className="text-muted-foreground/50"> · </span>
<span>{t('group_skattekonto_title')}</span>
</p>
<p
className={cn(
'text-xs leading-5',
overdue ? 'text-destructive' : 'text-muted-foreground',
)}
>
{t('group_same_day', { count: deadlines.length })}
</p>
<div className="mt-1">
{deadlines.map((deadline) => (
<div
key={deadline.id}
onClick={() => onEdit?.(deadline)}
className={cn(
'group flex items-center gap-3 rounded-sm py-1.5 -mx-2 px-2 transition-colors duration-150',
onEdit && 'cursor-pointer hover:bg-secondary/35',
)}
>
<p className="min-w-0 flex-1 truncate text-sm">{deadline.title}</p>
<button
type="button"
onClick={(e) => {
e.stopPropagation()
onRequestToggle(deadline)
}}
className={cn(QUIET_LINK_CLASS, HOVER_REVEAL_CLASS, 'shrink-0')}
>
{t('group_mark_done')}
</button>
{onEdit && (
<Pencil
className="h-3.5 w-3.5 shrink-0 text-muted-foreground/0 transition-colors group-hover:text-muted-foreground/50"
aria-hidden="true"
/>
)}
</div>
))}
</div>
</div>
</div>
)
}
+246
View File
@@ -0,0 +1,246 @@
'use client'
import { useMemo, useState } from 'react'
import { useTranslations } from 'next-intl'
import { Deadline, DeadlineType } from '@/types'
import { DeadlineRow, deadlineDateLabel } from './DeadlineRow'
import { DeadlineGroupCard, isSkattekontoDeadline } from './DeadlineGroupCard'
import { ConfirmDialog } from '@/components/ui/confirm-dialog'
import { SegmentedControl } from '@/components/ui/segmented-control'
import { isDeadlineOverdue, parseDate, startOfDay } from '@/lib/calendar/utils'
type TypeSegment = 'all' | 'tax' | 'invoicing' | 'own'
const SEGMENT_TYPES: Record<Exclude<TypeSegment, 'all'>, ReadonlyArray<DeadlineType>> = {
tax: ['tax'],
invoicing: ['invoicing'],
own: ['delivery', 'report', 'other'],
}
interface DeadlineListProps {
deadlines: Deadline[]
onDeadlineToggle: (deadline: Deadline) => Promise<void>
onDeadlineEdit: (deadline: Deadline) => void
}
/**
* Viktiga datum as the concept thread (scene 17): a type seg, borderless
* rows under hairline section headers, and a "Närmast" countdown pane on the
* right. Marking done confirms up front via ConfirmDialog.
*/
export function DeadlineList({
deadlines,
onDeadlineToggle,
onDeadlineEdit,
}: DeadlineListProps) {
const t = useTranslations('deadlines')
const [segment, setSegment] = useState<TypeSegment>('all')
const [confirmTarget, setConfirmTarget] = useState<Deadline | null>(null)
const filteredDeadlines = useMemo(() => {
if (segment === 'all') return deadlines
const types = SEGMENT_TYPES[segment]
return deadlines.filter((d) => types.includes(d.deadline_type))
}, [deadlines, segment])
const groupedDeadlines = useMemo(() => {
const today = new Date().toISOString().split('T')[0]
const overdue: Deadline[] = []
const todayDeadlines: Deadline[] = []
const upcoming: Deadline[] = []
const completed: Deadline[] = []
for (const d of filteredDeadlines) {
if (d.is_completed) {
completed.push(d)
} else if (isDeadlineOverdue(d)) {
overdue.push(d)
} else if (d.due_date === today) {
todayDeadlines.push(d)
} else {
upcoming.push(d)
}
}
return { overdue, today: todayDeadlines, upcoming, completed }
}, [filteredDeadlines])
// "Närmast" pane: days to the nearest pending deadline (across the
// unfiltered list: the countdown is page context, not a filter readout).
const nearest = useMemo(() => {
const pending = deadlines
.filter((d) => !d.is_completed && !isDeadlineOverdue(d))
.sort((a, b) => a.due_date.localeCompare(b.due_date))
const first = pending[0]
if (!first) return null
const today = startOfDay(new Date())
const days = Math.round(
(parseDate(first.due_date).getTime() - today.getTime()) / (1000 * 60 * 60 * 24),
)
return { deadline: first, days: Math.max(0, days) }
}, [deadlines])
const overdueCount = useMemo(
() => deadlines.filter((d) => !d.is_completed && isDeadlineOverdue(d)).length,
[deadlines],
)
const handleRequestToggle = (deadline: Deadline) => {
// Un-completing is a harmless revert: no confirmation (matches the undo
// toast the page already offers).
if (deadline.is_completed) {
void onDeadlineToggle(deadline)
return
}
setConfirmTarget(deadline)
}
const sections = [
{ key: 'overdue', label: t('section_overdue'), items: groupedDeadlines.overdue },
{ key: 'today', label: t('section_today'), items: groupedDeadlines.today },
{ key: 'upcoming', label: t('section_upcoming'), items: groupedDeadlines.upcoming },
{ key: 'completed', label: t('section_completed'), items: groupedDeadlines.completed },
].filter((s) => s.items.length > 0)
// Skattekonto obligations legally share the same due date (moms + AGI +
// preliminärskatt all fall on "den 12:e"): collapse 2+ such rows into one
// grouped row per date instead of near-identical rows. Other deadlines
// render as before, in their original order.
type ListEntry =
| { kind: 'single'; deadline: Deadline }
| { kind: 'group'; date: string; items: Deadline[] }
const toEntries = (items: Deadline[]): ListEntry[] => {
const byDate = new Map<string, Deadline[]>()
for (const d of items) {
if (!isSkattekontoDeadline(d)) continue
const group = byDate.get(d.due_date) ?? []
group.push(d)
byDate.set(d.due_date, group)
}
const emittedDates = new Set<string>()
const entries: ListEntry[] = []
for (const d of items) {
const group = byDate.get(d.due_date)
if (isSkattekontoDeadline(d) && group && group.length >= 2) {
if (!emittedDates.has(d.due_date)) {
emittedDates.add(d.due_date)
entries.push({ kind: 'group', date: d.due_date, items: group })
}
continue
}
entries.push({ kind: 'single', deadline: d })
}
return entries
}
return (
<div className="space-y-6">
{/* Toolbar: the type seg (concept: Alla / Skatt / Fakturering / Egna) */}
<SegmentedControl
value={segment}
onChange={setSegment}
options={[
{ value: 'all', label: t('seg_all') },
{ value: 'tax', label: t('seg_tax') },
{ value: 'invoicing', label: t('seg_invoicing') },
{ value: 'own', label: t('seg_own') },
]}
/>
<div className="gap-8 lg:grid lg:grid-cols-[minmax(0,1fr)_240px] lg:items-start">
{/* The thread */}
{filteredDeadlines.length === 0 ? (
<p className="py-16 text-center text-sm text-muted-foreground">
{segment !== 'all' ? t('empty_filtered') : t('empty_title')}
</p>
) : (
<div className="stagger-enter space-y-8">
{sections.map(({ key, label, items }) => (
<section key={key}>
<div className="mb-1 flex items-center gap-3 px-1">
<h2 className="text-xs uppercase tracking-wider text-muted-foreground">
{label}
</h2>
<span className="text-xs tabular-nums text-muted-foreground/50">
{items.length}
</span>
<div className="h-px flex-1 bg-border/60" />
</div>
<div>
{toEntries(items).map((entry) =>
entry.kind === 'group' ? (
<DeadlineGroupCard
key={`skattekonto-${entry.date}`}
deadlines={entry.items}
onEdit={onDeadlineEdit}
onRequestToggle={handleRequestToggle}
/>
) : (
<DeadlineRow
key={entry.deadline.id}
deadline={entry.deadline}
onEdit={onDeadlineEdit}
onRequestToggle={handleRequestToggle}
/>
),
)}
</div>
</section>
))}
</div>
)}
{/* "Närmast" pane (concept aside) */}
<aside className="mt-8 lg:mt-0">
<div className="rounded-lg border border-border">
<div className="border-b border-border px-4 py-2.5">
<p className="text-[11px] font-medium uppercase tracking-wider text-muted-foreground">
{t('nearest_title')}
</p>
</div>
<div className="px-4 py-6 text-center">
{nearest ? (
<>
<p className="font-display text-4xl leading-none tracking-tight tabular-nums">
{nearest.days === 0 ? t('rel_today') : nearest.days}
</p>
<p className="mt-2 text-xs text-muted-foreground">
{nearest.days === 0
? nearest.deadline.title
: t('nearest_days_to', { title: nearest.deadline.title })}
</p>
<p className="mt-1 text-xs tabular-nums text-muted-foreground/60">
{deadlineDateLabel(nearest.deadline.due_date)}
</p>
</>
) : (
<p className="py-4 text-xs text-muted-foreground">{t('nearest_empty')}</p>
)}
{overdueCount > 0 && (
<p className="mt-3 text-xs font-medium text-destructive">
{t('nearest_overdue', { count: overdueCount })}
</p>
)}
</div>
</div>
</aside>
</div>
<ConfirmDialog
open={confirmTarget !== null}
onOpenChange={(open) => !open && setConfirmTarget(null)}
title={t('confirm_done_title')}
description={
confirmTarget
? `${deadlineDateLabel(confirmTarget.due_date)} · ${confirmTarget.title}`
: undefined
}
confirmLabel={t('group_confirm')}
onConfirm={async () => {
if (confirmTarget) await onDeadlineToggle(confirmTarget)
}}
/>
</div>
)
}
+193
View File
@@ -0,0 +1,193 @@
'use client'
import { useTranslations } from 'next-intl'
import { Deadline } from '@/types'
import { cn } from '@/lib/utils'
import { isDeadlineOverdue, parseDate, startOfDay } from '@/lib/calendar/utils'
import { HOVER_REVEAL_CLASS, QUIET_LINK_CLASS } from '@/components/ui/dry-table'
import {
CalendarClock,
Check,
FileText,
Landmark,
Pencil,
ReceiptText,
Truck,
} from 'lucide-react'
interface DeadlineRowProps {
deadline: Deadline
/** Row click: open the edit dialog. */
onEdit?: (deadline: Deadline) => void
/** "Markera klar" (or un-done): the list confirms before toggling. */
onRequestToggle: (deadline: Deadline) => void
}
function daysFromToday(dateStr: string): number {
const today = startOfDay(new Date())
const target = parseDate(dateStr)
return Math.round((target.getTime() - today.getTime()) / (1000 * 60 * 60 * 24))
}
const TYPE_ICONS: Record<Deadline['deadline_type'], typeof CalendarClock> = {
tax: Landmark,
invoicing: ReceiptText,
delivery: Truck,
report: FileText,
other: CalendarClock,
}
// Statutory deadlines carry the receiving authority's mark: Bolagsverket for
// the company-law dates, Skatteverket for everything tax-shaped. Non-system
// deadlines keep the neutral type icons.
const BOLAGSVERKET_TYPES = new Set(['arsredovisning', 'arsstamma'])
export function deadlineAuthorityLogo(deadline: Deadline): { src: string; alt: string } | null {
if (deadline.tax_deadline_type) {
return BOLAGSVERKET_TYPES.has(deadline.tax_deadline_type)
? { src: '/logos/bolagsverket.jpg', alt: 'Bolagsverket' }
: { src: '/logos/skatteverket_color.svg', alt: 'Skatteverket' }
}
// Manual deadlines (including user-created tax-category ones) keep the
// neutral type icons: the authority crest is reserved for statutory dates
// the system generated from the tax settings.
return null
}
/** The shared 28px round mark: authority logo on white, or a muted type icon. */
export function DeadlineMark({
deadline,
completed = false,
}: {
deadline: Deadline
completed?: boolean
}) {
const logo = deadlineAuthorityLogo(deadline)
if (completed) {
return (
<span className="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground/60">
<Check className="h-3.5 w-3.5" aria-hidden="true" />
</span>
)
}
if (logo) {
// Deliberately white in both themes: the authority marks are badges, not
// chrome, and their brand colors need a white ground.
return (
<span className="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center overflow-hidden rounded-full border border-border bg-white">
<img src={logo.src} alt={logo.alt} className="h-4 w-4 object-contain" />
</span>
)
}
const Icon = TYPE_ICONS[deadline.deadline_type] ?? CalendarClock
return (
<span className="mt-0.5 flex h-7 w-7 shrink-0 items-center justify-center rounded-full border border-border text-muted-foreground">
<Icon className="h-3.5 w-3.5" aria-hidden="true" />
</span>
)
}
const SWEDISH_MONTHS_SHORT = [
'jan', 'feb', 'mar', 'apr', 'maj', 'jun',
'jul', 'aug', 'sep', 'okt', 'nov', 'dec',
]
export function deadlineDateLabel(dateStr: string): string {
const date = parseDate(dateStr)
return `${date.getDate()} ${SWEDISH_MONTHS_SHORT[date.getMonth()]}`
}
/**
* One deadline as a concept thread row (scene 17): icon circle, "12 aug ·
* Title" line, muted status sentence below, quiet hover actions. Rows are
* borderless; the section headers carry the structure.
*/
export function DeadlineRow({ deadline, onEdit, onRequestToggle }: DeadlineRowProps) {
const t = useTranslations('deadlines')
const overdue = isDeadlineOverdue(deadline)
const completed = deadline.is_completed
const diff = daysFromToday(deadline.due_date)
const relative = completed
? null
: diff === 0
? t('rel_today')
: diff === 1
? t('rel_tomorrow')
: diff < 0
? t('rel_days_ago', { count: Math.abs(diff) })
: diff <= 14
? t('rel_in_days', { count: diff })
: null
const subParts = [
relative,
deadline.due_time ? `kl ${deadline.due_time.slice(0, 5)}` : null,
deadline.customer?.name ?? null,
].filter(Boolean) as string[]
return (
<div
onClick={() => onEdit?.(deadline)}
className={cn(
'group flex items-start gap-3 rounded-sm py-3 -mx-2 px-2 transition-colors duration-150',
onEdit && 'cursor-pointer hover:bg-secondary/35',
completed && 'opacity-60',
)}
>
<DeadlineMark deadline={deadline} completed={completed} />
<div className="min-w-0 flex-1">
<p className={cn('text-sm leading-6', completed && 'line-through text-muted-foreground')}>
<span className="tabular-nums text-muted-foreground">
{deadlineDateLabel(deadline.due_date)}
</span>
<span className="text-muted-foreground/50"> · </span>
<span>{deadline.title}</span>
</p>
{subParts.length > 0 && (
<p
className={cn(
'text-xs leading-5',
overdue && !completed ? 'text-destructive' : 'text-muted-foreground',
)}
>
{subParts.join(' · ')}
</p>
)}
</div>
<div className="flex shrink-0 items-center gap-3 pt-1">
{completed ? (
<button
type="button"
onClick={(e) => {
e.stopPropagation()
onRequestToggle(deadline)
}}
className={cn(QUIET_LINK_CLASS, HOVER_REVEAL_CLASS)}
>
{t('mark_not_done')}
</button>
) : (
<button
type="button"
onClick={(e) => {
e.stopPropagation()
onRequestToggle(deadline)
}}
className={cn(QUIET_LINK_CLASS, HOVER_REVEAL_CLASS)}
>
{t('group_mark_done')}
</button>
)}
{onEdit && (
<Pencil
className="h-3.5 w-3.5 text-muted-foreground/0 transition-colors group-hover:text-muted-foreground/50"
aria-hidden="true"
/>
)}
</div>
</div>
)
}