PageSourceSearch

https://www.abbeytheatre.co.uk/assets/AdminCompanyForm-CPkFWUyl.js

js abbeytheatre.co.uk collected 2026-09-25 08:04:43 UTC 15,592 bytes, 1 lines download raw bytes

1import{i as ee,a5 as se,l as te,k as ae,r as p,s as g,q as n,j as e,B as x,A as re,ah as ie,v as l,a7 as le,a8 as oe,a as F,Z as ne,I as m,P as ce,M as de,bd as q}from"./index-tvAeWDDu.js";import{T as me}from"./textarea-DCmtwFFs.js";import{S as ue,a as he,b as pe,c as ge,d as N}from"./select-D_9989fq.js";import{processImageForUpload as xe,IMAGE_PRESETS as fe}from"./imageUtils-RoQh2GsP.js";import{I as je}from"./inbox-63GrwqeH.js";import{M as be}from"./mail-DB-vKzSm.js";import{B as ye}from"./building-2-DEVKhFGO.js";import{U as ve}from"./upload-D8RcvExm.js";import"./index-BdQq_4o_.js";import"./chevron-down-DdqJBhHb.js";import"./chevron-up-eQONr_xY.js";const _e=ee("Ban",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"m4.9 4.9 14.2 14.2",key:"1m5liu"}]]);let M=0;const we=1100;async function Ne(){const r=Date.now(),c=M+we-r;c>0&&await new Promise(o=>setTimeout(o,c)),M=Date.now()}async function Ce(r){const c=[r.postcode,r.town,r.county,"United Kingdom"].map(y=>(y||"").trim()).filter(Boolean).join(", ");if(!c)return null;await Ne();const o=new URL("https://nominatim.openstreetmap.org/search");o.searchParams.set("q",c),o.searchParams.set("format","json"),o.searchParams.set("limit","1"),o.searchParams.set("countrycodes","gb"),o.searchParams.set("addressdetails","0");const b=await fetch(o.toString(),{headers:{Accept:"application/json"}});if(!b.ok)throw new Error(`Geocoder error ${b.status}`);const f=await b.json();return!f||f.length===0?null:{latitude:parseFloat(f[0].lat),longitude:parseFloat(f[0].lon),display_name:f[0].display_name}}function qe(){const{id:r}=se(),c=te(),{user:o,isAdmin:b,isTrustee:f,loading:y}=ae(),v=b||f,[C,j]=p.useState(!1),[S,L]=p.useState(!1),[I,P]=p.useState(!1),[D,T]=p.useState([]),[k,U]=p.useState([]),[A,E]=p.useState(""),[d,B]=p.useState(null),[t,i]=p.useState({name:"",slug:"",logo_url:"",description:"",facebook_url:"",instagram_url:"",email:"",phone:"",website_url:"",entry_type:"company",town:"",county:"Warwickshire",postcode:"",latitude:"",longitude:"",is_published:!0,is_featured:!1}),R=s=>s.toLowerCase().replace(/[^a-z0-9]+/g,"-").replace(/^-+|-+$/g,""),$=s=>{i(a=>({...a,name:s,...r?{}:{slug:R(s)}}))};p.useEffect(()=>{!y&&(!o||!v)&&c("/admin/login")},[o,v,y,c]),p.useEffect(()=>{o&&v&&(z(),r&&G())},[r,o,v]);const z=async()=>{const{data:s}=await g.from("directory_categories").select("id, name").eq("is_active",!0).order("sort_order");T(s||[])},G=async()=>{if(!r)return;const{data:s,error:a}=await g.from("companies").select("*, company_categories(category_id)").eq("id",r).single();if(a||!s){n.error("Failed to load company"),c("/admin/companies");return}i({name:s.name,slug:s.slug,logo_url:s.logo_url||"",description:s.description||"",facebook_url:s.facebook_url||"",instagram_url:s.instagram_url||"",email:s.email||"",phone:s.phone||"",website_url:s.website_url||"",entry_type:s.entry_type||"company",town:s.town||"",county:s.county||"Warwickshire",postcode:s.postcode||"",latitude:s.latitude!=null?String(s.latitude):"",longitude:s.longitude!=null?String(s.longitude):"",is_published:s.is_published??!0,is_featured:s.is_featured??!1}),E((s.tags||[]).join(", ")),U((s.company_categories||[]).map(h=>h.category_id)),B({submitter_name:s.submitter_name||null,submitter_email:s.submitter_email||null,submitted_by:s.submitted_by||null,approved_at:s.approved_at||null,rejected_at:s.rejected_at||null,created_at:s.created_at||null})},V=!!d&&(d.submitted_by!==null||!!d.submitter_name||!!d.submitter_email)&&!d.approved_at&&!d.rejected_at&&!t.is_published,W=async()=>{if(r){j(!0);try{const{error:s}=await g.from("companies").update({is_published:!0,approved_at:new Date().toISOString(),approved_by:o?.id||null}).eq("id",r);if(s)throw s;n.success("Suggestion approved and published"),c("/admin/companies")}catch(s){console.error(s),n.error("Failed to approve")}finally{j(!1)}}},O=async()=>{if(!r)return;const s=prompt("Reason for rejection (optional, kept for audit):")||null;if(confirm("Reject this suggestion? It will be hidden from public view.")){j(!0);try{const{error:a}=await g.from("companies").update({rejected_at:new Date().toISOString(),rejection_reason:s,is_published:!1}).eq("id",r);
1if(a)throw a;n.success("Suggestion rejected"),c("/admin/companies")}catch(a){console.error(a),n.error("Failed to reject")}finally{j(!1)}}},H=async s=>{const a=s.target.files?.[0];if(a){L(!0);try{const h=await xe(a,{...fe.thumbnail,maxWidth:400,maxHeight:400}),u=`logos/${`${Date.now()}-${Math.random().toString(36).substring(7)}.webp`}`,{error:w}=await g.storage.from("company-logos").upload(u,h.file);if(w)throw w;const{data:Q}=g.storage.from("company-logos").getPublicUrl(u);i(Y=>({...Y,logo_url:Q.publicUrl})),n.success("Logo uploaded")}catch(h){console.error(h),n.error("Failed to upload logo")}finally{L(!1)}}},K=()=>i(s=>({...s,logo_url:""})),X=s=>{U(a=>a.includes(s)?a.filter(h=>h!==s):[...a,s])},Z=async()=>{if(!t.postcode&&!t.town){n.error("Enter at least a town or postcode first");return}P(!0);try{const s=await Ce({postcode:t.postcode,town:t.town,county:t.county});if(!s){n.error("No location found for that address");return}i(a=>({...a,latitude:s.latitude.toFixed(6),longitude:s.longitude.toFixed(6)})),n.success("Coordinates updated")}catch(s){console.error(s),n.error("Geocoding failed")}finally{P(!1)}},J=async s=>{if(s.preventDefault(),!t.name.trim()){n.error("Name is required");return}j(!0);try{const a=A.split(",").map(u=>u.trim()).filter(Boolean),h={name:t.name.trim(),slug:t.slug||R(t.name),logo_url:t.logo_url||null,description:t.description||null,facebook_url:t.facebook_url||null,instagram_url:t.instagram_url||null,email:t.email||null,phone:t.phone||null,website_url:t.website_url||null,entry_type:t.entry_type,town:t.town||null,county:t.county||null,postcode:t.postcode||null,latitude:t.latitude.trim()===""?null:Number(t.latitude),longitude:t.longitude.trim()===""?null:Number(t.longitude),tags:a,is_published:t.is_published,is_featured:t.is_featured};let _=r;if(r){const{error:u}=await g.from("companies").update(h).eq("id",r);if(u)throw u}else{const{data:u,error:w}=await g.from("companies").insert([h]).select("id").single();if(w)throw w;_=u.id}_&&(await g.from("company_categories").delete().eq("company_id",_),k.length>0&&await g.from("company_categories").insert(k.map(u=>({company_id:_,category_id:u})))),n.success(r?"Listing updated":"Listing created"),c("/admin/companies")}catch(a){console.error(a),a?.code==="23505"?n.error("Slug already in use"):n.error("Failed to save")}finally{j(!1)}};return y||!o||!v?null:e.jsxs("div",{className:"min-h-screen bg-background",children:[e.jsx("header",{className:"border-b border-border",children:e.jsxs("div",{className:"container mx-auto px-4 py-4 flex items-center gap-3",children:[e.jsx(x,{variant:"ghost",size:"icon",onClick:()=>c("/admin/companies"),children:e.jsx(re,{className:"h-5 w-5"})}),e.jsx("h1",{className:"text-2xl font-bold text-foreground",children:r?"Edit Listing":"New Listing"})]})}),e.jsxs("main",{className:"container mx-auto px-4 py-8 max-w-2xl",children:[V&&d&&e.jsx("div",{className:"mb-6 rounded-lg border-2 border-primary/40 bg-primary/5 p-4",children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(je,{className:"h-5 w-5 text-primary mt-0.5 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsx("h2",{className:"font-semibold text-foreground",children:"Pending public suggestion"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["Submitted",d.created_at&&` on ${new Date(d.created_at).toLocaleDateString()}`,d.submitter_name&&` by ${d.submitter_name}`,d.submitter_email&&e.jsxs(e.Fragment,{children:[" — ",e.jsxs("a",{href:`mailto:${d.submitter_email}`,className:"text-primary inline-flex items-center gap-1 hover:underline",children:[e.jsx(be,{className:"h-3 w-3"}),d.submitter_email]})]})]}),e.jsxs("div",{className:"flex gap-2 mt-3 flex-wrap",children:[e.jsxs(x,{type:"button",size:"sm",onClick:W,disabled:C,children:[e.jsx(ie,{className:"mr-2 h-4 w-4"}),"Approve & publish"]}),e.jsxs(x,{type:"button",size:"sm",variant:"destructive",onClick:O,disabled:C,children:[e.jsx(_e,{className:"mr-2 h-4 w-4"}),"Reject"]}),e.jsx("p",{className:"text-xs text-muted-foreground self-center ml-2",children:"Or edit the details below and Save as draft."})]})]})]})}),e.jsxs("form",{onSubmit:J,className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Logo / Image"}),e.jsxs("div",{className:"mt-2 flex items-center gap-4",children:[e.jsx("div",{className:"h-24 w-24 rounded-lg overflow-hidden bg-muted flex items-center justify-center border",children:t.logo_url?e.jsx(le,{src:oe(t.logo_url),alt:"Logo",className:"h-full w-full object-contain"}):e.jsx(ye,{className:"h-8 w-8 text-muted-foreground"})}),e.jsxs("div",{className:"flex flex-col gap-2",children:[e.jsxs("label",{className:"cursor-pointer",children:[e.jsx("input",{type:"file",accept:"image/*",onChange:H,className:"hidden",disabled:S}),e.jsx(x,{type:"button",variant:"outline",size:"sm",disabled:S,asChild:!0,children:e.jsxs("span",{children:[S?e.jsx(F,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(ve,{className:"mr-2 h-4 w-4"}),"Upload"]})})]}),t.logo_url&&e.jsxs(x,{type:"button",variant:"ghost",size:"sm",onClick:K,children:[e.jsx(ne,{className:"mr-2 h-4 w-4"}),"Remove"]})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"name",children:"Name *"}),e.jsx(m,{id:"name",value:t.name,onChange:s=>$(s.target.value),required:!0,className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"slug",children:"URL Slug"}),e.jsx(m,{id:"slug",value:t.slug,onChange:s=>i({...t,slug:s.target.value.toLowerCase().replace(/[^a-z0-9-]+/g,"-").replace(/^-+|-+$/g,"")}),className:"mt-1"}),e.jsxs("p",{className:"text-sm text-muted-foreground mt-1",children:["URL: /company/",t.slug||"name"]})]}),e.jsxs("div",{children:[e.jsx(l,{children:"Entry Type"}),e.jsxs(ue,{value:t.entry_type,onValueChange:s=>i({...t,entry_type:s}),children:[e.jsx(he,{className:"mt-1",children:e.jsx(pe,{})}),e.jsxs(ge,{children:[e.jsx(N,{value:"company",children:"Company / Organisation"}),e.jsx(N,{value:"venue",children:"Venue"}),e.jsx(N,{value:"individual",children:"Individual / Practitioner"}),e.jsx(N,{value:"group",children:"Group / Society"}),e.jsx(N,{value:"school",children:"School / Academy"})]})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"description",children:"Description"}),e.jsx(me,{id:"description",value:t.description,onChange:s=>i({...t,description:s.target.value}),rows:4,className:"mt-1"})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx(l,{children:"Categories"}),e.jsx("p",{className:"text-sm text-muted-foreground mb-2",children:"Select all that apply. Used for browsing the directory."}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[D.map(s=>
1e.jsx(ce,{variant:k.includes(s.id)?"default":"outline",className:"cursor-pointer",onClick:()=>X(s.id),children:s.name},s.id)),D.length===0&&e.jsx("p",{className:"text-sm text-muted-foreground",children:"No categories yet — add some in Directory Categories."})]})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"tags",children:"Tags"}),e.jsx(m,{id:"tags",value:A,onChange:s=>E(s.target.value),placeholder:"amateur, youth, comedy",className:"mt-1"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Comma-separated."})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Location"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-3",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"town",children:"Town"}),e.jsx(m,{id:"town",value:t.town,onChange:s=>i({...t,town:s.target.value}),placeholder:"Nuneaton",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"county",children:"County"}),e.jsx(m,{id:"county",value:t.county,onChange:s=>i({...t,county:s.target.value}),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"postcode",children:"Postcode"}),e.jsx(m,{id:"postcode",value:t.postcode,onChange:s=>i({...t,postcode:s.target.value}),placeholder:"CV11 5DB",className:"mt-1"})]})]}),e.jsxs("div",{className:"mt-6 rounded-md border border-border p-4 bg-muted/20",children:[e.jsxs("div",{className:"flex items-center justify-between gap-3 mb-3 flex-wrap",children:[e.jsxs("div",{children:[e.jsx(l,{className:"text-base",children:"Map coordinates"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Used to place a pin on the Arts Directory map."})]}),e.jsxs(x,{type:"button",variant:"outline",size:"sm",onClick:Z,disabled:I,children:[I?e.jsx(F,{className:"mr-2 h-4 w-4 animate-spin"}):e.jsx(de,{className:"mr-2 h-4 w-4"}),"Geocode from address"]})]}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"latitude",className:"text-xs",children:"Latitude"}),e.jsx(m,{id:"latitude",inputMode:"decimal",value:t.latitude,onChange:s=>i({...t,latitude:s.target.value}),placeholder:"52.523",className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"longitude",className:"text-xs",children:"Longitude"}),e.jsx(m,{id:"longitude",inputMode:"decimal",value:t.longitude,onChange:s=>i({...t,longitude:s.target.value}),placeholder:"-1.466",className:"mt-1"})]})]})]})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Contact Details"}),e.jsxs("div",{className:"grid gap-4 sm:grid-cols-2",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"email",children:"Email"}),e.jsx(m,{id:"email",type:"email",value:t.email,onChange:s=>i({...t,email:s.target.value}),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"phone",children:"Phone"}),e.jsx(m,{id:"phone",type:"tel",value:t.phone,onChange:s=>i({...t,phone:s.target.value}),className:"mt-1"})]})]})]}),e.jsxs("div",{className:"border-t pt-6",children:[e.jsx("h2",{className:"text-lg font-semibold mb-4",children:"Social & Web Links"}),e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(l,{htmlFor:"website_url",children:"Website"}),e.jsx(m,{id:"website_url",type:"url",value:t.website_url,onChange:s=>i({...t,website_url:s.target.value}),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"facebook_url",children:"Facebook"}),e.jsx(m,{id:"facebook_url",type:"url",value:t.facebook_url,onChange:s=>i({...t,facebook_url:s.target.value}),className:"mt-1"})]}),e.jsxs("div",{children:[e.jsx(l,{htmlFor:"instagram_url",children:"Instagram"}),e.jsx(m,{id:"instagram_url",type:"url",value:t.instagram_url,onChange:s=>i({...t,instagram_url:s.target.value}),className:"mt-1"})]})]})]}),e.jsxs("div",{className:"border-t pt-6 space-y-4",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Published"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Show this listing in the directory."})]}),e.jsx(q,{checked:t.is_published,onCheckedChange:s=>i({...t,is_published:s})})]}),e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{children:[e.jsx(l,{children:"Featured"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Pin to the top of directory results."})]}),e.jsx(q,{checked:t.is_featured,onCheckedChange:s=>i({...t,is_featured:s})})]})]}),e.jsxs("div",{className:"flex gap-4 pt-6",children:[e.jsx(x,{type:"submit",disabled:C,children:C?e.jsxs(e.Fragment,{children:[e.jsx(F,{className:"mr-2 h-4 w-4 animate-spin"}),"Saving..."]}):r?"Update Listing":"Create Listing"}),e.jsx(x,{type:"button",variant:"outline",onClick:()=>c("/admin/companies"),children:"Cancel"})]})]})]})]})}export{qe 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.