HifiPlanet-Website/hifi/assets/Partners-B5umAj33.js
2026-10-19 22:07:47 +00:00

1 line
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{o as P,r as n,p as R,j as e,c as h}from"./index-Cc1wEeIX.js";import{I as F}from"./ImageUploadField-DYOhdPMm.js";import{S as L,s as C}from"./SortableList-DIXFCDYS.js";import{V as E}from"./ViewOnSite-CStAY6xT.js";import"./resizeImage-C6PvAwh0.js";import"./sortable.esm-D8IvDAze.js";import"./grip-vertical-0BUKE4NU.js";const u={name:"",logo_path:"",sort_order:0};function z(){const o=P(),[i,d]=n.useState([]),[a,c]=n.useState(u),[y,f]=n.useState(u),[s,j]=n.useState(null),[N,x]=n.useState(""),p=n.useRef(null);R(JSON.stringify(a)!==JSON.stringify(y),"partners");const g=()=>h.get("/partners").then(d);n.useEffect(()=>{g()},[]);const w=t=>{const r={name:t.name,logo_path:t.logo_path||"",sort_order:t.sort_order};j(t.id),c(r),f(r),x(""),requestAnimationFrame(()=>{var l,m,k;(l=p.current)==null||l.scrollIntoView({behavior:"smooth",block:"start"}),(k=(m=p.current)==null?void 0:m.querySelector("input"))==null||k.focus({preventScroll:!0})})},b=()=>{j(null),c(u),f(u)},v=async t=>{t.preventDefault(),x("");try{if(s)await h.put(`/partners/${s}`,a);else{const r=i.reduce((l,m)=>Math.max(l,Number(m.sort_order)||0),0)+10;await h.post("/partners",{...a,sort_order:r})}o.success(s?"Partner gespeichert.":"Partner angelegt."),b(),g()}catch(r){x(r.message)}},S=async t=>{if(confirm("Partner wirklich löschen?"))try{await h.delete(`/partners/${t}`),s===t&&b(),o.success("Partner gelöscht."),g()}catch(r){o.error(`Löschen fehlgeschlagen: ${r.message}`)}},_=async t=>{const r=i;d(t);try{d(await C("partners",t)),o.success("Reihenfolge gespeichert.")}catch(l){d(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-4 flex flex-wrap items-center justify-between gap-2",children:[e.jsx("h1",{className:"text-xl font-bold text-neutral-900 dark:text-white",children:"Partner"}),e.jsx(E,{to:"/",label:"Startseite ansehen"})]}),e.jsx("p",{className:"mb-4 text-sm text-neutral-500 dark:text-neutral-400",children:"Die Marken-Logozeile auf der Startseite. Ohne Logo wird der Name als Text angezeigt. Reihenfolge am Griff links per Ziehen ändern."}),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:"Logo"}),e.jsx("th",{className:"px-4 py-2",children:"Name"}),e.jsx("th",{className:"px-4 py-2 text-right",children:"Aktionen"})]})}),e.jsx(L,{items:i,onReorder:_,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.logo_path?e.jsx("img",{src:t.logo_path,alt:"",className:"h-10 w-10 rounded-md object-contain"}):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: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:()=>w(t),className:"mr-3 text-brand-600 hover:underline",children:"Bearbeiten"}),e.jsx("button",{onClick:()=>S(t.id),className:"text-red-600 hover:underline",children:"Löschen"})]})]})}),i.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 Partner angelegt."})})})]})})]}),e.jsxs("form",{ref:p,onSubmit:v,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:s?"Partner bearbeiten":"Neuer Partner"}),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:a.name,onChange:t=>c({...a,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"})]}),e.jsx(F,{value:a.logo_path,onChange:t=>c({...a,logo_path:t}),label:"Logo (optional)"}),N&&e.jsx("p",{className:"text-sm text-red-600",children:N}),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:s?"Speichern":"Anlegen"}),s&&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"})]})]})]})}export{z as default};