1 line
No EOL
11 KiB
JavaScript
1 line
No EOL
11 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,67240,e=>{"use strict";let s=(0,e.i(75254).default)("RotateCcw",[["path",{d:"M3 12a9 9 0 1 0 9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"1357e3"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}]]);e.s(["RotateCcw",0,s],67240)},95468,e=>{"use strict";let s=(0,e.i(75254).default)("CircleCheck",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);e.s(["CheckCircle2",0,s],95468)},66531,e=>{"use strict";let s=(0,e.i(75254).default)("CloudUpload",[["path",{d:"M12 13v8",key:"1l5pq0"}],["path",{d:"M4 14.899A7 7 0 1 1 15.71 8h1.79a4.5 4.5 0 0 1 2.5 8.242",key:"1pljnt"}],["path",{d:"m8 17 4-4 4 4",key:"1quai1"}]]);e.s(["UploadCloud",0,s],66531)},78894,e=>{"use strict";let s=(0,e.i(75254).default)("TriangleAlert",[["path",{d:"m21.73 18-8-14a2 2 0 0 0-3.48 0l-8 14A2 2 0 0 0 4 21h16a2 2 0 0 0 1.73-3",key:"wmoenq"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);e.s(["AlertTriangle",0,s],78894)},92158,e=>{"use strict";var s=e.i(43476),t=e.i(78894),r=e.i(95468),a=e.i(43527),l=e.i(67240),n=e.i(66531),i=e.i(22016),c=e.i(71645),d=e.i(28779);let o={NEU_ANLEGEN:"Neu anlegen",BESTEHENDEN_AKTUALISIEREN:"Aktualisieren",UEBERSPRINGEN:"Überspringen",ERROR:"Fehler"},m=[{value:"all",label:"Alle"},{value:"NEU_ANLEGEN",label:"Neu"},{value:"BESTEHENDEN_AKTUALISIEREN",label:"Aktualisieren"},{value:"duplicates",label:"Mögliche Dubletten"},{value:"ERROR",label:"Fehler"},{value:"UEBERSPRINGEN",label:"Überspringen"}];async function u(e,s){try{return(await e.json()).detail??s}catch{return s}}function h({label:e,value:t}){return(0,s.jsxs)("div",{className:"rounded-lg border border-border bg-white p-3",children:[(0,s.jsx)("div",{className:"text-2xl font-semibold",children:t??0}),(0,s.jsx)("div",{className:"text-sm text-text-light",children:e})]})}e.s(["default",0,function(){let{user:e}=(0,d.useAuth)(),[x,p]=(0,c.useState)(null),[b,g]=(0,c.useState)(null),[j,N]=(0,c.useState)({}),[f,v]=(0,c.useState)({}),[y,w]=(0,c.useState)("all"),[k,S]=(0,c.useState)(!0),[E,C]=(0,c.useState)(null),[_,A]=(0,c.useState)(""),[R,U]=(0,c.useState)(""),z=(0,c.useMemo)(()=>{let e=b?.rows??[];return"all"===y?e:"duplicates"===y?e.filter(e=>e.matches&&Object.keys(e.matches).length>0&&"UEBERSPRINGEN"===e.action):e.filter(e=>(f[String(e.row_number)]??e.action)===y)},[y,b?.rows,f]);if(e?.role!=="admin")return(0,s.jsx)("div",{className:"rounded-lg border border-border bg-surface p-6 text-text-light",children:"Nur fuer Administratoren verfuegbar."});async function T(e){if(!x)return void U("Bitte zuerst eine Datei auswählen.");A("preview"),U(""),C(null);let s=new FormData;s.set("file",x),e&&s.set("mapping",JSON.stringify(e));let t=await fetch("/api/customer-imports/preview",{method:"POST",body:s,credentials:"include"});if(!t.ok){U(await u(t,"Importvorschau konnte nicht erzeugt werden.")),A("");return}let r=await t.json();g(r),N(r.mapping),v(Object.fromEntries(r.rows.map(e=>[String(e.row_number),e.action]))),A("")}async function I(){if(!x||!b)return;A("confirm"),U("");let e=new FormData;e.set("file",x),e.set("mapping",JSON.stringify(j)),e.set("row_actions",JSON.stringify(f)),e.set("ignore_empty_values",String(k));let s=await fetch("/api/customer-imports/confirm",{method:"POST",body:e,credentials:"include"});if(!s.ok){U(await u(s,"Kundenimport konnte nicht ausgeführt werden.")),A("");return}C(await s.json()),A("")}return(0,s.jsxs)("div",{className:"space-y-6 pb-10",children:[(0,s.jsxs)("header",{className:"flex flex-col gap-3 md:flex-row md:items-center md:justify-between",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h1",{className:"text-3xl font-semibold text-text",children:"Kunden importieren"}),(0,s.jsx)("p",{className:"mt-2 text-text-light",children:"CSV- oder XLSX-Kundenstamm kontrolliert prüfen und übernehmen."})]}),(0,s.jsx)(i.default,{href:"/customers",className:"btn btn-secondary h-12",children:"Zur Kundenliste"})]}),R?(0,s.jsx)("div",{className:"rounded-lg border border-danger/40 bg-danger/10 p-4 text-sm text-danger",children:R}):null,(0,s.jsx)("section",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:(0,s.jsxs)("div",{className:"flex items-start gap-4",children:[(0,s.jsx)("div",{className:"rounded-lg bg-accent/20 p-3 text-primary",children:(0,s.jsx)(n.UploadCloud,{className:"h-6 w-6"})}),(0,s.jsxs)("div",{className:"flex-1",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold",children:"1. Datei hochladen"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-text-light",children:"Erlaubt sind UTF-8 CSV und XLSX bis 5 MB. Der Upload verändert noch keine Daten."}),(0,s.jsxs)("label",{className:"mt-4 flex min-h-32 cursor-pointer flex-col items-center justify-center rounded-lg border border-dashed border-primary/40 bg-background p-5 text-center transition hover:border-primary hover:bg-accent/10",children:[(0,s.jsx)(a.FileUp,{className:"h-7 w-7 text-primary"}),(0,s.jsx)("span",{className:"mt-2 font-semibold",children:x?x.name:"Datei auswählen oder hier ablegen"}),(0,s.jsx)("span",{className:"text-sm text-text-light",children:"CSV oder XLSX"}),(0,s.jsx)("input",{type:"file",accept:".csv,.xlsx,text/csv,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",className:"sr-only",onChange:e=>{p(e.target.files?.[0]??null),g(null),C(null)}})]}),(0,s.jsxs)("div",{className:"mt-4 flex flex-wrap gap-3",children:[(0,s.jsxs)("button",{type:"button",className:"btn btn-primary h-12",disabled:!x||"preview"===_,onClick:()=>T(),children:["preview"===_?(0,s.jsx)("span",{className:"spinner"}):null,"Vorschau vorbereiten"]}),(0,s.jsxs)("button",{type:"button",className:"btn btn-secondary h-12",onClick:function(){p(null),g(null),N({}),v({}),C(null),U("")},children:[(0,s.jsx)(l.RotateCcw,{className:"h-4 w-4"})," Zurücksetzen"]})]})]})]})}),b?(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("section",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold",children:"2. Spalten zuordnen"}),(0,s.jsx)("p",{className:"mt-1 text-sm text-text-light",children:"Bitte automatische Zuordnung prüfen und bei Bedarf ändern."}),b.warnings.map(e=>(0,s.jsxs)("div",{className:"mt-3 flex items-center gap-2 rounded-lg border border-warning/40 bg-warning/10 p-3 text-sm text-[#7A5A00]",children:[(0,s.jsx)(t.AlertTriangle,{className:"h-4 w-4"})," ",e]},e)),(0,s.jsx)("div",{className:"mt-4 grid gap-3 md:grid-cols-2",children:b.columns.map(e=>(0,s.jsxs)("label",{className:"grid gap-2 rounded-lg border border-border p-3",children:[(0,s.jsx)("span",{className:"text-sm font-semibold",children:e}),(0,s.jsx)("select",{value:j[e]??"ignore",onChange:s=>N(t=>({...t,[e]:s.target.value})),className:"h-11 rounded-lg border border-border px-3",children:Object.entries(b.target_fields).map(([e,t])=>(0,s.jsx)("option",{value:e,children:t},e))})]},e))}),(0,s.jsxs)("button",{type:"button",className:"btn btn-secondary mt-4 h-12",disabled:"preview"===_,onClick:()=>T(j),children:["preview"===_?(0,s.jsx)("span",{className:"spinner"}):null,"Vorschau mit Zuordnung aktualisieren"]})]}),(0,s.jsxs)("section",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold",children:"3. Importvorschau prüfen"}),(0,s.jsx)("div",{className:"mt-3 flex flex-wrap gap-2",children:m.map(e=>(0,s.jsx)("button",{type:"button",onClick:()=>w(e.value),className:`rounded-lg border px-3 py-2 text-sm font-semibold transition hover:shadow-soft ${y===e.value?"border-primary bg-primary text-white":"border-border bg-white text-text"}`,children:e.label},e.value))}),(0,s.jsx)("div",{className:"mt-4 overflow-x-auto",children:(0,s.jsxs)("table",{className:"min-w-full text-left text-sm",children:[(0,s.jsx)("thead",{className:"bg-background text-xs uppercase text-text-light",children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{className:"px-4 py-3",children:"Zeile"}),(0,s.jsx)("th",{className:"px-4 py-3",children:"Kunde"}),(0,s.jsx)("th",{className:"px-4 py-3",children:"Standort"}),(0,s.jsx)("th",{className:"px-4 py-3",children:"Ansprechpartner"}),(0,s.jsx)("th",{className:"px-4 py-3",children:"Hinweis"}),(0,s.jsx)("th",{className:"px-4 py-3",children:"Aktion"})]})}),(0,s.jsx)("tbody",{className:"divide-y divide-border",children:z.map(e=>{let t=f[String(e.row_number)]??e.action;return(0,s.jsxs)("tr",{className:"hover:bg-accent/10",children:[(0,s.jsx)("td",{className:"px-4 py-3",children:e.row_number}),(0,s.jsxs)("td",{className:"px-4 py-3",children:[(0,s.jsx)("strong",{children:e.recognized.customer.name||"nicht erkannt"}),(0,s.jsx)("br",{}),(0,s.jsx)("span",{className:"text-text-light",children:e.recognized.customer.external_id||e.recognized.customer.email})]}),(0,s.jsxs)("td",{className:"px-4 py-3",children:[e.recognized.location.name,(0,s.jsx)("br",{}),(0,s.jsxs)("span",{className:"text-text-light",children:[e.recognized.location.postal_code," ",e.recognized.location.city]})]}),(0,s.jsx)("td",{className:"px-4 py-3",children:e.recognized.contact.full_name||"nicht erfasst"}),(0,s.jsx)("td",{className:"px-4 py-3",children:e.errors.length?(0,s.jsx)("span",{className:"text-danger",children:e.errors.join(", ")}):e.message}),(0,s.jsx)("td",{className:"px-4 py-3",children:(0,s.jsx)("select",{value:t,disabled:e.allowed_actions.length<=1,onChange:s=>v(t=>({...t,[String(e.row_number)]:s.target.value})),className:"h-10 rounded-lg border border-border px-3",children:e.allowed_actions.map(e=>(0,s.jsx)("option",{value:e,children:o[e]},e))})})]},e.row_number)})})]})})]}),(0,s.jsxs)("section",{className:"rounded-lg border border-border bg-surface p-5 shadow-soft",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold",children:"4. Import bestätigen"}),(0,s.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-5",children:[(0,s.jsx)(h,{label:"Zeilen",value:b.summary.total}),(0,s.jsx)(h,{label:"Neu",value:b.summary.new}),(0,s.jsx)(h,{label:"Aktualisieren",value:b.summary.update}),(0,s.jsx)(h,{label:"Dubletten",value:b.summary.duplicates}),(0,s.jsx)(h,{label:"Fehler",value:b.summary.errors})]}),(0,s.jsxs)("label",{className:"mt-4 flex items-center gap-3 text-sm font-semibold",children:[(0,s.jsx)("input",{type:"checkbox",checked:k,onChange:e=>S(e.target.checked),className:"h-5 w-5"}),"Leere Importfelder ignorieren"]}),(0,s.jsxs)("button",{type:"button",className:"btn btn-primary mt-4 h-12",disabled:"confirm"===_||!b.rows.length,onClick:I,children:["confirm"===_?(0,s.jsx)("span",{className:"spinner"}):(0,s.jsx)(r.CheckCircle2,{className:"h-4 w-4"}),"confirm"===_?"Import läuft...":"Kunden jetzt importieren"]})]})]}):null,E?(0,s.jsxs)("section",{className:"rounded-lg border border-success/40 bg-success/10 p-5 shadow-soft",children:[(0,s.jsx)("h2",{className:"text-xl font-semibold text-success",children:"Import abgeschlossen"}),(0,s.jsxs)("div",{className:"mt-3 grid gap-3 sm:grid-cols-3",children:[(0,s.jsx)(h,{label:"Kunden neu",value:E.summary.created_customers}),(0,s.jsx)(h,{label:"Kunden aktualisiert",value:E.summary.updated_customers}),(0,s.jsx)(h,{label:"Fehler",value:E.summary.error_rows}),(0,s.jsx)(h,{label:"Standorte neu",value:E.summary.created_locations}),(0,s.jsx)(h,{label:"Ansprechpartner neu",value:E.summary.created_contacts}),(0,s.jsx)(h,{label:"Übersprungen",value:E.summary.skipped_rows})]})]}):null]})}])}]); |