HifiPlanet-Website/hifi/assets/ContactRequests-C1no5-Tu.js

1 line
7.3 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{k as z,p as _,x as M,r,j as t,c as b}from"./index-t1kn-QYw.js";import{t as R,m as F,a as K,v as y}from"./contactRequests-Qfsfq7Lb.js";const D=s=>new Intl.NumberFormat("de-DE",{style:"currency",currency:"EUR"}).format(s),S={new:"Neu",in_progress:"In Bearbeitung",done:"Erledigt"},P={new:"bg-brand-100 text-brand-700 dark:bg-brand-900/40 dark:text-brand-300",in_progress:"bg-amber-100 text-amber-700 dark:bg-amber-900/40 dark:text-amber-300",done:"bg-green-100 text-green-700 dark:bg-green-900/40 dark:text-green-300"},T=()=>t.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"1.75",className:"h-4 w-4",children:t.jsx("path",{strokeLinecap:"round",strokeLinejoin:"round",d:"M4 7h16M9 7V5a1 1 0 0 1 1-1h4a1 1 0 0 1 1 1v2m3 0-.8 12.1a1 1 0 0 1-1 .9H7.8a1 1 0 0 1-1-.9L6 7h12ZM10 11v6M14 11v6"})});function U({request:s,onSaved:u}){const[d,p]=r.useState(s.internal_note||""),[i,l]=r.useState(!1),{toast:m}=_(),x=s.internal_note||"",g=async()=>{if(d!==x){l(!0);try{await b.patch(`/contact/${s.id}`,{internal_note:d}),u(s.id,{internal_note:d}),m.success("Notiz gespeichert.")}catch(o){m.error(`Notiz nicht gespeichert: ${o.message}`)}finally{l(!1)}}};return t.jsxs("div",{className:"mt-3",children:[t.jsxs("label",{className:"mb-1 block text-xs font-semibold uppercase tracking-wide text-neutral-400",htmlFor:`note-${s.id}`,children:["Interne Notiz ",i&&t.jsx("span",{className:"normal-case",children:"– speichert…"})]}),t.jsx("textarea",{id:`note-${s.id}`,rows:2,value:d,onChange:o=>p(o.target.value),onBlur:g,placeholder:"Nur für dein Team sichtbar, z. B. „Angebot geschickt am …“",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"})]})}function H(){const{hasPermission:s}=z(),{toast:u,refreshCounters:d}=_(),[p]=M(),i=p.get("id"),[l,m]=r.useState(null),[x,g]=r.useState(""),[o,A]=r.useState(i?"all":"new"),[j,E]=r.useState(""),f=r.useRef(null),L=()=>b.get("/contact").then(e=>{m(e),g("")}).catch(e=>g(e.message));r.useEffect(()=>{L()},[]),r.useEffect(()=>{i&&l&&f.current&&f.current.scrollIntoView({behavior:"smooth",block:"center"})},[i,l]);const k=(e,a)=>m(n=>n.map(c=>c.id===e?{...c,...a}:c)),$=async(e,a)=>{var c;const n=(c=l.find(v=>v.id===e))==null?void 0:c.status;k(e,{status:a});try{await b.patch(`/contact/${e}`,{status:a}),u.success(`Status: ${S[a]}`),d()}catch(v){k(e,{status:n}),u.error(`Status nicht geändert: ${v.message}`)}},C=async e=>{if(confirm("Diese Kontaktanfrage wirklich unwiderruflich löschen?"))try{await b.delete(`/contact/${e}`),m(a=>a.filter(n=>n.id!==e)),u.success("Anfrage gelöscht."),d()}catch(a){u.error(`Löschen fehlgeschlagen: ${a.message}`)}},h=l||[],B=r.useMemo(()=>({all:h.length,new:h.filter(e=>e.status==="new").length,in_progress:h.filter(e=>e.status==="in_progress").length,done:h.filter(e=>e.status==="done").length}),[h]),w=j.trim().toLowerCase(),N=h.filter(e=>o==="all"||e.status===o).filter(e=>!w||[e.name,e.email,e.phone,e.brand_name,e.model_name,e.package_name,e.message,e.internal_note].filter(Boolean).some(a=>String(a).toLowerCase().includes(w))),I=[{value:"new",label:"Neu"},{value:"in_progress",label:"In Bearbeitung"},{value:"done",label:"Erledigt"},{value:"all",label:"Alle"}];return t.jsxs("div",{children:[t.jsx("h1",{className:"mb-1 text-xl font-bold text-neutral-900 dark:text-white",children:"Anfragen"}),t.jsx("p",{className:"mb-4 text-sm text-neutral-500 dark:text-neutral-400",children:"Anfragen aus dem Kontaktformular. Mit „Antworten“ öffnet sich dein E-Mail-Programm mit fertigem Betreff. Setze den Status auf „Erledigt“, wenn alles geklärt ist."}),t.jsxs("div",{className:"mb-5 flex flex-wrap items-center gap-2",children:[I.map(e=>t.jsxs("button",{onClick:()=>A(e.value),className:`rounded-full px-4 py-1.5 text-sm font-medium transition ${o===e.value?"bg-brand-500 text-white":"bg-neutral-100 text-neutral-600 hover:bg-neutral-200 dark:bg-neutral-800 dark:text-neutral-300 dark:hover:bg-neutral-700"}`,children:[e.label," (",B[e.value],")"]},e.value)),t.jsx("input",{type:"search",value:j,onChange:e=>E(e.target.value),placeholder:"Suchen: Name, Fahrzeug, Text…",className:"ml-auto w-full rounded-md border border-neutral-300 bg-white px-3 py-1.5 text-sm dark:border-neutral-700 dark:bg-neutral-900 sm:w-64"})]}),x&&t.jsxs("p",{className:"mb-4 text-sm text-red-600",children:["Anfragen konnten nicht geladen werden: ",x]}),l===null&&!x&&t.jsx("p",{className:"text-sm text-neutral-400",children:"Lädt…"}),t.jsxs("div",{className:"space-y-3",children:[N.map(e=>{var a;return t.jsxs("div",{ref:String(e.id)===i?f:void 0,className:`rounded-xl border bg-white p-4 dark:bg-neutral-900 ${String(e.id)===i?"border-brand-500 ring-2 ring-brand-500/30":"border-neutral-200 dark:border-neutral-800"}`,children:[t.jsxs("div",{className:"mb-2 flex flex-wrap items-start justify-between gap-2",children:[t.jsxs("div",{className:"min-w-0",children:[t.jsx("p",{className:"font-semibold text-neutral-800 dark:text-neutral-100",children:e.name}),t.jsxs("p",{className:"text-sm text-neutral-600 dark:text-neutral-300",children:[e.email,e.phone?` · ${e.phone}`:""]}),e.vin&&t.jsxs("p",{className:"text-xs text-neutral-500 dark:text-neutral-400",children:["FIN: ",t.jsx("span",{className:"font-mono",children:e.vin})]}),t.jsx("p",{className:"text-xs text-neutral-400",title:new Date(e.created_at.replace(" ","T")).toLocaleString("de-DE"),children:R(e.created_at)})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[t.jsx("a",{href:F(e),className:"rounded-md bg-brand-500 px-3 py-1.5 text-sm font-semibold text-white hover:bg-brand-600",children:"Antworten"}),e.phone&&t.jsx("a",{href:K(e.phone),className:"rounded-md border border-neutral-300 px-3 py-1.5 text-sm font-medium text-neutral-700 hover:bg-neutral-100 dark:border-neutral-700 dark:text-neutral-200 dark:hover:bg-neutral-800",children:"Anrufen"}),t.jsx("select",{value:e.status,onChange:n=>$(e.id,n.target.value),"aria-label":"Status",className:`rounded-full border-0 px-3 py-1.5 text-xs font-medium ${P[e.status]}`,children:Object.entries(S).map(([n,c])=>t.jsx("option",{value:n,children:c},n))}),s("contact.delete")&&t.jsx("button",{onClick:()=>C(e.id),"aria-label":"Anfrage löschen",title:"Anfrage löschen",className:"rounded-md p-1.5 text-neutral-400 hover:bg-red-50 hover:text-red-600 dark:hover:bg-red-900/20",children:t.jsx(T,{})})]})]}),(y(e)||e.product_name)&&t.jsx("p",{className:"mb-2 text-sm text-neutral-500 dark:text-neutral-400",children:[y(e),e.product_name].filter(Boolean).join(" · ")}),((a=e.selected_upgrades)==null?void 0:a.length)>0&&t.jsxs("div",{className:"mb-2 rounded-md bg-brand-50 p-2 text-sm text-brand-800 dark:bg-brand-900/20 dark:text-brand-200",children:[t.jsx("p",{className:"font-semibold",children:"Gewünschte Upgrades:"}),t.jsx("ul",{className:"list-disc pl-5",children:e.selected_upgrades.map(n=>t.jsxs("li",{children:[n.name," – ",D(n.price)]},n.id))})]}),e.message&&t.jsx("p",{className:"whitespace-pre-line text-sm text-neutral-700 dark:text-neutral-300",children:e.message}),t.jsx(U,{request:e,onSaved:k})]},e.id)}),l!==null&&N.length===0&&t.jsx("p",{className:"text-neutral-400",children:w?"Keine Anfrage passt zur Suche.":o==="new"?"Keine neuen Anfragen – alles beantwortet.":o==="all"?"Noch keine Kontaktanfragen eingegangen.":"Keine Anfragen mit diesem Status."})]})]})}export{H as default};