mirror of
http://172.20.10.11:3000/gitadmin/INSIGHT-MVP.git
synced 2026-06-24 23:56:40 +02:00
feat(frontend): add Lexware Office Import/Export admin page
New admin page under /crm/lexware-sync with two tabs: - Import: Search Lexware contacts and import as CRM company or contact - Export: List CRM companies/contacts and push to Lexware Office Accessible via CRM Settings page (admin-only). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
6b847cb9f6
commit
4f05026bc8
5 changed files with 1193 additions and 0 deletions
|
|
@ -487,6 +487,30 @@ export function useSyncFromLexware() {
|
|||
});
|
||||
}
|
||||
|
||||
export function useImportLexwareAsCompany() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { lexwareContactId: string }) =>
|
||||
lexwareContactsApi.importCompany(data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: crmKeys.companies.all });
|
||||
qc.invalidateQueries({ queryKey: crmKeys.lexware.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
export function useImportLexwareAsContact() {
|
||||
const qc = useQueryClient();
|
||||
return useMutation({
|
||||
mutationFn: (data: { lexwareContactId: string }) =>
|
||||
lexwareContactsApi.importContact(data),
|
||||
onSuccess: () => {
|
||||
qc.invalidateQueries({ queryKey: crmKeys.contacts.all });
|
||||
qc.invalidateQueries({ queryKey: crmKeys.lexware.all });
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Lexware Office — Vouchers
|
||||
// ============================================================
|
||||
|
|
|
|||
438
packages/frontend/src/crm/lexware/LexwareSyncPage.module.css
Normal file
438
packages/frontend/src/crm/lexware/LexwareSyncPage.module.css
Normal file
|
|
@ -0,0 +1,438 @@
|
|||
/* Lexware Sync Page */
|
||||
|
||||
.backLink {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.875rem;
|
||||
text-decoration: none;
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.backLink:hover {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.header {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.title {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.625rem;
|
||||
font-size: 1.5rem;
|
||||
font-weight: 600;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.lxBadge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 32px;
|
||||
height: 32px;
|
||||
border-radius: 6px;
|
||||
background: linear-gradient(135deg, #2563eb, #7c3aed);
|
||||
color: white;
|
||||
font-size: 0.75rem;
|
||||
font-weight: 700;
|
||||
letter-spacing: 0.5px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Tab Bar */
|
||||
.tabBar {
|
||||
display: flex;
|
||||
gap: 0;
|
||||
border-bottom: 2px solid var(--color-border);
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.tab {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.75rem 1.25rem;
|
||||
background: none;
|
||||
border: none;
|
||||
border-bottom: 2px solid transparent;
|
||||
margin-bottom: -2px;
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text-muted);
|
||||
cursor: pointer;
|
||||
transition: color 0.15s, border-color 0.15s;
|
||||
}
|
||||
|
||||
.tab:hover {
|
||||
color: var(--color-text);
|
||||
}
|
||||
|
||||
.tabActive {
|
||||
color: var(--color-primary);
|
||||
border-bottom-color: var(--color-primary);
|
||||
}
|
||||
|
||||
/* Card (tab content wrapper) */
|
||||
.card {
|
||||
background: var(--color-bg-card);
|
||||
border-radius: 0 0 var(--radius-md) var(--radius-md);
|
||||
box-shadow: var(--shadow-sm);
|
||||
border: 1px solid var(--color-border);
|
||||
border-top: none;
|
||||
padding: 1.5rem;
|
||||
}
|
||||
|
||||
.tabDesc {
|
||||
font-size: 0.875rem;
|
||||
color: var(--color-text-muted);
|
||||
margin: 0 0 1rem;
|
||||
}
|
||||
|
||||
/* Search input */
|
||||
.searchInput {
|
||||
width: 100%;
|
||||
padding: 0.625rem 0.875rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
font-size: 0.9375rem;
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text);
|
||||
outline: none;
|
||||
transition: border-color 0.15s;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.searchInput:focus {
|
||||
border-color: var(--color-primary);
|
||||
box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
|
||||
}
|
||||
|
||||
.searchInput::placeholder {
|
||||
color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
/* Results list */
|
||||
.resultsList {
|
||||
margin-top: 1rem;
|
||||
}
|
||||
|
||||
.hint {
|
||||
text-align: center;
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.875rem;
|
||||
padding: 1.5rem 0;
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
/* Result card */
|
||||
.resultCard {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.875rem 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.resultCard:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.resultInfo {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.resultName {
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.resultMeta {
|
||||
display: flex;
|
||||
flex-wrap: wrap;
|
||||
gap: 0.375rem;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 0.125rem;
|
||||
}
|
||||
|
||||
.roleBadge {
|
||||
display: inline-block;
|
||||
padding: 0 0.375rem;
|
||||
border-radius: 4px;
|
||||
background: #ede9fe;
|
||||
color: #6d28d9;
|
||||
font-size: 0.6875rem;
|
||||
font-weight: 600;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .roleBadge {
|
||||
background: #4c1d95;
|
||||
color: #c4b5fd;
|
||||
}
|
||||
|
||||
.resultActions {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Import buttons */
|
||||
.importBtn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-bg-card);
|
||||
color: var(--color-text-secondary);
|
||||
font-size: 0.8125rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.importBtn:hover:not(:disabled) {
|
||||
border-color: var(--color-primary);
|
||||
color: var(--color-primary);
|
||||
background: var(--color-primary-bg, #eff6ff);
|
||||
}
|
||||
|
||||
.importBtn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
/* Success / Error banners */
|
||||
.successBanner {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: #d1fae5;
|
||||
border: 1px solid #a7f3d0;
|
||||
border-radius: var(--radius-sm);
|
||||
color: #065f46;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .successBanner {
|
||||
background: #064e3b;
|
||||
border-color: #065f46;
|
||||
color: #a7f3d0;
|
||||
}
|
||||
|
||||
.errorBanner {
|
||||
padding: 0.625rem 0.875rem;
|
||||
background: #fee2e2;
|
||||
border: 1px solid #fecaca;
|
||||
border-radius: var(--radius-sm);
|
||||
color: #991b1b;
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
margin-top: 0.75rem;
|
||||
}
|
||||
|
||||
:global([data-theme='dark']) .errorBanner {
|
||||
background: #7f1d1d;
|
||||
border-color: #991b1b;
|
||||
color: #fecaca;
|
||||
}
|
||||
|
||||
/* Filter tabs (Export) */
|
||||
.filterTabs {
|
||||
display: flex;
|
||||
gap: 0.5rem;
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
|
||||
.filterTab {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.5rem 1rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: 9999px;
|
||||
background: var(--color-bg);
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.875rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
|
||||
.filterTab:hover {
|
||||
color: var(--color-text);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.filterTabActive {
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.filterTabActive:hover {
|
||||
color: white;
|
||||
border-color: var(--color-primary);
|
||||
}
|
||||
|
||||
.countBadge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-width: 20px;
|
||||
height: 20px;
|
||||
padding: 0 0.375rem;
|
||||
border-radius: 9999px;
|
||||
background: rgba(0, 0, 0, 0.1);
|
||||
font-size: 0.75rem;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.filterTabActive .countBadge {
|
||||
background: rgba(255, 255, 255, 0.2);
|
||||
}
|
||||
|
||||
/* Export sections */
|
||||
.exportSection {
|
||||
margin-bottom: 1.5rem;
|
||||
}
|
||||
|
||||
.exportSection:last-child {
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.exportSectionTitle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0.5rem;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 600;
|
||||
color: var(--color-text-muted);
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.025em;
|
||||
margin: 0 0 0.75rem;
|
||||
padding-bottom: 0.5rem;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.linkedDot {
|
||||
width: 8px;
|
||||
height: 8px;
|
||||
border-radius: 50%;
|
||||
background: #059669;
|
||||
display: inline-block;
|
||||
}
|
||||
|
||||
.exportList {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 0;
|
||||
}
|
||||
|
||||
.exportItem {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
gap: 1rem;
|
||||
padding: 0.625rem 0;
|
||||
border-bottom: 1px solid var(--color-border);
|
||||
}
|
||||
|
||||
.exportItem:last-child {
|
||||
border-bottom: none;
|
||||
}
|
||||
|
||||
.exportItemLinked {
|
||||
opacity: 0.75;
|
||||
}
|
||||
|
||||
.exportItemInfo {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.exportItemName {
|
||||
display: block;
|
||||
font-size: 0.9375rem;
|
||||
font-weight: 500;
|
||||
color: var(--color-text);
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.exportItemMeta {
|
||||
display: block;
|
||||
font-size: 0.8125rem;
|
||||
color: var(--color-text-muted);
|
||||
margin-top: 0.125rem;
|
||||
white-space: nowrap;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
/* Export button */
|
||||
.exportBtn {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border: none;
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-primary);
|
||||
color: white;
|
||||
font-size: 0.8125rem;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: opacity 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.exportBtn:hover:not(:disabled) {
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.exportBtn:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: wait;
|
||||
}
|
||||
|
||||
.exportBtnSecondary {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
gap: 0.375rem;
|
||||
padding: 0.375rem 0.75rem;
|
||||
border: 1px solid var(--color-border);
|
||||
border-radius: var(--radius-sm);
|
||||
background: var(--color-bg-card);
|
||||
color: var(--color-text-muted);
|
||||
font-size: 0.8125rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.exportBtnSecondary:hover:not(:disabled) {
|
||||
color: var(--color-text);
|
||||
border-color: var(--color-text-muted);
|
||||
}
|
||||
|
||||
.exportBtnSecondary:disabled {
|
||||
opacity: 0.5;
|
||||
cursor: wait;
|
||||
}
|
||||
666
packages/frontend/src/crm/lexware/LexwareSyncPage.tsx
Normal file
666
packages/frontend/src/crm/lexware/LexwareSyncPage.tsx
Normal file
|
|
@ -0,0 +1,666 @@
|
|||
import { useState, useEffect, useRef } from 'react';
|
||||
import { Link, Navigate } from 'react-router-dom';
|
||||
import { useAuth } from '../../auth/AuthContext';
|
||||
import { useCrmSettings } from '../settings/CrmSettingsContext';
|
||||
import {
|
||||
useLexwareContactSearch,
|
||||
useImportLexwareAsCompany,
|
||||
useImportLexwareAsContact,
|
||||
useCompanies,
|
||||
useContacts,
|
||||
usePushToLexware,
|
||||
} from '../hooks';
|
||||
import type { LexwareContact, Company, Contact } from '../types';
|
||||
import styles from './LexwareSyncPage.module.css';
|
||||
|
||||
// ============================================================
|
||||
// Helpers
|
||||
// ============================================================
|
||||
|
||||
function lexwareDisplayName(c: LexwareContact): string {
|
||||
const companyName = c.company?.name;
|
||||
const personName = [c.person?.firstName, c.person?.lastName]
|
||||
.filter(Boolean)
|
||||
.join(' ');
|
||||
if (companyName && personName) return `${companyName} (${personName})`;
|
||||
return companyName || personName || 'Unbenannt';
|
||||
}
|
||||
|
||||
function lexwareEmail(c: LexwareContact): string | null {
|
||||
const emails = c.emailAddresses;
|
||||
if (!emails) return null;
|
||||
return (
|
||||
emails.business?.[0] ??
|
||||
emails.office?.[0] ??
|
||||
emails.private?.[0] ??
|
||||
emails.other?.[0] ??
|
||||
null
|
||||
);
|
||||
}
|
||||
|
||||
function lexwareAddress(c: LexwareContact): string | null {
|
||||
const addr = c.addresses?.billing?.[0] ?? c.addresses?.shipping?.[0];
|
||||
if (!addr) return null;
|
||||
const parts = [addr.street, [addr.zip, addr.city].filter(Boolean).join(' ')];
|
||||
return parts.filter(Boolean).join(', ') || null;
|
||||
}
|
||||
|
||||
function lexwareRoles(c: LexwareContact): string {
|
||||
const roles: string[] = [];
|
||||
if (c.roles?.customer) roles.push('Kunde');
|
||||
if (c.roles?.vendor) roles.push('Lieferant');
|
||||
return roles.join(', ') || '—';
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Import Tab — Lexware → CRM
|
||||
// ============================================================
|
||||
|
||||
function ImportTab() {
|
||||
const [searchTerm, setSearchTerm] = useState('');
|
||||
const [debouncedTerm, setDebouncedTerm] = useState('');
|
||||
const [successMessage, setSuccessMessage] = useState('');
|
||||
const inputRef = useRef<HTMLInputElement>(null);
|
||||
|
||||
const importAsCompany = useImportLexwareAsCompany();
|
||||
const importAsContact = useImportLexwareAsContact();
|
||||
|
||||
useEffect(() => {
|
||||
setTimeout(() => inputRef.current?.focus(), 100);
|
||||
}, []);
|
||||
|
||||
// Debounce
|
||||
useEffect(() => {
|
||||
const timer = setTimeout(() => {
|
||||
setDebouncedTerm(searchTerm.trim());
|
||||
}, 400);
|
||||
return () => clearTimeout(timer);
|
||||
}, [searchTerm]);
|
||||
|
||||
const { data, isLoading } = useLexwareContactSearch(
|
||||
{ name: debouncedTerm },
|
||||
debouncedTerm.length >= 2,
|
||||
);
|
||||
|
||||
const results: LexwareContact[] = data?.data ?? [];
|
||||
const isImporting = importAsCompany.isPending || importAsContact.isPending;
|
||||
|
||||
const handleImportAsCompany = (lexwareContactId: string, name: string) => {
|
||||
importAsCompany.mutate(
|
||||
{ lexwareContactId },
|
||||
{
|
||||
onSuccess: () => {
|
||||
setSuccessMessage(`"${name}" als Unternehmen importiert`);
|
||||
setTimeout(() => setSuccessMessage(''), 4000);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const handleImportAsContact = (lexwareContactId: string, name: string) => {
|
||||
importAsContact.mutate(
|
||||
{ lexwareContactId },
|
||||
{
|
||||
onSuccess: () => {
|
||||
setSuccessMessage(`"${name}" als Kontakt importiert`);
|
||||
setTimeout(() => setSuccessMessage(''), 4000);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p className={styles.tabDesc}>
|
||||
Lexware Office Kontakte durchsuchen und als Unternehmen oder Kontakt in
|
||||
das CRM importieren.
|
||||
</p>
|
||||
|
||||
<input
|
||||
ref={inputRef}
|
||||
type="text"
|
||||
className={styles.searchInput}
|
||||
placeholder="Name oder Firma in Lexware suchen..."
|
||||
value={searchTerm}
|
||||
onChange={(e) => setSearchTerm(e.target.value)}
|
||||
/>
|
||||
|
||||
{successMessage && (
|
||||
<div className={styles.successBanner}>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M3 8.5l3 3 7-7" />
|
||||
</svg>
|
||||
{successMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{(importAsCompany.isError || importAsContact.isError) && (
|
||||
<div className={styles.errorBanner}>
|
||||
Import fehlgeschlagen:{' '}
|
||||
{(importAsCompany.error ?? importAsContact.error)?.message ??
|
||||
'Unbekannter Fehler'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
<div className={styles.resultsList}>
|
||||
{debouncedTerm.length < 2 && (
|
||||
<p className={styles.hint}>Mindestens 2 Zeichen eingeben...</p>
|
||||
)}
|
||||
|
||||
{debouncedTerm.length >= 2 && isLoading && (
|
||||
<p className={styles.hint}>Suche in Lexware Office...</p>
|
||||
)}
|
||||
|
||||
{debouncedTerm.length >= 2 && !isLoading && results.length === 0 && (
|
||||
<p className={styles.hint}>Keine Ergebnisse gefunden</p>
|
||||
)}
|
||||
|
||||
{results.map((contact) => {
|
||||
const name = lexwareDisplayName(contact);
|
||||
const email = lexwareEmail(contact);
|
||||
const address = lexwareAddress(contact);
|
||||
const roles = lexwareRoles(contact);
|
||||
|
||||
return (
|
||||
<div key={contact.id} className={styles.resultCard}>
|
||||
<div className={styles.resultInfo}>
|
||||
<div className={styles.resultName}>{name}</div>
|
||||
<div className={styles.resultMeta}>
|
||||
{roles !== '—' && (
|
||||
<span className={styles.roleBadge}>{roles}</span>
|
||||
)}
|
||||
{email && <span>{email}</span>}
|
||||
{address && <span>{address}</span>}
|
||||
</div>
|
||||
</div>
|
||||
<div className={styles.resultActions}>
|
||||
<button
|
||||
className={styles.importBtn}
|
||||
disabled={isImporting}
|
||||
onClick={() => handleImportAsCompany(contact.id, name)}
|
||||
title="Als Unternehmen importieren"
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<rect x="2" y="6" width="12" height="9" rx="1" />
|
||||
<path d="M5 6V3a1 1 0 011-1h4a1 1 0 011 1v3" />
|
||||
</svg>
|
||||
Unternehmen
|
||||
</button>
|
||||
<button
|
||||
className={styles.importBtn}
|
||||
disabled={isImporting}
|
||||
onClick={() => handleImportAsContact(contact.id, name)}
|
||||
title="Als Kontakt importieren"
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<circle cx="8" cy="5" r="3" />
|
||||
<path d="M2 14c0-2.5 2.5-4.5 6-4.5s6 2 6 4.5" />
|
||||
</svg>
|
||||
Kontakt
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// Export Tab — CRM → Lexware
|
||||
// ============================================================
|
||||
|
||||
function ExportTab() {
|
||||
const [entityFilter, setEntityFilter] = useState<'companies' | 'contacts'>(
|
||||
'companies',
|
||||
);
|
||||
const [successMessage, setSuccessMessage] = useState('');
|
||||
|
||||
const pushToLexware = usePushToLexware();
|
||||
|
||||
// Fetch all companies (page 1, big page size)
|
||||
const companiesQuery = useCompanies({
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
sort: 'name',
|
||||
order: 'asc',
|
||||
});
|
||||
const contactsQuery = useContacts({
|
||||
page: 1,
|
||||
pageSize: 200,
|
||||
sort: 'lastName',
|
||||
order: 'asc',
|
||||
});
|
||||
|
||||
const companies: Company[] = companiesQuery.data?.data ?? [];
|
||||
const contacts: Contact[] = contactsQuery.data?.data ?? [];
|
||||
|
||||
// Split into linked / unlinked
|
||||
const unlinkedCompanies = companies.filter((c) => !c.lexwareContactId);
|
||||
const linkedCompanies = companies.filter((c) => !!c.lexwareContactId);
|
||||
const unlinkedContacts = contacts.filter((c) => !c.lexwareContactId);
|
||||
const linkedContacts = contacts.filter((c) => !!c.lexwareContactId);
|
||||
|
||||
const handlePush = (
|
||||
entityType: 'company' | 'contact',
|
||||
entityId: string,
|
||||
name: string,
|
||||
) => {
|
||||
pushToLexware.mutate(
|
||||
{ entityType, entityId },
|
||||
{
|
||||
onSuccess: () => {
|
||||
setSuccessMessage(`"${name}" nach Lexware exportiert`);
|
||||
setTimeout(() => setSuccessMessage(''), 4000);
|
||||
},
|
||||
},
|
||||
);
|
||||
};
|
||||
|
||||
const isExporting = pushToLexware.isPending;
|
||||
|
||||
return (
|
||||
<div>
|
||||
<p className={styles.tabDesc}>
|
||||
CRM-Daten zu Lexware Office exportieren. Noch nicht verknüpfte Einträge
|
||||
werden als neue Lexware-Kontakte angelegt.
|
||||
</p>
|
||||
|
||||
{/* Filter Tabs */}
|
||||
<div className={styles.filterTabs}>
|
||||
<button
|
||||
className={`${styles.filterTab} ${entityFilter === 'companies' ? styles.filterTabActive : ''}`}
|
||||
onClick={() => setEntityFilter('companies')}
|
||||
>
|
||||
Unternehmen
|
||||
<span className={styles.countBadge}>{companies.length}</span>
|
||||
</button>
|
||||
<button
|
||||
className={`${styles.filterTab} ${entityFilter === 'contacts' ? styles.filterTabActive : ''}`}
|
||||
onClick={() => setEntityFilter('contacts')}
|
||||
>
|
||||
Kontakte
|
||||
<span className={styles.countBadge}>{contacts.length}</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{successMessage && (
|
||||
<div className={styles.successBanner}>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M3 8.5l3 3 7-7" />
|
||||
</svg>
|
||||
{successMessage}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{pushToLexware.isError && (
|
||||
<div className={styles.errorBanner}>
|
||||
Export fehlgeschlagen: {pushToLexware.error?.message ?? 'Unbekannter Fehler'}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Companies */}
|
||||
{entityFilter === 'companies' && (
|
||||
<>
|
||||
{companiesQuery.isLoading ? (
|
||||
<p className={styles.hint}>Unternehmen werden geladen...</p>
|
||||
) : companies.length === 0 ? (
|
||||
<p className={styles.hint}>Keine Unternehmen vorhanden</p>
|
||||
) : (
|
||||
<>
|
||||
{/* Unlinked first */}
|
||||
{unlinkedCompanies.length > 0 && (
|
||||
<div className={styles.exportSection}>
|
||||
<h3 className={styles.exportSectionTitle}>
|
||||
Noch nicht verknüpft ({unlinkedCompanies.length})
|
||||
</h3>
|
||||
<div className={styles.exportList}>
|
||||
{unlinkedCompanies.map((c) => (
|
||||
<div key={c.id} className={styles.exportItem}>
|
||||
<div className={styles.exportItemInfo}>
|
||||
<span className={styles.exportItemName}>{c.name}</span>
|
||||
<span className={styles.exportItemMeta}>
|
||||
{[c.email, c.city].filter(Boolean).join(' · ') ||
|
||||
'Keine Details'}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
className={styles.exportBtn}
|
||||
disabled={isExporting}
|
||||
onClick={() =>
|
||||
handlePush('company', c.id, c.name)
|
||||
}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M8 12V3M4 7l4-4 4 4" />
|
||||
</svg>
|
||||
{isExporting ? 'Export...' : 'Exportieren'}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Linked */}
|
||||
{linkedCompanies.length > 0 && (
|
||||
<div className={styles.exportSection}>
|
||||
<h3 className={styles.exportSectionTitle}>
|
||||
<span className={styles.linkedDot} />
|
||||
Bereits verknüpft ({linkedCompanies.length})
|
||||
</h3>
|
||||
<div className={styles.exportList}>
|
||||
{linkedCompanies.map((c) => (
|
||||
<div
|
||||
key={c.id}
|
||||
className={`${styles.exportItem} ${styles.exportItemLinked}`}
|
||||
>
|
||||
<div className={styles.exportItemInfo}>
|
||||
<span className={styles.exportItemName}>{c.name}</span>
|
||||
<span className={styles.exportItemMeta}>
|
||||
{c.lexwareSyncedAt
|
||||
? `Sync: ${new Date(c.lexwareSyncedAt).toLocaleDateString('de-DE')}`
|
||||
: 'Verknüpft'}
|
||||
{c.email ? ` · ${c.email}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
className={styles.exportBtnSecondary}
|
||||
disabled={isExporting}
|
||||
onClick={() =>
|
||||
handlePush('company', c.id, c.name)
|
||||
}
|
||||
title="Erneut synchronisieren"
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M1 8a7 7 0 0112.9-3.8M15 8a7 7 0 01-12.9 3.8" />
|
||||
<path d="M14 1v3.2h-3.2M2 15v-3.2h3.2" />
|
||||
</svg>
|
||||
Re-Push
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
|
||||
{/* Contacts */}
|
||||
{entityFilter === 'contacts' && (
|
||||
<>
|
||||
{contactsQuery.isLoading ? (
|
||||
<p className={styles.hint}>Kontakte werden geladen...</p>
|
||||
) : contacts.length === 0 ? (
|
||||
<p className={styles.hint}>Keine Kontakte vorhanden</p>
|
||||
) : (
|
||||
<>
|
||||
{/* Unlinked first */}
|
||||
{unlinkedContacts.length > 0 && (
|
||||
<div className={styles.exportSection}>
|
||||
<h3 className={styles.exportSectionTitle}>
|
||||
Noch nicht verknüpft ({unlinkedContacts.length})
|
||||
</h3>
|
||||
<div className={styles.exportList}>
|
||||
{unlinkedContacts.map((c) => {
|
||||
const name =
|
||||
[c.firstName, c.lastName].filter(Boolean).join(' ') ||
|
||||
c.companyName ||
|
||||
'—';
|
||||
return (
|
||||
<div key={c.id} className={styles.exportItem}>
|
||||
<div className={styles.exportItemInfo}>
|
||||
<span className={styles.exportItemName}>{name}</span>
|
||||
<span className={styles.exportItemMeta}>
|
||||
{[c.email, c.city, c.company?.name]
|
||||
.filter(Boolean)
|
||||
.join(' · ') || 'Keine Details'}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
className={styles.exportBtn}
|
||||
disabled={isExporting}
|
||||
onClick={() =>
|
||||
handlePush('contact', c.id, name)
|
||||
}
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M8 12V3M4 7l4-4 4 4" />
|
||||
</svg>
|
||||
{isExporting ? 'Export...' : 'Exportieren'}
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Linked */}
|
||||
{linkedContacts.length > 0 && (
|
||||
<div className={styles.exportSection}>
|
||||
<h3 className={styles.exportSectionTitle}>
|
||||
<span className={styles.linkedDot} />
|
||||
Bereits verknüpft ({linkedContacts.length})
|
||||
</h3>
|
||||
<div className={styles.exportList}>
|
||||
{linkedContacts.map((c) => {
|
||||
const name =
|
||||
[c.firstName, c.lastName].filter(Boolean).join(' ') ||
|
||||
c.companyName ||
|
||||
'—';
|
||||
return (
|
||||
<div
|
||||
key={c.id}
|
||||
className={`${styles.exportItem} ${styles.exportItemLinked}`}
|
||||
>
|
||||
<div className={styles.exportItemInfo}>
|
||||
<span className={styles.exportItemName}>{name}</span>
|
||||
<span className={styles.exportItemMeta}>
|
||||
{c.lexwareSyncedAt
|
||||
? `Sync: ${new Date(c.lexwareSyncedAt).toLocaleDateString('de-DE')}`
|
||||
: 'Verknüpft'}
|
||||
{c.email ? ` · ${c.email}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
<button
|
||||
className={styles.exportBtnSecondary}
|
||||
disabled={isExporting}
|
||||
onClick={() =>
|
||||
handlePush('contact', c.id, name)
|
||||
}
|
||||
title="Erneut synchronisieren"
|
||||
>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M1 8a7 7 0 0112.9-3.8M15 8a7 7 0 01-12.9 3.8" />
|
||||
<path d="M14 1v3.2h-3.2M2 15v-3.2h3.2" />
|
||||
</svg>
|
||||
Re-Push
|
||||
</button>
|
||||
</div>
|
||||
);
|
||||
})}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</>
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
// ============================================================
|
||||
// LexwareSyncPage — Main
|
||||
// ============================================================
|
||||
|
||||
type TabKey = 'import' | 'export';
|
||||
|
||||
export function LexwareSyncPage() {
|
||||
const { user } = useAuth();
|
||||
const { isModuleEnabled } = useCrmSettings();
|
||||
const [activeTab, setActiveTab] = useState<TabKey>('import');
|
||||
|
||||
// Zugriffskontrolle
|
||||
if (
|
||||
user?.role !== 'PLATFORM_ADMIN' &&
|
||||
user?.role !== 'TENANT_ADMIN'
|
||||
) {
|
||||
return <Navigate to="/" replace />;
|
||||
}
|
||||
|
||||
if (!isModuleEnabled('lexware')) {
|
||||
return <Navigate to="/crm/settings" replace />;
|
||||
}
|
||||
|
||||
return (
|
||||
<div>
|
||||
{/* Zurück */}
|
||||
<Link to="/crm/settings" className={styles.backLink}>
|
||||
<svg
|
||||
width="14"
|
||||
height="14"
|
||||
viewBox="0 0 14 14"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
>
|
||||
<path d="M9 2L4 7l5 5" />
|
||||
</svg>
|
||||
Zurück zu CRM Einstellungen
|
||||
</Link>
|
||||
|
||||
{/* Header */}
|
||||
<div className={styles.header}>
|
||||
<h1 className={styles.title}>
|
||||
<span className={styles.lxBadge}>LX</span>
|
||||
Lexware Office Synchronisation
|
||||
</h1>
|
||||
</div>
|
||||
|
||||
{/* Tab Bar */}
|
||||
<div className={styles.tabBar}>
|
||||
<button
|
||||
className={`${styles.tab} ${activeTab === 'import' ? styles.tabActive : ''}`}
|
||||
onClick={() => setActiveTab('import')}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M8 3v9M4 8l4 4 4-4" />
|
||||
<path d="M2 14h12" />
|
||||
</svg>
|
||||
Import (Lexware → CRM)
|
||||
</button>
|
||||
<button
|
||||
className={`${styles.tab} ${activeTab === 'export' ? styles.tabActive : ''}`}
|
||||
onClick={() => setActiveTab('export')}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M8 12V3M4 7l4-4 4 4" />
|
||||
<path d="M2 14h12" />
|
||||
</svg>
|
||||
Export (CRM → Lexware)
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* Tab Content */}
|
||||
<div className={styles.card}>
|
||||
{activeTab === 'import' && <ImportTab />}
|
||||
{activeTab === 'export' && <ExportTab />}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
@ -224,6 +224,69 @@ export function CrmSettingsPage() {
|
|||
)}
|
||||
</div>
|
||||
|
||||
{/* Lexware Synchronisation — nur wenn Modul aktiv */}
|
||||
{settings.modules.lexware?.enabled && (
|
||||
<div className={styles.card}>
|
||||
<h2 className={styles.cardTitle}>
|
||||
<span
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
justifyContent: 'center',
|
||||
width: 24,
|
||||
height: 24,
|
||||
borderRadius: 4,
|
||||
background: 'linear-gradient(135deg, #2563eb, #7c3aed)',
|
||||
color: 'white',
|
||||
fontSize: '0.5625rem',
|
||||
fontWeight: 700,
|
||||
letterSpacing: '0.5px',
|
||||
marginRight: '0.5rem',
|
||||
verticalAlign: 'middle',
|
||||
}}
|
||||
>
|
||||
LX
|
||||
</span>
|
||||
Lexware Office Synchronisation
|
||||
</h2>
|
||||
<p className={styles.cardDesc}>
|
||||
Kontakte aus Lexware Office importieren oder CRM-Daten nach Lexware
|
||||
exportieren.
|
||||
</p>
|
||||
<Link
|
||||
to="/crm/lexware-sync"
|
||||
style={{
|
||||
display: 'inline-flex',
|
||||
alignItems: 'center',
|
||||
gap: '0.5rem',
|
||||
padding: '0.5rem 1rem',
|
||||
background: 'var(--color-primary)',
|
||||
color: 'white',
|
||||
borderRadius: 'var(--radius-sm)',
|
||||
textDecoration: 'none',
|
||||
fontSize: '0.875rem',
|
||||
fontWeight: 500,
|
||||
transition: 'opacity 0.15s',
|
||||
}}
|
||||
>
|
||||
<svg
|
||||
width="16"
|
||||
height="16"
|
||||
viewBox="0 0 16 16"
|
||||
fill="none"
|
||||
stroke="currentColor"
|
||||
strokeWidth="1.5"
|
||||
strokeLinecap="round"
|
||||
strokeLinejoin="round"
|
||||
>
|
||||
<path d="M1 8a7 7 0 0112.9-3.8M15 8a7 7 0 01-12.9 3.8" />
|
||||
<path d="M14 1v3.2h-3.2M2 15v-3.2h3.2" />
|
||||
</svg>
|
||||
Import / Export öffnen
|
||||
</Link>
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Platzhalter für zukünftige Einstellungen */}
|
||||
<div className={styles.card} style={{ opacity: 0.6 }}>
|
||||
<h2 className={styles.cardTitle}>Weitere Einstellungen</h2>
|
||||
|
|
|
|||
|
|
@ -20,6 +20,7 @@ import { CompaniesPage } from '../crm/companies/CompaniesPage';
|
|||
import { CompanyDetailPage } from '../crm/companies/CompanyDetailPage';
|
||||
import { CrmSettingsProvider, CrmModuleGuard } from '../crm/settings/CrmSettingsContext';
|
||||
import { CrmSettingsPage } from '../crm/settings/CrmSettingsPage';
|
||||
import { LexwareSyncPage } from '../crm/lexware/LexwareSyncPage';
|
||||
|
||||
function PrivateRoute({ children }: { children: React.ReactNode }) {
|
||||
const { isAuthenticated, isLoading } = useAuth();
|
||||
|
|
@ -68,6 +69,7 @@ export function App() {
|
|||
<Route path="crm/deals/:id" element={<CrmModuleGuard module="deals"><DealDetailPage /></CrmModuleGuard>} />
|
||||
<Route path="crm/pipelines" element={<CrmModuleGuard module="pipelines"><PipelinesPage /></CrmModuleGuard>} />
|
||||
<Route path="crm/settings" element={<CrmSettingsPage />} />
|
||||
<Route path="crm/lexware-sync" element={<LexwareSyncPage />} />
|
||||
{/* Admin-Bereich mit eigenem Layout (Top-Tabs) */}
|
||||
<Route path="admin" element={<AdminLayout />}>
|
||||
<Route index element={<Navigate to="users" replace />} />
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue