PageSourceSearch

https://www.abbeytheatre.co.uk/assets/AdminNewsForm-DMCM1n8O.js

js abbeytheatre.co.uk collected 2026-10-02 21:28:37 UTC 15,403 bytes, 1 lines download raw bytes

1import{bS as $,r as d,s as h,j as e,C,e as S,a as P,c as D,d as L,B as A,L as O,v as g,I as E,a2 as te,P as K,Z as W,a5 as se,k as ae,l as re,A as ie,a7 as le,bd as ne}from"./index-D6S94l3r.js";import{T as U}from"./textarea-zkxjn3Pk.js";import{R as ce}from"./RichTextEditor-CAuSqiXf.js";import{processImageForUpload as de,IMAGE_PRESETS as oe}from"./imageUtils-RoQh2GsP.js";import{S as ue,a as me,b as he,c as pe,d as V}from"./select-BkXyGY_9.js";import{M as xe}from"./megaphone-B9W7KI_L.js";import{P as Z}from"./plus-BOxbBXe6.js";import{U as ge}from"./upload-DP2pymot.js";import"./index-DxKCTtkd.js";import"./index-DRYfENKC.js";import"./with-selector-DuwCZk0N.js";import"./popover-DtuDutnd.js";import"./list-WBYbipnp.js";import"./quote-DgGJCVmp.js";import"./minus-B45-gXHA.js";import"./image-C8tXgUOP.js";import"./index-BdQq_4o_.js";import"./chevron-down-0kA1qCjF.js";import"./chevron-up-D18T203o.js";function fe({newsArticleId:l}){const{toast:u}=$(),[_,F]=d.useState([]),[N,y]=d.useState([]),[T,f]=d.useState(!0),[v,o]=d.useState(null);d.useEffect(()=>{b()},[l]);const b=async()=>{f(!0);const[n,i]=await Promise.all([h.from("marketing_platforms").select("id, name, display_order").order("display_order"),h.from("news_article_blurbs").select("*").eq("news_article_id",l).order("display_order")]);F(n.data||[]),y(i.data||[]),f(!1)},a=async()=>{o("new");const n=N.reduce((s,m)=>Math.max(s,m.display_order),-1),{data:i,error:j}=await h.from("news_article_blurbs").insert({news_article_id:l,blurb:"",display_order:n+1}).select().single();j?u({title:"Error",description:"Failed to add blurb",variant:"destructive"}):y(s=>[...s,i]),o(null)},c=async(n,i)=>{o(n);const{error:j}=await h.from("news_article_blurbs").update(i).eq("id",n);j?u({title:"Error",description:"Failed to update blurb",variant:"destructive"}):y(s=>s.map(m=>m.id===n?{...m,...i}:m)),o(null)},B=async n=>{const{error:i}=await h.from("news_article_blurbs").delete().eq("id",n);i?u({title:"Error",description:"Failed to delete blurb",variant:"destructive"}):y(j=>j.filter(s=>s.id!==n))};return T?e.jsx(C,{children:e.jsx(S,{className:"py-6 flex justify-center",children:e.jsx(P,{className:"h-5 w-5 animate-spin text-muted-foreground"})})}):e.jsxs(C,{children:[e.jsx(D,{children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx(L,{children:"Social Media Blurbs"}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(A,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(O,{to:`/admin/socials?news_article=${l}`,children:[e.jsx(xe,{className:"mr-1 h-3 w-3"}),"Schedule Post"]})}),e.jsxs(A,{size:"sm",onClick:a,disabled:v==="new",children:[v==="new"?e.jsx(P,{className:"mr-1 h-3 w-3 animate-spin"}):e.jsx(Z,{className:"mr-1 h-3 w-3"}),"Add Blurb"]})]})]})}),e.jsx(S,{className:"space-y-4",children:N.length===0?e.jsx("p",{className:"text-sm text-muted-foreground text-center py-4",children:"No blurbs yet. Add platform-specific blurbs for social media posts."}):N.map(n=>e.jsxs("div",{className:"border rounded-lg p-4 space-y-3",children:[e.jsxs("div",{className:"grid gap-3 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsx(g,{className:"text-xs",children:"Platform"}),e.jsxs(ue,{value:n.platform_id||"none",onValueChange:i=>c(n.id,{platform_id:i==="none"?null:i}),children:[e.jsx(me,{className:"h-8 text-sm",children:e.jsx(he,{})}),e.jsxs(pe,{children:[e.jsx(V,{value:"none",children:"General (all platforms)"}),_.map(i=>e.jsx(V,{value:i.id,children:i.name},i.id))]})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(g,{className:"text-xs",children:"Author"}),e.jsx(E,{className:"h-8 text-sm",value:n.author||"",onChange:i=>c(n.id,{author:i.target.value||null}),placeholder:"Optional author"})]})]}),e.jsxs("div",{className:"space-y-1",children:[e.jsx(g,{className:"text-xs",children:"Blurb Text"}),e.jsx(U,{value:n.blurb,onChange:i=>c(n.id,{blurb:i.target.value}),placeholder:"Write the blurb text...",rows:3,className:"text-sm"})]}),e.jsx("div",{className:"flex justify-end",children:e.jsxs(A,{variant:"ghost",size:"sm",className:"text-destructive hover:text-destructive",onClick:()=>B(n.id),children:[e.jsx(te,{className:"mr-1 h-3 w-3"}),"Delete"]})})]},n.id))})]})}const je=l=>l.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim();function _e({selectedTagIds:l,onChange:u}){const{toast:_}
1=$(),[F,N]=d.useState([]),[y,T]=d.useState(!0),[f,v]=d.useState(!1),[o,b]=d.useState("");d.useEffect(()=>{a()},[]);const a=async()=>{const{data:s,error:m}=await h.from("news_tags").select("id, name, slug, color").order("name");!m&&s&&N(s),T(!1)},c=s=>{l.includes(s)?u(l.filter(m=>m!==s)):u([...l,s])},B=async()=>{const s=o.trim();if(!s)return;const m=F.find(R=>R.name.toLowerCase()===s.toLowerCase());if(m){l.includes(m.id)||u([...l,m.id]),b("");return}v(!0);const{data:q,error:I}=await h.from("news_tags").insert({name:s,slug:je(s)}).select("id, name, slug, color").single();if(v(!1),I){_({title:"Error",description:"Failed to create tag",variant:"destructive"});return}N(R=>[...R,q].sort((M,z)=>M.name.localeCompare(z.name))),u([...l,q.id]),b("")},n=s=>{s.key==="Enter"&&(s.preventDefault(),B())},i=F.filter(s=>l.includes(s.id)),j=F.filter(s=>!l.includes(s.id));return e.jsxs("div",{className:"space-y-3",children:[e.jsx(g,{children:"Tags"}),y?e.jsx(P,{className:"h-4 w-4 animate-spin text-muted-foreground"}):e.jsxs(e.Fragment,{children:[i.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:i.map(s=>e.jsxs(K,{variant:"default",className:"cursor-pointer",onClick:()=>c(s.id),children:[s.name,e.jsx(W,{className:"h-3 w-3 ml-1"})]},s.id))}),j.length>0&&e.jsx("div",{className:"flex flex-wrap gap-2",children:j.map(s=>e.jsx(K,{variant:"outline",className:"cursor-pointer hover:bg-accent",onClick:()=>c(s.id),children:s.name},s.id))}),e.jsxs("div",{className:"flex gap-2",children:[e.jsx(E,{value:o,onChange:s=>b(s.target.value),onKeyDown:n,placeholder:"Create a new tag...",className:"max-w-xs"}),e.jsxs(A,{type:"button",variant:"outline",size:"sm",onClick:B,disabled:f||!o.trim(),children:[f?e.jsx(P,{className:"h-4 w-4 animate-spin"}):e.jsx(Z,{className:"h-4 w-4"}),"Add"]})]}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Click a tag to add or remove it. Type a new name and press Enter to create one."})]})]})}const ve={title:"",slug:"",excerpt:"",content:"",featured_image_url:"",featured_image_alt:"",meta_title:"",meta_description:"",is_published:!1,published_at:"",author_name:""};function Me(){const{id:l}=se(),u=!!l,{user:_,isAdmin:F,isMarketing:N,isTrustee:y,loading:T}=ae(),f=F||N||y,v=re(),{toast:o}
1=$(),b=d.useRef(null),[a,c]=d.useState(ve),[B,n]=d.useState(u),[i,j]=d.useState(!1),[s,m]=d.useState(!1),[q,I]=d.useState([]),[R,M]=d.useState([]),z=d.useRef(!1);d.useEffect(()=>{!T&&(!_||!f)&&v("/auth?redirect=/admin/news")},[_,f,T,v]),d.useEffect(()=>{u&&_&&f&&!z.current&&(z.current=!0,H())},[l,_,f]);const H=async()=>{try{const{data:t,error:r}=await h.from("news_articles").select("*").eq("id",l).single();if(r)throw r;c({title:t.title||"",slug:t.slug||"",excerpt:t.excerpt||"",content:t.content||"",featured_image_url:t.featured_image_url||"",featured_image_alt:t.featured_image_alt||"",meta_title:t.meta_title||"",meta_description:t.meta_description||"",is_published:t.is_published||!1,published_at:t.published_at?t.published_at.split("T")[0]:"",author_name:t.author_name||""});const{data:p}=await h.from("news_article_tags").select("tag_id").eq("article_id",t.id),x=(p||[]).map(w=>w.tag_id);I(x),M(x)}catch(t){console.error("Error fetching article:",t),o({title:"Error",description:"Failed to load article",variant:"destructive"}),v("/admin/news")}finally{n(!1)}},X=t=>t.toLowerCase().replace(/[^a-z0-9\s-]/g,"").replace(/\s+/g,"-").replace(/-+/g,"-").trim(),J=t=>{const r=t.target.value;c(p=>({...p,title:r,slug:u?p.slug:X(r)}))},Q=async t=>{const r=t.target.files?.[0];if(r){m(!0);try{const p=await de(r,oe.banner),x=`${Date.now()}-${r.name.replace(/[^a-zA-Z0-9.-]/g,"_")}`,{error:w}=await h.storage.from("news").upload(x,p.file);if(w)throw w;const{data:{publicUrl:k}}=h.storage.from("news").getPublicUrl(x);c(G=>({...G,featured_image_url:k,featured_image_alt:G.featured_image_alt||a.title})),o({title:"Success",description:"Image uploaded successfully"})}catch(p){console.error("Error uploading image:",p),o({title:"Error",description:"Failed to upload image",variant:"destructive"})}finally{m(!1),b.current&&(b.current.value="")}}},Y=()=>{c(t=>({...t,featured_image_url:"",featured_image_alt:""}))},ee=async t=>{if(t.preventDefault(),!a.title.trim()){o({title:"Error",description:"Title is required",variant:"destructive"});return}if(!a.slug.trim()){o({title:"Error",description:"Slug is required",variant:"destructive"});return}if(!a.excerpt.trim()){o({title:"Error",description:"Excerpt is required",variant:"destructive"});return}if(!a.content.trim()){o({title:"Error",description:"Content is required",variant:"destructive"});return}j(!0);try{const r={title:a.title.trim(),slug:a.slug.trim(),excerpt:a.excerpt.trim(),content:a.content,featured_image_url:a.featured_image_url||null,featured_image_alt:a.featured_image_alt||null,meta_title:a.meta_title.trim()||null,meta_description:a.meta_description.trim()||null,is_published:a.is_published,published_at:a.published_at?new Date(a.published_at).toISOString():a.is_published?new Date().toISOString():null,author_name:a.author_name.trim()||null};let p=l;if(u){const{error:x}=await h.from("news_articles").update(r).eq("id",l);if(x)throw x;o({title:"Success",description:"Article updated"})}else{const{data:x,error:w}=await h.from("news_articles").insert({...r,created_by:_?.id}).select("id").single();if(w)throw w;p=x.id,o({title:"Success",description:"Article created"})}if(p){const x=q.filter(k=>!R.includes(k)),w=R.filter(k=>!q.includes(k));w.length>0&&await h.from("news_article_tags").delete().eq("article_id",p).in("tag_id",w),x.length>0&&await h.from("news_article_tags").insert(x.map(k=>({article_id:p,tag_id:k})))}v("/admin/news")}catch(r){console.error("Error saving article:",r),o({title:"Error",description:r.message?.includes("unique")?"An article with this slug already exists":"Failed to save article",variant:"destructive"})}finally{j(!1)}};return T||B?e.jsx("div",{className:"min-h-screen flex items-center justify-center",children:e.jsx(P,{className:"h-8 w-8 animate-spin text-primary"})}):!_||!f?null:e.jsx("div",{className:"min-h-screen bg-background",children:e.jsxs("div",{className:"container mx-auto px-4 py-8",children:[e.jsxs("div",{className:"flex items-center gap-4 mb-8",children:[e.jsx(A,{variant:"ghost",size:"icon",asChild:!0,children:e.jsx(O,{to:"/admin/news",children:e.jsx(ie,{className:"h-5 w-5"})})}),e.jsx("h1",{className:"text-3xl font-bold text-foreground",children:u?"Edit Article":"New Art
1icle"})]}),e.jsxs("form",{onSubmit:ee,className:"space-y-6 max-w-4xl",children:[e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"Article Details"})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"title",children:"Title *"}),e.jsx(E,{id:"title",value:a.title,onChange:J,placeholder:"Article title"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"slug",children:"Slug *"}),e.jsx(E,{id:"slug",value:a.slug,onChange:t=>c(r=>({...r,slug:t.target.value})),placeholder:"article-slug"})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"excerpt",children:"Excerpt *"}),e.jsx(U,{id:"excerpt",value:a.excerpt,onChange:t=>c(r=>({...r,excerpt:t.target.value})),placeholder:"Brief summary of the article (shown in listings)",rows:3})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"author",children:"Author Name"}),e.jsx(E,{id:"author",value:a.author_name,onChange:t=>c(r=>({...r,author_name:t.target.value})),placeholder:"Optional author name"})]})]})]}),e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"Tags"})}),e.jsx(S,{children:e.jsx(_e,{selectedTagIds:q,onChange:I})})]}),e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"Featured Image"})}),e.jsxs(S,{className:"space-y-4",children:[a.featured_image_url?e.jsxs("div",{className:"relative",children:[e.jsx(le,{src:a.featured_image_url,alt:a.featured_image_alt||a.title,className:"w-full max-h-64 object-cover rounded-lg"}),e.jsx(A,{type:"button",variant:"destructive",size:"icon",className:"absolute top-2 right-2",onClick:Y,children:e.jsx(W,{className:"h-4 w-4"})})]}):e.jsx("div",{className:"border-2 border-dashed border-border rounded-lg p-8 text-center cursor-pointer hover:border-primary/50 transition-colors",onClick:()=>b.current?.click(),children:s?e.jsx(P,{className:"h-8 w-8 animate-spin mx-auto text-muted-foreground"}):e.jsxs(e.Fragment,{children:[e.jsx(ge,{className:"h-8 w-8 mx-auto text-muted-foreground mb-2"}),e.jsx("p",{className:"text-muted-foreground",children:"Click to upload featured image"})]})}),e.jsx("input",{ref:b,type:"file",accept:"image/*",onChange:Q,className:"hidden"}),a.featured_image_url&&e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"imageAlt",children:"Image Alt Text"}),e.jsx(E,{id:"imageAlt",value:a.featured_image_alt,onChange:t=>c(r=>({...r,featured_image_alt:t.target.value})),placeholder:"Describe the image for accessibility"})]})]})]}),e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"Content *"})}),e.jsx(S,{children:e.jsx(ce,{value:a.content,onChange:t=>c(r=>({...r,content:t})),placeholder:"Write your article content here..."})})]}),u&&l&&e.jsx(fe,{newsArticleId:l}),e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"SEO Settings"})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"metaTitle",children:"Meta Title"}),e.jsx(E,{id:"metaTitle",value:a.meta_title,onChange:t=>c(r=>({...r,meta_title:t.target.value})),placeholder:"SEO title (defaults to article title)"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"metaDescription",children:"Meta Description"}),e.jsx(U,{id:"metaDescription",value:a.meta_description,onChange:t=>c(r=>({...r,meta_description:t.target.value})),placeholder:"SEO description (defaults to excerpt)",rows:2})]})]})]}),e.jsxs(C,{children:[e.jsx(D,{children:e.jsx(L,{children:"Publishing"})}),e.jsxs(S,{className:"space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(g,{htmlFor:"published",children:"Published"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Make this article visible to the public"})]}),e.jsx(ne,{id:"published",checked:a.is_published,onCheckedChange:t=>c(r=>({...r,is_published:t}))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(g,{htmlFor:"publishedAt",children:"Published Date"}),e.jsx(E,{id:"publishedAt",type:"date",value:a.published_at,onChange:t=>c(r=>({...r,published_at:t.target.value}))}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Leave empty to use current date when publishing"})]})]})]}),e.jsxs("div",{className:"flex items-center gap-4",children:[e.jsxs(A,{type:"submit",disabled:i,children:[i&&e.jsx(P,{className:"h-4 w-4 mr-2 animate-spin"}),u?"Update Article":"Create Article"]}),e.jsx(A,{type:"button",variant:"outline",asChild:!0,children:e.jsx(O,{to:"/admin/news",children:"Cancel"})})]})]})]})})}export{Me 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.