PageSourceSearch

https://vendor-marketplace.58facettes.fr/assets/detail-BIbXTodO.js

js 58facettes.fr collected 2026-09-25 06:05:59 UTC 10,810 bytes, 1 lines download raw bytes

1import{a as V,r as w,j as e,B as S,i as C,b as K,n as Q,d as W,u as X,l as Y,c as Z}from"./index-Dl5bkxzX.js";import{u as M,a as ee}from"./zod-DQXzxldH.js";import{B as P}from"./badge-DN17TH-P.js";import{C as se,L as U,a as te,b as ae,c as re,f as ie,d as ne,I as F}from"./index-DrdJe9kq.js";import{S as H}from"./spinner-BKMTYztm.js";import{b as le,c as ce,d as oe,e as de,f as me,g as ue,h as xe,i as pe}from"./hooks-CwXL86AS.js";import{u as he}from"./hooks-D7j9Kg4i.js";import{o as fe,s as $}from"./schemas-xc_cwyzA.js";import"./useQuery-D_rzzTGc.js";import"./useMutation-Dxv3fnjY.js";import"./use-auth-jVVOyhk5.js";function ge({admin:s,onSuccess:n}){const a=V().admins.detail.scopes,{data:d,isLoading:m,isError:l}=le(),{data:p,isLoading:A,isError:L}=ce(s.id),r=oe(),[h,i]=w.useState(new Set),[c,u]=w.useState(null);w.useEffect(()=>{p?.scopes?i(new Set(p.scopes)):i(new Set)},[p?.scopes]);const x=s.is_superuser,v=new Set(p?.scopes??[]),_=!ve(h,v),T=m||A,j=l||L,E=o=>{x||(i(g=>{const f=new Set(g);return f.has(o)?f.delete(o):f.add(o),f}),u(null))},k=()=>{if(x||!d)return;const o=new Set;d.forEach(g=>{g.scopes.forEach(f=>{o.add(f.scope)})}),i(o),u(null)},q=()=>{x||(i(new Set),u(null))},I=async o=>{if(o.preventDefault(),!!_){u(null);try{await r.mutateAsync({adminId:s.id,payload:{scopes:Array.from(h)}}),u({type:"success",text:a.updateSuccess}),n?.()}catch(g){const f=C(g)?g.payload?.message??a.updateError:a.updateError;u({type:"error",text:f})}}};return T?e.jsxs("div",{className:"flex h-48 items-center justify-center",children:[e.jsx(H,{className:"h-6 w-6"}),e.jsx("span",{className:"ml-2 text-sm text-neutral-600",children:a.loading})]}):j||!d||!p?e.jsx("div",{className:"rounded-2xl border border-rose-200 bg-rose-50 px-6 py-5 text-sm text-rose-600",children:a.loadError}):e.jsxs("form",{onSubmit:I,className:"space-y-6",children:[x?e.jsxs("div",{className:"rounded-2xl border border-amber-200 bg-amber-50 px-6 py-4 text-sm text-amber-800",children:[e.jsx("p",{className:"font-medium",children:a.superuserNote}),e.jsx("p",{className:"mt-1 text-amber-700",children:a.cannotEditSuperuser})]}):e.jsxs("div",{className:"flex gap-3",children:[e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:k,disabled:r.isPending,className:"border border-neutral-300",children:a.selectAll}),e.jsx(S,{type:"button",variant:"ghost",size:"sm",onClick:q,disabled:r.isPending,className:"border border-neutral-300",children:a.deselectAll})]}),e.jsx("div",{className:"space-y-6",children:d.map(o=>e.jsx(be,{category:o,selectedScopes:h,onToggleScope:E,disabled:x,copy:a},o.category))}),x?null:e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center border-t pt-6",children:[e.jsx(S,{type:"submit",disabled:r.isPending||!_,children:r.isPending?a.updating:a.updateAction}),c?e.jsx("p",{className:c.type==="success"?"text-sm text-emerald-600":"text-sm text-rose-600",role:"status",children:c.text}):null]})]})}function be({category:s,selectedScopes:n,onToggleScope:t,disabled:a,copy:d}){const m=d.categoryLabels[s.category]??s.description;return e.jsxs("div",{className:"space-y-3",children:[e.jsx("div",{className:"pb-2",children:e.jsx("h3",{className:"font-semibold text-neutral-900",children:m})}),e.jsx("div",{className:"grid gap-3 sm:grid-cols-2",children:s.scopes.map(l=>e.jsxs("div",{className:"flex items-start gap-3 rounded-lg border border-neutral-200 bg-white p-4",children:[e.jsx(se,{id:`scope-${l.scope}`,checked:n.has(l.scope),onCheckedChange:()=>t(l.scope),disabled:a,className:"mt-0.5"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx(U,{htmlFor:`scope-${l.scope}`,className:"block font-medium text-sm text-neutral-900 cursor-pointer",children:l.name}),e.jsx("p",{className:"mt-1 text-sm text-neutral-600",children:l.description})]})]},l.scope))})]})}function ve(s,n){if(s.size!==n.size)return!1;for(const t of s)if(!n.has(t))return!1;return!0}function qe(){const s=V(),[n]=K(),t=s.admins.detail,a=s.account.profile,{data:d}=he(),m=fe({name:$().max(120,{message:t.update.nameLength}).optional(),email:$().email(t.update.emailInvalid).optional()}),{id:l}=Q(),[p,A]=W(),L=X(),{data:r,isLoading:h,isError:i,error:c}=de(l),u=me(),x=ue(),v=xe(),_=pe(),[T,j]=w.useState(null),E=p.get("tab")||"profile",k=d?.is_superuser??!1,{register:q,handleSubmit:I,reset:o,setError:g,formState:{errors:f,isDirty:O}}=M({resolver:ee(m),defaultValues:{name:"",email:""}});w.useEffect(()=>{r&&o({name:r.name??"",email:r.email})},[r,o]),w.useEffect(()=>{r&&(document.title=r.name||r.email)},[r]);const B=y=>{A(N=>{const b=new URLSearchParams(N);return b.set("tab",y),b})},G=I(async y=>{if(!l||!r)return;j(null);const N=ye(y.name),b=y.email?.trim(),D={};if(N!==r.name&&(D.name=N),b&&b!==r.email&&(D.email=b),Object.keys(D).length!==0)try{const z=await u.mutateAsync({id:l,payload:D});o({name:z.name??"",email:z.email}),j({type:"success",text:t.update.success})}catch(z){je(z,g,j,t.update.error)}}),J=async()=>
1{if(!(!l||!window.confirm(t.delete.confirm)))try{await _.mutateAsync(l),L(Y(Z.admins.list,n),{replace:!0})}catch(N){const b=C(N)?N.payload?.message??t.delete.error:t.delete.error;j({type:"error",text:b})}};if(h)return e.jsx("div",{className:"flex h-96 items-center justify-center",children:e.jsx(H,{className:"h-8 w-8"})});if(i){const y=C(c)?c.payload?.message??t.update.error:t.update.error;return e.jsx("div",{className:"rounded-2xl border border-rose-200 bg-rose-50 px-6 py-5 text-sm text-rose-600",children:y})}return r?e.jsx("div",{className:"space-y-6",children:e.jsxs(te,{children:[e.jsx(ae,{children:e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsxs("div",{children:[e.jsx(re,{children:t.heading}),e.jsx(ie,{children:r.email})]}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(P,{variant:r.is_active?"success":"outline",children:r.is_active?a.statuses.active:a.statuses.inactive}),e.jsx(P,{variant:r.is_superuser?"warning":"outline",children:r.is_superuser?a.statuses.superuser:a.statuses.staff}),e.jsx(P,{variant:r.is_verified?"success":"warning",children:r.is_verified?a.statuses.verified:a.statuses.unverified})]})]})}),e.jsxs(ne,{children:[e.jsx("div",{className:"border-b border-neutral-200",children:e.jsxs("nav",{className:"-mb-px flex gap-6","aria-label":"Tabs",children:[e.jsx("button",{type:"button",onClick:()=>B("profile"),className:`py-3 px-1 border-b-2 font-medium text-sm transition-colors ${E==="profile"?"border-blue-600 text-blue-600":"border-transparent text-neutral-600 hover:text-neutral-900 hover:border-neutral-300"}`,children:t.tabs.profile}),k?e.jsx("button",{type:"button",onClick:()=>B("permissions"),className:`py-3 px-1 border-b-2 font-medium text-sm transition-colors ${E==="permissions"?"border-blue-600 text-blue-600":"border-transparent text-neutral-600 hover:text-neutral-900 hover:border-neutral-300"}`,children:t.tabs.permissions}):null]})}),e.jsx("div",{className:"mt-6",children:E==="profile"?e.jsx(Ne,{admin:r,onSubmit:G,register:q,errors:f,isDirty:O,updateAdmin:u,invite:x,activate:v,deactivateSuper:_,handleDeactivate:J,formMessage:T,setFormMessage:j,copy:t,profileCopy:a,id:l}):E==="permissions"&&k?e.jsx(Se,{admin:r}):null})]})]})}):null}function je(s,n,t,a){if(C(s)){if(s.status===422&&s.payload?.details){const d=R(s.payload.details,"name");if(d){n("name",{type:"server",message:d});return}const m=R(s.payload.details,"email");if(m){n("email",{type:"server",message:m});return}}t({type:"error",text:s.payload?.message??a});return}t({type:"error",text:a})}function R(s,n){if(Array.isArray(s)){for(const t of s)if((Array.isArray(t?.loc)?t.loc:[]).slice(-1)[0]===n){const m=t?.msg??t?.message??t?.detail;if(typeof m=="string")return m}}if(s&&typeof s=="object"&&n in s){const t=s[n];if(typeof t=="string")return t;if(Array.isArray(t)&&typeof t[0]=="string")return t[0]}return null}function ye(s){if(!s)return null;const n=s.trim();return n.length>0?n:null}function Ne({admin:s,onSubmit:n,register:t,errors:a,isDirty:d,updateAdmin:m,invite:l,activate:p,deactivateSuper:A,handleDeactivate:L,formMessage:r,setFormMessage:h,copy:i,profileCopy:c,id:u}){return e.jsxs("form",{className:"space-y-6",onSubmit:n,noValidate:!0,children:[e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"admin-email",children:i.emailLabel}),e.jsx(F,{id:"admin-email",type:"email",placeholder:c.emailPlaceholder,...t("email"),"aria-invalid":a.email?"true":"false"}),a.email?e.jsx("p",{className:"text-sm text-rose-600",children:a.email.message}):null]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(U,{htmlFor:"admin-name",children:i.nameLabel}),e.jsx(F,{id:"admin-name",placeholder:c.namePlaceholder,...t("name"),"aria-invalid":a.name?"true":"false"}),a.name?e.jsx("p",{className:"text-sm text-rose-600",children:a.name.message}):null]})]}),e.jsxs("div",{className:"pt-4",children:[e.jsx("h3",{className:"text-sm font-medium text-neutral-900 mb-4",children:i.statusLabel}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsx(P,{variant:s.is_active?"success":"outline",children:s.is_active?c.statuses.active:c.statuses.inactive}),e.jsx(P,{variant:s.is_superuser?"warning":"outline",children:s.is_superuser?c.statuses.superuser:c.statuses.staff}),e.jsx(P,{variant:s.is_verified?"success":"warning",children:s.is_verified?c.statuses.verified:c.statuses.unverified})]})]})]}),e.jsxs("div",{className:"flex flex-col gap-4 sm:flex-row sm:items-center pt-6",children:[e.jsx(S,{type:"submit",disabled:m.isPending||!d,children:m.isPending?i.update.saving:i.update.action}),s.is_active?null:e.jsx(e.Fragment,{children:e.jsx(S,{type:"button",variant:"ghost",className:"text-sm hover:bg-blue-100 text-blue-700 hover:text-blue-700",onClick:async()=>
1{if(u)try{await l.mutateAsync(u),h({type:"success",text:i.invite.success})}catch(x){const v=C(x)?x.payload?.message??i.invite.error:i.invite.error;h({type:"error",text:v})}},disabled:l.isPending,children:l.isPending?i.invite.inviting:i.invite.action})}),s.is_active?e.jsx(S,{type:"button",variant:"ghost",className:"text-sm text-rose-600 hover:bg-rose-100 hover:text-rose-600",onClick:L,disabled:A.isPending,children:A.isPending?i.delete.deleting:i.delete.action}):e.jsx(S,{type:"button",variant:"ghost",className:"text-sm text-emerald-700 hover:bg-emerald-100 hover:text-emerald-700",onClick:async()=>{if(u)try{await p.mutateAsync(u),h({type:"success",text:i.activate.success})}catch(x){const v=C(x)?x.payload?.message??i.activate.error:i.activate.error;h({type:"error",text:v})}},disabled:p.isPending,children:p.isPending?i.activate.activating:i.activate.action}),r?e.jsx("p",{className:r.type==="success"?"text-sm text-emerald-600":"text-sm text-rose-600",role:"status",children:r.text}):null]})]})}function Se({admin:s}){return e.jsx(ge,{admin:s})}export{qe as AdminDetailRoute};

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.