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
@@ -0,0 +1,66 @@
'use client'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useTranslations } from 'next-intl'
/**
* Multi-user grace countdown: shown to EVERYONE in a company whose
* multi_user entitlement has lapsed but is still inside its 20-day grace
* window, and only when the company actually has affected people (at least
* one non-owner member). The affected member reads their own version; the
* owner (and everyone else) reads which accounts pause and when.
*
* Server-gated: the dashboard layout renders this only in the grace state
* with a non-empty affected list, so the component itself only formats.
* Same chrome treatment as SandboxBanner: environment notice on secondary,
* never a warning fill (status colors are data, not chrome).
*/
export function MultiUserGraceBanner({
graceEndsAt,
affectedEmails,
isAffectedUser,
companyName,
}: {
graceEndsAt: string
affectedEmails: string[]
/** True when the signed-in user is one of the accounts that will pause. */
isAffectedUser: boolean
companyName: string
}) {
const t = useTranslations('multi_user')
// Computed in an effect so server and client markup agree at hydration;
// an hourly tick keeps a long-lived tab honest (same pattern as
// SubscriptionTouchpoint).
const [daysLeft, setDaysLeft] = useState<number | null>(null)
useEffect(() => {
const update = () => {
const msLeft = new Date(graceEndsAt).getTime() - Date.now()
setDaysLeft(Math.max(0, Math.ceil(msLeft / 86_400_000)))
}
update()
const id = setInterval(update, 3_600_000)
return () => clearInterval(id)
}, [graceEndsAt])
if (daysLeft === null) return null
const message = isAffectedUser
? t('banner_affected', { companyName, days: daysLeft })
: t('banner_owner', { emails: affectedEmails.join(', '), days: daysLeft })
return (
<div className="relative z-50 flex flex-wrap items-center justify-center gap-x-3 gap-y-1 border-b border-border bg-secondary px-4 py-2 text-sm text-secondary-foreground">
<span className="text-center text-xs font-medium sm:text-sm">{message}</span>
<Link
href="/settings/billing"
className="shrink-0 rounded-full bg-foreground/10 px-3 py-0.5 text-xs font-semibold transition-colors hover:bg-foreground/15"
>
{t('banner_cta')}
</Link>
</div>
)
}
export default MultiUserGraceBanner
@@ -0,0 +1,121 @@
'use client'
import { useEffect, useState } from 'react'
import Link from 'next/link'
import { useTranslations } from 'next-intl'
import { ChevronRight, Clock, Lock } from 'lucide-react'
import { useCompany } from '@/contexts/CompanyContext'
/**
* The chrome-level subscription touchpoint: the paywall is a lifecycle flow,
* not a settings page, so trial state stays quietly visible in the chrome
* instead of only inside Inställningar -> Abonnemang.
*
* trial -> the countdown pill ("Provperiod: N dagar kvar").
* trial_expired /
* lapsed_subscription -> a muted pill linking to /settings/billing. This is
* the navigation affordance a lapsed user could not
* find (2026-08-18 report), so it is NOT dismissable
* and, unlike the countdown, stays visible when the
* sidebar is collapsed (icon-only with aria-label).
*
* Hidden for sandbox/demo (no checkout; sandbox companies carry trial grants
* too) and for paying companies. Muted chrome tone throughout: status colors
* are data, never chrome.
*/
export function SubscriptionTouchpoint({
variant,
collapsed = false,
onNavigate,
}: {
variant: 'sidebar' | 'mobile'
collapsed?: boolean
onNavigate?: () => void
}) {
const { entitlementState, trialEndsAt, isSandbox } = useCompany()
const tNav = useTranslations('nav')
// Trial countdown. Computed in an effect (not during render) so server and
// client markup agree at hydration; an hourly tick keeps a long-lived tab
// from showing yesterday's count.
const [trialDaysLeft, setTrialDaysLeft] = useState<number | null>(null)
useEffect(() => {
if (!trialEndsAt) {
// eslint-disable-next-line react-hooks/set-state-in-effect
setTrialDaysLeft(null)
return
}
const update = () => {
const msLeft = new Date(trialEndsAt).getTime() - Date.now()
setTrialDaysLeft(msLeft > 0 ? Math.ceil(msLeft / 86_400_000) : null)
}
update()
const id = setInterval(update, 3_600_000)
return () => clearInterval(id)
}, [trialEndsAt])
if (isSandbox) return null
const lapsed =
entitlementState === 'trial_expired' || entitlementState === 'lapsed_subscription'
const showCountdown =
entitlementState === 'trial' && trialDaysLeft !== null
if (!lapsed && !showCountdown) return null
const label = lapsed
? tNav(
entitlementState === 'lapsed_subscription'
? 'subscription_lapsed_cta'
: 'trial_expired_cta',
)
: tNav('trial_days_left', { days: trialDaysLeft ?? 0 })
const Icon = lapsed ? Lock : Clock
if (variant === 'mobile') {
return (
<Link
href="/settings/billing"
onClick={onNavigate}
className="flex items-center gap-3 px-3 min-h-[44px] rounded-lg text-foreground transition-colors active:bg-muted/60"
>
<Icon className="h-[18px] w-[18px] flex-shrink-0 text-muted-foreground" />
<span className="text-sm flex-1">{label}</span>
<ChevronRight className="h-4 w-4 flex-shrink-0 text-muted-foreground/50" />
</Link>
)
}
// Sidebar. The countdown keeps its pre-existing behavior of hiding when the
// rail is collapsed; the lapsed CTA must not vanish, so it collapses to an
// icon-only link instead.
if (collapsed) {
if (!lapsed) return null
return (
<div className="flex flex-shrink-0 justify-center pb-2">
<Link
href="/settings/billing"
title={label}
aria-label={label}
className="flex h-9 w-9 items-center justify-center rounded-lg text-muted-foreground hover:bg-secondary/60 hover:text-foreground transition-colors duration-150"
>
<Icon className="h-[17px] w-[17px]" />
</Link>
</div>
)
}
return (
<div className="flex-shrink-0 px-3 pb-2">
<Link
href="/settings/billing"
className="flex items-center gap-2 rounded-lg border border-border px-3 py-2 text-xs text-muted-foreground hover:bg-secondary/60 hover:text-foreground transition-colors duration-150"
>
<Icon className="h-3.5 w-3.5 shrink-0" />
<span className="flex-1 truncate">{label}</span>
<ChevronRight className="h-3.5 w-3.5 shrink-0 opacity-50" />
</Link>
</div>
)
}
export default SubscriptionTouchpoint
+92
View File
@@ -0,0 +1,92 @@
'use client'
import { useState } from 'react'
import { usePathname, useRouter } from 'next/navigation'
import { useTranslations } from 'next-intl'
import { Button } from '@/components/ui/button'
import {
Dialog,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogTitle,
} from '@/components/ui/dialog'
import { persistUiState } from '@/lib/ui-state/client'
import { useFormat } from '@/lib/hooks/use-format'
import type { EntitlementState } from '@/lib/entitlements/has-capability'
/**
* One-time on-entry notice that the trial (or a cancelled subscription) has
* lapsed, with the path to Abonnemang. Shown once per user AND company:
* the acknowledgement persists in user_preferences.ui_state
* (trial_expired_ack[companyId]), read server-side by the dashboard layout so
* an acked dialog never mounts (no flash). Both dismissing and clicking
* through count as acknowledged; afterwards the persistent
* SubscriptionTouchpoint in the chrome carries the CTA. The layout gates
* sandbox/anonymous users (no billing); this component additionally skips
* /settings/* so it never stacks on the routed settings modal.
*/
export function TrialExpiredDialog({
state,
trialExpiredAt,
companyId,
initialAcknowledged,
}: {
state: EntitlementState
trialExpiredAt: string | null
companyId: string
initialAcknowledged: boolean
}) {
const t = useTranslations('trial_expired_dialog')
const { formatDateLong } = useFormat()
const router = useRouter()
const pathname = usePathname()
const [open, setOpen] = useState(true)
const lapsed = state === 'trial_expired' || state === 'lapsed_subscription'
if (!lapsed || initialAcknowledged || pathname.startsWith('/settings')) {
return null
}
const acknowledge = () => {
setOpen(false)
persistUiState({
trial_expired_ack: { [companyId]: new Date().toISOString() },
})
}
const goToBilling = () => {
acknowledge()
router.push('/settings/billing')
}
return (
<Dialog open={open} onOpenChange={(next) => { if (!next) acknowledge() }}>
<DialogContent className="max-w-md">
<DialogHeader>
<DialogTitle className="font-display text-xl tracking-tight">
{state === 'lapsed_subscription'
? t('title_lapsed')
: trialExpiredAt
? t('title_dated', { date: formatDateLong(trialExpiredAt) })
: t('title')}
</DialogTitle>
<DialogDescription className="sr-only">{t('body_paused')}</DialogDescription>
</DialogHeader>
<div className="space-y-3 text-sm text-muted-foreground">
<p>{t('body_paused')}</p>
<p>{t('body_free')}</p>
</div>
<DialogFooter>
<Button variant="ghost" onClick={acknowledge}>
{t('cta_secondary')}
</Button>
<Button onClick={goToBilling}>{t('cta_primary')}</Button>
</DialogFooter>
</DialogContent>
</Dialog>
)
}
export default TrialExpiredDialog
+46
View File
@@ -0,0 +1,46 @@
import Link from 'next/link'
import { Lock } from 'lucide-react'
import { cn } from '@/lib/utils'
import { isSelfHosted } from '@/lib/env/public-flags'
/**
* Inline paywall note for a feature that is visible but not entitled.
* The feature stays on screen (conversion surface: never hide, disable
* with an upsell), this note explains why it's disabled and links to
* /settings/billing. Copy mirrors CAPABILITY_BLOCKED_MESSAGE_SV.
*
* On a SELF-HOST the note never mentions a subscription or links to the
* hosted Stripe billing page: the only capabilities that can be blocked
* there are the connector ones (everything local is always on), and their
* remedy is a connector key or the instance's own upstream credentials.
* Copy mirrors CAPABILITY_BLOCKED_MESSAGE_SELF_HOSTED_SV.
*/
export function UpgradeNote({ children, className }: { children?: React.ReactNode; className?: string }) {
const frame = (content: React.ReactNode) => (
<div
className={cn(
'flex items-start gap-2.5 rounded-lg border border-border bg-secondary/40 px-3 py-2.5 text-sm text-muted-foreground',
className,
)}
>
<Lock className="h-4 w-4 mt-0.5 shrink-0" />
<span>{content}</span>
</div>
)
if (isSelfHosted()) {
return frame(
<>
Den här funktionen kräver en connector-nyckel från Accounted (GNUBOK_CONNECTOR_KEY) eller
instansens egna API-uppgifter för tjänsten.
</>,
)
}
return frame(
<>
{children ?? 'Den här funktionen kräver ett abonnemang.'}{' '}
<Link href="/settings/billing" className="underline underline-offset-2 text-foreground">
Uppgradera
</Link>
</>,
)
}