PageSourceSearch

https://atzuma.co.il/assets/AdminPetitionApprovals-CmG1Wqmb.js

js atzuma.co.il collected 2026-10-02 07:47:08 UTC 17,581 bytes, 11 lines download raw bytes

1import{j as e}from"./index-C_Fqshtm.js";import{r as s}from"./router-BXL9ASSk.js";import{P as G}from"./PricingAssignmentModal-XL3cr0H4.js";import{S as J}from"./SegmentAssignDialog-CMIEx-lk.js";import"./vendor-BNcAc9ko.js";(function(){try{var l=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{};l.SENTRY_RELEASE={id:"[email protected]"}}catch{}})();try{(function(){var l=typeof window<"u"?window:typeof global<"u"?global:typeof globalThis<"u"?globalThis:typeof self<"u"?self:{},c=new l.Error().stack;c&&(l._sentryDebugIds=l._sentryDebugIds||{},l._sentryDebugIds[c]="5623ebfc-4b42-4459-9112-53b0ada64520",l._sentryDebugIdIdentifier="sentry-dbid-5623ebfc-4b42-4459-9112-53b0ada64520")})()}catch{}const m="/api/v1/admin/petitions",K=10,h=()=>({Authorization:`Bearer ${localStorage.getItem("auth_token")}`,Accept:"application/json","Content-Type":"application/json"}),Z=()=>{const[l,c]=s.useState([]),[M,O]=s.useState([]),[P,S]=s.useState(!0),[u,U]=s.useState(""),[r,o]=s.useState(null),[j,E]=s.useState(!1),[y,i]=s.useState(""),[C,T]=s.useState(null),[b,N]=s.useState([]),[A,D]=s.useState(!0),[d,z]=s.useState(7),[$,w]=s.useState(!1),[g,v]=s.useState(null),p=s.useCallback(async()=>{S(!0),i("");try{const t=u?`?search=${encodeURIComponent(u)}`:"",a=await fetch(`${m}/pending-approval${t}`,{headers:h()});if(!a.ok)throw new Error(`HTTP ${a.status}`);const n=await a.json();c(Array.isArray(n)?n:n.data??[])}catch{i("Failed to load petitions"),c([])}finally{S(!1)}},[u]),B=s.useCallback(async()=>{try{const t=await fetch(`${m}/approval-templates`,{headers:h()});if(!t.ok)return;const a=await t.json();O(Array.isArray(a)?a:[])}catch{}},[]),x=s.useCallback(async t=>{D(!0);try{const a=await fetch(`${m}/no-payment-recent?days=${t}`,{headers:h()});if(!a.ok)throw new Error(`HTTP ${a.status}`);const n=await a.json();N(Array.isArray(n)?n:n.data??[])}catch{N([])}finally{D(!1)}},[]),L=async t=>{if(window.confirm(`האם לאפשר תשלום לעצומה זו?
2${t.title}
3
4לאחר האישור, משתמשים שיחתמו יועברו לעמוד Hero.`)){N(n=>n.filter(_=>_.petition_id!==t.petition_id));try{const n=await fetch(`${m}/${t.petition_id}/payment-flag`,{method:"PATCH",headers:h(),body:JSON.stringify({is_payment_enabled:!0})});if(!n.ok)throw new Error(`HTTP ${n.status}`)}catch{x(d)}}},f=async(t,a,n,_)=>{if(!(!window.confirm(`Delete petition #${t}?
5"${a}"
6
7The petition will be permanently removed from the site (archived to deleted_petitions).`)||(_?n>0:n>K)&&window.prompt(`⚠️ This petition has ${n} signatures (and possibly payments).
8Signatures and payment records will be KEPT in the database, but the petition will be removed from the site.
9
10Type DELETE to confirm:`)!=="DELETE"))try{const k=await fetch(`${m}/${t}/hard-delete`,{method:"DELETE",headers:h()});if(!k.ok)throw new Error(`HTTP ${k.status}`);p(),x(d)}catch{alert("Delete failed")}};s.useEffect(()=>{p(),B()},[]),s.useEffect(()=>{x(d)},[d,x]);const I=t=>{i(""),o({petition:t,isPaymentEnabled:null,templateId:null})},F=async()=>{if(!r||r.isPaymentEnabled===null){i("You must choose whether payment is enabled");return}E(!0),i("");try{const t=await fetch(`${m}/${r.petition.petition_id}/approve`,{method:"POST",headers:h(),body:JSON.stringify({is_payment_enabled:r.isPaymentEnabled,template_id:r.templateId})});if(!t.ok)throw new Error(`HTTP ${t.status}`);o(null),p(),x(d)}catch{i("Approval failed. Please try again.")}finally{E(!1)}},H=(t,a)=>{window.location.href=`/sign/${a||t}/manage`},R=(t,a)=>{window.open(`/sign/${a||t}`,"_blank")};return e.jsxs("div",{className:"p-4 md:p-6 max-w-7xl mx-auto",dir:"ltr",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:justify-between md:items-center mb-6",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold text-gray-900",children:"📋 Petition Approvals"}),e.jsx("p",{className:"text-gray-500 text-sm mt-1",children:"Review and approve published petitions"})]}),e.jsx("a",{href:"/admin/main",className:"text-sm border border-gray-300 rounded px-4 py-2 hover:bg-gray-50 text-center md:text-left",children:"← Back to Admin"})]}),e.jsxs("div",{className:"mb-4 flex flex-col md:flex-row gap-3",children:[e.jsx("input",{type:"text",placeholder:"Search by title...",value:u,onChange:t=>U(t.target.value),onKeyDown:t=>t.key==="Enter"&&p(),className:"border rounded px-3 py-2 w-full md:w-64"}),e.jsx("button",{onClick:p,className:"bg-green-600 text-white px-4 py-2 rounded hover:bg-green-700",children:"Search"}),e.jsxs("span",{className:"md:self-center text-sm text-gray-500",children:[l.length," pending approval"]})]}),y&&!r&&e.jsxs("div",{className:"bg-red-50 border border-red-200 text-red-700 px-4 py-2 rounded mb-4",children:[y,e.jsx("button",{onClick:()=>i(""),className:"ml-2 font-bold",children:"×"})]}),e.jsx("div",{className:"hidden md:block bg-white border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Petition"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Signatures"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Creator"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Created"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Actions"})]})}),e.jsx("tbody",{children:P?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-8 text-gray-400",children:"Loading..."})}):l.length===0?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-8 text-gray-400",children:"No petitions pending approval"})}):l.map(t=>e.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("div",{className:"font-medium text-gray-900",children:t.title}),e.jsxs("div",{className:"text-xs text-gray-400",children:["#",t.petition_id]})]}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:t.current_signatures_count??0}),e.jsxs("td",{className:"px-4 py-3 text-gray-600 text-xs",children:[t.creator?.name,e.jsx("br",{}),e.jsx("span",{className:"text-gray-400",children:t.creator?.email})]}),e.jsx("td",{className:"px-4 py-3 text-gray-500 text-xs",children:new Date(t.created_at).toLocaleDateString("he-IL")}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex gap-2 flex-wrap",children:[e.jsx("button",{onClick:()=>H(t.petition_id,t.slug),className:"bg-green-600 text-white text-xs px-3 py-1.5 rounded hover:bg-green-700",children:"Manage"}),e.jsx("button",{onClick:()=>R(t.petition_id,t.slug),className:"border border-gray-300 text-gray-600 text-xs px-3 py-1.5 rounded hover:bg-gray-50",children:"View"}),e.jsx("button",{onClick:()=>I(t),className:"bg-purple-600 text-white text-xs px-3 py-1.5 rounded hover:bg-purple-700",children:"Approve →"}),e.jsx("button",{onClick:()=>T(t.petition_id),className:"bg-indigo-600 text-white text-xs px-3 py-1.5 rounded hover:bg-indigo-700",children:"Segments"}),e.jsx("button",{onClick:()=>f(t.petition_id,t.title,t.current_signatures_count??0,!1),className:"bg-red-600 text-white text-xs px-3 py-1.5 rounded hover:bg-red-700",children:"Delete"})]})})]},t.petition_id))})]})}),e.jsx("div",{className:"md:hidden space-y-3",children:P?e.jsx("div",{className:"bg-white border rounded-lg py-8 text-center text-gray-400",children:"Loading..."}):l.length===0?e.jsx("div",{className:"bg-white border rounded-lg py-8 text-center text-gray-400",children:"No petitions pending approval"}):l.map(t=>e.jsxs("div",{className:"bg-white border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-start gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("div",{className:"font-medium text-gray-900 break-words",children:t.title}),e.jsxs("div",{className:"text-xs text-gray-400",children:["#",t.petition_id]})]}),e.jsxs("span",{className:"shrink-0 text-xs font-medium bg-gray-100 text-gray-600 rounded-full px-2.5 py-1",children:[t.current_signatures_count??0," sigs"]})]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 space-y-0.5",children:[e.jsxs("div",{className:"break-words",children:[t.creator?.name," · ",e.jsx("span",{className:"text-gray-400",children:t.creator?.email})]}),e.jsx("div",{children:new Date(t.created_at).toLocaleDateString("he-IL")})]}),e.jsxs("div",{className:"mt-3 flex gap-2",children:[e.jsx("button",{onClick:()=>H(t.petition_id,t.slug),className:"flex-1 bg-green-600 text-white text-sm px-3 py-2.5 rounded hover:bg-green-700",children:"Manage"}),e.jsx("button",{onClick:()=>R(t.petition_id,t.slug),className:"flex-1 border border-gray-300 text-gray-600 text-sm px-3 py-2.5 rounded hover:bg-gray-50",children:"View"})]}),e.jsx("button",{onClick:()=>I(t),className:"mt-2 w-full bg-purple-600 text-white text-sm font-medium px-3 py-2.5 rounded hover:bg-purple-700",children:"Approve →"}),e.jsx("button",{onClick:()=>f(t.petition_id,t.title,t.current_signatures_count??0,!1),className:"mt-2 w-full bg-red-600 text-white text-sm font-medium px-3 py-2.5 rounded hover:bg-red-700",children:"Delete"})]},t.petition_id))}),e.jsxs("div",{className:"mt-12",children:[e.jsxs("div",{className:"flex flex-col gap-3 md:flex-row md:justify-between md:items-center mb-3",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-bold text-gray-900",children:"💸 Recently Added, Not Approved for Payment"}),e.jsx("p",{className:"text-gray-500 text-sm mt-1",children:"Approved & live petitions with payment still disabled. Click ₪ to enable."})]}),e.jsx("div",{className:"flex gap-2",children:[7,14,30].map(t=>e.jsxs("button",{onClick:()=>z(t),className:`text-sm px-4 py-2 rounded border transition-colors ${d===t?"bg-purple-600 text-white border-purple-600":"bg-white text-gray-600 border-gray-300 hover:bg-gray-50"}`,children:[t," ימים"]},t))})]}),e.jsx("div",{className:"hidden md:block bg-white border rounded-lg overflow-hidden",children:e.jsxs("table",{className:"w-full text-sm",children:[e.jsx("thead",{className:"bg-gray-50 border-b",children:e.jsxs("tr",{children:[e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Petition"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Signatures"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Creator"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Created"}),e.jsx("th",{className:"text-left px-4 py-3 font-medium text-gray-600",children:"Payment"})]})}),e.jsx("tbody",{children:A?e.jsx("tr",{children:e.jsx("td",{colSpan:5,className:"text-center py-8 text-gray-400",children:"Loading..."})}):b.length===0?e.jsx("tr",{children:e.jsxs("td",{colSpan:5,className:"text-center py-8 text-gray-400",children:["No petitions in the last ",d," days awaiting payment"]})}):b.map(t=>e.jsxs("tr",{className:"border-b hover:bg-gray-50",children:[e.jsxs("td",{className:"px-4 py-3",children:[e.jsx("a",{href:`/sign/${t.slug||t.petition_id}`,target:"_blank",rel:"noopener noreferrer",className:"font-medium text-blue-700 hover:underline",children:t.title}),e.jsxs("div",{className:"text-xs text-gray-400",children:["#",t.petition_id]})]}),e.jsx("td",{className:"px-4 py-3 text-gray-600",children:t.current_signatures_count??0}),e.jsxs("td",{className:"px-4 py-3 text-gray-600 text-xs",children:[t.creator?.name,e.jsx("br",{}),e.jsx("span",{className:"text-gray-400",children:t.creator?.email})]}),e.jsx("td",{className:"px-4 py-3 text-gray-500 text-xs",children:new Date(t.created_at).toLocaleDateString("he-IL")}),e.jsx("td",{className:"px-4 py-3",children:e.jsxs("div",{className:"flex gap-2 items-center",children:[e.jsx("button",{onClick:()=>L(t),title:"Payment disabled — click to enable (Hero page after sign)",className:"bg-gray-100 text-gray-400 border border-gray-300 text-base px-3 py-1.5 rounded hover:bg-green-50 hover:text-green-600 hover:border-green-500 transition-colors",children:"🚫 → ₪"}),e.jsx("button",{onClick:()=>{v(t),w(!0)},className:"bg-emerald-600 text-white text-xs px-3 py-1.5 rounded hover:bg-emerald-700",children:"Pricing"}),e.jsx("button",{onClick:()=>f(t.petition_id,t.title,t.current_signatures_count??0,!0),className:"bg-red-600 text-white text-xs px-3 py-1.5 rounded hover:bg-red-700",children:"Delete"})]})})]},t.petition_id))})]})}),e.jsx("div",{className:"md:hidden space-y-3",children:A?e.jsx("div",{className:"bg-white border rounded-lg py-8 text-center text-gray-400",children:"Loading..."}):b.length===0?e.jsxs("div",{className:"bg-white border rounded-lg py-8 text-center text-gray-400",children:["No petitions in the last ",d," days awaiting payment"]}):b.map(t=>e.jsxs("div",{className:"bg-white border rounded-lg p-4",children:[e.jsxs("div",{className:"flex justify-between items-start gap-3",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("a",{href:`/sign/${t.slug||t.petition_id}`,target:"_blank",rel:"noopener noreferrer",className:"font-medium text-blue-700 hover:underline break-words",children:t.title}),e.jsxs("div",{className:"text-xs text-gray-400",children:["#",t.petition_id]})]}),e.jsxs("span",{className:"shrink-0 text-xs font-medium bg-gray-100 text-gray-600 rounded-full px-2.5 py-1",children:[t.current_signatures_count??0," sigs"]})]}),e.jsxs("div",{className:"mt-2 text-xs text-gray-500 space-y-0.5",children:[e.jsxs("div",{className:"break-words",children:[t.creator?.name," · ",e.jsx("span",{className:"text-gray-400",children:t.creator?.email})]}),e.jsx("div",{children:new Date(t.created_at).toLocaleDateString("he-IL")})]}),e.jsx("button",{onClick:()=>L(t),className:"mt-3 w-full bg-gray-100 text-gray-500 border border-gray-300 text-sm font-medium px-3 py-2.5 rounded hover:bg-green-50 hover:text-green-600 hover:border-green-500 transition-colors",children:"🚫 → ₪  Enable payment"}),e.jsx("button",{onClick:()=>{v(t),w(!0)},className:"mt-2 w-full bg-emerald-600 text-white text-sm font-medium px-3 py-2.5 rounded hover:bg-emerald-700",children:"Pricing"}),e.jsx("button",{onClick:()=>f(t.petition_id,t.title,t.current_signatures_count??0,!0),className:"mt-2 w-full bg-red-600 text-white text-sm font-medium px-3 py-2.5 rounded hover:bg-red-700",children:"Delete"})]},t.petition_id))})]}),$&&g&&e.jsx(G,{isOpen:$,language:"en",petition:{id:g.petition_id,slug:g.slug??"",title:g.title,signature_count:g.current_signatures_count},onClose:()=>{w(!1),v(null)},onSuccess:()=>{x(d)}}),r&&e.jsx("div",{className:"fixed inset-0 bg-black bg-opacity-40 flex items-end justify-center md:items-center z-50",children:e.jsxs("div",{className:"bg-white rounded-t-2xl md:rounded-lg shadow-xl p-6 w-full max-w-md max-h-[90vh] overflow-y-auto",children:[e.jsx("div",{className:"md:hidden w-10 h-1 bg-gray-300 rounded-full mx-auto mb-4"}),e.jsx("h2",{className:"text-lg font-bold mb-1",children:"Approve Petition"}),e.jsx("p",{className:"text-sm text-gray-500 mb-4 truncate",children:r.petition.title}),e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Payment Enabled ",e.jsx("span",{className:"text-red-500",children:"*"})]}),e.jsxs("div",{className:"flex flex-col md:flex-row gap-3 md:gap-4",children:[e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"payment",checked:r.isPaymentEnabled===!0,onChange:()=>o({...r,isPaymentEnabled:!0})}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-green-700",children:"Yes"}),e.jsx("span",{className:"text-gray-400 ml-1",children:"→ Hero page after sign"})]})]}),e.jsxs("label",{className:"flex items-center gap-2 cursor-pointer",children:[e.jsx("input",{type:"radio",name:"payment",checked:r.isPaymentEnabled===!1,onChange:()=>o({...r,isPaymentEnabled:!1,templateId:null})}),e.jsxs("span",{className:"text-sm",children:[e.jsx("span",{className:"font-medium text-orange-600",children:"No"}),e.jsx("span",{className:"text-gray-400 ml-1",children:"→ Share page after sign"})]})]})]})]}),r.isPaymentEnabled===!0&&e.jsxs("div",{className:"mb-4",children:[e.jsxs("label",{className:"block text-sm font-medium text-gray-700 mb-2",children:["Pricing Temp
10late ",e.jsx("span",{className:"text-gray-400 font-normal",children:"(optional — uses default if not set)"})]}),e.jsxs("select",{value:r.templateId??"",onChange:t=>o({...r,templateId:t.target.value?Number(t.target.value):null}),className:"border rounded px-3 py-2 w-full text-sm",children:[e.jsx("option",{value:"",children:"Use default template"}),M.map(t=>e.jsxs("option",{value:t.id,children:[t.name," (",t.currency,")"]},t.id))]})]}),y&&e.jsx("p",{className:"text-red-600 text-sm mb-3",children:y}),e.jsxs("div",{className:"flex flex-col md:flex-row md:justify-end gap-2 md:gap-3 mt-4",children:[e.jsx("button",{onClick:()=>{o(null),i("")},className:"w-full md:w-auto border border-gray-300 text-gray-600 px-4 py-2.5 md:py-2 rounded hover:bg-gray-50",disabled:j,children:"Cancel"}),e.jsx("button",{onClick:F,disabled:j||r.isPaymentEnabled===null,className:"w-full md:w-auto bg-purple-600 text-white px-4 py-2.5 md:py-2 rounded hover:bg-purple-700 disabled:opacity-50 disabled:cursor-not-allowed",children:j?"Approving...":"Approve Petition"})]})]})}),C!==null&&e.jsx(J,{petitionId:C,onClose:()=>T(null)})]})};export{Z as default};
11//# sourceMappingURL=AdminPetitionApprovals-CmG1Wqmb.js.map

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.