Suchfeld ueber den Marken-Kacheln: findet Marken und Modelle beim Tippen (z. B. "golf 7", "vw golf", "bmw 3er"), Pfeiltasten + Enter, Link zum Kontakt ohne Treffer. Neuer oeffentlicher Endpunkt GET /vehicle-search. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_0174bfXbDqAn2M7TjkdqGCrn
1 line
6.9 KiB
JavaScript
1 line
6.9 KiB
JavaScript
import{q,r as n,s as E,j as e,c as x}from"./index-ChDBksRH.js";import{I as A}from"./ImageUploadField-BMNuKxUf.js";import{T}from"./TextStyleWidget-BuJJTOb7.js";import{S as z,s as L}from"./SortableList-M4z5YSr0.js";import{V as O}from"./ViewOnSite-C6aN_Z35.js";import"./resizeImage-C6PvAwh0.js";import"./sortable.esm-B6M0695A.js";import"./grip-vertical-pCKMVb6X.js";const p={name:"",brand_id:"",image_path:"",sort_order:0};function G(){const c=q(),[i,h]=n.useState([]),[v,F]=n.useState([]),[l,m]=n.useState(p),[R,y]=n.useState(p),[d,w]=n.useState(null),[_,g]=n.useState(""),[o,M]=n.useState("all"),f=n.useRef(null);E(JSON.stringify(l)!==JSON.stringify(R),"models");const u=o!=="all",j=n.useMemo(()=>o==="all"?i:i.filter(t=>String(t.brand_id)===o),[i,o]),k=()=>{x.get("/models").then(h),x.get("/brands").then(F)};n.useEffect(k,[]);const C=t=>{const r={name:t.name,brand_id:t.brand_id,image_path:t.image_path||"",sort_order:t.sort_order};w(t.id),m(r),y(r),g(""),requestAnimationFrame(()=>{var a,s,b;(a=f.current)==null||a.scrollIntoView({behavior:"smooth",block:"start"}),(b=(s=f.current)==null?void 0:s.querySelector("select, input"))==null||b.focus({preventScroll:!0})})},N=()=>{w(null),m(p),y(p)},B=async t=>{t.preventDefault(),g("");const r={...l,brand_id:Number(l.brand_id)};try{if(d)await x.put(`/models/${d}`,r);else{const a=i.filter(s=>Number(s.brand_id)===r.brand_id).reduce((s,b)=>Math.max(s,Number(b.sort_order)||0),0)+10;await x.post("/models",{...r,sort_order:a})}c.success(d?"Modell gespeichert.":"Modell angelegt."),N(),k()}catch(a){g(a.message)}},I=async t=>{if(confirm("Modell inkl. aller Pakete/Produkte wirklich löschen?"))try{await x.delete(`/models/${t}`),d===t&&N(),c.success("Modell gelöscht."),k()}catch(r){c.error(`Löschen fehlgeschlagen: ${r.message}`)}},S=(t,r)=>{const a=[...r];return t.map(s=>String(s.brand_id)===o?a.shift():s)},$=async t=>{const r=i;h(S(i,t));try{const a=await L("models",t);h(s=>S(s,a)),c.success("Reihenfolge gespeichert.")}catch(a){h(r),c.error(`Reihenfolge konnte nicht gespeichert werden: ${a.message}`)}};return e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2",children:[e.jsx("h1",{className:"mb-4 text-xl font-bold text-neutral-900 dark:text-white",children:"Modelle"}),e.jsxs("div",{className:"mb-3 flex flex-wrap items-center gap-2",children:[e.jsx("label",{className:"text-sm font-medium text-neutral-600 dark:text-neutral-300",children:"Nach Marke filtern:"}),e.jsxs("select",{value:o,onChange:t=>M(t.target.value),className:"rounded-md border border-neutral-300 bg-white px-3 py-1.5 text-sm dark:border-neutral-700 dark:bg-neutral-900",children:[e.jsx("option",{value:"all",children:"Alle Marken"}),v.map(t=>e.jsx("option",{value:String(t.id),children:t.name},t.id))]}),o!=="all"&&e.jsx("button",{onClick:()=>M("all"),className:"text-sm text-brand-600 hover:underline",children:"Filter zurücksetzen"}),e.jsxs("span",{className:"text-sm text-neutral-400",children:[j.length," von ",i.length]})]}),e.jsx("p",{className:"mb-3 text-xs text-neutral-500 dark:text-neutral-400",children:u?"Reihenfolge am Griff links per Ziehen ändern – so erscheinen die Modelle auf der Website.":"Zum Sortieren erst eine Marke auswählen."}),e.jsx("div",{className:"overflow-x-auto rounded-xl border border-neutral-200 dark:border-neutral-800",children:e.jsxs("table",{className:"w-full text-left text-sm",children:[e.jsx("thead",{className:"bg-neutral-50 text-neutral-500 dark:bg-neutral-900 dark:text-neutral-400",children:e.jsxs("tr",{children:[u&&e.jsx("th",{className:"w-8 px-2 py-2","aria-label":"Reihenfolge"}),e.jsx("th",{className:"px-4 py-2",children:"Bild"}),e.jsx("th",{className:"px-4 py-2",children:"Marke"}),e.jsx("th",{className:"px-4 py-2",children:"Modell"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Aktionen"})]})}),e.jsx(z,{items:j,onReorder:$,as:"tbody",disabled:!u,className:"divide-y divide-neutral-100 dark:divide-neutral-800",children:(t,r)=>e.jsxs(e.Fragment,{children:[u&&e.jsx("td",{className:"bg-white px-2 py-2 dark:bg-neutral-950",children:r}),e.jsx("td",{className:"bg-white px-4 py-2 dark:bg-neutral-950",children:t.image_path?e.jsx("img",{src:t.image_path,alt:"",className:"h-10 w-10 rounded-md object-cover"}):e.jsx("span",{className:"flex h-10 w-10 items-center justify-center rounded-md bg-neutral-100 text-xs text-neutral-400 dark:bg-neutral-800",children:"–"})}),e.jsx("td",{className:"bg-white px-4 py-2 dark:bg-neutral-950",children:t.brand_name}),e.jsx("td",{className:"bg-white px-4 py-2 font-medium text-neutral-800 dark:bg-neutral-950 dark:text-neutral-100",children:t.name}),e.jsxs("td",{className:"whitespace-nowrap bg-white px-4 py-2 text-right dark:bg-neutral-950",children:[e.jsx(O,{to:`/fahrzeuge/${t.brand_slug}/${t.slug}`,className:"mr-3"}),e.jsx("button",{onClick:()=>C(t),className:"mr-3 text-brand-600 hover:underline",children:"Bearbeiten"}),e.jsx("button",{onClick:()=>I(t.id),className:"text-red-600 hover:underline",children:"Löschen"})]})]})}),j.length===0&&e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{colSpan:u?5:4,className:"px-4 py-6 text-center text-neutral-400",children:i.length===0?"Noch keine Modelle angelegt.":"Keine Modelle für diese Marke."})})})]})})]}),e.jsxs("form",{ref:f,onSubmit:B,className:"h-fit scroll-mt-20 space-y-4 rounded-xl border border-neutral-200 bg-white p-5 dark:border-neutral-800 dark:bg-neutral-900",children:[e.jsx("h2",{className:"font-bold text-neutral-900 dark:text-white",children:d?"Modell bearbeiten":"Neues Modell"}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Marke *"}),e.jsxs("select",{required:!0,value:l.brand_id,onChange:t=>m({...l,brand_id:t.target.value}),className:"w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900",children:[e.jsx("option",{value:"",children:"Bitte wählen…"}),v.map(t=>e.jsx("option",{value:t.id,children:t.name},t.id))]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Modellname *"}),e.jsx("input",{required:!0,value:l.name,onChange:t=>m({...l,name:t.target.value}),className:"w-full rounded-md border border-neutral-300 bg-white px-3 py-2 text-sm dark:border-neutral-700 dark:bg-neutral-900"}),d&&e.jsx(T,{fieldKey:`car_models.${d}.name`,previewText:l.name||"Beispieltext"})]}),e.jsx(A,{value:l.image_path,onChange:t=>m({...l,image_path:t}),label:"Bild (optional)"}),_&&e.jsx("p",{className:"text-sm text-red-600",children:_}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx("button",{type:"submit",className:"rounded-md bg-brand-500 px-4 py-2 text-sm font-semibold text-white hover:bg-brand-600",children:d?"Speichern":"Anlegen"}),d&&e.jsx("button",{type:"button",onClick:N,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"})]})]})]})}export{G as default};
|