PageSourceSearch

https://laerosol.com/assets/admin-pos-sites-CAWnXk0_.js

js laerosol.com collected 2026-10-02 20:53:44 UTC 17,100 bytes, 1 lines download raw bytes

1import{f as Ce,s as we,r as l,a as C,b as d,t as m,E as c,j as e,L as Z,B as n,D as me,I as g}from"./index-BK1sFRZj.js";import{C as T,a as q,b as Ee,c as Pe}from"./card-BeHTkU89.js";import{L as u}from"./label-DPLsJRG_.js";import{T as ue}from"./textarea-4Wp5-Fkf.js";import{B as xe}from"./badge-BBwRzimo.js";import{D as A,a as I,b as D,c as z}from"./dialog-Dlan3cK0.js";import{S as Te,a as qe,b as Ae,c as Ie,d as De}from"./select-CoDbtEwq.js";import{u as ze}from"./useMeta-CH4vqPmJ.js";import{A as Fe}from"./arrow-left-Dalle_P7.js";import{M as F}from"./map-pin-DBfO8eWW.js";import{P as G}from"./plus-Br8sqPUI.js";import{P as he}from"./pen-CJ47Vaip.js";import{C as U}from"./chevron-right-0nGDWDTu.js";import{P as J}from"./package-BEZdWw8s.js";import{T as pe}from"./trash-2-CwA3J-i0.js";import{T as je}from"./table-Z5FCU_Zg.js";import{Q as Ke}from"./qr-code-CVwwksAa.js";import"./index-Dk8kPU04.js";import"./chevron-down-JNotcG1N.js";import"./chevron-up-6qfqPAup.js";function ge(f){return f.toLowerCase().normalize("NFD").replace(/[\u0300-\u036f]/g,"").replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,"")}const W={name:"",slug:"",description:"",color:"#6366f1"},X={name:"",description:""},ee={name:"",seats:4,zone:""};function as(){ze({title:"Sites & Stocks POS - L'Aérosol",description:"Gestion hiérarchie POS.",noIndex:!0});const{user:f,hasAdminAccess:fe}=Ce(),v=(f==null?void 0:f.posCatalogId)!=null,{toast:r}=we(),[t,se]=l.useState(null),[te,ae]=l.useState(null),[N,b]=l.useState(null),[i,h]=l.useState(W),[K,ie]=l.useState(null),[w,S]=l.useState(null),[p,y]=l.useState(X),[M,ne]=l.useState(null),[ve,L]=l.useState(!1),[x,k]=l.useState(ee),[Ne,$]=l.useState(!1),[Q,re]=l.useState(null),[O,le]=l.useState(""),{data:E=[],isLoading:be}=C({queryKey:["/api/pos/sites"]}),{data:j=[]}=C({queryKey:["/api/pos/sites",t,"stocks"],queryFn:()=>fetch(`/api/pos/sites/${t}/stocks`,{credentials:"include"}).then(s=>s.json()),enabled:!!t});C({queryKey:["/api/pos/stocks"]});const{data:ce=[]}=C({queryKey:["/api/pos/venues"]}),{data:P=[]}=C({queryKey:["/api/pos/sites",t,"tables"],queryFn:()=>fetch(`/api/pos/sites/${t}/tables`,{credentials:"include"}).then(s=>s.json()),enabled:!!t&&!v}),oe=E.find(s=>s.id===t),Se=s=>ce.filter(a=>a.stockId===s),V=d({mutationFn:()=>m("POST","/api/pos/sites",i),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites"]}),b(null),h(W),r({title:"Site créé"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})}),B=d({mutationFn:()=>m("PATCH",`/api/pos/sites/${K==null?void 0:K.id}`,i),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites"]}),b(null),ie(null),r({title:"Site mis à jour"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})});d({mutationFn:s=>m("DELETE",`/api/pos/sites/${s}`),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites"]}),t&&se(null),r({title:"Site désactivé"})}});const H=d({mutationFn:()=>m("POST",`/api/pos/sites/${t}/stocks`,p),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites",t,"stocks"]}),c.invalidateQueries({queryKey:["/api/pos/stocks"]}),S(null),y(X),r({title:"Stock créé"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})}),R=d({mutationFn:()=>m("PATCH",`/api/pos/stocks/${M==null?void 0:M.id}`,p),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites",t,"stocks"]}),c.invalidateQueries({queryKey:["/api/pos/stocks"]}),S(null),ne(null),r({title:"Stock mis à jour"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})}),ye=d({mutationFn:s=>m("DELETE",`/api/pos/stocks/${s}`),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites",t,"stocks"]}),c.invalidateQueries({queryKey:["/api/pos/stocks"]}),te&&ae(null)}}),_=d({mutationFn:()=>m("POST",`/api/pos/sites/${t}/tables`,x),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/sites",t,"tables"]}),L(!1),k(ee),r({title:"Table créée"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})}),ke=d({mutationFn:s=>m("DELETE",`/api/pos/tables/${s}`),onSuccess:()=>c.invalidateQueries({queryKey:["/api/pos/sites",t,"tables"]})}),Y=d({mutationFn:()=>m("PATCH",`/api/pos/venues/${Q==null?void 0:Q.venueId}`,{stockId:parseInt(O)}),onSuccess:()=>{c.invalidateQueries({queryKey:["/api/pos/venues"]}),$(!1),re(null),r({title:"Caisse liée au stock"})},onError:s=>r({title:"Erreur",description:s.message,variant:"destructive"})});return fe?e.jsxs("div",{className:"min-h-screen py-10",children:[e.jsxs("div",{className:"container max-w-6xl mx-auto px-4",children:[e.jsxs(Z,{href:"/admin-pos",className:"inline-flex items-center gap-1 text-sm text-muted-foreground mb-4 hover:text-primary",children:[e.jsx(Fe,{className:"h-4 w-4"})," Retour POS"]}
1),e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsxs("div",{children:[e.jsxs("h1",{className:"text-3xl font-bold flex items-center gap-2",children:[e.jsx(F,{className:"h-7 w-7 text-primary"})," Sites & Stocks"]}),e.jsxs("p",{className:"text-muted-foreground mt-1",children:["Hiérarchie : ",e.jsx("span",{className:"font-medium",children:"Sites géographiques"})," → ",e.jsx("span",{className:"font-medium",children:"Zones de stockage"})," → ",e.jsx("span",{className:"font-medium",children:"Caisses"})]})]}),e.jsxs(n,{disabled:v,onClick:()=>{h(W),b("create")},children:[e.jsx(G,{className:"h-4 w-4 mr-2"})," Nouveau site"]})]}),e.jsxs("div",{className:"grid grid-cols-1 lg:grid-cols-3 gap-6",children:[e.jsxs("div",{className:"lg:col-span-1",children:[e.jsxs("h2",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide mb-3 flex items-center gap-1",children:[e.jsx(F,{className:"h-3 w-3"})," Sites (",E.length,")"]}),be?e.jsx("p",{className:"text-sm text-muted-foreground",children:"Chargement…"}):E.length===0?e.jsx(T,{children:e.jsxs(q,{className:"py-10 text-center",children:[e.jsx(F,{className:"h-8 w-8 mx-auto mb-2 text-muted-foreground/40"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aucun site configuré."})]})}):e.jsx("div",{className:"space-y-2",children:E.map(s=>e.jsxs("div",{onClick:()=>{se(s.id),ae(null)},className:`p-3 rounded-lg border cursor-pointer transition-all hover:shadow-sm ${t===s.id?"border-primary bg-primary/5 shadow-sm":"border-border bg-card"}`,children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2 min-w-0",children:[e.jsx("div",{className:"w-3 h-3 rounded-full flex-shrink-0",style:{backgroundColor:s.color||"#6366f1"}}),e.jsx("span",{className:"font-medium text-sm truncate",children:s.name})]}),e.jsxs("div",{className:"flex items-center gap-1 flex-shrink-0",children:[e.jsx(n,{size:"icon",variant:"ghost",className:"h-6 w-6",onClick:a=>{a.stopPropagation(),ie(s),h({name:s.name,slug:s.slug,description:s.description||"",color:s.color||"#6366f1"}),b("edit")},children:e.jsx(he,{className:"h-3 w-3"})}),e.jsx(U,{className:`h-4 w-4 text-muted-foreground transition-transform ${t===s.id?"rotate-90":""}`})]})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1 truncate",children:s.description}),e.jsx("div",{className:"flex items-center gap-1 mt-1",children:e.jsx(xe,{variant:s.isActive?"default":"secondary",className:"text-[10px] py-0 px-1",children:s.isActive?"Actif":"Inactif"})})]},s.id))})]}),oe?e.jsxs("div",{className:"lg:col-span-2 space-y-6",children:[e.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[e.jsx("span",{className:"font-medium text-foreground",children:oe.name}),e.jsx(U,{className:"h-3 w-3"}),e.jsxs("span",{children:[j.length," stock",j.length!==1?"s":""," · ",P.length," table",P.length!==1?"s":""]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-1",children:[e.jsx(J,{className:"h-3 w-3"})," Zones de stockage / Bars"]}),e.jsxs(n,{size:"sm",variant:"outline",disabled:v,onClick:()=>{y(X),S("create")},children:[e.jsx(G,{className:"h-3 w-3 mr-1"})," Nouveau stock"]})]}),j.length===0?e.jsx(T,{children:e.jsxs(q,{className:"py-8 text-center",children:[e.jsx(J,{className:"h-8 w-8 mx-auto mb-2 text-muted-foreground/40"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aucun stock pour ce site."})]})}):e.jsx("div",{className:"space-y-3",children:j.map(s=>{const a=Se(s.id);return e.jsxs(T,{className:`border-l-4 transition-all ${te===s.id?"border-l-primary shadow-md":"border-l-transparent hover:border-l-muted-foreground/30"}`,children:[e.jsxs(Ee,{className:"pb-2 pt-3 px-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(J,{className:"h-4 w-4 text-primary"}),e.jsx(Pe,{className:"text-base",children:s.name}),e.jsx(xe,{variant:s.isActive?"default":"secondary",className:"text-[10px]",children:s.isActive?"Actif":"Inactif"})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(n,{size:"icon",variant:"ghost",className:"h-7 w-7",onClick:()=>{ne(s),y({name:s.name,description:s.description||""}),S("edit")},children:e.jsx(he,{className:"h-3 w-3"})}),e.jsx(n,{size:"icon",variant:"ghost",className:"h-7 w-7 text-destructive hover:text-destructive",onClick:()=>ye.mutate(s.id),children:e.jsx(pe,{className:"h-3 w-3"})})]})]}),s.description&&e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:s.description})]}),e.jsxs(q,{className:"px-4 pb-3",children:[e.jsxs("div",{className:"flex items-center gap-1 mb-2",children:[e.jsx(me,{className:"h-3 w-3 text-muted-foreground"}),e.jsxs("span",{className:"text-xs font-medium text-muted-foreground",children:["Caisses liées (",a.length,")"]})]}),a.length===0?e.jsx("p",{className:"text-xs text-muted-foreground italic",children:"Aucune caisse liée à ce stock."}):e.jsx("div",{className:"flex flex-wrap gap-2",children:a.map(o=>e.jsxs("div",{className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-muted text-xs",children:[e.jsx("div",{className:"w-2 h-2 rounded-full",style:{backgroundColor:o.color||"#6366f1"}}),e.jsx("span",{className:"font-medium",children:o.name}),e.jsx(Z,{href:`/admin-pos/${o.id}`,children:e.jsx(n,{size:"icon",variant:"ghost",className:"h-4 w-4 ml-0.5",children:e.jsx(U,{className:"h-2.5 w-2.5"})})})]},o.id))}),e.jsxs("p",{className:"text-xs text-muted-foreground mt-2",children:["Ingrédients et fournisseurs de ce stock :",e.jsx(Z,{href:"/admin-pos",className:"ml-1 text-primary underline",children:"voir dans config caisse"})]})]})]},s.id)})})]}),!v&&e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-3",children:[e.jsxs("h2",{className:"text-xs font-semibold text-muted-foreground uppercase tracking-wide flex items-center gap-1",children:[e.jsx(je,{className:"h-3 w-3"})," Tables du site (communes)"]}),e.jsxs(n,{size:"sm",variant:"outline",disabled:v,onClick:()=>{k(ee),L(!0)},children:[e.jsx(G,{className:"h-3 w-3 mr-1"})," Nouvelle table"]})]}),P.length===0?e.jsx(T,{children:e.jsxs(q,{className:"py-6 text-center",children:[e.jsx(je,{className:"h-7 w-7 mx-auto mb-2 text-muted-foreground
1/40"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Aucune table pour ce site."})]})}):e.jsx("div",{className:"grid grid-cols-2 sm:grid-cols-3 gap-2",children:P.map(s=>e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg border bg-card hover:bg-muted/30 transition-colors",children:[e.jsxs("div",{children:[e.jsx("p",{className:"text-sm font-medium",children:s.name}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:[s.seats," places",s.zone?` · ${s.zone}`:""]})]}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx("a",{href:`/carte/${s.token}`,target:"_blank",rel:"noopener noreferrer",children:e.jsx(n,{size:"icon",variant:"ghost",className:"h-6 w-6",children:e.jsx(Ke,{className:"h-3 w-3"})})}),e.jsx(n,{size:"icon",variant:"ghost",className:"h-6 w-6 text-destructive hover:text-destructive",onClick:()=>ke.mutate(s.id),children:e.jsx(pe,{className:"h-3 w-3"})})]})]},s.id))})]}),(()=>{const s=ce.filter(a=>!a.stockId||!j.find(o=>o.id===a.stockId));return s.length===0?null:e.jsxs("div",{children:[e.jsxs("h2",{className:"text-xs font-semibold text-amber-600 uppercase tracking-wide mb-3 flex items-center gap-1",children:[e.jsx(me,{className:"h-3 w-3"})," Caisses non liées à un stock"]}),e.jsx("div",{className:"space-y-2",children:s.map(a=>e.jsxs("div",{className:"flex items-center justify-between p-2.5 rounded-lg border border-amber-200 bg-amber-50",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("div",{className:"w-2.5 h-2.5 rounded-full",style:{backgroundColor:a.color||"#6366f1"}}),e.jsx("span",{className:"text-sm font-medium",children:a.name})]}),e.jsx(n,{size:"sm",variant:"outline",className:"text-xs h-7",onClick:()=>{var o,de;re({venueId:a.id,currentStockId:a.stockId??null}),le(((de=(o=j[0])==null?void 0:o.id)==null?void 0:de.toString())||""),$(!0)},children:"Lier à un stock"})]},a.id))})]})})()]}):e.jsx("div",{className:"lg:col-span-2 flex items-center justify-center text-center py-20",children:e.jsxs("div",{children:[e.jsx(F,{className:"h-12 w-12 mx-auto mb-3 text-muted-foreground/30"}),e.jsx("p",{className:"text-muted-foreground",children:"Sélectionnez un site pour voir ses stocks et tables."})]})})]})]}),e.jsx(A,{open:!!N,onOpenChange:s=>!s&&b(null),children:e.jsxs(I,{children:[e.jsx(D,{children:e.jsx(z,{children:N==="edit"?"Modifier le site":"Nouveau site géographique"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Nom *"}),e.jsx(g,{value:i.name,onChange:s=>h({...i,name:s.target.value,slug:N==="create"?ge(s.target.value):i.slug}),placeholder:"Marseille"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Slug (URL) *"}),e.jsx(g,{value:i.slug,onChange:s=>h({...i,slug:ge(s.target.value)}),placeholder:"marseille"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description"}),e.jsx(ue,{value:i.description,onChange:s=>h({...i,description:s.target.value}),rows:2})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Couleur"}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"color",value:i.color,onChange:s=>h({...i,color:s.target.value}),className:"h-9 w-14 rounded border cursor-pointer"}),e.jsx("span",{className:"text-sm text-muted-foreground",children:i.color})]})]}),e.jsx(n,{className:"w-full",disabled:!i.name||!i.slug||V.isPending||B.isPending,onClick:()=>N==="edit"?B.mutate():V.mutate(),children:V.isPending||B.isPending?"Enregistrement…":N==="edit"?"Enregistrer":"Créer le site"})]})]})}),e.jsx(A,{open:!!w,onOpenChange:s=>!s&&S(null),children:e.jsxs(I,{children:[e.jsx(D,{children:e.jsx(z,{children:w==="edit"?"Modifier le stock":"Nouveau stock / bar"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Nom *"}),e.jsx(g,{value:p.name,onChange:s=>y({...p,name:s.target.value}),placeholder:"Bar principal"})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Description"}),e.jsx(ue,{value:p.description,onChange:s=>y({...p,description:s.target.value}),rows:2})]}),e.jsx(n,{className:"w-full",disabled:!p.name||H.isPending||R.isPending,onClick:()=>w==="edit"?R.mutate():H.mutate(),children:H.isPending||R.isPending?"Enregistrement…":w==="edit"?"Enregistrer":"Créer le stock"})]})]})}),e.jsx(A,{open:ve,onOpenChange:L,children:e.jsxs(I,{children:[e.jsx(D,{children:e.jsx(z,{children:"Nouvelle table"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Nom *"}),e.jsx(g,{value:x.name,onChange:s=>k({...x,name:s.target.value}),placeholder:"Table 1"})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-3",children:[e.jsxs("div",{children:[e.jsx(u,{children:"Places"}),e.jsx(g,{type:"number",value:x.seats,onChange:s=>k({...x,seats:parseInt(s.target.value)})})]}),e.jsxs("div",{children:[e.jsx(u,{children:"Zone"}),e.jsx(g,{value:x.zone,onChange:s=>k({...x,zone:s.target.value}),placeholder:"Terrasse"})]})]}),e.jsx(n,{className:"w-full",disabled:!x.name||_.isPending,onClick:()=>_.mutate(),children:_.isPending?"Création…":"Créer la table"})]})]})}),e.jsx(A,{open:Ne,onOpenChange:$,children:e.jsxs(I,{children:[e.jsx(D,{children:e.jsx(z,{children:"Lier une caisse à un stock"})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("p",{className:"text-sm text-muted-foreground",children:"Sélectionnez le stock de ce site auquel la caisse sera rattachée."}),e.jsxs(Te,{value:O,onValueChange:le,children:[e.jsx(qe,{children:e.jsx(Ae,{placeholder:"Choisir un stock…"})}),e.jsx(Ie,{children:j.map(s=>e.jsx(De,{value:s.id.toString(),children:s.name},s.id))})]}),e.jsx(n,{className:"w-full",disabled:!O||Y.isPending,onClick:()=>Y.mutate(),children:Y.isPending?"Liaison…":"Lier la caisse"})]})]})})]}):e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx("p",{className:"text-muted-foreground",children:"Accès réservé."})})}export{as as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.