HifiPlanet-Website/hifi/assets/Brands-DZYHYqSw.js

1 line
5.5 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import{q as R,r as n,s as F,j as e,L as I,c as h}from"./index-t1kn-QYw.js";import{I as B}from"./ImageUploadField-BY4fnpKh.js";import{T as E}from"./TextStyleWidget-DSUcYkZU.js";import{S as $,s as A}from"./SortableList-B4XEFHmY.js";import{V as L}from"./VehicleCatalogDialog-RPszNVaP.js";import"./resizeImage-C6PvAwh0.js";import"./sortable.esm-dNCeQGtw.js";import"./grip-vertical-BnqeYamB.js";const x={name:"",image_path:"",sort_order:0};function W(){const o=R(),[d,i]=n.useState([]),[s,c]=n.useState(x),[v,f]=n.useState(x),[a,k]=n.useState(null),[j,p]=n.useState(""),[w,N]=n.useState(!1),g=n.useRef(null);F(JSON.stringify(s)!==JSON.stringify(v),"brands");const m=()=>h.get("/brands").then(i);n.useEffect(()=>{m()},[]);const S=t=>{const r={name:t.name,image_path:t.image_path||"",sort_order:t.sort_order};k(t.id),c(r),f(r),p(""),requestAnimationFrame(()=>{var l,u,y;(l=g.current)==null||l.scrollIntoView({behavior:"smooth",block:"start"}),(y=(u=g.current)==null?void 0:u.querySelector("input"))==null||y.focus({preventScroll:!0})})},b=()=>{k(null),c(x),f(x)},_=async t=>{t.preventDefault(),p("");try{if(a)await h.put(`/brands/${a}`,s);else{const r=d.reduce((l,u)=>Math.max(l,Number(u.sort_order)||0),0)+10;await h.post("/brands",{...s,sort_order:r})}o.success(a?"Marke gespeichert.":"Marke angelegt."),b(),m()}catch(r){p(r.message)}},M=async t=>{if(confirm("Marke inkl. aller Modelle/Pakete/Produkte wirklich löschen?"))try{await h.delete(`/brands/${t}`),a===t&&b(),o.success("Marke gelöscht."),m()}catch(r){o.error(`Löschen fehlgeschlagen: ${r.message}`)}},C=async t=>{const r=d;i(t);try{i(await A("brands",t)),o.success("Reihenfolge gespeichert.")}catch(l){i(r),o.error(`Reihenfolge konnte nicht gespeichert werden: ${l.message}`)}};return e.jsxs("div",{className:"grid gap-6 lg:grid-cols-3",children:[e.jsxs("div",{className:"lg:col-span-2",children:[e.jsxs("div",{className:"mb-1 flex items-center justify-between gap-3",children:[e.jsx("h1",{className:"text-xl font-bold text-neutral-900 dark:text-white",children:"Marken"}),e.jsx("button",{type:"button",onClick:()=>N(!0),className:"shrink-0 rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-50 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800",children:"Aus Vorlage laden"})]}),e.jsx("p",{className:"mb-4 text-sm text-neutral-500 dark:text-neutral-400",children:"Reihenfolge am Griff links per Ziehen ändern – so erscheinen die Marken auf der Website."}),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:[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:"Name"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Aktionen"})]})}),e.jsx($,{items:d,onReorder:C,as:"tbody",className:"divide-y divide-neutral-100 dark:divide-neutral-800",children:(t,r)=>e.jsxs(e.Fragment,{children:[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 font-medium text-neutral-800 dark:bg-neutral-950 dark:text-neutral-100",children:e.jsx(I,{to:`/fahrzeuge/${t.slug}`,target:"_blank",className:"hover:text-brand-500",children:t.name})}),e.jsxs("td",{className:"whitespace-nowrap bg-white px-4 py-2 text-right dark:bg-neutral-950",children:[e.jsx("button",{onClick:()=>S(t),className:"mr-3 text-brand-600 hover:underline",children:"Bearbeiten"}),e.jsx("button",{onClick:()=>M(t.id),className:"text-red-600 hover:underline",children:"Löschen"})]})]})}),d.length===0&&e.jsx("tbody",{children:e.jsx("tr",{children:e.jsx("td",{colSpan:4,className:"px-4 py-6 text-center text-neutral-400",children:"Noch keine Marken angelegt."})})})]})})]}),e.jsxs("form",{ref:g,onSubmit:_,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:a?"Marke bearbeiten":"Neue Marke"}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-1 block text-sm font-medium text-neutral-700 dark:text-neutral-300",children:"Name *"}),e.jsx("input",{required:!0,value:s.name,onChange:t=>c({...s,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"}),a&&e.jsx(E,{fieldKey:`brands.${a}.name`,previewText:s.name||"Beispieltext"})]}),e.jsx(B,{value:s.image_path,onChange:t=>c({...s,image_path:t}),label:"Bild (optional)"}),j&&e.jsx("p",{className:"text-sm text-red-600",children:j}),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:a?"Speichern":"Anlegen"}),a&&e.jsx("button",{type:"button",onClick:b,className:"rounded-md border border-neutral-300 px-4 py-2 text-sm dark:border-neutral-700",children:"Abbrechen"})]})]}),e.jsx(L,{open:w,onClose:()=>N(!1),onImported:m})]})}export{W as default};