* Implement company and account deletion features - Add event types for company and account deletion to CoreEvent. - Enhance Supabase middleware to handle company context resolution and cookie management for archived companies. - Create API routes for deleting accounts and companies, including necessary validations and event emissions. - Implement tests for account and company deletion endpoints to ensure proper functionality and error handling. - Add retention notice component to inform users about bookkeeping data retention during destructive actions. - Create database migrations to support soft deletion of companies and anonymization of user accounts, ensuring compliance with retention laws. * feat: enhance account deletion process and update user notifications * Add service client for onboarding completion check and update escape hatch visibility * Enhance invite flow and email handling for company members * Refactor company context and RLS policies for active company isolation - Update `switchCompany` to remove unnecessary revalidation as client handles navigation. - Revise `getActiveCompanyId` to prioritize `user_preferences` and validate against non-archived memberships. - Modify `setActiveCompany` to ensure `user_preferences` is the authoritative source while maintaining cookie compatibility. - Enhance middleware to resolve active company using `user_preferences` and fallback to first non-archived membership. - Introduce new API route `/api/company/current` to fetch the active company ID for cross-tab synchronization. - Implement `CompanyTabSync` component for real-time active company enforcement across tabs. - Create migration for RLS policies to enforce single-active-company isolation using `current_active_company_id()`. * feat: implement viewer role enforcement for write permissions - Added `useCanWrite` hook to determine if the current user has write permissions based on their role in the active company. - Updated various components (JournalEntryForm, CustomerForm, DeadlineForm, etc.) to disable write actions and show a lock icon with a tooltip for users without write permissions. - Introduced `requireWritePermission` function to enforce write permissions at the API level, returning a 403 response for viewers. - Created tests to verify the behavior of the viewer role and write permissions. - Added database migration to enforce read-only access for viewers at the database level.
153 lines
5.1 KiB
TypeScript
153 lines
5.1 KiB
TypeScript
'use client'
|
||
|
||
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
|
||
import { Button } from '@/components/ui/button'
|
||
import { Badge } from '@/components/ui/badge'
|
||
import {
|
||
ArrowLeft,
|
||
Loader2,
|
||
Play,
|
||
FileText,
|
||
Link2,
|
||
Calendar,
|
||
Lock,
|
||
} from 'lucide-react'
|
||
import { formatCurrency } from '@/lib/utils'
|
||
import { useCanWrite } from '@/lib/hooks/use-can-write'
|
||
import type { BankFileParseResult } from '@/lib/import/bank-file/types'
|
||
|
||
interface BankFileConfirmStepProps {
|
||
parseResult: BankFileParseResult
|
||
onExecute: (options: { skip_duplicates: boolean; auto_categorize: boolean }) => void
|
||
onBack: () => void
|
||
isLoading: boolean
|
||
}
|
||
|
||
export default function BankFileConfirmStep({
|
||
parseResult,
|
||
onExecute,
|
||
onBack,
|
||
isLoading,
|
||
}: BankFileConfirmStepProps) {
|
||
const { canWrite } = useCanWrite()
|
||
const { transactions, stats, date_from, date_to } = parseResult
|
||
const refsCount = transactions.filter((t) => t.reference).length
|
||
|
||
if (isLoading) {
|
||
return (
|
||
<div className="flex flex-col items-center justify-center py-24 space-y-6">
|
||
<div className="relative">
|
||
<Loader2 className="h-12 w-12 animate-spin text-primary" />
|
||
</div>
|
||
<div className="text-center space-y-2">
|
||
<p className="text-lg font-medium">Importerar transaktioner...</p>
|
||
<p className="text-sm text-muted-foreground">
|
||
{stats.parsed_rows} transaktioner bearbetas
|
||
</p>
|
||
</div>
|
||
<div className="w-48 h-1 bg-muted rounded-full overflow-hidden">
|
||
<div className="h-full bg-primary rounded-full animate-pulse" style={{ width: '60%' }} />
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|
||
|
||
return (
|
||
<div className="space-y-6">
|
||
{/* Summary */}
|
||
<Card>
|
||
<CardHeader>
|
||
<CardTitle>Bekräfta import</CardTitle>
|
||
<CardDescription>
|
||
Granska sammanfattningen och importera transaktionerna.
|
||
</CardDescription>
|
||
</CardHeader>
|
||
<CardContent className="space-y-6">
|
||
{/* Stats grid */}
|
||
<div className="grid grid-cols-2 md:grid-cols-4 gap-4">
|
||
<div className="p-4 bg-muted/50 rounded-lg">
|
||
<div className="flex items-center gap-2 text-muted-foreground mb-1">
|
||
<FileText className="h-4 w-4" />
|
||
<span className="text-xs">Transaktioner</span>
|
||
</div>
|
||
<p className="text-xl font-display font-medium tabular-nums">{stats.parsed_rows}</p>
|
||
</div>
|
||
|
||
<div className="p-4 bg-muted/50 rounded-lg">
|
||
<div className="flex items-center gap-2 text-muted-foreground mb-1">
|
||
<Calendar className="h-4 w-4" />
|
||
<span className="text-xs">Period</span>
|
||
</div>
|
||
<p className="text-sm font-medium">
|
||
{date_from} – {date_to}
|
||
</p>
|
||
</div>
|
||
|
||
<div className="p-4 bg-muted/50 rounded-lg">
|
||
<div className="flex items-center gap-2 text-muted-foreground mb-1">
|
||
<span className="text-xs">Inkomster</span>
|
||
</div>
|
||
<p className="text-xl font-display font-medium tabular-nums">
|
||
{formatCurrency(stats.total_income)}
|
||
</p>
|
||
</div>
|
||
|
||
<div className="p-4 bg-muted/50 rounded-lg">
|
||
<div className="flex items-center gap-2 text-muted-foreground mb-1">
|
||
<span className="text-xs">Utgifter</span>
|
||
</div>
|
||
<p className="text-xl font-display font-medium tabular-nums">
|
||
{formatCurrency(stats.total_expenses)}
|
||
</p>
|
||
</div>
|
||
</div>
|
||
|
||
{/* Additional info */}
|
||
{refsCount > 0 && (
|
||
<div className="flex flex-wrap gap-2">
|
||
<Badge variant="outline" className="text-primary border-primary/30">
|
||
<Link2 className="mr-1 h-3 w-3" />
|
||
{refsCount} med OCR/referens
|
||
</Badge>
|
||
</div>
|
||
)}
|
||
</CardContent>
|
||
</Card>
|
||
|
||
{/* Actions */}
|
||
<div className="flex flex-col-reverse gap-3 sm:flex-row sm:justify-between">
|
||
<Button variant="outline" className="min-h-11" onClick={onBack} disabled={isLoading}>
|
||
<ArrowLeft className="mr-2 h-4 w-4" />
|
||
Tillbaka
|
||
</Button>
|
||
<Button
|
||
className="min-h-11"
|
||
onClick={() => onExecute({
|
||
skip_duplicates: true,
|
||
auto_categorize: false,
|
||
})}
|
||
disabled={isLoading || !canWrite}
|
||
title={!canWrite ? 'Du har endast läsbehörighet i detta företag' : undefined}
|
||
>
|
||
{isLoading ? (
|
||
<>
|
||
<Loader2 className="mr-2 h-4 w-4 animate-spin" />
|
||
Importerar...
|
||
</>
|
||
) : !canWrite ? (
|
||
<>
|
||
<Lock className="mr-2 h-4 w-4" />
|
||
Importera {stats.parsed_rows} transaktioner
|
||
</>
|
||
) : (
|
||
<>
|
||
<Play className="mr-2 h-4 w-4" />
|
||
Importera {stats.parsed_rows} transaktioner
|
||
</>
|
||
)}
|
||
</Button>
|
||
</div>
|
||
</div>
|
||
)
|
||
}
|