PageSourceSearch

https://seniormoments.co.nz/assets/admin.contributors-BAOpW0Ml.js

js seniormoments.co.nz collected 2026-10-09 22:04:59 UTC 7,259 bytes, 1 lines download raw bytes

1import{b,r as g,c as h,s as d,j as e,t as l,a7 as i}from"./index-B8x47Np6.js";const u=n=>n.toLowerCase().trim().replace(/[^a-z0-9]+/g,"-").replace(/(^-|-$)/g,"");function y(){const n=b(),[t,a]=g.useState(null),{data:c,isLoading:o}=h({queryKey:["admin-contributors"],queryFn:async()=>{const{data:r,error:s}=await d.from("contributors").select("*").order("sort_order",{ascending:!0}).order("name",{ascending:!0});if(s)throw s;return r??[]}}),x=async()=>{if(!t)return;const r={name:t.name?.trim(),slug:(t.slug||u(t.name||"")).trim(),description:t.description??null,avatar_url:t.avatar_url??null,badge_label:t.badge_label||"Verified contributor",category:t.category??null,source_required_default:!!t.source_required_default,can_auto_publish:!!t.can_auto_publish,is_active:t.is_active??!0,sort_order:t.sort_order??0};if(!r.name||!r.slug){l.error("Name and slug are required");return}if(t.id){const{error:s}=await d.from("contributors").update(r).eq("id",t.id);if(s)return l.error(s.message);i({action:"contributor.update",target_type:"contributor",target_id:t.id,details:r})}else{const{error:s,data:p}=await d.from("contributors").insert(r).select("id").single();if(s)return l.error(s.message);i({action:"contributor.create",target_type:"contributor",target_id:p?.id,details:r})}l.success("Saved"),a(null),n.invalidateQueries({queryKey:["admin-contributors"]})},m=async r=>{const{error:s}=await d.from("contributors").update({is_active:!r.is_active}).eq("id",r.id);s?l.error(s.message):(i({action:r.is_active?"contributor.deactivate":"contributor.activate",target_type:"contributor",target_id:r.id}),n.invalidateQueries({queryKey:["admin-contributors"]}))};return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("h1",{className:"font-display text-3xl",children:"Verified contributors"}),e.jsx("button",{onClick:()=>a({source_required_default:!0,can_auto_publish:!1,is_active:!0,badge_label:"Verified contributor"}),className:"!min-h-0 rounded-full bg-primary px-4 py-2 text-sm text-primary-foreground",children:"+ New contributor"})]}),e.jsx("div",{className:"overflow-hidden rounded-2xl border border-border bg-card",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-secondary/50 text-left text-xs uppercase tracking-wider text-muted-foreground",children:e.jsxs("tr",{children:[e.jsx("th",{className:"px-4 py-3",children:"Name"}),e.jsx("th",{className:"px-4 py-3",children:"Slug"}),e.jsx("th",{className:"px-4 py-3",children:"Category"}),e.jsx("th",{className:"px-4 py-3",children:"Source req."}),e.jsx("th",{className:"px-4 py-3",children:"Auto-pub"}),e.jsx("th",{className:"px-4 py-3",children:"Active"}),e.jsx("th",{className:"px-4 py-3",children:"Actions"})]})}),e.jsxs("tbody",{children:[o&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-muted-foreground",children:"Loading…"})}),!o&&(c??[]).length===0&&e.jsx("tr",{children:e.jsx("td",{colSpan:7,className:"px-4 py-8 text-center text-muted-foreground",children:"No contributors yet."})}),(c??[]).map(r=>e.jsxs("tr",{className:"border-t border-border",children:[e.jsx("td",{className:"px-4 py-3 font-medium",children:r.name}),e.jsx("td",{className:"px-4 py-3 text-muted-foreground",children:r.slug}),e.jsx("td",{className:"px-4 py-3",children:r.category??"—"}),e.jsx("td",{className:"px-4 py-3",children:r.source_required_default?"Yes":"No"}),e.jsx("td",{className:"px-4 py-3",children:r.can_auto_publish?"Yes":"No"}),e.jsx("td",{className:"px-4 py-3",children:r.is_active?"Yes":"No"}),e.jsxs("td",{className:"px-4 py-3 space-x-3",children:[e.jsx("button",{onClick:()=>a(r),className:"!min-h-0 text-xs underline",children:"Edit"}),e.jsx("button",{onClick:()=>m(r),className:"!min-h-0 text-xs underline",children:r.is_active?"Deactivate":"Activate"})]})]},r.id))]})]})}),t&&e.jsx("div",{className:"fixed inset-0 z-50 grid place-items-center bg-black/50 p-4",children:e.jsxs("div",{className:"w-full max-w-xl space-y-4 rounded-2xl bg-card p-6",children:[e.jsx("h2",{className:"font-display text-xl",children:t.id?"
1Edit contributor":"New contributor"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("label",{className:"col-span-2 block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Name"}),e.jsx("input",{value:t.name??"",onChange:r=>a({...t,name:r.target.value,slug:t.slug||u(r.target.value)}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Slug"}),e.jsx("input",{value:t.slug??"",onChange:r=>a({...t,slug:r.target.value}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Category"}),e.jsx("input",{value:t.category??"",onChange:r=>a({...t,category:r.target.value}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"col-span-2 block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Description"}),e.jsx("textarea",{value:t.description??"",onChange:r=>a({...t,description:r.target.value}),className:"mt-1 h-20 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Avatar URL"}),e.jsx("input",{value:t.avatar_url??"",onChange:r=>a({...t,avatar_url:r.target.value}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Badge label"}),e.jsx("input",{value:t.badge_label??"Verified contributor",onChange:r=>a({...t,badge_label:r.target.value}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!t.source_required_default,onChange:r=>a({...t,source_required_default:r.target.checked})}),"Source required by default"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:!!t.can_auto_publish,onChange:r=>a({...t,can_auto_publish:r.target.checked})}),"Can auto-publish"]}),e.jsxs("label",{className:"flex items-center gap-2",children:[e.jsx("input",{type:"checkbox",checked:t.is_active??!0,onChange:r=>a({...t,is_active:r.target.checked})}),"Active"]}),e.jsxs("label",{className:"block",children:[e.jsx("span",{className:"text-muted-foreground",children:"Sort order"}),e.jsx("input",{type:"number",value:t.sort_order??0,onChange:r=>a({...t,sort_order:Number(r.target.value)}),className:"mt-1 w-full rounded-md border border-input bg-background px-3 py-2"})]})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx("button",{onClick:()=>a(null),className:"!min-h-0 rounded-full border border-border px-4 py-2 text-sm",children:"Cancel"}),e.jsx("button",{onClick:x,className:"!min-h-0 rounded-full bg-primary px-4 py-2 text-sm text-primary-foreground",children:"Save"})]})]})})]})}export{y as component};

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.