Merge remote-tracking branch 'origin/dev' into sync-github-and-ci-fix

This commit is contained in:
Bernd Rodler
2026-08-07 14:03:10 +02:00
62 changed files with 7794 additions and 125 deletions
@@ -18,6 +18,7 @@ export function ContactsSettings() {
const { client } = useAuthStore();
const {
contacts,
addressBooks,
supportsSync,
importContacts,
} = useContactStore();
@@ -46,6 +47,7 @@ export function ContactsSettings() {
<div className="border border-border rounded-lg overflow-hidden" style={{ minHeight: 400 }}>
<ContactImportDialog
existingContacts={contacts}
addressBooks={addressBooks}
onImport={handleImport}
onClose={() => setShowImport(false)}
/>
+245
View File
@@ -0,0 +1,245 @@
"use client";
import { useState, useRef, useCallback, useEffect } from "react";
import { useTranslations } from "next-intl";
import { Upload, FolderOpen, Download, AlertTriangle, Check, X } from "lucide-react";
import { Button } from "@/components/ui/button";
import { SettingsSection, SettingItem, RadioGroup, Select } from "./settings-section";
import { importEmails, type ConflictResolution, type ImportProgress, type ImportResult } from "@/lib/email-import";
import { useAuthStore } from "@/stores/auth-store";
import { useEmailStore } from "@/stores/email-store";
import { EML_IMPORT_ACCEPT } from "@/lib/eml-import";
import { toast } from "@/stores/toast-store";
import { cn } from "@/lib/utils";
export function ImportSettings() {
const t = useTranslations("settings.importer");
const { client } = useAuthStore();
const { mailboxes } = useEmailStore();
const fileRef = useRef<HTMLInputElement>(null);
const [files, setFiles] = useState<File[]>([]);
const [destination, setDestination] = useState("");
const [conflict, setConflict] = useState<ConflictResolution>("skip");
const [progress, setProgress] = useState<ImportProgress | null>(null);
const [result, setResult] = useState<ImportResult | null>(null);
const [error, setError] = useState<string | null>(null);
const [importing, setImporting] = useState(false);
const abortRef = useRef<AbortController | null>(null);
useEffect(() => {
if (mailboxes.length > 0 && !destination) {
const inbox = mailboxes.find((m) => m.role === "inbox") || mailboxes[0];
if (inbox) setDestination(inbox.id);
}
}, [mailboxes, destination]);
const folderOptions = mailboxes.map((m) => ({
value: m.id,
label: m.name,
}));
const handleFileChange = useCallback((e: React.ChangeEvent<HTMLInputElement>) => {
const selected = e.target.files;
if (!selected || selected.length === 0) return;
setError(null);
setResult(null);
setProgress(null);
setFiles(Array.from(selected));
}, []);
const handleImport = useCallback(async () => {
if (!client || files.length === 0 || !destination) return;
setImporting(true);
setError(null);
setResult(null);
const controller = new AbortController();
abortRef.current = controller;
try {
const res = await importEmails({
client,
files,
destinationMailboxId: destination,
conflictResolution: conflict,
onProgress: (p) => setProgress({ ...p }),
signal: controller.signal,
});
setResult(res);
if (res.imported > 0) {
toast.success(t("success", { count: res.imported }));
}
} catch (err) {
if (!controller.signal.aborted) {
const msg = err instanceof Error ? err.message : t("fail");
setError(msg);
toast.error(msg);
}
} finally {
setImporting(false);
abortRef.current = null;
}
}, [client, files, destination, conflict, t]);
const handleCancel = () => {
abortRef.current?.abort();
setImporting(false);
};
const reset = () => {
setFiles([]);
setResult(null);
setProgress(null);
setError(null);
if (fileRef.current) fileRef.current.value = "";
};
const progressPercent = progress && progress.total > 0
? Math.round((progress.processed / progress.total) * 100)
: 0;
return (
<SettingsSection
title={t("title")}
description={t("description")}
>
<SettingItem
label={t("file_label")}
description={t("file_description")}
>
<div className="flex items-center gap-2">
<input
ref={fileRef}
type="file"
accept={EML_IMPORT_ACCEPT}
multiple
onChange={handleFileChange}
className="hidden"
/>
<Button
variant="outline"
size="sm"
onClick={() => fileRef.current?.click()}
disabled={importing}
>
<Upload className="w-4 h-4 me-2" />
{files.length > 0
? t("files_selected", { count: files.length })
: t("choose_files")}
</Button>
{files.length > 0 && !importing && (
<Button variant="ghost" size="sm" onClick={reset}>
<X className="w-4 h-4" />
</Button>
)}
</div>
</SettingItem>
<SettingItem
label={t("folder_label")}
description={t("folder_description")}
>
<Select
value={destination}
onChange={setDestination}
options={folderOptions}
disabled={importing || folderOptions.length === 0}
/>
</SettingItem>
<SettingItem
label={t("conflict_label")}
description={t("conflict_description")}
>
<RadioGroup
value={conflict}
onChange={(v) => setConflict(v as ConflictResolution)}
options={[
{ value: "skip", label: t("conflict_skip") },
{ value: "replace", label: t("conflict_replace") },
{ value: "copy", label: t("conflict_copy") },
]}
/>
</SettingItem>
{files.length > 0 && !result && (
<SettingItem label={t("action_label")} description="">
<Button
onClick={handleImport}
disabled={importing || !destination}
>
{importing ? t("importing") : t("start_import", { count: files.length })}
</Button>
</SettingItem>
)}
{error && (
<div className="text-sm text-red-600 dark:text-red-400 bg-red-50 dark:bg-red-950 px-3 py-2 rounded flex items-center gap-2">
<AlertTriangle className="w-4 h-4 flex-shrink-0" />
{error}
</div>
)}
{progress && importing && (
<div className="space-y-2">
<div className="flex items-center justify-between text-sm text-muted-foreground">
<span>{progress.currentFile}</span>
<span>{progressPercent}%</span>
</div>
<div className="w-full bg-muted rounded-full h-2">
<div
className="bg-primary h-2 rounded-full transition-all duration-300"
style={{ width: `${progressPercent}%` }}
/>
</div>
<div className="flex justify-between text-xs text-muted-foreground">
<span>{t("progress_imported", { count: progress.imported })}</span>
<span>{t("progress_skipped", { count: progress.skipped })}</span>
<span>{t("progress_failed", { count: progress.failed })}</span>
</div>
<div className="flex justify-center">
<Button variant="outline" size="sm" onClick={handleCancel}>
{t("cancel")}
</Button>
</div>
</div>
)}
{result && !importing && (
<div className={cn(
"rounded-lg p-4 space-y-3",
result.failed > 0
? "bg-warning/10 border border-warning/30"
: "bg-green-50 dark:bg-green-950 border border-green-200 dark:border-green-800"
)}>
<div className="flex items-center gap-2">
<Check className="w-5 h-5 text-green-600 dark:text-green-400" />
<span className="font-medium text-sm">{t("import_complete")}</span>
</div>
<div className="text-sm space-y-1">
<p>{t("summary_imported", { count: result.imported })}</p>
<p>{t("summary_skipped", { count: result.skipped })}</p>
<p>{t("summary_failed", { count: result.failed })}</p>
</div>
{result.errors.length > 0 && (
<details className="text-xs">
<summary className="cursor-pointer text-muted-foreground hover:text-foreground">
{t("error_details", { count: result.errors.length })}
</summary>
<ul className="mt-2 space-y-1 ps-4 list-disc">
{result.errors.map((e, i) => (
<li key={i} className="text-red-600 dark:text-red-400">
<span className="font-medium">{e.file}</span>: {e.error}
</li>
))}
</ul>
</details>
)}
<Button variant="outline" size="sm" onClick={reset}>
{t("import_more")}
</Button>
</div>
)}
</SettingsSection>
);
}
+279
View File
@@ -0,0 +1,279 @@
"use client";
import { useEffect, useState, useCallback } from "react";
import { useTranslations } from "next-intl";
import { Button } from "@/components/ui/button";
import { Avatar } from "@/components/ui/avatar";
import {
Loader2,
RefreshCw,
Check,
X,
Folder,
Calendar,
BookUser,
HardDrive,
Trash2,
} from "lucide-react";
import { cn } from "@/lib/utils";
import { useAuthStore } from "@/stores/auth-store";
import { useSharingStore, type SharedResourceKind, type SharedFolder } from "@/stores/sharing-store";
const ICON_CLASS = "w-4 h-4 shrink-0";
function KindIcon({ kind }: { kind: SharedResourceKind }) {
switch (kind) {
case "mailbox":
return <Folder className={cn(ICON_CLASS, "text-blue-600/80")} />;
case "calendar":
return <Calendar className={cn(ICON_CLASS, "text-emerald-600/80")} />;
case "addressBook":
return <BookUser className={cn(ICON_CLASS, "text-violet-600/80")} />;
case "file":
return <HardDrive className={cn(ICON_CLASS, "text-amber-600/80")} />;
}
}
function KindLabel({ kind }: { kind: SharedResourceKind }) {
switch (kind) {
case "mailbox":
return "Mail";
case "calendar":
return "Calendar";
case "addressBook":
return "Contacts";
case "file":
return "Files";
}
}
export function SharingSettings() {
const t = useTranslations("settings");
const tSharing = useTranslations("sharing");
const client = useAuthStore((s) => s.client);
const {
sharedByMe,
sharedWithMe,
loading,
fetchShares,
revokeShare,
changeRole,
acceptShare,
declineShare,
} = useSharingStore();
const [activeTab, setActiveTab] = useState<"byMe" | "withMe">("byMe");
const handleRefresh = useCallback(() => {
if (client) fetchShares(client);
}, [client, fetchShares]);
useEffect(() => {
if (client) handleRefresh();
}, [client, handleRefresh]);
const handleRevoke = async (share: SharedFolder) => {
if (!client) return;
await revokeShare(
client,
share.resourceId,
share.resourceKind,
share.principalId,
share.accountId,
);
};
const handleChangeRole = async (share: SharedFolder, role: string) => {
if (!client) return;
await changeRole(
client,
share.resourceId,
share.resourceKind,
share.principalId,
role,
share.accountId,
);
};
const handleAccept = async (share: SharedFolder) => {
if (!client) return;
await acceptShare(client, share);
};
const handleDecline = async (share: SharedFolder) => {
if (!client) return;
await declineShare(client, share);
};
return (
<div>
<div className="flex items-center gap-1 border-b border-border mb-4">
<button
onClick={() => setActiveTab("byMe")}
className={cn(
"px-4 py-2 text-sm font-medium border-b-2 transition-colors -mb-px",
activeTab === "byMe"
? "border-primary text-primary"
: "border-transparent text-muted-foreground hover:text-foreground",
)}
>
{tSharing("tab_shared_by_me")}
</button>
<button
onClick={() => setActiveTab("withMe")}
className={cn(
"px-4 py-2 text-sm font-medium border-b-2 transition-colors -mb-px",
activeTab === "withMe"
? "border-primary text-primary"
: "border-transparent text-muted-foreground hover:text-foreground",
)}
>
{tSharing("tab_shared_with_me")}
</button>
<div className="flex-1" />
<button
onClick={handleRefresh}
disabled={loading}
className="p-2 rounded-md hover:bg-muted text-muted-foreground disabled:opacity-50 transition-colors"
title={t("refresh")}
>
<RefreshCw
className={cn("w-4 h-4", loading && "animate-spin")}
/>
</button>
</div>
{loading && (
<div className="flex items-center justify-center py-8 text-muted-foreground">
<Loader2 className="w-5 h-5 animate-spin me-2" />
{t("loading")}
</div>
)}
{!loading && activeTab === "byMe" && (
<>
{sharedByMe.length === 0 ? (
<div className="text-sm text-muted-foreground py-8 text-center">
{tSharing("no_shares_by_me")}
</div>
) : (
<div className="space-y-1">
{sharedByMe.map((share) => (
<div
key={share.id}
className="flex items-center gap-3 px-3 py-2.5 rounded-md border border-border bg-card"
>
<KindIcon kind={share.resourceKind} />
<div className="flex-1 min-w-0">
<div className="text-sm font-medium truncate">
{share.resourceName}
</div>
<div className="text-xs text-muted-foreground flex items-center gap-1">
<KindLabel kind={share.resourceKind} />
<span className="mx-1 opacity-40">|</span>
<Avatar
name={share.principalName}
email={share.principalEmail ?? undefined}
size="sm"
className="shrink-0 me-1"
/>
<span className="truncate">{share.principalName}</span>
</div>
</div>
<select
value={share.role}
onChange={(e) => handleChangeRole(share, e.target.value)}
className="appearance-none rounded-md border border-input bg-background px-2 py-1 text-xs focus:outline-none focus:ring-2 focus:ring-ring"
>
<option value="read">
{tSharing("preset.read")}
</option>
<option value="readWrite">
{tSharing("preset.readWrite")}
</option>
<option value="manager">
{tSharing("preset.manager")}
</option>
</select>
<button
onClick={() => handleRevoke(share)}
className="p-1.5 rounded-md hover:bg-destructive/10 text-muted-foreground hover:text-destructive transition-colors"
title={tSharing("remove")}
>
<Trash2 className="w-4 h-4" />
</button>
</div>
))}
</div>
)}
</>
)}
{!loading && activeTab === "withMe" && (
<>
{sharedWithMe.length === 0 ? (
<div className="text-sm text-muted-foreground py-8 text-center">
{tSharing("no_shares_with_me")}
</div>
) : (
<div className="space-y-1">
{sharedWithMe.map((share) => (
<div
key={share.id}
className="flex items-center gap-3 px-3 py-2.5 rounded-md border border-border bg-card"
>
<KindIcon kind={share.resourceKind} />
<div className="flex-1 min-w-0">
<div className="text-sm font-medium truncate">
{share.resourceName}
</div>
<div className="text-xs text-muted-foreground flex items-center gap-1">
<KindLabel kind={share.resourceKind} />
<span className="mx-1 opacity-40">|</span>
<span className="truncate">
{tSharing("shared_by")}: {share.principalName}
</span>
</div>
</div>
<span className="text-xs bg-muted rounded px-2 py-0.5 text-muted-foreground">
{tSharing(`preset.${share.role}`)}
</span>
{share.pending ? (
<div className="flex items-center gap-1">
<Button
size="sm"
variant="default"
onClick={() => handleAccept(share)}
className="h-7 px-2 text-xs"
>
<Check className="w-3 h-3 me-1" />
{tSharing("accept")}
</Button>
<Button
size="sm"
variant="ghost"
onClick={() => handleDecline(share)}
className="h-7 px-2 text-xs"
>
<X className="w-3 h-3 me-1" />
{tSharing("decline")}
</Button>
</div>
) : (
<Button
size="sm"
variant="ghost"
onClick={() => handleDecline(share)}
className="h-7 px-2 text-xs text-muted-foreground hover:text-destructive"
>
{tSharing("remove")}
</Button>
)}
</div>
))}
</div>
)}
</>
)}
</div>
);
}
@@ -0,0 +1,399 @@
'use client';
import { useState, useCallback } from 'react';
import { useTranslations } from 'next-intl';
import { useEditor, EditorContent } from '@tiptap/react';
import StarterKit from '@tiptap/starter-kit';
import Paragraph from '@tiptap/extension-paragraph';
import Underline from '@tiptap/extension-underline';
import Link from '@tiptap/extension-link';
import TextAlign from '@tiptap/extension-text-align';
import { TextStyle } from '@tiptap/extension-text-style';
import Color from '@tiptap/extension-color';
import { useFocusTrap } from '@/hooks/use-focus-trap';
import { Button } from '@/components/ui/button';
import { Input } from '@/components/ui/input';
import { cn } from '@/lib/utils';
import { htmlToPlainText } from '@/lib/html-to-text';
import type { Signature } from '@/stores/signature-store';
import {
Bold,
Italic,
Underline as UnderlineIcon,
Strikethrough,
List,
ListOrdered,
AlignLeft,
AlignCenter,
AlignRight,
Link as LinkIcon,
Baseline,
X,
} from 'lucide-react';
interface SignatureEditorModalProps {
signature?: Signature | null;
onSave: (data: { name: string; body: string; plainText: string }) => void;
onClose: () => void;
}
const StyledParagraph = Paragraph.extend({
addAttributes() {
return {
...this.parent?.(),
style: {
default: null as string | null,
parseHTML: (el: HTMLElement) => el.getAttribute('style'),
renderHTML: (attrs: Record<string, string | null>) =>
attrs.style ? { style: attrs.style } : {},
},
class: {
default: null as string | null,
parseHTML: (el: HTMLElement) => el.getAttribute('class'),
renderHTML: (attrs: Record<string, string | null>) =>
attrs.class ? { class: attrs.class } : {},
},
};
},
});
const TEXT_COLORS = [
'#000000', '#5f6368', '#9aa0a6', '#c5221f', '#e8710a', '#f9ab00', '#188038', '#1967d2',
'#7627bb', '#c2185b', '#795548', '#fa5252', '#fd7e14', '#40c057', '#4dabf7', '#e64980',
];
function ToolbarButton({
active,
onClick,
children,
title,
disabled,
}: {
active?: boolean;
onClick: () => void;
children: React.ReactNode;
title: string;
disabled?: boolean;
}) {
return (
<button
type="button"
onClick={onClick}
disabled={disabled}
title={title}
className={cn(
'p-1.5 rounded hover:bg-accent transition-colors',
active && 'bg-accent text-accent-foreground',
disabled && 'opacity-40 cursor-not-allowed'
)}
>
{children}
</button>
);
}
function ToolbarSeparator() {
return <div className="w-px h-5 bg-border mx-0.5" />;
}
export function SignatureEditorModal({
signature,
onSave,
onClose,
}: SignatureEditorModalProps) {
const t = useTranslations('signatures');
const tCommon = useTranslations('common');
const isEditing = !!signature;
const [name, setName] = useState(signature?.name ?? '');
const [nameError, setNameError] = useState('');
const [showPreview, setShowPreview] = useState(false);
const [colorMenuOpen, setColorMenuOpen] = useState(false);
const dialogRef = useFocusTrap({
isActive: true,
onEscape: onClose,
restoreFocus: true,
});
const editor = useEditor({
extensions: [
StarterKit.configure({
heading: false,
paragraph: false,
link: false,
underline: false,
codeBlock: false,
}),
StyledParagraph,
Underline,
Link.configure({
openOnClick: false,
HTMLAttributes: { rel: 'noopener noreferrer nofollow' },
}),
TextAlign.configure({
types: ['paragraph'],
}),
TextStyle,
Color,
],
content: signature?.body ?? '<p></p>',
editorProps: {
attributes: {
class: 'tiptap min-h-[120px] px-3 py-2 text-sm text-foreground focus:outline-none',
},
},
immediatelyRender: false,
});
const addLink = useCallback(() => {
if (!editor) return;
const previousUrl = editor.getAttributes('link').href;
const url = window.prompt('URL', previousUrl);
if (url === null) return;
if (url === '') {
editor.chain().focus().extendMarkRange('link').unsetLink().run();
return;
}
editor.chain().focus().extendMarkRange('link').setLink({ href: url }).run();
}, [editor]);
const handleSave = () => {
const trimmedName = name.trim();
if (!trimmedName) {
setNameError(t('name_required'));
return;
}
const html = editor?.getHTML() ?? '<p></p>';
const plainText = htmlToPlainText(html);
onSave({ name: trimmedName, body: html, plainText });
};
const bodyHtml = editor?.getHTML() ?? '';
const bodyPlainText = htmlToPlainText(bodyHtml);
return (
<div className="fixed inset-0 bg-black/50 backdrop-blur-[1px] flex items-start justify-center z-[60] p-4 pt-[10vh] animate-in fade-in duration-150">
<div
ref={dialogRef}
role="dialog"
aria-modal="true"
className="bg-background border border-border rounded-lg shadow-xl w-full max-w-2xl animate-in zoom-in-95 duration-200"
>
<div className="flex items-center justify-between px-6 py-4 border-b border-border">
<h2 className="text-lg font-semibold text-foreground">
{isEditing ? t('edit_signature') : t('new_signature')}
</h2>
<Button variant="ghost" size="icon" onClick={onClose} className="h-8 w-8">
<X className="w-4 h-4" />
</Button>
</div>
<div className="p-6 space-y-4 max-h-[70vh] overflow-y-auto">
<div>
<label htmlFor="sig-name" className="block text-sm font-medium mb-1">
{t('name_label')}
</label>
<Input
id="sig-name"
type="text"
value={name}
onChange={(e) => {
setName(e.target.value);
if (nameError) setNameError('');
}}
placeholder={t('name_placeholder')}
className={cn(nameError && 'border-destructive')}
aria-invalid={!!nameError}
aria-describedby={nameError ? 'sig-name-error' : undefined}
/>
{nameError && (
<p id="sig-name-error" className="text-sm text-destructive mt-1" role="alert">
{nameError}
</p>
)}
</div>
<div>
<div className="flex items-center justify-between mb-1">
<span className="text-sm font-medium">{t('editor_label')}</span>
<Button
type="button"
variant="ghost"
size="sm"
onClick={() => setShowPreview(!showPreview)}
className="h-7 text-xs"
>
{showPreview ? t('show_editor') : t('show_preview')}
</Button>
</div>
{showPreview ? (
<div className="border border-border rounded-md bg-muted/30 p-4 min-h-[200px]">
<div className="text-xs text-muted-foreground mb-2 font-medium">
{t('html_preview_label')}
</div>
<div
className="text-sm text-foreground [&_a]:text-primary [&_a]:underline-offset-2"
dangerouslySetInnerHTML={{ __html: bodyHtml }}
/>
<div className="mt-4 pt-4 border-t border-border">
<div className="text-xs text-muted-foreground mb-2 font-medium">
{t('plain_text_preview_label')}
</div>
<pre className="text-sm text-foreground whitespace-pre-wrap font-sans">
{bodyPlainText}
</pre>
</div>
</div>
) : (
<div className={cn('flex flex-col border border-border rounded-md overflow-hidden')}>
<div className="flex flex-wrap items-center gap-0.5 px-3 py-1.5 border-b border-border/50 bg-muted/30">
<ToolbarButton
active={editor?.isActive('bold')}
onClick={() => editor?.chain().focus().toggleBold().run()}
title={t('toolbar.bold')}
>
<Bold className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive('italic')}
onClick={() => editor?.chain().focus().toggleItalic().run()}
title={t('toolbar.italic')}
>
<Italic className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive('underline')}
onClick={() => editor?.chain().focus().toggleUnderline().run()}
title={t('toolbar.underline')}
>
<UnderlineIcon className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive('strike')}
onClick={() => editor?.chain().focus().toggleStrike().run()}
title={t('toolbar.strikethrough')}
>
<Strikethrough className="w-4 h-4" />
</ToolbarButton>
<div className="relative">
<ToolbarButton
active={!!editor?.getAttributes('textStyle').color}
onClick={() => setColorMenuOpen((v) => !v)}
title={t('toolbar.text_color')}
>
<Baseline
className="w-4 h-4"
style={{ color: editor?.getAttributes('textStyle').color || undefined }}
/>
</ToolbarButton>
{colorMenuOpen && (
<div className="absolute z-50 top-full start-0 mt-1 bg-popover border border-border rounded-md shadow-md p-2">
<div
className="grid gap-0.5"
style={{ gridTemplateColumns: 'repeat(8, 1fr)' }}
>
{TEXT_COLORS.map((color) => (
<button
key={color}
type="button"
title={color}
onClick={() => {
editor?.chain().focus().setColor(color).run();
setColorMenuOpen(false);
}}
className={cn(
'w-4 h-4 border border-border/60 rounded-[2px] transition-transform hover:scale-110',
editor?.getAttributes('textStyle').color === color &&
'ring-1 ring-ring ring-offset-1'
)}
style={{ backgroundColor: color }}
/>
))}
</div>
<div className="h-px bg-border my-1.5" />
<button
type="button"
className="flex items-center gap-2 px-2 py-1 text-sm rounded hover:bg-accent text-start w-full"
onClick={() => {
editor?.chain().focus().unsetColor().run();
setColorMenuOpen(false);
}}
>
{t('toolbar.remove_color')}
</button>
</div>
)}
</div>
<ToolbarSeparator />
<ToolbarButton
active={editor?.isActive('bulletList')}
onClick={() => editor?.chain().focus().toggleBulletList().run()}
title={t('toolbar.bullet_list')}
>
<List className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive('orderedList')}
onClick={() => editor?.chain().focus().toggleOrderedList().run()}
title={t('toolbar.ordered_list')}
>
<ListOrdered className="w-4 h-4" />
</ToolbarButton>
<ToolbarSeparator />
<ToolbarButton
active={editor?.isActive({ textAlign: 'left' })}
onClick={() => editor?.chain().focus().setTextAlign('left').run()}
title={t('toolbar.align_left')}
>
<AlignLeft className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive({ textAlign: 'center' })}
onClick={() => editor?.chain().focus().setTextAlign('center').run()}
title={t('toolbar.align_center')}
>
<AlignCenter className="w-4 h-4" />
</ToolbarButton>
<ToolbarButton
active={editor?.isActive({ textAlign: 'right' })}
onClick={() => editor?.chain().focus().setTextAlign('right').run()}
title={t('toolbar.align_right')}
>
<AlignRight className="w-4 h-4" />
</ToolbarButton>
<ToolbarSeparator />
<ToolbarButton
active={editor?.isActive('link')}
onClick={addLink}
title={t('toolbar.link')}
>
<LinkIcon className="w-4 h-4" />
</ToolbarButton>
</div>
<EditorContent editor={editor} />
</div>
)}
</div>
</div>
<div className="flex items-center justify-end gap-3 px-6 pb-6">
<Button variant="outline" onClick={onClose}>
{tCommon('cancel')}
</Button>
<Button onClick={handleSave}>
{tCommon('save')}
</Button>
</div>
</div>
</div>
);
}
+273
View File
@@ -0,0 +1,273 @@
'use client';
import { useState } from 'react';
import { useTranslations } from 'next-intl';
import { Button } from '@/components/ui/button';
import { ConfirmDialog } from '@/components/ui/confirm-dialog';
import { SettingsSection, SettingItem, Select } from './settings-section';
import { SignatureEditorModal } from './signature-editor-modal';
import { useSignatureStore, type Signature } from '@/stores/signature-store';
import { useIdentityStore } from '@/stores/identity-store';
import { truncateText } from '@/lib/utils';
import {
Plus,
Pencil,
Copy,
Trash2,
ChevronRight,
} from 'lucide-react';
export function SignatureSettings() {
const t = useTranslations('signatures');
const tCommon = useTranslations('common');
const {
signatures,
defaultSignatureId,
replySignatureId,
identitySignatureMap,
addSignature,
updateSignature,
deleteSignature,
duplicateSignature,
setDefaultSignatureId,
setReplySignatureId,
setIdentitySignature,
} = useSignatureStore();
const identities = useIdentityStore((s) => s.identities);
const [editingSignature, setEditingSignature] = useState<Signature | null>(null);
const [showEditor, setShowEditor] = useState(false);
const [deleteTarget, setDeleteTarget] = useState<Signature | null>(null);
const handleAdd = () => {
setEditingSignature(null);
setShowEditor(true);
};
const handleEdit = (sig: Signature) => {
setEditingSignature(sig);
setShowEditor(true);
};
const handleDuplicate = (id: string) => {
duplicateSignature(id);
};
const handleDeleteConfirm = () => {
if (deleteTarget) {
deleteSignature(deleteTarget.id);
setDeleteTarget(null);
}
};
const handleSave = (data: { name: string; body: string; plainText: string }) => {
if (editingSignature) {
updateSignature(editingSignature.id, data);
} else {
addSignature(data);
}
setShowEditor(false);
setEditingSignature(null);
};
const signatureOptions = [
{ value: '', label: t('no_signature') },
...signatures.map((sig) => ({ value: sig.id, label: sig.name })),
];
return (
<>
<SettingsSection title={t('title')} description={t('description')}>
<SettingItem
label={t('default_signature.label')}
description={t('default_signature.description')}
>
<div className="flex items-center gap-2">
<Select
value={defaultSignatureId ?? ''}
onChange={(value) => setDefaultSignatureId(value || null)}
options={signatureOptions}
ariaLabel={t('default_signature.label')}
/>
</div>
</SettingItem>
<SettingItem
label={t('reply_signature.label')}
description={t('reply_signature.description')}
>
<div className="flex items-center gap-2">
<Select
value={replySignatureId ?? ''}
onChange={(value) => setReplySignatureId(value || null)}
options={signatureOptions}
ariaLabel={t('reply_signature.label')}
/>
</div>
</SettingItem>
{identities.length > 0 && (
<SettingItem
label={t('per_identity_signatures.label')}
description={t('per_identity_signatures.description')}
>
<div className="space-y-2 max-w-xs">
{identities.map((identity) => {
const mapping = identitySignatureMap[identity.id] ?? {};
const identitySigOptions = [
{ value: '', label: t('use_global_default') },
...signatures.map((sig) => ({ value: sig.id, label: sig.name })),
];
return (
<div key={identity.id} className="border border-border rounded-md p-3 space-y-2">
<span className="text-sm font-medium block truncate">
{identity.name ? `${identity.name} <${identity.email}>` : identity.email}
</span>
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground w-16 shrink-0">
{t('default')}
</span>
<select
value={mapping.defaultId ?? ''}
onChange={(e) =>
setIdentitySignature(identity.id, 'default', e.target.value || null)
}
className="flex-1 px-2 py-1 text-xs rounded-md bg-muted border border-border text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
>
{identitySigOptions.map((opt) => (
<option key={opt.value} value={opt.value}>
{opt.label}
</option>
))}
</select>
</div>
<div className="flex items-center gap-2">
<span className="text-xs text-muted-foreground w-16 shrink-0">
{t('reply')}
</span>
<select
value={mapping.replyId ?? ''}
onChange={(e) =>
setIdentitySignature(identity.id, 'reply', e.target.value || null)
}
className="flex-1 px-2 py-1 text-xs rounded-md bg-muted border border-border text-foreground focus:outline-none focus:ring-2 focus:ring-ring"
>
{identitySigOptions.map((opt) => (
<option key={opt.value} value={opt.value}>
{opt.label}
</option>
))}
</select>
</div>
</div>
);
})}
</div>
</SettingItem>
)}
<div className="pt-2">
<div className="flex items-center justify-between mb-3">
<h4 className="text-sm font-medium text-foreground">
{t('your_signatures', { count: signatures.length })}
</h4>
<Button size="sm" onClick={handleAdd}>
<Plus className="w-4 h-4 me-1" />
{t('add_signature')}
</Button>
</div>
{signatures.length === 0 ? (
<p className="text-sm text-muted-foreground py-4 text-center">
{t('no_signatures')}
</p>
) : (
<div className="border border-border rounded-md divide-y divide-border">
{signatures.map((sig) => (
<div
key={sig.id}
className="flex items-center justify-between px-4 py-3 hover:bg-muted/50 transition-colors"
>
<button
type="button"
className="flex-1 flex items-center gap-3 min-w-0 text-start"
onClick={() => handleEdit(sig)}
>
<div className="min-w-0 flex-1">
<div className="text-sm font-medium text-foreground truncate">
{sig.name}
</div>
<div className="text-xs text-muted-foreground truncate mt-0.5">
{truncateText(sig.plainText, 80)}
</div>
</div>
<ChevronRight className="w-4 h-4 text-muted-foreground shrink-0" />
</button>
<div className="flex items-center gap-0.5 ml-2 shrink-0">
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleDuplicate(sig.id);
}}
title={t('duplicate')}
className="h-8 w-8 p-0"
>
<Copy className="w-4 h-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
handleEdit(sig);
}}
title={tCommon('edit')}
className="h-8 w-8 p-0"
>
<Pencil className="w-4 h-4" />
</Button>
<Button
variant="ghost"
size="sm"
onClick={(e) => {
e.stopPropagation();
setDeleteTarget(sig);
}}
title={tCommon('delete')}
className="h-8 w-8 p-0 text-destructive hover:text-destructive"
>
<Trash2 className="w-4 h-4" />
</Button>
</div>
</div>
))}
</div>
)}
</div>
</SettingsSection>
{showEditor && (
<SignatureEditorModal
signature={editingSignature}
onSave={handleSave}
onClose={() => {
setShowEditor(false);
setEditingSignature(null);
}}
/>
)}
<ConfirmDialog
isOpen={!!deleteTarget}
onClose={() => setDeleteTarget(null)}
onConfirm={handleDeleteConfirm}
title={t('delete_title')}
message={t('delete_message', { name: deleteTarget?.name ?? '' })}
variant="destructive"
confirmText={tCommon('delete')}
/>
</>
);
}