Changeset 3799706
- Timestamp:
- 11/13/2026 05:20:51 AM (3 days ago)
- Location:
- clientcopy-portal/tags/2.1.1
- Files:
-
- 12 edited
- 1 copied
-
. (copied) (copied from clientcopy-portal/trunk )
-
CHANGELOG.md (modified) (1 diff)
-
build/admin/index.asset.php (modified) (1 diff)
-
build/admin/index.js (modified) (1 diff)
-
clientcopy-portal.php (modified) (2 diffs)
-
includes/class-requests.php (modified) (1 diff)
-
includes/class-submissions.php (modified) (1 diff)
-
includes/class-workflow.php (modified) (6 diffs)
-
includes/rest/class-admin-controller.php (modified) (2 diffs)
-
readme.txt (modified) (2 diffs)
-
src/admin/api.js (modified) (1 diff)
-
src/admin/components/ActivityTab.js (modified) (3 diffs)
-
src/admin/components/ReviewPanel.js (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
clientcopy-portal/tags/2.1.1/CHANGELOG.md
r3799111 r3799706 1 1 # Changelog 2 3 ## 2.1.1 - 2026-11-13 4 - Fix: a decision now applies to the exact version you were reviewing. If the client has sent a newer version since you opened the item (for example after you asked for changes and they resubmitted), approving or requesting changes is refused with a prompt to reload, so unseen text is never written to a page. The review endpoint takes an optional `submission_id` for this; the admin screen always sends it. 5 - Fix: if two people decide the same item at the same moment, only the first decision is applied. 6 - The activity log and the review screen show which version of an item was submitted, approved or sent back. 2 7 3 8 ## 2.1.0 - 2026-11-06 -
clientcopy-portal/tags/2.1.1/build/admin/index.asset.php
r3799111 r3799706 7 7 'wp-i18n' 8 8 ), 9 'version' => ' b6a3fbe2b1c6ce4b36bf'9 'version' => '5110db34332e54e24774' 10 10 ); -
clientcopy-portal/tags/2.1.1/build/admin/index.js
r3799111 r3799706 1 (()=>{"use strict";var e={639(e,t,l){const a=window.wp.element,i=window.wp.i18n,s=window.ReactJSXRuntime,n=[{value:"text",label:(0,i.__)("Short text","clientcopy-portal")},{value:"rich_text",label:(0,i.__)("Rich text","clientcopy-portal")},{value:"image",label:(0,i.__)("Image","clientcopy-portal")},{value:"gallery",label:(0,i.__)("Gallery","clientcopy-portal")},{value:"file",label:(0,i.__)("File","clientcopy-portal")},{value:"url",label:(0,i.__)("URL","clientcopy-portal")},{value:"credentials",label:(0,i.__)("Credentials","clientcopy-portal")}],c=e=>(n.find(t=>t.value===e)||{}).label||e,r={pending:(0,i.__)("Waiting on client","clientcopy-portal"),submitted:(0,i.__)("Needs review","clientcopy-portal"),approved:(0,i.__)("Approved","clientcopy-portal"),rejected:(0,i.__)("Changes requested","clientcopy-portal"),active:(0,i.__)("Active","clientcopy-portal"),completed:(0,i.__)("Completed","clientcopy-portal"),archived:(0,i.__)("Archived","clientcopy-portal")},o={post_title:(0,i.__)("Title","clientcopy-portal"),post_content:(0,i.__)("Content","clientcopy-portal"),post_excerpt:(0,i.__)("Excerpt","clientcopy-portal"),featured_image:(0,i.__)("Featured image","clientcopy-portal"),site_logo:(0,i.__)("Site logo","clientcopy-portal"),acf:(0,i.__)("ACF field","clientcopy-portal"),meta:(0,i.__)("Custom field","clientcopy-portal")},p={post_title:["text"],post_content:["text","rich_text"],post_excerpt:["text","rich_text"],featured_image:["image"],site_logo:["image"],acf:["text","rich_text","image","file","gallery","url"],meta:["text","rich_text","image","file","gallery","url"]},d=(e,t)=>{if(!e)return"";const l=o[e]||e;return t?`${l} (${t})`:l};function _({status:e}){return(0,s.jsxs)("span",{className:`cc-badge cc-badge--${e}`,children:[(0,s.jsx)("i",{"aria-hidden":"true"}),r[e]||e]})}function u({done:e,total:t}){const l=t?Math.round(e/t*100):0;return(0,s.jsxs)("div",{className:"cc-progress",title:`${e}/${t}`,children:[(0,s.jsx)("div",{className:"cc-progress__track",children:(0,s.jsx)("div",{className:"cc-progress__bar",style:{width:`${l}%`}})}),(0,s.jsx)("span",{className:"cc-progress__label",children:`${e}/${t}`})]})}const m={text:(0,s.jsx)("path",{d:"M4 6h16M4 12h16M4 18h10"}),rich_text:(0,s.jsx)("path",{d:"M4 20h4L19 9l-4-4L4 16v4zM13 7l4 4"}),image:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),(0,s.jsx)("circle",{cx:"9",cy:"10",r:"1.5"}),(0,s.jsx)("path",{d:"M21 16l-5-5-8 8"})]}),gallery:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1.5"})]}),file:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"}),(0,s.jsx)("path",{d:"M14 3v5h5"})]}),url:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("path",{d:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"}),(0,s.jsx)("path",{d:"M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"})]}),credentials:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"4",y:"11",width:"16",height:"10",rx:"2"}),(0,s.jsx)("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]})};function h({type:e}){return(0,s.jsx)("span",{className:`cc-ticon cc-ticon--${e}`,"aria-hidden":"true",children:(0,s.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:m[e]||m.text})})}const x=e=>e?new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"",y=e=>e?new Date(e+"T00:00:00").toLocaleDateString(void 0,{dateStyle:"medium"}):"",j=e=>!!e.due_date&&"active"===e.status&&new Date(e.due_date+"T23:59:59")<new Date,g=e=>{window.location.hash=e};function v(e,t=[]){const[l,i]=(0,a.useState)({data:null,error:null,loading:!0}),s=(0,a.useCallback)(()=>(i(e=>({...e,loading:!0,error:null})),e().then(e=>i({data:e,error:null,loading:!1})).catch(e=>i({data:null,error:e,loading:!1}))),t);return(0,a.useEffect)(()=>{s()},[s]),{...l,reload:s,set:e=>i({data:e,error:null,loading:!1})}}const f=window.wp.apiFetch;var b=l.n(f);const w=(e,t="GET",l)=>b()({path:"/clientcopy/v1"+e,method:t,data:l}),N=()=>w("/queue"),C=()=>w("/projects"),S=(e,t)=>w(`/projects/${e}`,"PUT",t),k=()=>w("/templates"),$=()=>w("/settings"),B=e=>e&&e.message||"Something went wrong.",D=window.wp.components;function T({items:e,zipUrl:t}){return e.length?(0,s.jsxs)("div",{children:[(0,s.jsx)("ul",{className:"cc-attachments",children:e.map(e=>(0,s.jsxs)("li",{children:[(0,s.jsxs)("a",{href:e.url,target:"_blank",rel:"noreferrer",title:(0,i.__)("Open original","clientcopy-portal"),children:[e.thumb?(0,s.jsx)("img",{src:e.thumb,alt:""}):(0,s.jsx)("span",{className:"cc-file-icon",children:"📄"}),(0,s.jsx)("span",{children:e.filename})]}),(0,s.jsxs)("a",{className:"cc-download",href:e.download_url,children:["↓ ",(0,i.__)("Download","clientcopy-portal")]})]},e.id))}),t&&(0,s.jsx)("p",{children:(0,s.jsxs)("a",{className:"components-button is-secondary",href:t,children:["↓ ",(0,i.__)("Download all as .zip","clientcopy-portal")]})})]}):null}function q({request:e}){const[t,l]=(0,a.useState)(null),[n,c]=(0,a.useState)("");return t?(0,s.jsx)("dl",{className:"cc-creds",children:[["url","Site / URL"],["username","Username"],["password","Password"],["notes","Notes"]].map(([e,l])=>t[e]?(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{children:l}),(0,s.jsx)("dd",{children:(0,s.jsx)("code",{children:t[e]})})]},e):null)}):(0,s.jsxs)(s.Fragment,{children:[n&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:n}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are encrypted. Viewing them is recorded in the activity log.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:async()=>{try{l(await(t=e.id,w(`/requests/${t}/credentials`,"POST")))}catch(e){c(B(e))}var t},children:(0,i.__)("Reveal credentials","clientcopy-portal")})]})}function M({request:e,onResult:t,onProject:l}){const n=e.submission,[c,r]=(0,a.useState)(""),[o,p]=(0,a.useState)(!1),[d,_]=(0,a.useState)("") ;if(!n)return(0,s.jsx)("p",{className:"cc-muted",children:e.client_editing?(0,i.__)("The client has started a draft.","clientcopy-portal"):(0,i.__)("Nothing submitted yet.","clientcopy-portal")});const u=async l=>{p(!0),_("");try{t(await((e,t,l)=>w(`/requests/${e}/review`,"POST",{decision:t,note:l}))(e.id,l,c)),r("")}catch(e){_(B(e))}p(!1)},m=!!e.target_field_type;return(0,s.jsxs)("div",{className:"cc-review",children:[d&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:d}),(0,s.jsxs)("p",{className:"cc-muted",children:[(0,i.__)("Submitted","clientcopy-portal")," ",x(n.submitted_at)]}),"credentials"===e.item_type&&(0,s.jsx)(q,{request:e}),"rich_text"===e.item_type&&(0,s.jsx)("div",{className:"cc-value cc-value--html",dangerouslySetInnerHTML:{__html:n.value}}),["text","url"].includes(e.item_type)&&(0,s.jsx)("div",{className:"cc-value",children:n.value}),(0,s.jsx)(T,{items:n.attachments,zipUrl:n.zip_url}),"submitted"===e.status&&(0,s.jsxs)("div",{className:"cc-decision",children:[(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Note to the client","clientcopy-portal"),help:(0,i.__)("Required when requesting changes.","clientcopy-portal"),value:c,onChange:r,rows:2}),(0,s.jsxs)("div",{className:"cc-actions cc-actions--left",children:[(0,s.jsx)(D.Button,{variant:"primary",isBusy:o,disabled:o,onClick:()=>u("approve"),children:m?(0,i.__)("Approve & write to site","clientcopy-portal"):(0,i.__)("Approve","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",isDestructive:!0,disabled:o||!c.trim(),onClick:()=>u("reject"),children:(0,i.__)("Request changes","clientcopy-portal")})]})]}),"approved"===e.status&&m&&(0,s.jsx)(D.Button,{variant:"secondary",isBusy:o,disabled:o,onClick:async()=>{p(!0);try{t(await(l=e.id,w(`/requests/${l}/reapply`,"POST")))}catch(e){_(B(e))}var l;p(!1)},children:(0,i.__)("Re-apply to site","clientcopy-portal")}),"rejected"===e.status&&n.review_note&&(0,s.jsxs)("p",{className:"cc-note",children:[(0,s.jsx)("strong",{children:(0,i.__)("Your note:","clientcopy-portal")})," ",n.review_note]}),e.client_editing&&"rejected"===e.status&&(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("The client is working on a revision.","clientcopy-portal")})]})}function E(){const{data:e,error:t,loading:l,set:n}=v(N),[r,o]=(0,a.useState)(""),[p,_]=(0,a.useState)(null);if(t)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)});if(l&&!e)return(0,s.jsx)(D.Spinner,{});const u=[];e.forEach(e=>{u.some(t=>t.id===e.project.id)||u.push(e.project)});const m=r?e.filter(e=>String(e.project.id)===r):e,y=t=>({result:l})=>{n(e.filter(e=>e.id!==t.id)),window.dispatchEvent(new Event("clientcopy:queue-changed")),"rejected"===l.status?_({status:"success",text:(0,i.sprintf)((0,i.__)("“%s”: changes requested. It is back in the client portal.","clientcopy-portal"),t.label)}):l.write&&"written"!==l.write.status?_({status:"warning",text:`“${t.label}”: ${(0,i.__)("approved, but not written to the site:","clientcopy-portal")} ${l.write.message}`}):_({status:"success",text:`“${t.label}”: ${(0,i.__)("approved.","clientcopy-portal")} ${l.write?l.write.message:""}`})};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Review","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:e.length?(0,i.sprintf)((0,i._n)("%d item is waiting for you, oldest first.","%d items are waiting for you, oldest first.",e.length,"clientcopy-portal"),e.length):(0,i.__)("Everything your clients have sent has been reviewed.","clientcopy-portal")})]}),u.length>1&&(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Project","clientcopy-portal"),hideLabelFromVision:!0,value:r,onChange:o,options:[{value:"",label:(0,i.__)("All projects","clientcopy-portal")},...u.map(e=>({value:String(e.id),label:e.title}))]})]}),p&&(0,s.jsx)(D.Notice,{status:p.status,onRemove:()=>_(null),children:p.text}),!e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("You are all caught up","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("New submissions from clients will show up here.","clientcopy-portal")})]}),(0,s.jsx)("ul",{className:"cc-queue",children:m.map(e=>{const t="site_logo"===e.target_field_type?(0,i.__)("Site logo (whole site)","clientcopy-portal"):e.target_post?`${e.target_post.title} → ${d(e.target_field_type,e.target_field_key)}`:"";return(0,s.jsxs)("li",{className:"cc-queue__item",children:[(0,s.jsxs)("div",{className:"cc-queue__head",children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("div",{className:"cc-queue__title",children:[(0,s.jsx)("strong",{children:e.label}),(0,s.jsxs)("span",{className:"cc-muted",children:[(0,s.jsx)("a",{href:`#/project/${e.project.id}`,onClick:t=>{t.preventDefault(),g(`/project/${e.project.id}`)},children:e.project.title}),e.project.client_name?` · ${e.project.client_name}`:"",` · ${c(e.item_type)}`,t?` · ${(0,i.__)("writes to","clientcopy-portal")} ${t}`:""]})]}),(0,s.jsx)("span",{className:"cc-muted cc-queue__time",children:x(e.submission?.submitted_at)})]}),e.instructions&&(0,s.jsxs)("p",{className:"cc-muted cc-queue__ask",children:[(0,i.__)("Asked:","clientcopy-portal")," ",e.instructions]}),(0,s.jsx)(M,{request:e,onResult:y(e),onProject:()=>{}})]},e.id)})})]})}function z({project:e,onClose:t,onSaved:l}){const n=!!e,c=v(()=>n?Promise.resolve([]):k(),[n]),[r,o]=(0,a.useState)({title:e?.title||"",client_name:e?.client_name||"",client_email:e?.client_email||"",due_date:e?.due_date||"",template_id:"",create_pages:!0}),[p,d]=(0,a.useState)(!1),[_,u]=(0,a.useState)(""),m=e=>t=>o(l=>({...l,[e]:t}));return(0,s.jsx)(D.Modal,{title:n?(0,i.__)("Edit project","clientcopy-portal"):(0,i.__)("New project","clientcopy-portal"),onRequestClose:t,size:"medium",children:(0,s.jsxs)("form",{onSubmit:async t=>{t.preventDefault(),d(!0),u("");try{const t={...r,template_id:r.template_id?parseInt(r.template_id,10):0},i=n?await S(e.id,t):await(a=t,w("/projects","POST",a));l(i)}catch(e){u(B(e)),d(!1)}var a},className:"cc-form",children:[_&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:_}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Project title","clientcopy-portal"),value:r.title,onChange:m("title"),required:!0}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Client name","clientcopy-portal"),value:r.client_name,onChange:m("client_name")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Client email","clientcopy-portal"),type:"email",value:r.client_email,onChange:m("client_email"),help:(0,i.__)("Used for reminders.","clientcopy-portal")})]}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Due date","clientcopy-portal"),type:"date",value:r.due_date,onChange:m("due_date"),help:(0,i.__)("Reminders start once this date has passed.","clientcopy-portal")}),!n&&c.data&&c.data.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Start from a template","clientcopy-portal"),value:r.template_id,onChange:m("template_id"),options:[{value:"",label:(0,i.__)("Blank project","clientcopy-portal")},...c.data.map(e=>({value:String(e.id),label:`${e.title} (${e.items.length})`}))]}),r.template_id&&(0,s.jsx)(D.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Create a draft page for each section and map the items to it","clientcopy-portal"),checked:r.create_pages,onChange:m("create_pages")})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:p,disabled:p||!r.title.trim(),children:n?(0,i.__)("Save","clientcopy-portal"):(0,i.__)("Create project","clientcopy-portal")})]})]})})}function H(){const{data:e,error:t,loading:l}=v(C),[n,c]=(0,a.useState)(!1),r=(e||[]).filter(e=>"active"===e.status),o=r.reduce((e,t)=>e+(t.submitted||0),0),p=r.reduce((e,t)=>e+t.pending+t.rejected,0),d=r.filter(j).length,m=[[(0,i.__)("Active projects","clientcopy-portal"),r.length,""],[(0,i.__)("Needs your review","clientcopy-portal"),o,o?"is-alert":""],[(0,i.__)("Waiting on clients","clientcopy-portal"),p,""],[(0,i.__)("Overdue","clientcopy-portal"),d,d?"is-danger":""]];return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Projects","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Everything you are collecting from clients, in one place.","clientcopy-portal")})]}),(0,s.jsx)(D.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:()=>c(!0),children:(0,i.__)("New project","clientcopy-portal")})]}),e&&e.length>0&&(0,s.jsx)("div",{className:"cc-stats-grid",children:m.map(([e,t,l])=>(0,s.jsxs)("div",{className:`cc-stat ${l}`,children:[(0,s.jsx)("span",{className:"cc-stat__value",children:t}),(0,s.jsx)("span",{className:"cc-stat__label",children:e})]},e))}),t&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)}),l&&!e&&(0,s.jsx)(D.Spinner,{}),e&&0===e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("No projects yet","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("Create a project, add the content you need, and send your client the magic link.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>c(!0),children:(0,i.__)("Create your first project","clientcopy-portal")})]}),e&&e.length>0&&(0,s.jsxs)("table",{className:"cc-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:(0,i.__)("Project","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Progress","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Needs review","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Due","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Status","clientcopy-portal")})]})}),(0,s.jsx)("tbody",{children:e.map(e=>{return(0,s.jsxs)("tr",{onClick:()=>g(`/project/${e.id}`),className:"is-clickable",children:[(0,s.jsx)("td",{children:(0,s.jsxs)("div",{className:"cc-project-cell",children:[(0,s.jsx)("span",{className:"cc-avatar","aria-hidden":"true",children:(t=e.client_name||e.title,(t||"?").split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(""))}),(0,s.jsxs)("div",{children:[(0,s.jsx)("a",{href:`#/project/${e.id}`,onClick:e=>e.stopPropagation(),className:"cc-table__title",children:e.title}),(0,s.jsx)("div",{className:"cc-muted",children:e.client_name||e.client_email||(0,i.__)("No client yet","clientcopy-portal")})]})]})}),(0,s.jsx)("td",{children:(0,s.jsx)(u,{done:e.approved,total:e.total})}),(0,s.jsx)("td",{children:e.submitted>0?(0,s.jsx)("span",{className:"cc-pill",children:e.submitted}):(0,s.jsx)("span",{className:"cc-muted",children:"–"})}),(0,s.jsx)("td",{className:j(e)?"cc-overdue":"",children:y(e.due_date)||"–"}),(0,s.jsx)("td",{children:(0,s.jsx)(_,{status:e.status})})]},e.id);var t})})]}),n&&(0,s.jsx)(z,{onClose:()=>c(!1),onSaved:e=>{c(!1),g(`/project/${e.id}`)}})]})}const P=(e,t)=>e?`${e}|${t||""}`:"";function A({value:e,onChange:t}){const[l,n]=(0,a.useState)(""),[c,r]=(0,a.useState)([]),[o,p]=(0,a.useState)(!1),[d,_]=(0,a.useState)(""),u=(0,a.useRef)();return(0,a.useEffect)(()=>(clearTimeout(u.current),u.current=setTimeout(()=>{p(!0),(e=>w(`/targets/posts?search=${encodeURIComponent(e)}`))(l).then(r).catch(e=>_(B(e))).finally(()=>p(!1))},250),()=>clearTimeout(u.current)),[l]),(0,s.jsxs)("div",{className:"cc-picker",children:[d&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:d}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Find a page or post","clientcopy-portal"),placeholder:(0,i.__)("Search by title…","clientcopy-portal"),value:l,onChange:n}),(0,s.jsxs)("ul",{className:"cc-picker__list",children:[o&&(0,s.jsx)("li",{children:(0,s.jsx)(D.Spinner,{})}),!o&&c.map(l=>(0,s.jsx)("li",{children:(0,s.jsxs)("button",{type:"button",className:e?.id===l.id?"is-selected":"",onClick:()=>t(l),children:[(0,s.jsx)("strong",{children:l.title}),(0,s.jsxs)("span",{className:"cc-muted",children:[l.type," · ",l.status]})]})},l.id))]}),l.trim()&&(0,s.jsxs)(D.Button,{variant:"link",onClick:async()=>{_("");try{t(await(e=l.trim(),w("/targets/posts","POST",{title:e})))}catch(e){_(B(e))}var e},children:[(0,i.__)("Create a new draft page called","clientcopy-portal")," “",l.trim(),"”"]})]})}function R({projectId:e,request:t,sections:l,onClose:c,onSaved:r}){const p=!!t,[d,_]=(0,a.useState)({section_label:t?.section_label||"",label:t?.label||"",item_type:t?.item_type||"text",instructions:t?.instructions||"",required:!t||t.required}),[u,m]=(0,a.useState)(!!t?.target_field_type),[h,x]=(0,a.useState)("site_logo"===t?.target_field_type?"site_logo":"post"),[y,j]=(0,a.useState)(t?.target_post||null),[g,v]=(0,a.useState)(P(t?.target_field_type,t?.target_field_key)),[f,b]=(0,a.useState)("meta"===t?.target_field_type?t.target_field_key:""),[N,C]=(0,a.useState)(null),[S,k]=(0,a.useState)(!1),[$,T]=(0,a.useState)(""),q=e=>t=>_(l=>({...l,[e]:t}));(0,a.useEffect)(()=>{var e;y?(e=y.id,w(`/targets/fields?post_id=${e}`)).then(C).catch(e=>T(B(e))):C(null)},[y?.id]);const M="credentials"===d.item_type,E=d.item_type,z=[];N&&(N.native.filter(e=>e.item_types.includes(E)).forEach(e=>z.push({value:P(e.type,""),label:e.label})),N.acf.filter(e=>e.item_types.includes(E)).forEach(e=>z.push({value:P("acf",e.key),label:`ACF: ${e.label}`})),z.push({value:"meta|",label:(0,i.__)("Custom field (post meta key)…","clientcopy-portal")}));const H=g.split("|")[0];return(0,s.jsx)(D.Modal,{title:p?(0,i.__)("Edit item","clientcopy-portal"):(0,i.__)("Add item","clientcopy-portal"),onRequestClose:c,size:"large",children:(0,s.jsxs)("form",{onSubmit:async l=>{l.preventDefault(),k(!0),T("");const a={...d};if(u&&"image"===E&&"site_logo"===h)a.target_post_id=0,a.target_field_type="site_logo",a.target_field_key="";else if(u&&!M&&y&&g){const[e,t]=g.split("|");a.target_post_id=y.id,a.target_field_type=e,a.target_field_key="meta"===e?f.trim():t}else a.target_post_id=0,a.target_field_type="",a.target_field_key="";try{const l=p?await(i=t.id,s=a,w(`/requests/${i}`,"PUT",s)):await((e,t)=>w(`/projects/${e}/requests`,"POST",t))(e,a);r(l)}catch(e){T(B(e)),k(!1)}var i,s},className:"cc-form",children:[$&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:$}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Section (page or group)","clientcopy-portal"),value:d.section_label,onChange:q("section_label"),list:"cc-sections",help:(0,i.__)("Items with the same section are grouped together for the client.","clientcopy-portal")}),(0,s.jsx)("datalist",{id:"cc-sections",children:l.map(e=>(0,s.jsx)("option",{value:e},e))})]}),(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Type","clientcopy-portal"),value:d.item_type,options:n,onChange:e=>{q("item_type")(e),v("")}})]}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("What do you need?","clientcopy-portal"),value:d.label,onChange:q("label"),required:!0}),(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Instructions for the client","clientcopy-portal"),value:d.instructions,onChange:q("instructions"),rows:3}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Required","clientcopy-portal"),checked:d.required,onChange:q("required")}),(0,s.jsx)("hr",{}),M?(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are stored encrypted and are never written to a page.","clientcopy-portal")}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Write approved content into the site","clientcopy-portal"),help:(0,i.__)("When you approve this item, it is saved to the page or field you choose.","clientcopy-portal"),checked:u,onChange:m}),u&&(0,s.jsxs)("div",{className:"cc-mapping",children:["image"===E&&(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Where should it go?","clientcopy-portal"),value:h,onChange:x,options:[{value:"post",label:(0,i.__)("A page or post (featured image or field)","clientcopy-portal")},{value:"site_logo",label:(0,i.__)("The site logo (whole website)","clientcopy-portal")}]}),"image"===E&&"site_logo"===h&&(0,s.jsx)(D.Notice,{status:"warning",isDismissible:!1,children:(0,i.__)("Approving this changes your live site logo immediately.","clientcopy-portal")}),!("image"===E&&"site_logo"===h)&&y&&(0,s.jsxs)("p",{className:"cc-selected-post",children:[(0,i.__)("Target:","clientcopy-portal")," ",(0,s.jsx)("strong",{children:y.title})," ",(0,s.jsxs)("span",{className:"cc-muted",children:["(",y.type,", ",y.status,")"]})," ",(0,s.jsx)(D.Button,{variant:"link",onClick:()=>{j(null),v("")},children:(0,i.__)("Change","clientcopy-portal")})]}),!("image"===E&&"site_logo"===h)&&!y&&(0,s.jsx)(A,{value:y,onChange:j}),!("image"===E&&"site_logo"===h)&&y&&!N&&(0,s.jsx)(D.Spinner,{}),!("image"===E&&"site_logo"===h)&&y&&N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Field","clientcopy-portal"),value:g,options:[{value:"",label:(0,i.__)("Select a field…","clientcopy-portal")},...z],onChange:v,help:N.acf_active?void 0:(0,i.__)("Install Advanced Custom Fields to map to ACF fields.","clientcopy-portal")}),"meta"===H&&(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Meta key","clientcopy-portal"),value:f,onChange:b}),H&&(0,s.jsx)("p",{className:"cc-muted",children:o[H]})]})]})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:c,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:S,disabled:S||!d.label.trim()||u&&!M&&!("image"===E&&"site_logo"===h)&&(!y||!g),children:p?(0,i.__)("Save item","clientcopy-portal"):(0,i.__)("Add item","clientcopy-portal")})]})]})})}const O=e=>{const t=e.meta||{},l=t.label?`“${t.label}”`:"";switch(e.action){case"project_created":return(0,i.__)("created the project","clientcopy-portal");case"project_completed":return(0,i.__)("All items approved: project completed","clientcopy-portal");case"link_regenerated":return(0,i.__)("issued a new portal link (the old one stopped working)","clientcopy-portal");case"request_added":return`${(0,i.__)("added","clientcopy-portal")} ${l}`;case"request_removed":return`${(0,i.__)("removed","clientcopy-portal")} ${l}`;case"template_applied":return`${(0,i.__)("applied template","clientcopy-portal")} “${t.template}”`;case"submitted":return`${(0,i.__)("submitted","clientcopy-portal")} ${l}`;case"approved":return`${(0,i.__)("approved","clientcopy-portal")} ${l}`;case"rejected":return`${(0,i.__)("requested changes on","clientcopy-portal")} ${l}${t.note?`: “${t.note}”`:""}`;case"content_written":return`${l} → ${t.field} (#${t.post_id}): ${t.message}`;case"write_skipped":return`${(0,i.__)("skipped writing","clientcopy-portal")} ${l}: ${t.message}`;case"write_error":return`${(0,i.__)("failed to write","clientcopy-portal")} ${l}: ${t.message}`;case"credentials_viewed":return`${(0,i.__)("viewed credentials","clientcopy-portal")} ${l}`;case"files_downloaded":return`${(0,i.__)("downloaded","clientcopy-portal")} ${t.count} ${1===t.count?(0,i.__)("file","clientcopy-portal"):(0,i.__)("files","clientcopy-portal")} (${t.label})`;case"invite_sent":return(0,i.__)("emailed the portal invite","clientcopy-portal");case"reminder_sent":return(0,i.__)("sent a reminder email","clientcopy-portal");default:return"string"==typeof t.summary&&t.summary?t.summary:e.action}};function F({projectId:e,refreshKey:t}){const{data:l,loading:a,error:n}=v(()=>w(`/projects/${e}/activity`),[e,t]);return n?(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(n)}):a&&!l?(0,s.jsx)(D.Spinner,{}):l&&l.length?(0,s.jsx)("ul",{className:"cc-activity",children:l.map(e=>(0,s.jsxs)("li",{className:`cc-activity--${e.actor_type}`,children:[(0,s.jsx)("time",{children:x(e.created_at)}),(0,s.jsxs)("span",{children:["project_completed"===e.action||"content_written"===e.action||"write_skipped"===e.action||"write_error"===e.action?"":(0,s.jsxs)("strong",{children:[e.actor," "]}),O(e)]})]},e.id))}):(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("No activity yet.","clientcopy-portal")})}function L({project:e,onClose:t,onNotice:l}){const[n,c]=(0,a.useState)(e.title),[r,o]=(0,a.useState)(!1),[p,d]=(0,a.useState)("");return(0,s.jsx)(D.Modal,{title:(0,i.__)("Save as template","clientcopy-portal"),onRequestClose:t,children:(0,s.jsxs)("form",{onSubmit:async a=>{a.preventDefault(),o(!0);try{await((e,t)=>w(`/projects/${e}/save-as-template`,"POST",{title:t}))(e.id,n),l({status:"success",text:(0,i.__)("Template saved.","clientcopy-portal")}),t()}catch(e){d(B(e)),o(!1)}},className:"cc-form",children:[p&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:p}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template name","clientcopy-portal"),value:n,onChange:c}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("The items and their field mappings are saved. Page selections are not, because they are specific to this site.","clientcopy-portal")}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:r,disabled:r||!n.trim(),children:(0,i.__)("Save template","clientcopy-portal")})]})]})})}function I({project:e,onClose:t,onApplied:l}){const n=v(k),[c,r]=(0,a.useState)(""),[o,p]=(0,a.useState)(!0),[d,_]=(0,a.useState)(!1),[u,m]=(0,a.useState)("");return(0,s.jsx)(D.Modal,{title:(0,i.__)("Add items from a template","clientcopy-portal"),onRequestClose:t,children:(0,s.jsxs)("form",{onSubmit:async t=>{t.preventDefault(),_(!0);try{l(await(a=e.id,i={template_id:parseInt(c,10),create_pages:o},w(`/projects/${a}/apply-template`,"POST",i)))}catch(e){m(B(e)),_(!1)}var a,i},className:"cc-form",children:[u&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:u}),n.data?(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template","clientcopy-portal"),value:c,onChange:r,options:[{value:"",label:(0,i.__)("Choose…","clientcopy-portal")},...n.data.map(e=>({value:String(e.id),label:`${e.title} (${e.items.length})`}))]}):(0,s.jsx)(D.Spinner,{}),(0,s.jsx)(D.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Create a draft page for each section and map the items to it","clientcopy-portal"),checked:o,onChange:p}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:d,disabled:d||!c,children:(0,i.__)("Add items","clientcopy-portal")})]})]})})}function U({project:e,onProject:t,onNotice:l}){const[n,c]=(0,a.useState)(!1);return(0,s.jsxs)("div",{className:"cc-link",children:[(0,s.jsx)("input",{type:"text",readOnly:!0,value:e.portal_url,onFocus:e=>e.target.select(),"aria-label":(0,i.__)("Client portal link","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:async()=>{try{await navigator.clipboard.writeText(e.portal_url),l({status:"success",text:(0,i.__)("Link copied.","clientcopy-portal")})}catch(t){window.prompt((0,i.__)("Copy this link","clientcopy-portal"),e.portal_url)}},children:(0,i.__)("Copy","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",href:e.portal_url,target:"_blank",rel:"noreferrer",children:(0,i.__)("Open","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:async()=>{if(window.confirm((0,i.__)("Issue a new link? The current link will stop working immediately.","clientcopy-portal"))){c(!0);try{t(await(a=e.id,w(`/projects/${a}/regenerate-link`,"POST"))),l({status:"success",text:(0,i.__)("New link issued.","clientcopy-portal")})}catch(e){l({status:"error",text:B(e)})}c(!1)}var a},disabled:n,children:(0,i.__)("New link","clientcopy-portal")})]})}function W({r:e}){const t=e.submission;if(!t)return null;if("credentials"===e.item_type)return(0,s.jsxs)("span",{className:"cc-preview cc-muted",children:["🔒 ",(0,i.__)("Credentials received","clientcopy-portal")]});if(t.attachments.length)return(0,s.jsxs)("span",{className:"cc-preview cc-preview--files",children:[t.attachments.slice(0,4).map(e=>e.thumb?(0,s.jsx)("img",{src:e.thumb,alt:e.filename},e.id):(0,s.jsxs)("span",{className:"cc-preview__file",children:["📄 ",e.filename]},e.id)),t.attachments.length>4&&(0,s.jsxs)("span",{className:"cc-muted",children:["+",t.attachments.length-4]})]});const l=(e=>{const t=String(e).replace(/<\/(p|div|h[1-6]|li|blockquote)>|<br\s*\/?>/gi," $&");return((new window.DOMParser).parseFromString(t,"text/html").body.textContent||"").replace(/\s+/g," ").trim()})(t.value);return l?(0,s.jsx)("span",{className:"cc-preview cc-muted",children:l.length>120?`${l.slice(0,120)}…`:l}):null}function V({r:e,first:t,last:l,open:a,onToggle:n,onMove:r,onEdit:p,onDelete:d,onResult:u,onProject:m}){const x="site_logo"===e.target_field_type?(0,i.__)("Site logo (whole site)","clientcopy-portal"):e.target_post?`${e.target_post.title} → ${o[e.target_field_type]||e.target_field_type}${"acf"===e.target_field_type||"meta"===e.target_field_type?` (${e.target_field_key})`:""}`:"";return(0,s.jsxs)("li",{className:`cc-request cc-request--${e.status}`,children:[(0,s.jsxs)("div",{className:"cc-request__head",onClick:n,children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("button",{type:"button",className:"cc-request__main",onClick:e=>{e.stopPropagation(),n()},"aria-expanded":a,children:[(0,s.jsxs)("span",{className:"cc-request__label",children:[e.label,e.required&&(0,s.jsx)("abbr",{title:(0,i.__)("Required","clientcopy-portal"),children:" *"})]}),(0,s.jsxs)("span",{className:"cc-muted",children:[c(e.item_type),x?` · ${x}`:""]}),!a&&(0,s.jsx)(W,{r:e})]}),(0,s.jsx)(_,{status:e.status}),(0,s.jsx)("span",{className:"cc-chevron"+(a?" is-open":""),"aria-hidden":"true"}),(0,s.jsxs)("div",{className:"cc-request__tools",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(D.Button,{size:"small",icon:"arrow-up-alt2",label:(0,i.__)("Move up","clientcopy-portal"),disabled:t,onClick:()=>r(-1)}),(0,s.jsx)(D.Button,{size:"small",icon:"arrow-down-alt2",label:(0,i.__)("Move down","clientcopy-portal"),disabled:l,onClick:()=>r(1)}),(0,s.jsx)(D.Button,{size:"small",icon:"edit",label:(0,i.__)("Edit","clientcopy-portal"),onClick:p}),(0,s.jsx)(D.Button,{size:"small",icon:"trash",label:(0,i.__)("Delete","clientcopy-portal"),isDestructive:!0,onClick:d})]})]}),a&&(0,s.jsxs)("div",{className:"cc-request__body",children:[e.instructions&&(0,s.jsx)("p",{className:"cc-muted",children:e.instructions}),(0,s.jsx)(M,{request:e,onResult:u,onProject:m})]})]})}function G({id:e}){const{data:t,error:l,loading:n,set:c}=v(()=>(e=>w(`/projects/${e}`))(e),[e]),[r,o]=(0,a.useState)(null),[p,d]=(0,a.useState)(null),[m,h]=(0,a.useState)({}),[x,f]=(0,a.useState)(0);if(l)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(l)});if(n&&!t)return(0,s.jsx)(D.Spinner,{});if(!t)return null;const b=e=>{c(e),f(e=>e+1)},N=async(e,t)=>{try{const l=await e();return l&&l.requests&&b(l),t&&o({status:"success",text:t}),l}catch(e){o({status:"error",text:B(e)})}return null},C=({result:e,project:t})=>{b(t),"rejected"===e.status?o({status:"success",text:(0,i.__)("Changes requested. The item is back in the client portal.","clientcopy-portal")}):e.write&&"written"!==e.write.status?o({status:"warning",text:`${(0,i.__)("Approved, but the content was not written:","clientcopy-portal")} ${e.write.message}`}):e.write?o({status:"success",text:`${(0,i.__)("Approved.","clientcopy-portal")} ${e.write.message}`}):o({status:"success",text:(0,i.__)("Approved.","clientcopy-portal")})},k=[];t.requests.forEach((e,t)=>{const l=e.section_label||(0,i.__)("General","clientcopy-portal");let a=k.find(e=>e.label===l);a||(a={label:l,items:[]},k.push(a)),a.items.push({r:e,index:t})});const $=k.map(e=>e.label),T=t.submitted||0;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("a",{className:"cc-back",href:"#/",onClick:e=>{e.preventDefault(),g("/")},children:["← ",(0,i.__)("All projects","clientcopy-portal")]}),(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h2",{children:[t.title," ",(0,s.jsx)(_,{status:t.status})]}),(0,s.jsxs)("p",{className:"cc-muted",children:[t.client_name,t.client_name&&t.client_email?" · ":"",t.client_email,t.due_date&&(0,s.jsxs)("span",{className:j(t)?"cc-overdue":"",children:[" · ",(0,i.__)("Due","clientcopy-portal")," ",y(t.due_date)]})]})]}),(0,s.jsxs)("div",{className:"cc-actions cc-actions--left",children:[(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>d({type:"project"}),children:(0,i.__)("Edit","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>N(()=>(e=>w(`/projects/${e}/invite`,"POST"))(t.id),(0,i.__)("Invite emailed to the client.","clientcopy-portal")),disabled:!t.client_email||!t.requests.length,title:t.client_email?(0,i.__)("Email the client their portal link and what you need from them","clientcopy-portal"):(0,i.__)("Add a client email first","clientcopy-portal"),children:(0,i.__)("Email invite","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>N(()=>(e=>w(`/projects/${e}/remind`,"POST"))(t.id),(0,i.__)("Reminder sent.","clientcopy-portal")),disabled:!t.client_email,children:(0,i.__)("Send reminder","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",onClick:()=>N(()=>S(t.id,{status:"archived"===t.status?"active":"archived"})),children:"archived"===t.status?(0,i.__)("Unarchive","clientcopy-portal"):(0,i.__)("Archive","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:async()=>{window.confirm((0,i.__)("Delete this project and all submissions? Uploaded files stay in the media library.","clientcopy-portal"))&&await N(()=>(e=>w(`/projects/${e}`,"DELETE"))(t.id))&&g("/")},children:(0,i.__)("Delete","clientcopy-portal")})]})]}),r&&(0,s.jsx)(D.Notice,{status:r.status,onRemove:()=>o(null),children:r.text}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Client portal link","clientcopy-portal")}),(0,s.jsx)(U,{project:t,onProject:b,onNotice:o}),"archived"===t.status&&(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Archived projects are not accessible to the client.","clientcopy-portal")}),t.zip_url&&(0,s.jsxs)("p",{className:"cc-files-row",children:[(0,s.jsxs)("a",{className:"components-button is-secondary",href:t.zip_url,children:["↓ ",(0,i.__)("Download all client files (.zip)","clientcopy-portal")]}),(0,s.jsx)("a",{className:"cc-media-link",href:t.media_url,children:(0,i.__)("View in Media Library","clientcopy-portal")}),(0,s.jsx)("span",{className:"cc-muted",children:(0,i.sprintf)((0,i._n)("%d file, organised by section and item","%d files, organised by section and item",t.file_count,"clientcopy-portal"),t.file_count)})]}),(0,s.jsxs)("div",{className:"cc-stats",children:[(0,s.jsx)(u,{done:t.approved,total:t.total}),(0,s.jsx)("span",{children:(0,i.sprintf)((0,i.__)("%1$d waiting on client · %2$d need review · %3$d approved","clientcopy-portal"),t.pending+t.rejected,t.submitted,t.approved)})]})]}),(0,s.jsx)(D.TabPanel,{className:"cc-tabs",tabs:[{name:"requests",title:T?`${(0,i.__)("Requests","clientcopy-portal")} (${T})`:(0,i.__)("Requests","clientcopy-portal")},{name:"activity",title:(0,i.__)("Activity","clientcopy-portal")}],children:e=>"activity"===e.name?(0,s.jsx)(F,{projectId:t.id,refreshKey:x}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-actions cc-actions--left cc-toolbar",children:[(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>d({type:"request"}),children:(0,i.__)("Add item","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>d({type:"apply"}),children:(0,i.__)("Add from template","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",onClick:()=>d({type:"save"}),disabled:!t.requests.length,children:(0,i.__)("Save as template","clientcopy-portal")})]}),!t.requests.length&&(0,s.jsx)("div",{className:"cc-empty",children:(0,s.jsx)("p",{children:(0,i.__)("No items yet. Add what you need from the client, or start from a template.","clientcopy-portal")})}),k.map(e=>(0,s.jsxs)("section",{className:"cc-section",children:[(0,s.jsxs)("h3",{children:[e.label,(0,s.jsxs)("span",{className:"cc-section__count",children:[e.items.filter(({r:e})=>"approved"===e.status).length,"/",e.items.length]})]}),(0,s.jsx)("ul",{className:"cc-requests",children:e.items.map(({r:e,index:l})=>(0,s.jsx)(V,{r:e,first:0===l,last:l===t.requests.length-1,open:m[e.id]??"submitted"===e.status,onToggle:()=>h(t=>({...t,[e.id]:!(t[e.id]??"submitted"===e.status)})),onMove:e=>((e,l)=>{const a=t.requests.map(e=>e.id),i=e+l;[a[e],a[i]]=[a[i],a[e]],N(()=>((e,t)=>w(`/projects/${e}/requests/reorder`,"POST",{ids:t}))(t.id,a))})(l,e),onEdit:()=>d({type:"request",request:e}),onDelete:()=>(e=>{window.confirm((0,i.sprintf)((0,i.__)("Delete “%s” and anything the client submitted for it?","clientcopy-portal"),e.label))&&N(()=>(e=>w(`/requests/${e}`,"DELETE"))(e.id))})(e),onResult:C,onProject:b},e.id))})]},e.label))]})}),"project"===p?.type&&(0,s.jsx)(z,{project:t,onClose:()=>d(null),onSaved:e=>{b(e),d(null)}}),"request"===p?.type&&(0,s.jsx)(R,{projectId:t.id,request:p.request,sections:$,onClose:()=>d(null),onSaved:e=>{b(e),d(null)}}),"apply"===p?.type&&(0,s.jsx)(I,{project:t,onClose:()=>d(null),onApplied:e=>{b(e),d(null)}}),"save"===p?.type&&(0,s.jsx)(L,{project:t,onClose:()=>d(null),onNotice:o})]})}function K({items:e}){const t=[];return e.forEach(e=>{const l=e.section_label||(0,i.__)("General","clientcopy-portal");let a=t.find(e=>e.label===l);a||(a={label:l,items:[]},t.push(a)),a.items.push(e)}),(0,s.jsx)("div",{className:"cc-tpl-view",children:t.map(e=>(0,s.jsxs)("section",{children:[(0,s.jsx)("h4",{children:e.label}),(0,s.jsx)("ul",{children:e.items.map((e,t)=>(0,s.jsxs)("li",{children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("strong",{children:[e.label,e.required&&(0,s.jsx)("abbr",{title:(0,i.__)("Required","clientcopy-portal"),children:" *"})]}),(0,s.jsxs)("span",{className:"cc-muted",children:[c(e.item_type),e.target_field_type?` · ${(0,i.__)("writes to","clientcopy-portal")} ${d(e.target_field_type,e.target_field_key)}`:""]}),e.instructions&&(0,s.jsx)("span",{className:"cc-muted",children:e.instructions})]})]},t))})]},e.label))})}function Y(){const{data:e,error:t,loading:l,reload:n}=v(k),[c,r]=(0,a.useState)({}),[o,p]=(0,a.useState)(null);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Templates","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Reusable request sets. Start a project from one, or save any project as a template.","clientcopy-portal")})]}),(0,s.jsx)(D.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:()=>g("/templates/new"),children:(0,i.__)("New template","clientcopy-portal")})]}),o&&(0,s.jsx)(D.Notice,{status:o.status,onRemove:()=>p(null),children:o.text}),t&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)}),l&&!e&&(0,s.jsx)(D.Spinner,{}),e&&!e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("No templates yet","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("Build one from scratch, or save an existing project as a template.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>g("/templates/new"),children:(0,i.__)("Create a template","clientcopy-portal")})]}),e&&e.map(e=>{const t=new Set(e.items.map(e=>e.section_label||"")).size,l=!!c[e.id];return(0,s.jsxs)("div",{className:"cc-card cc-tpl",children:[(0,s.jsxs)("div",{className:"cc-card__head",children:[(0,s.jsxs)("button",{type:"button",className:"cc-tpl__toggle","aria-expanded":l,onClick:()=>r(t=>({...t,[e.id]:!t[e.id]})),children:[(0,s.jsx)("span",{className:"cc-chevron"+(l?" is-open":""),"aria-hidden":"true"}),(0,s.jsxs)("span",{children:[(0,s.jsx)("h3",{children:e.title}),(0,s.jsx)("span",{className:"cc-muted",children:(0,i.sprintf)((0,i.__)("%1$d items across %2$d sections","clientcopy-portal"),e.items.length,t)})]})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>r(t=>({...t,[e.id]:!t[e.id]})),children:l?(0,i.__)("Hide","clientcopy-portal"):(0,i.__)("View","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>g(`/templates/${e.id}`),children:(0,i.__)("Edit","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:()=>(async e=>{if(window.confirm((0,i.sprintf)((0,i.__)("Delete the template “%s”? Existing projects are not affected.","clientcopy-portal"),e.title)))try{await(t=e.id,w(`/templates/${t}`,"DELETE")),p({status:"success",text:(0,i.__)("Template deleted.","clientcopy-portal")}),n()}catch(e){p({status:"error",text:B(e)})}var t})(e),children:(0,i.__)("Delete","clientcopy-portal")})]})]}),l&&(0,s.jsx)(K,{items:e.items})]},e.id)})]})}const J=(e="")=>({section_label:e,item_type:"text",label:"",instructions:"",required:!0,target_field_type:"",target_field_key:""});function X({item:e,index:t,count:l,sections:a,onChange:c,onMove:r,onRemove:d}){const _=t=>c({...e,...t}),u=e.item_type,m=Object.keys(p).filter(e=>p[e].includes(u)),x="acf"===e.target_field_type||"meta"===e.target_field_type;return(0,s.jsxs)("div",{className:"cc-tpl-item",children:[(0,s.jsxs)("div",{className:"cc-tpl-item__head",children:[(0,s.jsx)(h,{type:u}),(0,s.jsx)("strong",{children:e.label||(0,i.__)("New item","clientcopy-portal")}),(0,s.jsxs)("span",{className:"cc-tpl-item__tools",children:[(0,s.jsx)(D.Button,{size:"small",icon:"arrow-up-alt2",label:(0,i.__)("Move up","clientcopy-portal"),disabled:0===t,onClick:()=>r(-1)}),(0,s.jsx)(D.Button,{size:"small",icon:"arrow-down-alt2",label:(0,i.__)("Move down","clientcopy-portal"),disabled:t===l-1,onClick:()=>r(1)}),(0,s.jsx)(D.Button,{size:"small",icon:"trash",isDestructive:!0,label:(0,i.__)("Remove item","clientcopy-portal"),onClick:d})]})]}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("What do you need?","clientcopy-portal"),value:e.label,onChange:e=>_({label:e})}),(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Type","clientcopy-portal"),value:u,options:n,onChange:t=>{const l=!e.target_field_type||"credentials"!==t&&p[e.target_field_type].includes(t);_(l?{item_type:t}:{item_type:t,target_field_type:"",target_field_key:""})}})]}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)("div",{children:(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Section (becomes a page)","clientcopy-portal"),value:e.section_label,onChange:e=>_({section_label:e}),list:"cc-tpl-sections"})}),"credentials"!==u?(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("When approved, write to","clientcopy-portal"),value:e.target_field_type,options:[{value:"",label:(0,i.__)("Nothing (just collect it)","clientcopy-portal")},...m.map(e=>({value:e,label:o[e]}))],onChange:e=>_({target_field_type:e,target_field_key:""})}):(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are encrypted and never written to a page.","clientcopy-portal")})]}),x&&(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:"acf"===e.target_field_type?(0,i.__)("ACF field key","clientcopy-portal"):(0,i.__)("Custom field (meta) key","clientcopy-portal"),help:"acf"===e.target_field_type?(0,i.__)("For example field_5f3a1b2c. Find it in the ACF field group settings.","clientcopy-portal"):void 0,value:e.target_field_key,onChange:e=>_({target_field_key:e})}),(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Instructions for the client","clientcopy-portal"),value:e.instructions,onChange:e=>_({instructions:e}),rows:2}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Required","clientcopy-portal"),checked:e.required,onChange:e=>_({required:e})}),(0,s.jsx)("datalist",{id:"cc-tpl-sections",children:a.map(e=>(0,s.jsx)("option",{value:e},e))})]})}function Q({id:e}){const[t,l]=(0,a.useState)(""),[n,c]=(0,a.useState)(e?null:[J()]),[r,o]=(0,a.useState)(""),[p,d]=(0,a.useState)(null),[_,u]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{e&&(e=>w(`/templates/${e}`))(e).then(e=>{l(e.title),c(e.items)}).catch(e=>o(B(e)))},[e]),(0,a.useEffect)(()=>{if(!m)return;const e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[m]),r)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:r});if(!n)return(0,s.jsx)(D.Spinner,{});const x=e=>{h(!0),e()},y=[...new Set(n.map(e=>e.section_label).filter(Boolean))],j=e=>{e.preventDefault(),m&&!window.confirm((0,i.__)("Discard your unsaved changes?","clientcopy-portal"))||(h(!1),g("/templates"))};return(0,s.jsxs)("form",{onSubmit:async a=>{a.preventDefault(),u(!0),d(null);try{const a=await((e,t)=>e?w(`/templates/${e}`,"PUT",t):w("/templates","POST",t))(e,{title:t,items:n});h(!1),e?(l(a.title),c(a.items),d({status:"success",text:(0,i.__)("Template saved.","clientcopy-portal")})):g(`/templates/${a.id}`)}catch(e){d({status:"error",text:B(e)})}u(!1)},children:[(0,s.jsxs)("a",{className:"cc-back",href:"#/templates",onClick:j,children:["← ",(0,i.__)("All templates","clientcopy-portal")]}),(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:e?(0,i.__)("Edit template","clientcopy-portal"):(0,i.__)("New template","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.sprintf)((0,i.__)("%d items. Changes only affect projects you start from this template later.","clientcopy-portal"),n.length)})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:j,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:_,disabled:_||!t.trim()||!n.length,children:(0,i.__)("Save template","clientcopy-portal")})]})]}),p&&(0,s.jsx)(D.Notice,{status:p.status,onRemove:()=>d(null),children:p.text}),(0,s.jsx)("div",{className:"cc-card",children:(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template name","clientcopy-portal"),value:t,onChange:e=>x(()=>l(e)),placeholder:(0,i.__)("e.g. 5 Page Business Site","clientcopy-portal")})}),n.map((e,t)=>(0,s.jsx)(X,{item:e,index:t,count:n.length,sections:y,onChange:e=>((e,t)=>x(()=>c(l=>l.map((l,a)=>a===e?t:l))))(t,e),onMove:e=>((e,t)=>x(()=>c(l=>{const a=[...l];return[a[e],a[e+t]]=[a[e+t],a[e]],a})))(t,e),onRemove:()=>(e=>x(()=>c(t=>t.filter((t,l)=>l!==e))))(t)},t)),(0,s.jsxs)(D.Button,{variant:"secondary",onClick:()=>x(()=>c(e=>[...e,J(e.length?e[e.length-1].section_label:"")])),children:["+ ",(0,i.__)("Add item","clientcopy-portal")]})]})}function Z(){const{data:e,error:t,loading:l}=v($),[n,c]=(0,a.useState)(null),[r,o]=(0,a.useState)(null),[p,d]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{e&&c(e)},[e]),t)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)});if(l||!n)return(0,s.jsx)(D.Spinner,{});const _=window.clientcopyAdmin||{},u=e=>t=>c(l=>({...l,[e]:t}));return(0,s.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),d(!0);try{const e={};["reminders_enabled","reminder_cadence_days","reminder_max_count","notify_admin_on_submit","admin_notify_email","notify_client_on_reject","notify_client_on_approve","from_name","allow_publish_writes","show_credit"].forEach(t=>{e[t]=n[t]});const t=await(e=>w("/settings","POST",e))(e);c(e=>({...e,...t})),o({status:"success",text:(0,i.__)("Settings saved.","clientcopy-portal")})}catch(e){o({status:"error",text:B(e)})}d(!1)},className:"cc-form cc-settings",children:[(0,s.jsx)("div",{className:"cc-page-head",children:(0,s.jsx)("h2",{children:(0,i.__)("Settings","clientcopy-portal")})}),r&&(0,s.jsx)(D.Notice,{status:r.status,onRemove:()=>o(null),children:r.text}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Reminders","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Send automatic reminder emails","clientcopy-portal"),help:(0,i.__)("Clients get a reminder for outstanding items once the project due date has passed (or, with no due date, once the interval has passed since creation).","clientcopy-portal"),checked:n.reminders_enabled,onChange:u("reminders_enabled")}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"number",min:"1",max:"60",label:(0,i.__)("Repeat every (days)","clientcopy-portal"),value:n.reminder_cadence_days,onChange:u("reminder_cadence_days")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"number",min:"1",max:"50",label:(0,i.__)("Maximum reminders per project","clientcopy-portal"),value:n.reminder_max_count,onChange:u("reminder_max_count")})]})]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Notifications","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email me when a client submits an item","clientcopy-portal"),checked:n.notify_admin_on_submit,onChange:u("notify_admin_on_submit")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"email",label:(0,i.__)("Notification email","clientcopy-portal"),value:n.admin_notify_email,onChange:u("admin_notify_email")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email the client when changes are requested","clientcopy-portal"),checked:n.notify_client_on_reject,onChange:u("notify_client_on_reject")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email the client when an item is approved","clientcopy-portal"),checked:!!n.notify_client_on_approve,onChange:u("notify_client_on_approve")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Sender name","clientcopy-portal"),value:n.from_name,onChange:u("from_name")})]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Client portal and emails","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Show “powered by ClientCopy”","clientcopy-portal"),help:(0,i.__)("Off by default. When on, a small credit line appears at the bottom of the client portal and in client emails.","clientcopy-portal"),checked:!!n.show_credit,onChange:u("show_credit")}),_.proActive?(0,s.jsxs)("p",{className:"cc-muted",children:[(0,i.__)("Logo, colours, portal path and email wording are in ","clientcopy-portal"),(0,s.jsx)("a",{href:_.proUrl,children:(0,i.__)("ClientCopy Pro","clientcopy-portal")}),"."]}):_.learnProUrl?(0,s.jsxs)("p",{className:"cc-muted",children:[(0,i.__)("Want your own logo, colours and email wording? The optional ","clientcopy-portal"),(0,s.jsx)("a",{href:_.learnProUrl,target:"_blank",rel:"noreferrer",children:(0,i.__)("ClientCopy Pro add-on","clientcopy-portal")}),(0,i.__)(" adds them.","clientcopy-portal")]}):null]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Writing content to the site","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Allow writing to published content","clientcopy-portal"),help:(0,i.__)("Off by default: approved content is only written to draft, pending, or scheduled pages so nothing changes live by surprise.","clientcopy-portal"),checked:n.allow_publish_writes,onChange:u("allow_publish_writes")})]}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:p,disabled:p,children:(0,i.__)("Save settings","clientcopy-portal")})]})}function ee(){const e=function(){const e=()=>window.location.hash.replace(/^#/,"")||"/",[t,l]=(0,a.useState)(e);return(0,a.useEffect)(()=>{const t=()=>l(e());return window.addEventListener("hashchange",t),()=>window.removeEventListener("hashchange",t)},[]),t}(),[t,l]=(0,a.useState)(0);(0,a.useEffect)(()=>{const e=()=>N().then(e=>l(e.length)).catch(()=>{});return e(),window.addEventListener("clientcopy:queue-changed",e),()=>window.removeEventListener("clientcopy:queue-changed",e)},[e]);const n=e.match(/^\/project\/(\d+)/);let c=(0,s.jsx)(H,{}),r="projects";if(n)c=(0,s.jsx)(G,{id:parseInt(n[1],10)},n[1]);else if(e.startsWith("/review"))c=(0,s.jsx)(E,{}),r="review";else if(e.startsWith("/templates")){const t=e.match(/^\/templates\/(new|\d+)/);c=t?(0,s.jsx)(Q,{id:"new"===t[1]?0:parseInt(t[1],10)},t[1]):(0,s.jsx)(Y,{}),r="templates"}else e.startsWith("/settings")&&(c=(0,s.jsx)(Z,{}),r="settings");const o=[["projects","/",(0,i.__)("Projects","clientcopy-portal")],["review","/review",(0,i.__)("Review","clientcopy-portal")],["templates","/templates",(0,i.__)("Templates","clientcopy-portal")],["settings","/settings",(0,i.__)("Settings","clientcopy-portal")]];return(0,s.jsxs)("div",{className:"cc-app",children:[(0,s.jsxs)("header",{className:"cc-nav",children:[(0,s.jsxs)("h1",{className:"cc-nav__brand",children:[(0,s.jsx)("svg",{className:"cc-logo",viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false",children:(0,s.jsx)("path",{fill:"#4f46e5",d:"M18 2H14A10 10 0 0 0 4 12v8a10 10 0 0 0 10 10h10a4 4 0 0 0 4-4v-4H14a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h4zm2 0 8 8h-8z"})}),"ClientCopy"]}),(0,s.jsxs)("nav",{children:[o.map(([e,l,a])=>(0,s.jsxs)("a",{href:`#${l}`,className:r===e?"is-active":"",onClick:e=>{e.preventDefault(),g(l)},children:[a,"review"===e&&t>0&&(0,s.jsx)("span",{className:"cc-nav__count",children:t})]},e)),window.clientcopyAdmin?.docsUrl&&(0,s.jsxs)("a",{className:"cc-nav__docs",href:window.clientcopyAdmin.docsUrl,target:"_blank",rel:"noopener noreferrer",children:[(0,i.__)("Docs","clientcopy-portal"),(0,s.jsx)("span",{"aria-hidden":"true",children:" ↗"})]})]})]}),(0,s.jsx)("main",{className:"cc-main",children:c})]})}const te=document.getElementById("clientcopy-admin-root");te&&(0,a.createRoot)(te).render((0,s.jsx)(ee,{}))}};const t={};function l(a){const i=t[a];if(void 0!==i)return i.exports;const s=t[a]={exports:{}};return e[a](s,s.exports,l),s.exports}l.m=e,(()=>{const e=[];l.O=(t,a,i)=>{if(!a){for(var s=0;s<e.length;s++){let[a,i]=e[s],c=!0;for(var n=0;n<a.length;n++)l.O.j(a[n])?a.splice(n--,1):c=!1;if(c){e.splice(s--,1);const l=i();void 0!==l&&(t=l)}}return t}e.push([a,i])}})(),l.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},l.d=(e,t)=>{for(var a in t)l.o(t,a)&&!l.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},l.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={773:0,641:0};l.O.j=t=>0===e[t];const t=(t,a)=>{let[i,s,n]=a;var c,r,o=0;if(i.some(t=>0!==e[t])){for(c in s)l.o(s,c)&&(l.m[c]=s[c]);if(n)var p=n(l)}for(t&&t(a);o<i.length;o++)r=i[o],l.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return l.O(p)},a=globalThis.webpackChunkclientcopy_portal||=[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();let a=l.O(void 0,[641],()=>l(639));a=l.O(a)})();1 (()=>{"use strict";var e={639(e,t,l){const a=window.wp.element,i=window.wp.i18n,s=window.ReactJSXRuntime,n=[{value:"text",label:(0,i.__)("Short text","clientcopy-portal")},{value:"rich_text",label:(0,i.__)("Rich text","clientcopy-portal")},{value:"image",label:(0,i.__)("Image","clientcopy-portal")},{value:"gallery",label:(0,i.__)("Gallery","clientcopy-portal")},{value:"file",label:(0,i.__)("File","clientcopy-portal")},{value:"url",label:(0,i.__)("URL","clientcopy-portal")},{value:"credentials",label:(0,i.__)("Credentials","clientcopy-portal")}],c=e=>(n.find(t=>t.value===e)||{}).label||e,r={pending:(0,i.__)("Waiting on client","clientcopy-portal"),submitted:(0,i.__)("Needs review","clientcopy-portal"),approved:(0,i.__)("Approved","clientcopy-portal"),rejected:(0,i.__)("Changes requested","clientcopy-portal"),active:(0,i.__)("Active","clientcopy-portal"),completed:(0,i.__)("Completed","clientcopy-portal"),archived:(0,i.__)("Archived","clientcopy-portal")},o={post_title:(0,i.__)("Title","clientcopy-portal"),post_content:(0,i.__)("Content","clientcopy-portal"),post_excerpt:(0,i.__)("Excerpt","clientcopy-portal"),featured_image:(0,i.__)("Featured image","clientcopy-portal"),site_logo:(0,i.__)("Site logo","clientcopy-portal"),acf:(0,i.__)("ACF field","clientcopy-portal"),meta:(0,i.__)("Custom field","clientcopy-portal")},p={post_title:["text"],post_content:["text","rich_text"],post_excerpt:["text","rich_text"],featured_image:["image"],site_logo:["image"],acf:["text","rich_text","image","file","gallery","url"],meta:["text","rich_text","image","file","gallery","url"]},d=(e,t)=>{if(!e)return"";const l=o[e]||e;return t?`${l} (${t})`:l};function _({status:e}){return(0,s.jsxs)("span",{className:`cc-badge cc-badge--${e}`,children:[(0,s.jsx)("i",{"aria-hidden":"true"}),r[e]||e]})}function u({done:e,total:t}){const l=t?Math.round(e/t*100):0;return(0,s.jsxs)("div",{className:"cc-progress",title:`${e}/${t}`,children:[(0,s.jsx)("div",{className:"cc-progress__track",children:(0,s.jsx)("div",{className:"cc-progress__bar",style:{width:`${l}%`}})}),(0,s.jsx)("span",{className:"cc-progress__label",children:`${e}/${t}`})]})}const m={text:(0,s.jsx)("path",{d:"M4 6h16M4 12h16M4 18h10"}),rich_text:(0,s.jsx)("path",{d:"M4 20h4L19 9l-4-4L4 16v4zM13 7l4 4"}),image:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"3",y:"4",width:"18",height:"16",rx:"2"}),(0,s.jsx)("circle",{cx:"9",cy:"10",r:"1.5"}),(0,s.jsx)("path",{d:"M21 16l-5-5-8 8"})]}),gallery:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"3",y:"3",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"13",y:"3",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"3",y:"13",width:"8",height:"8",rx:"1.5"}),(0,s.jsx)("rect",{x:"13",y:"13",width:"8",height:"8",rx:"1.5"})]}),file:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("path",{d:"M14 3H7a2 2 0 0 0-2 2v14a2 2 0 0 0 2 2h10a2 2 0 0 0 2-2V8z"}),(0,s.jsx)("path",{d:"M14 3v5h5"})]}),url:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("path",{d:"M10 14a4 4 0 0 0 5.7 0l3-3a4 4 0 0 0-5.7-5.7l-1 1"}),(0,s.jsx)("path",{d:"M14 10a4 4 0 0 0-5.7 0l-3 3a4 4 0 0 0 5.7 5.7l1-1"})]}),credentials:(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)("rect",{x:"4",y:"11",width:"16",height:"10",rx:"2"}),(0,s.jsx)("path",{d:"M8 11V7a4 4 0 0 1 8 0v4"})]})};function h({type:e}){return(0,s.jsx)("span",{className:`cc-ticon cc-ticon--${e}`,"aria-hidden":"true",children:(0,s.jsx)("svg",{viewBox:"0 0 24 24",width:"18",height:"18",fill:"none",stroke:"currentColor",strokeWidth:"1.8",strokeLinecap:"round",strokeLinejoin:"round",children:m[e]||m.text})})}const x=e=>e?new Date(e).toLocaleString(void 0,{dateStyle:"medium",timeStyle:"short"}):"",y=e=>e?new Date(e+"T00:00:00").toLocaleDateString(void 0,{dateStyle:"medium"}):"",j=e=>!!e.due_date&&"active"===e.status&&new Date(e.due_date+"T23:59:59")<new Date,g=e=>{window.location.hash=e};function v(e,t=[]){const[l,i]=(0,a.useState)({data:null,error:null,loading:!0}),s=(0,a.useCallback)(()=>(i(e=>({...e,loading:!0,error:null})),e().then(e=>i({data:e,error:null,loading:!1})).catch(e=>i({data:null,error:e,loading:!1}))),t);return(0,a.useEffect)(()=>{s()},[s]),{...l,reload:s,set:e=>i({data:e,error:null,loading:!1})}}const f=window.wp.apiFetch;var b=l.n(f);const w=(e,t="GET",l)=>b()({path:"/clientcopy/v1"+e,method:t,data:l}),N=()=>w("/queue"),C=()=>w("/projects"),S=(e,t)=>w(`/projects/${e}`,"PUT",t),k=()=>w("/templates"),$=()=>w("/settings"),B=e=>e&&e.message||"Something went wrong.",D=window.wp.components;function T({items:e,zipUrl:t}){return e.length?(0,s.jsxs)("div",{children:[(0,s.jsx)("ul",{className:"cc-attachments",children:e.map(e=>(0,s.jsxs)("li",{children:[(0,s.jsxs)("a",{href:e.url,target:"_blank",rel:"noreferrer",title:(0,i.__)("Open original","clientcopy-portal"),children:[e.thumb?(0,s.jsx)("img",{src:e.thumb,alt:""}):(0,s.jsx)("span",{className:"cc-file-icon",children:"📄"}),(0,s.jsx)("span",{children:e.filename})]}),(0,s.jsxs)("a",{className:"cc-download",href:e.download_url,children:["↓ ",(0,i.__)("Download","clientcopy-portal")]})]},e.id))}),t&&(0,s.jsx)("p",{children:(0,s.jsxs)("a",{className:"components-button is-secondary",href:t,children:["↓ ",(0,i.__)("Download all as .zip","clientcopy-portal")]})})]}):null}function q({request:e}){const[t,l]=(0,a.useState)(null),[n,c]=(0,a.useState)("");return t?(0,s.jsx)("dl",{className:"cc-creds",children:[["url","Site / URL"],["username","Username"],["password","Password"],["notes","Notes"]].map(([e,l])=>t[e]?(0,s.jsxs)("div",{children:[(0,s.jsx)("dt",{children:l}),(0,s.jsx)("dd",{children:(0,s.jsx)("code",{children:t[e]})})]},e):null)}):(0,s.jsxs)(s.Fragment,{children:[n&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:n}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are encrypted. Viewing them is recorded in the activity log.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:async()=>{try{l(await(t=e.id,w(`/requests/${t}/credentials`,"POST")))}catch(e){c(B(e))}var t},children:(0,i.__)("Reveal credentials","clientcopy-portal")})]})}function M({request:e,onResult:t,onProject:l}){const n=e.submission,[c,r]=(0,a.useState)(""),[o,p]=(0,a.useState)(!1),[d,_]=(0,a.useState)(""),[u,m]=(0,a.useState)(!1);if(!n)return(0,s.jsx)("p",{className:"cc-muted",children:e.client_editing?(0,i.__)("The client has started a draft.","clientcopy-portal"):(0,i.__)("Nothing submitted yet.","clientcopy-portal")});const h=async l=>{p(!0),_("");try{t(await((e,t,l,a)=>w(`/requests/${e}/review`,"POST",{decision:t,note:l,submission_id:a}))(e.id,l,c,n.id)),r("")}catch(e){_(B(e)),m(!!e&&("clientcopy_stale"===e.code||"clientcopy_state"===e.code))}p(!1)},y=!!e.target_field_type;return(0,s.jsxs)("div",{className:"cc-review",children:[d&&(0,s.jsxs)(D.Notice,{status:"error",isDismissible:!1,children:[d,u&&(0,s.jsxs)(s.Fragment,{children:[" ",(0,s.jsx)(D.Button,{variant:"link",onClick:()=>window.location.reload(),children:(0,i.__)("Reload","clientcopy-portal")})]})]}),(0,s.jsxs)("p",{className:"cc-muted",children:[n.revision>1&&(0,s.jsxs)("strong",{children:[(0,i.sprintf)(/* translators: %d: version number */ /* translators: %d: version number */(0,i.__)("Version %d","clientcopy-portal"),n.revision)," · "]}),(0,i.__)("Submitted","clientcopy-portal")," ",x(n.submitted_at)]}),"credentials"===e.item_type&&(0,s.jsx)(q,{request:e}),"rich_text"===e.item_type&&(0,s.jsx)("div",{className:"cc-value cc-value--html",dangerouslySetInnerHTML:{__html:n.value}}),["text","url"].includes(e.item_type)&&(0,s.jsx)("div",{className:"cc-value",children:n.value}),(0,s.jsx)(T,{items:n.attachments,zipUrl:n.zip_url}),"submitted"===e.status&&(0,s.jsxs)("div",{className:"cc-decision",children:[(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Note to the client","clientcopy-portal"),help:(0,i.__)("Required when requesting changes.","clientcopy-portal"),value:c,onChange:r,rows:2}),(0,s.jsxs)("div",{className:"cc-actions cc-actions--left",children:[(0,s.jsx)(D.Button,{variant:"primary",isBusy:o,disabled:o,onClick:()=>h("approve"),children:y?(0,i.__)("Approve & write to site","clientcopy-portal"):(0,i.__)("Approve","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",isDestructive:!0,disabled:o||!c.trim(),onClick:()=>h("reject"),children:(0,i.__)("Request changes","clientcopy-portal")})]})]}),"approved"===e.status&&y&&(0,s.jsx)(D.Button,{variant:"secondary",isBusy:o,disabled:o,onClick:async()=>{p(!0);try{t(await(l=e.id,w(`/requests/${l}/reapply`,"POST")))}catch(e){_(B(e))}var l;p(!1)},children:(0,i.__)("Re-apply to site","clientcopy-portal")}),"rejected"===e.status&&n.review_note&&(0,s.jsxs)("p",{className:"cc-note",children:[(0,s.jsx)("strong",{children:(0,i.__)("Your note:","clientcopy-portal")})," ",n.review_note]}),e.client_editing&&"rejected"===e.status&&(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("The client is working on a revision.","clientcopy-portal")})]})}function E(){const{data:e,error:t,loading:l,set:n}=v(N),[r,o]=(0,a.useState)(""),[p,_]=(0,a.useState)(null);if(t)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)});if(l&&!e)return(0,s.jsx)(D.Spinner,{});const u=[];e.forEach(e=>{u.some(t=>t.id===e.project.id)||u.push(e.project)});const m=r?e.filter(e=>String(e.project.id)===r):e,y=t=>({result:l})=>{n(e.filter(e=>e.id!==t.id)),window.dispatchEvent(new Event("clientcopy:queue-changed")),"rejected"===l.status?_({status:"success",text:(0,i.sprintf)((0,i.__)("“%s”: changes requested. It is back in the client portal.","clientcopy-portal"),t.label)}):l.write&&"written"!==l.write.status?_({status:"warning",text:`“${t.label}”: ${(0,i.__)("approved, but not written to the site:","clientcopy-portal")} ${l.write.message}`}):_({status:"success",text:`“${t.label}”: ${(0,i.__)("approved.","clientcopy-portal")} ${l.write?l.write.message:""}`})};return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Review","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:e.length?(0,i.sprintf)((0,i._n)("%d item is waiting for you, oldest first.","%d items are waiting for you, oldest first.",e.length,"clientcopy-portal"),e.length):(0,i.__)("Everything your clients have sent has been reviewed.","clientcopy-portal")})]}),u.length>1&&(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Project","clientcopy-portal"),hideLabelFromVision:!0,value:r,onChange:o,options:[{value:"",label:(0,i.__)("All projects","clientcopy-portal")},...u.map(e=>({value:String(e.id),label:e.title}))]})]}),p&&(0,s.jsx)(D.Notice,{status:p.status,onRemove:()=>_(null),children:p.text}),!e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("You are all caught up","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("New submissions from clients will show up here.","clientcopy-portal")})]}),(0,s.jsx)("ul",{className:"cc-queue",children:m.map(e=>{const t="site_logo"===e.target_field_type?(0,i.__)("Site logo (whole site)","clientcopy-portal"):e.target_post?`${e.target_post.title} → ${d(e.target_field_type,e.target_field_key)}`:"";return(0,s.jsxs)("li",{className:"cc-queue__item",children:[(0,s.jsxs)("div",{className:"cc-queue__head",children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("div",{className:"cc-queue__title",children:[(0,s.jsx)("strong",{children:e.label}),(0,s.jsxs)("span",{className:"cc-muted",children:[(0,s.jsx)("a",{href:`#/project/${e.project.id}`,onClick:t=>{t.preventDefault(),g(`/project/${e.project.id}`)},children:e.project.title}),e.project.client_name?` · ${e.project.client_name}`:"",` · ${c(e.item_type)}`,t?` · ${(0,i.__)("writes to","clientcopy-portal")} ${t}`:""]})]}),(0,s.jsx)("span",{className:"cc-muted cc-queue__time",children:x(e.submission?.submitted_at)})]}),e.instructions&&(0,s.jsxs)("p",{className:"cc-muted cc-queue__ask",children:[(0,i.__)("Asked:","clientcopy-portal")," ",e.instructions]}),(0,s.jsx)(M,{request:e,onResult:y(e),onProject:()=>{}})]},e.id)})})]})}function z({project:e,onClose:t,onSaved:l}){const n=!!e,c=v(()=>n?Promise.resolve([]):k(),[n]),[r,o]=(0,a.useState)({title:e?.title||"",client_name:e?.client_name||"",client_email:e?.client_email||"",due_date:e?.due_date||"",template_id:"",create_pages:!0}),[p,d]=(0,a.useState)(!1),[_,u]=(0,a.useState)(""),m=e=>t=>o(l=>({...l,[e]:t}));return(0,s.jsx)(D.Modal,{title:n?(0,i.__)("Edit project","clientcopy-portal"):(0,i.__)("New project","clientcopy-portal"),onRequestClose:t,size:"medium",children:(0,s.jsxs)("form",{onSubmit:async t=>{t.preventDefault(),d(!0),u("");try{const t={...r,template_id:r.template_id?parseInt(r.template_id,10):0},i=n?await S(e.id,t):await(a=t,w("/projects","POST",a));l(i)}catch(e){u(B(e)),d(!1)}var a},className:"cc-form",children:[_&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:_}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Project title","clientcopy-portal"),value:r.title,onChange:m("title"),required:!0}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Client name","clientcopy-portal"),value:r.client_name,onChange:m("client_name")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Client email","clientcopy-portal"),type:"email",value:r.client_email,onChange:m("client_email"),help:(0,i.__)("Used for reminders.","clientcopy-portal")})]}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Due date","clientcopy-portal"),type:"date",value:r.due_date,onChange:m("due_date"),help:(0,i.__)("Reminders start once this date has passed.","clientcopy-portal")}),!n&&c.data&&c.data.length>0&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Start from a template","clientcopy-portal"),value:r.template_id,onChange:m("template_id"),options:[{value:"",label:(0,i.__)("Blank project","clientcopy-portal")},...c.data.map(e=>({value:String(e.id),label:`${e.title} (${e.items.length})`}))]}),r.template_id&&(0,s.jsx)(D.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Create a draft page for each section and map the items to it","clientcopy-portal"),checked:r.create_pages,onChange:m("create_pages")})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:p,disabled:p||!r.title.trim(),children:n?(0,i.__)("Save","clientcopy-portal"):(0,i.__)("Create project","clientcopy-portal")})]})]})})}function H(){const{data:e,error:t,loading:l}=v(C),[n,c]=(0,a.useState)(!1),r=(e||[]).filter(e=>"active"===e.status),o=r.reduce((e,t)=>e+(t.submitted||0),0),p=r.reduce((e,t)=>e+t.pending+t.rejected,0),d=r.filter(j).length,m=[[(0,i.__)("Active projects","clientcopy-portal"),r.length,""],[(0,i.__)("Needs your review","clientcopy-portal"),o,o?"is-alert":""],[(0,i.__)("Waiting on clients","clientcopy-portal"),p,""],[(0,i.__)("Overdue","clientcopy-portal"),d,d?"is-danger":""]];return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Projects","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Everything you are collecting from clients, in one place.","clientcopy-portal")})]}),(0,s.jsx)(D.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:()=>c(!0),children:(0,i.__)("New project","clientcopy-portal")})]}),e&&e.length>0&&(0,s.jsx)("div",{className:"cc-stats-grid",children:m.map(([e,t,l])=>(0,s.jsxs)("div",{className:`cc-stat ${l}`,children:[(0,s.jsx)("span",{className:"cc-stat__value",children:t}),(0,s.jsx)("span",{className:"cc-stat__label",children:e})]},e))}),t&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)}),l&&!e&&(0,s.jsx)(D.Spinner,{}),e&&0===e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("No projects yet","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("Create a project, add the content you need, and send your client the magic link.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>c(!0),children:(0,i.__)("Create your first project","clientcopy-portal")})]}),e&&e.length>0&&(0,s.jsxs)("table",{className:"cc-table",children:[(0,s.jsx)("thead",{children:(0,s.jsxs)("tr",{children:[(0,s.jsx)("th",{children:(0,i.__)("Project","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Progress","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Needs review","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Due","clientcopy-portal")}),(0,s.jsx)("th",{children:(0,i.__)("Status","clientcopy-portal")})]})}),(0,s.jsx)("tbody",{children:e.map(e=>{return(0,s.jsxs)("tr",{onClick:()=>g(`/project/${e.id}`),className:"is-clickable",children:[(0,s.jsx)("td",{children:(0,s.jsxs)("div",{className:"cc-project-cell",children:[(0,s.jsx)("span",{className:"cc-avatar","aria-hidden":"true",children:(t=e.client_name||e.title,(t||"?").split(/\s+/).filter(Boolean).slice(0,2).map(e=>e[0].toUpperCase()).join(""))}),(0,s.jsxs)("div",{children:[(0,s.jsx)("a",{href:`#/project/${e.id}`,onClick:e=>e.stopPropagation(),className:"cc-table__title",children:e.title}),(0,s.jsx)("div",{className:"cc-muted",children:e.client_name||e.client_email||(0,i.__)("No client yet","clientcopy-portal")})]})]})}),(0,s.jsx)("td",{children:(0,s.jsx)(u,{done:e.approved,total:e.total})}),(0,s.jsx)("td",{children:e.submitted>0?(0,s.jsx)("span",{className:"cc-pill",children:e.submitted}):(0,s.jsx)("span",{className:"cc-muted",children:"–"})}),(0,s.jsx)("td",{className:j(e)?"cc-overdue":"",children:y(e.due_date)||"–"}),(0,s.jsx)("td",{children:(0,s.jsx)(_,{status:e.status})})]},e.id);var t})})]}),n&&(0,s.jsx)(z,{onClose:()=>c(!1),onSaved:e=>{c(!1),g(`/project/${e.id}`)}})]})}const P=(e,t)=>e?`${e}|${t||""}`:"";function R({value:e,onChange:t}){const[l,n]=(0,a.useState)(""),[c,r]=(0,a.useState)([]),[o,p]=(0,a.useState)(!1),[d,_]=(0,a.useState)(""),u=(0,a.useRef)();return(0,a.useEffect)(()=>(clearTimeout(u.current),u.current=setTimeout(()=>{p(!0),(e=>w(`/targets/posts?search=${encodeURIComponent(e)}`))(l).then(r).catch(e=>_(B(e))).finally(()=>p(!1))},250),()=>clearTimeout(u.current)),[l]),(0,s.jsxs)("div",{className:"cc-picker",children:[d&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:d}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Find a page or post","clientcopy-portal"),placeholder:(0,i.__)("Search by title…","clientcopy-portal"),value:l,onChange:n}),(0,s.jsxs)("ul",{className:"cc-picker__list",children:[o&&(0,s.jsx)("li",{children:(0,s.jsx)(D.Spinner,{})}),!o&&c.map(l=>(0,s.jsx)("li",{children:(0,s.jsxs)("button",{type:"button",className:e?.id===l.id?"is-selected":"",onClick:()=>t(l),children:[(0,s.jsx)("strong",{children:l.title}),(0,s.jsxs)("span",{className:"cc-muted",children:[l.type," · ",l.status]})]})},l.id))]}),l.trim()&&(0,s.jsxs)(D.Button,{variant:"link",onClick:async()=>{_("");try{t(await(e=l.trim(),w("/targets/posts","POST",{title:e})))}catch(e){_(B(e))}var e},children:[(0,i.__)("Create a new draft page called","clientcopy-portal")," “",l.trim(),"”"]})]})}function A({projectId:e,request:t,sections:l,onClose:c,onSaved:r}){const p=!!t,[d,_]=(0,a.useState)({section_label:t?.section_label||"",label:t?.label||"",item_type:t?.item_type||"text",instructions:t?.instructions||"",required:!t||t.required}),[u,m]=(0,a.useState)(!!t?.target_field_type),[h,x]=(0,a.useState)("site_logo"===t?.target_field_type?"site_logo":"post"),[y,j]=(0,a.useState)(t?.target_post||null),[g,v]=(0,a.useState)(P(t?.target_field_type,t?.target_field_key)),[f,b]=(0,a.useState)("meta"===t?.target_field_type?t.target_field_key:""),[N,C]=(0,a.useState)(null),[S,k]=(0,a.useState)(!1),[$,T]=(0,a.useState)(""),q=e=>t=>_(l=>({...l,[e]:t}));(0,a.useEffect)(()=>{var e;y?(e=y.id,w(`/targets/fields?post_id=${e}`)).then(C).catch(e=>T(B(e))):C(null)},[y?.id]);const M="credentials"===d.item_type,E=d.item_type,z=[];N&&(N.native.filter(e=>e.item_types.includes(E)).forEach(e=>z.push({value:P(e.type,""),label:e.label})),N.acf.filter(e=>e.item_types.includes(E)).forEach(e=>z.push({value:P("acf",e.key),label:`ACF: ${e.label}`})),z.push({value:"meta|",label:(0,i.__)("Custom field (post meta key)…","clientcopy-portal")}));const H=g.split("|")[0];return(0,s.jsx)(D.Modal,{title:p?(0,i.__)("Edit item","clientcopy-portal"):(0,i.__)("Add item","clientcopy-portal"),onRequestClose:c,size:"large",children:(0,s.jsxs)("form",{onSubmit:async l=>{l.preventDefault(),k(!0),T("");const a={...d};if(u&&"image"===E&&"site_logo"===h)a.target_post_id=0,a.target_field_type="site_logo",a.target_field_key="";else if(u&&!M&&y&&g){const[e,t]=g.split("|");a.target_post_id=y.id,a.target_field_type=e,a.target_field_key="meta"===e?f.trim():t}else a.target_post_id=0,a.target_field_type="",a.target_field_key="";try{const l=p?await(i=t.id,s=a,w(`/requests/${i}`,"PUT",s)):await((e,t)=>w(`/projects/${e}/requests`,"POST",t))(e,a);r(l)}catch(e){T(B(e)),k(!1)}var i,s},className:"cc-form",children:[$&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:$}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Section (page or group)","clientcopy-portal"),value:d.section_label,onChange:q("section_label"),list:"cc-sections",help:(0,i.__)("Items with the same section are grouped together for the client.","clientcopy-portal")}),(0,s.jsx)("datalist",{id:"cc-sections",children:l.map(e=>(0,s.jsx)("option",{value:e},e))})]}),(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Type","clientcopy-portal"),value:d.item_type,options:n,onChange:e=>{q("item_type")(e),v("")}})]}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("What do you need?","clientcopy-portal"),value:d.label,onChange:q("label"),required:!0}),(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Instructions for the client","clientcopy-portal"),value:d.instructions,onChange:q("instructions"),rows:3}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Required","clientcopy-portal"),checked:d.required,onChange:q("required")}),(0,s.jsx)("hr",{}),M?(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are stored encrypted and are never written to a page.","clientcopy-portal")}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Write approved content into the site","clientcopy-portal"),help:(0,i.__)("When you approve this item, it is saved to the page or field you choose.","clientcopy-portal"),checked:u,onChange:m}),u&&(0,s.jsxs)("div",{className:"cc-mapping",children:["image"===E&&(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Where should it go?","clientcopy-portal"),value:h,onChange:x,options:[{value:"post",label:(0,i.__)("A page or post (featured image or field)","clientcopy-portal")},{value:"site_logo",label:(0,i.__)("The site logo (whole website)","clientcopy-portal")}]}),"image"===E&&"site_logo"===h&&(0,s.jsx)(D.Notice,{status:"warning",isDismissible:!1,children:(0,i.__)("Approving this changes your live site logo immediately.","clientcopy-portal")}),!("image"===E&&"site_logo"===h)&&y&&(0,s.jsxs)("p",{className:"cc-selected-post",children:[(0,i.__)("Target:","clientcopy-portal")," ",(0,s.jsx)("strong",{children:y.title})," ",(0,s.jsxs)("span",{className:"cc-muted",children:["(",y.type,", ",y.status,")"]})," ",(0,s.jsx)(D.Button,{variant:"link",onClick:()=>{j(null),v("")},children:(0,i.__)("Change","clientcopy-portal")})]}),!("image"===E&&"site_logo"===h)&&!y&&(0,s.jsx)(R,{value:y,onChange:j}),!("image"===E&&"site_logo"===h)&&y&&!N&&(0,s.jsx)(D.Spinner,{}),!("image"===E&&"site_logo"===h)&&y&&N&&(0,s.jsxs)(s.Fragment,{children:[(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Field","clientcopy-portal"),value:g,options:[{value:"",label:(0,i.__)("Select a field…","clientcopy-portal")},...z],onChange:v,help:N.acf_active?void 0:(0,i.__)("Install Advanced Custom Fields to map to ACF fields.","clientcopy-portal")}),"meta"===H&&(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Meta key","clientcopy-portal"),value:f,onChange:b}),H&&(0,s.jsx)("p",{className:"cc-muted",children:o[H]})]})]})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:c,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:S,disabled:S||!d.label.trim()||u&&!M&&!("image"===E&&"site_logo"===h)&&(!y||!g),children:p?(0,i.__)("Save item","clientcopy-portal"):(0,i.__)("Add item","clientcopy-portal")})]})]})})}const F=e=>{const t=e.meta||{},l=t.label?`“${t.label}”`:"",a=t.revision>1?` (${(0,i.sprintf)(/* translators: %d: version number */ /* translators: %d: version number */(0,i.__)("version %d","clientcopy-portal"),t.revision)})`:"";switch(e.action){case"project_created":return(0,i.__)("created the project","clientcopy-portal");case"project_completed":return(0,i.__)("All items approved: project completed","clientcopy-portal");case"link_regenerated":return(0,i.__)("issued a new portal link (the old one stopped working)","clientcopy-portal");case"request_added":return`${(0,i.__)("added","clientcopy-portal")} ${l}`;case"request_removed":return`${(0,i.__)("removed","clientcopy-portal")} ${l}`;case"template_applied":return`${(0,i.__)("applied template","clientcopy-portal")} “${t.template}”`;case"submitted":return`${(0,i.__)("submitted","clientcopy-portal")} ${l}${a}`;case"approved":return`${(0,i.__)("approved","clientcopy-portal")} ${l}${a}`;case"rejected":return`${(0,i.__)("requested changes on","clientcopy-portal")} ${l}${a}${t.note?`: “${t.note}”`:""}`;case"content_written":return`${l} → ${t.field} (#${t.post_id}): ${t.message}`;case"write_skipped":return`${(0,i.__)("skipped writing","clientcopy-portal")} ${l}: ${t.message}`;case"write_error":return`${(0,i.__)("failed to write","clientcopy-portal")} ${l}: ${t.message}`;case"credentials_viewed":return`${(0,i.__)("viewed credentials","clientcopy-portal")} ${l}`;case"files_downloaded":return`${(0,i.__)("downloaded","clientcopy-portal")} ${t.count} ${1===t.count?(0,i.__)("file","clientcopy-portal"):(0,i.__)("files","clientcopy-portal")} (${t.label})`;case"invite_sent":return(0,i.__)("emailed the portal invite","clientcopy-portal");case"reminder_sent":return(0,i.__)("sent a reminder email","clientcopy-portal");default:return"string"==typeof t.summary&&t.summary?t.summary:e.action}};function O({projectId:e,refreshKey:t}){const{data:l,loading:a,error:n}=v(()=>w(`/projects/${e}/activity`),[e,t]);return n?(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(n)}):a&&!l?(0,s.jsx)(D.Spinner,{}):l&&l.length?(0,s.jsx)("ul",{className:"cc-activity",children:l.map(e=>(0,s.jsxs)("li",{className:`cc-activity--${e.actor_type}`,children:[(0,s.jsx)("time",{children:x(e.created_at)}),(0,s.jsxs)("span",{children:["project_completed"===e.action||"content_written"===e.action||"write_skipped"===e.action||"write_error"===e.action?"":(0,s.jsxs)("strong",{children:[e.actor," "]}),F(e)]})]},e.id))}):(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("No activity yet.","clientcopy-portal")})}function L({project:e,onClose:t,onNotice:l}){const[n,c]=(0,a.useState)(e.title),[r,o]=(0,a.useState)(!1),[p,d]=(0,a.useState)("");return(0,s.jsx)(D.Modal,{title:(0,i.__)("Save as template","clientcopy-portal"),onRequestClose:t,children:(0,s.jsxs)("form",{onSubmit:async a=>{a.preventDefault(),o(!0);try{await((e,t)=>w(`/projects/${e}/save-as-template`,"POST",{title:t}))(e.id,n),l({status:"success",text:(0,i.__)("Template saved.","clientcopy-portal")}),t()}catch(e){d(B(e)),o(!1)}},className:"cc-form",children:[p&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:p}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template name","clientcopy-portal"),value:n,onChange:c}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("The items and their field mappings are saved. Page selections are not, because they are specific to this site.","clientcopy-portal")}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:r,disabled:r||!n.trim(),children:(0,i.__)("Save template","clientcopy-portal")})]})]})})}function I({project:e,onClose:t,onApplied:l}){const n=v(k),[c,r]=(0,a.useState)(""),[o,p]=(0,a.useState)(!0),[d,_]=(0,a.useState)(!1),[u,m]=(0,a.useState)("");return(0,s.jsx)(D.Modal,{title:(0,i.__)("Add items from a template","clientcopy-portal"),onRequestClose:t,children:(0,s.jsxs)("form",{onSubmit:async t=>{t.preventDefault(),_(!0);try{l(await(a=e.id,i={template_id:parseInt(c,10),create_pages:o},w(`/projects/${a}/apply-template`,"POST",i)))}catch(e){m(B(e)),_(!1)}var a,i},className:"cc-form",children:[u&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:u}),n.data?(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template","clientcopy-portal"),value:c,onChange:r,options:[{value:"",label:(0,i.__)("Choose…","clientcopy-portal")},...n.data.map(e=>({value:String(e.id),label:`${e.title} (${e.items.length})`}))]}):(0,s.jsx)(D.Spinner,{}),(0,s.jsx)(D.CheckboxControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Create a draft page for each section and map the items to it","clientcopy-portal"),checked:o,onChange:p}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:t,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:d,disabled:d||!c,children:(0,i.__)("Add items","clientcopy-portal")})]})]})})}function U({project:e,onProject:t,onNotice:l}){const[n,c]=(0,a.useState)(!1);return(0,s.jsxs)("div",{className:"cc-link",children:[(0,s.jsx)("input",{type:"text",readOnly:!0,value:e.portal_url,onFocus:e=>e.target.select(),"aria-label":(0,i.__)("Client portal link","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:async()=>{try{await navigator.clipboard.writeText(e.portal_url),l({status:"success",text:(0,i.__)("Link copied.","clientcopy-portal")})}catch(t){window.prompt((0,i.__)("Copy this link","clientcopy-portal"),e.portal_url)}},children:(0,i.__)("Copy","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",href:e.portal_url,target:"_blank",rel:"noreferrer",children:(0,i.__)("Open","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:async()=>{if(window.confirm((0,i.__)("Issue a new link? The current link will stop working immediately.","clientcopy-portal"))){c(!0);try{t(await(a=e.id,w(`/projects/${a}/regenerate-link`,"POST"))),l({status:"success",text:(0,i.__)("New link issued.","clientcopy-portal")})}catch(e){l({status:"error",text:B(e)})}c(!1)}var a},disabled:n,children:(0,i.__)("New link","clientcopy-portal")})]})}function W({r:e}){const t=e.submission;if(!t)return null;if("credentials"===e.item_type)return(0,s.jsxs)("span",{className:"cc-preview cc-muted",children:["🔒 ",(0,i.__)("Credentials received","clientcopy-portal")]});if(t.attachments.length)return(0,s.jsxs)("span",{className:"cc-preview cc-preview--files",children:[t.attachments.slice(0,4).map(e=>e.thumb?(0,s.jsx)("img",{src:e.thumb,alt:e.filename},e.id):(0,s.jsxs)("span",{className:"cc-preview__file",children:["📄 ",e.filename]},e.id)),t.attachments.length>4&&(0,s.jsxs)("span",{className:"cc-muted",children:["+",t.attachments.length-4]})]});const l=(e=>{const t=String(e).replace(/<\/(p|div|h[1-6]|li|blockquote)>|<br\s*\/?>/gi," $&");return((new window.DOMParser).parseFromString(t,"text/html").body.textContent||"").replace(/\s+/g," ").trim()})(t.value);return l?(0,s.jsx)("span",{className:"cc-preview cc-muted",children:l.length>120?`${l.slice(0,120)}…`:l}):null}function V({r:e,first:t,last:l,open:a,onToggle:n,onMove:r,onEdit:p,onDelete:d,onResult:u,onProject:m}){const x="site_logo"===e.target_field_type?(0,i.__)("Site logo (whole site)","clientcopy-portal"):e.target_post?`${e.target_post.title} → ${o[e.target_field_type]||e.target_field_type}${"acf"===e.target_field_type||"meta"===e.target_field_type?` (${e.target_field_key})`:""}`:"";return(0,s.jsxs)("li",{className:`cc-request cc-request--${e.status}`,children:[(0,s.jsxs)("div",{className:"cc-request__head",onClick:n,children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("button",{type:"button",className:"cc-request__main",onClick:e=>{e.stopPropagation(),n()},"aria-expanded":a,children:[(0,s.jsxs)("span",{className:"cc-request__label",children:[e.label,e.required&&(0,s.jsx)("abbr",{title:(0,i.__)("Required","clientcopy-portal"),children:" *"})]}),(0,s.jsxs)("span",{className:"cc-muted",children:[c(e.item_type),x?` · ${x}`:""]}),!a&&(0,s.jsx)(W,{r:e})]}),(0,s.jsx)(_,{status:e.status}),(0,s.jsx)("span",{className:"cc-chevron"+(a?" is-open":""),"aria-hidden":"true"}),(0,s.jsxs)("div",{className:"cc-request__tools",onClick:e=>e.stopPropagation(),children:[(0,s.jsx)(D.Button,{size:"small",icon:"arrow-up-alt2",label:(0,i.__)("Move up","clientcopy-portal"),disabled:t,onClick:()=>r(-1)}),(0,s.jsx)(D.Button,{size:"small",icon:"arrow-down-alt2",label:(0,i.__)("Move down","clientcopy-portal"),disabled:l,onClick:()=>r(1)}),(0,s.jsx)(D.Button,{size:"small",icon:"edit",label:(0,i.__)("Edit","clientcopy-portal"),onClick:p}),(0,s.jsx)(D.Button,{size:"small",icon:"trash",label:(0,i.__)("Delete","clientcopy-portal"),isDestructive:!0,onClick:d})]})]}),a&&(0,s.jsxs)("div",{className:"cc-request__body",children:[e.instructions&&(0,s.jsx)("p",{className:"cc-muted",children:e.instructions}),(0,s.jsx)(M,{request:e,onResult:u,onProject:m})]})]})}function G({id:e}){const{data:t,error:l,loading:n,set:c}=v(()=>(e=>w(`/projects/${e}`))(e),[e]),[r,o]=(0,a.useState)(null),[p,d]=(0,a.useState)(null),[m,h]=(0,a.useState)({}),[x,f]=(0,a.useState)(0);if(l)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(l)});if(n&&!t)return(0,s.jsx)(D.Spinner,{});if(!t)return null;const b=e=>{c(e),f(e=>e+1)},N=async(e,t)=>{try{const l=await e();return l&&l.requests&&b(l),t&&o({status:"success",text:t}),l}catch(e){o({status:"error",text:B(e)})}return null},C=({result:e,project:t})=>{b(t),"rejected"===e.status?o({status:"success",text:(0,i.__)("Changes requested. The item is back in the client portal.","clientcopy-portal")}):e.write&&"written"!==e.write.status?o({status:"warning",text:`${(0,i.__)("Approved, but the content was not written:","clientcopy-portal")} ${e.write.message}`}):e.write?o({status:"success",text:`${(0,i.__)("Approved.","clientcopy-portal")} ${e.write.message}`}):o({status:"success",text:(0,i.__)("Approved.","clientcopy-portal")})},k=[];t.requests.forEach((e,t)=>{const l=e.section_label||(0,i.__)("General","clientcopy-portal");let a=k.find(e=>e.label===l);a||(a={label:l,items:[]},k.push(a)),a.items.push({r:e,index:t})});const $=k.map(e=>e.label),T=t.submitted||0;return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("a",{className:"cc-back",href:"#/",onClick:e=>{e.preventDefault(),g("/")},children:["← ",(0,i.__)("All projects","clientcopy-portal")]}),(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsxs)("h2",{children:[t.title," ",(0,s.jsx)(_,{status:t.status})]}),(0,s.jsxs)("p",{className:"cc-muted",children:[t.client_name,t.client_name&&t.client_email?" · ":"",t.client_email,t.due_date&&(0,s.jsxs)("span",{className:j(t)?"cc-overdue":"",children:[" · ",(0,i.__)("Due","clientcopy-portal")," ",y(t.due_date)]})]})]}),(0,s.jsxs)("div",{className:"cc-actions cc-actions--left",children:[(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>d({type:"project"}),children:(0,i.__)("Edit","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>N(()=>(e=>w(`/projects/${e}/invite`,"POST"))(t.id),(0,i.__)("Invite emailed to the client.","clientcopy-portal")),disabled:!t.client_email||!t.requests.length,title:t.client_email?(0,i.__)("Email the client their portal link and what you need from them","clientcopy-portal"):(0,i.__)("Add a client email first","clientcopy-portal"),children:(0,i.__)("Email invite","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>N(()=>(e=>w(`/projects/${e}/remind`,"POST"))(t.id),(0,i.__)("Reminder sent.","clientcopy-portal")),disabled:!t.client_email,children:(0,i.__)("Send reminder","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",onClick:()=>N(()=>S(t.id,{status:"archived"===t.status?"active":"archived"})),children:"archived"===t.status?(0,i.__)("Unarchive","clientcopy-portal"):(0,i.__)("Archive","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:async()=>{window.confirm((0,i.__)("Delete this project and all submissions? Uploaded files stay in the media library.","clientcopy-portal"))&&await N(()=>(e=>w(`/projects/${e}`,"DELETE"))(t.id))&&g("/")},children:(0,i.__)("Delete","clientcopy-portal")})]})]}),r&&(0,s.jsx)(D.Notice,{status:r.status,onRemove:()=>o(null),children:r.text}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Client portal link","clientcopy-portal")}),(0,s.jsx)(U,{project:t,onProject:b,onNotice:o}),"archived"===t.status&&(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Archived projects are not accessible to the client.","clientcopy-portal")}),t.zip_url&&(0,s.jsxs)("p",{className:"cc-files-row",children:[(0,s.jsxs)("a",{className:"components-button is-secondary",href:t.zip_url,children:["↓ ",(0,i.__)("Download all client files (.zip)","clientcopy-portal")]}),(0,s.jsx)("a",{className:"cc-media-link",href:t.media_url,children:(0,i.__)("View in Media Library","clientcopy-portal")}),(0,s.jsx)("span",{className:"cc-muted",children:(0,i.sprintf)((0,i._n)("%d file, organised by section and item","%d files, organised by section and item",t.file_count,"clientcopy-portal"),t.file_count)})]}),(0,s.jsxs)("div",{className:"cc-stats",children:[(0,s.jsx)(u,{done:t.approved,total:t.total}),(0,s.jsx)("span",{children:(0,i.sprintf)((0,i.__)("%1$d waiting on client · %2$d need review · %3$d approved","clientcopy-portal"),t.pending+t.rejected,t.submitted,t.approved)})]})]}),(0,s.jsx)(D.TabPanel,{className:"cc-tabs",tabs:[{name:"requests",title:T?`${(0,i.__)("Requests","clientcopy-portal")} (${T})`:(0,i.__)("Requests","clientcopy-portal")},{name:"activity",title:(0,i.__)("Activity","clientcopy-portal")}],children:e=>"activity"===e.name?(0,s.jsx)(O,{projectId:t.id,refreshKey:x}):(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-actions cc-actions--left cc-toolbar",children:[(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>d({type:"request"}),children:(0,i.__)("Add item","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>d({type:"apply"}),children:(0,i.__)("Add from template","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",onClick:()=>d({type:"save"}),disabled:!t.requests.length,children:(0,i.__)("Save as template","clientcopy-portal")})]}),!t.requests.length&&(0,s.jsx)("div",{className:"cc-empty",children:(0,s.jsx)("p",{children:(0,i.__)("No items yet. Add what you need from the client, or start from a template.","clientcopy-portal")})}),k.map(e=>(0,s.jsxs)("section",{className:"cc-section",children:[(0,s.jsxs)("h3",{children:[e.label,(0,s.jsxs)("span",{className:"cc-section__count",children:[e.items.filter(({r:e})=>"approved"===e.status).length,"/",e.items.length]})]}),(0,s.jsx)("ul",{className:"cc-requests",children:e.items.map(({r:e,index:l})=>(0,s.jsx)(V,{r:e,first:0===l,last:l===t.requests.length-1,open:m[e.id]??"submitted"===e.status,onToggle:()=>h(t=>({...t,[e.id]:!(t[e.id]??"submitted"===e.status)})),onMove:e=>((e,l)=>{const a=t.requests.map(e=>e.id),i=e+l;[a[e],a[i]]=[a[i],a[e]],N(()=>((e,t)=>w(`/projects/${e}/requests/reorder`,"POST",{ids:t}))(t.id,a))})(l,e),onEdit:()=>d({type:"request",request:e}),onDelete:()=>(e=>{window.confirm((0,i.sprintf)((0,i.__)("Delete “%s” and anything the client submitted for it?","clientcopy-portal"),e.label))&&N(()=>(e=>w(`/requests/${e}`,"DELETE"))(e.id))})(e),onResult:C,onProject:b},e.id))})]},e.label))]})}),"project"===p?.type&&(0,s.jsx)(z,{project:t,onClose:()=>d(null),onSaved:e=>{b(e),d(null)}}),"request"===p?.type&&(0,s.jsx)(A,{projectId:t.id,request:p.request,sections:$,onClose:()=>d(null),onSaved:e=>{b(e),d(null)}}),"apply"===p?.type&&(0,s.jsx)(I,{project:t,onClose:()=>d(null),onApplied:e=>{b(e),d(null)}}),"save"===p?.type&&(0,s.jsx)(L,{project:t,onClose:()=>d(null),onNotice:o})]})}function K({items:e}){const t=[];return e.forEach(e=>{const l=e.section_label||(0,i.__)("General","clientcopy-portal");let a=t.find(e=>e.label===l);a||(a={label:l,items:[]},t.push(a)),a.items.push(e)}),(0,s.jsx)("div",{className:"cc-tpl-view",children:t.map(e=>(0,s.jsxs)("section",{children:[(0,s.jsx)("h4",{children:e.label}),(0,s.jsx)("ul",{children:e.items.map((e,t)=>(0,s.jsxs)("li",{children:[(0,s.jsx)(h,{type:e.item_type}),(0,s.jsxs)("div",{children:[(0,s.jsxs)("strong",{children:[e.label,e.required&&(0,s.jsx)("abbr",{title:(0,i.__)("Required","clientcopy-portal"),children:" *"})]}),(0,s.jsxs)("span",{className:"cc-muted",children:[c(e.item_type),e.target_field_type?` · ${(0,i.__)("writes to","clientcopy-portal")} ${d(e.target_field_type,e.target_field_key)}`:""]}),e.instructions&&(0,s.jsx)("span",{className:"cc-muted",children:e.instructions})]})]},t))})]},e.label))})}function Y(){const{data:e,error:t,loading:l,reload:n}=v(k),[c,r]=(0,a.useState)({}),[o,p]=(0,a.useState)(null);return(0,s.jsxs)(s.Fragment,{children:[(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:(0,i.__)("Templates","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Reusable request sets. Start a project from one, or save any project as a template.","clientcopy-portal")})]}),(0,s.jsx)(D.Button,{variant:"primary",__next40pxDefaultSize:!0,onClick:()=>g("/templates/new"),children:(0,i.__)("New template","clientcopy-portal")})]}),o&&(0,s.jsx)(D.Notice,{status:o.status,onRemove:()=>p(null),children:o.text}),t&&(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)}),l&&!e&&(0,s.jsx)(D.Spinner,{}),e&&!e.length&&(0,s.jsxs)("div",{className:"cc-empty",children:[(0,s.jsx)("h3",{children:(0,i.__)("No templates yet","clientcopy-portal")}),(0,s.jsx)("p",{children:(0,i.__)("Build one from scratch, or save an existing project as a template.","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>g("/templates/new"),children:(0,i.__)("Create a template","clientcopy-portal")})]}),e&&e.map(e=>{const t=new Set(e.items.map(e=>e.section_label||"")).size,l=!!c[e.id];return(0,s.jsxs)("div",{className:"cc-card cc-tpl",children:[(0,s.jsxs)("div",{className:"cc-card__head",children:[(0,s.jsxs)("button",{type:"button",className:"cc-tpl__toggle","aria-expanded":l,onClick:()=>r(t=>({...t,[e.id]:!t[e.id]})),children:[(0,s.jsx)("span",{className:"cc-chevron"+(l?" is-open":""),"aria-hidden":"true"}),(0,s.jsxs)("span",{children:[(0,s.jsx)("h3",{children:e.title}),(0,s.jsx)("span",{className:"cc-muted",children:(0,i.sprintf)((0,i.__)("%1$d items across %2$d sections","clientcopy-portal"),e.items.length,t)})]})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"secondary",onClick:()=>r(t=>({...t,[e.id]:!t[e.id]})),children:l?(0,i.__)("Hide","clientcopy-portal"):(0,i.__)("View","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",onClick:()=>g(`/templates/${e.id}`),children:(0,i.__)("Edit","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"tertiary",isDestructive:!0,onClick:()=>(async e=>{if(window.confirm((0,i.sprintf)((0,i.__)("Delete the template “%s”? Existing projects are not affected.","clientcopy-portal"),e.title)))try{await(t=e.id,w(`/templates/${t}`,"DELETE")),p({status:"success",text:(0,i.__)("Template deleted.","clientcopy-portal")}),n()}catch(e){p({status:"error",text:B(e)})}var t})(e),children:(0,i.__)("Delete","clientcopy-portal")})]})]}),l&&(0,s.jsx)(K,{items:e.items})]},e.id)})]})}const J=(e="")=>({section_label:e,item_type:"text",label:"",instructions:"",required:!0,target_field_type:"",target_field_key:""});function X({item:e,index:t,count:l,sections:a,onChange:c,onMove:r,onRemove:d}){const _=t=>c({...e,...t}),u=e.item_type,m=Object.keys(p).filter(e=>p[e].includes(u)),x="acf"===e.target_field_type||"meta"===e.target_field_type;return(0,s.jsxs)("div",{className:"cc-tpl-item",children:[(0,s.jsxs)("div",{className:"cc-tpl-item__head",children:[(0,s.jsx)(h,{type:u}),(0,s.jsx)("strong",{children:e.label||(0,i.__)("New item","clientcopy-portal")}),(0,s.jsxs)("span",{className:"cc-tpl-item__tools",children:[(0,s.jsx)(D.Button,{size:"small",icon:"arrow-up-alt2",label:(0,i.__)("Move up","clientcopy-portal"),disabled:0===t,onClick:()=>r(-1)}),(0,s.jsx)(D.Button,{size:"small",icon:"arrow-down-alt2",label:(0,i.__)("Move down","clientcopy-portal"),disabled:t===l-1,onClick:()=>r(1)}),(0,s.jsx)(D.Button,{size:"small",icon:"trash",isDestructive:!0,label:(0,i.__)("Remove item","clientcopy-portal"),onClick:d})]})]}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("What do you need?","clientcopy-portal"),value:e.label,onChange:e=>_({label:e})}),(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Type","clientcopy-portal"),value:u,options:n,onChange:t=>{const l=!e.target_field_type||"credentials"!==t&&p[e.target_field_type].includes(t);_(l?{item_type:t}:{item_type:t,target_field_type:"",target_field_key:""})}})]}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)("div",{children:(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Section (becomes a page)","clientcopy-portal"),value:e.section_label,onChange:e=>_({section_label:e}),list:"cc-tpl-sections"})}),"credentials"!==u?(0,s.jsx)(D.SelectControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("When approved, write to","clientcopy-portal"),value:e.target_field_type,options:[{value:"",label:(0,i.__)("Nothing (just collect it)","clientcopy-portal")},...m.map(e=>({value:e,label:o[e]}))],onChange:e=>_({target_field_type:e,target_field_key:""})}):(0,s.jsx)("p",{className:"cc-muted",children:(0,i.__)("Credentials are encrypted and never written to a page.","clientcopy-portal")})]}),x&&(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:"acf"===e.target_field_type?(0,i.__)("ACF field key","clientcopy-portal"):(0,i.__)("Custom field (meta) key","clientcopy-portal"),help:"acf"===e.target_field_type?(0,i.__)("For example field_5f3a1b2c. Find it in the ACF field group settings.","clientcopy-portal"):void 0,value:e.target_field_key,onChange:e=>_({target_field_key:e})}),(0,s.jsx)(D.TextareaControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Instructions for the client","clientcopy-portal"),value:e.instructions,onChange:e=>_({instructions:e}),rows:2}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Required","clientcopy-portal"),checked:e.required,onChange:e=>_({required:e})}),(0,s.jsx)("datalist",{id:"cc-tpl-sections",children:a.map(e=>(0,s.jsx)("option",{value:e},e))})]})}function Q({id:e}){const[t,l]=(0,a.useState)(""),[n,c]=(0,a.useState)(e?null:[J()]),[r,o]=(0,a.useState)(""),[p,d]=(0,a.useState)(null),[_,u]=(0,a.useState)(!1),[m,h]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{e&&(e=>w(`/templates/${e}`))(e).then(e=>{l(e.title),c(e.items)}).catch(e=>o(B(e)))},[e]),(0,a.useEffect)(()=>{if(!m)return;const e=e=>{e.preventDefault(),e.returnValue=""};return window.addEventListener("beforeunload",e),()=>window.removeEventListener("beforeunload",e)},[m]),r)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:r});if(!n)return(0,s.jsx)(D.Spinner,{});const x=e=>{h(!0),e()},y=[...new Set(n.map(e=>e.section_label).filter(Boolean))],j=e=>{e.preventDefault(),m&&!window.confirm((0,i.__)("Discard your unsaved changes?","clientcopy-portal"))||(h(!1),g("/templates"))};return(0,s.jsxs)("form",{onSubmit:async a=>{a.preventDefault(),u(!0),d(null);try{const a=await((e,t)=>e?w(`/templates/${e}`,"PUT",t):w("/templates","POST",t))(e,{title:t,items:n});h(!1),e?(l(a.title),c(a.items),d({status:"success",text:(0,i.__)("Template saved.","clientcopy-portal")})):g(`/templates/${a.id}`)}catch(e){d({status:"error",text:B(e)})}u(!1)},children:[(0,s.jsxs)("a",{className:"cc-back",href:"#/templates",onClick:j,children:["← ",(0,i.__)("All templates","clientcopy-portal")]}),(0,s.jsxs)("div",{className:"cc-page-head",children:[(0,s.jsxs)("div",{children:[(0,s.jsx)("h2",{children:e?(0,i.__)("Edit template","clientcopy-portal"):(0,i.__)("New template","clientcopy-portal")}),(0,s.jsx)("p",{className:"cc-muted",children:(0,i.sprintf)((0,i.__)("%d items. Changes only affect projects you start from this template later.","clientcopy-portal"),n.length)})]}),(0,s.jsxs)("div",{className:"cc-actions",children:[(0,s.jsx)(D.Button,{variant:"tertiary",onClick:j,children:(0,i.__)("Cancel","clientcopy-portal")}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:_,disabled:_||!t.trim()||!n.length,children:(0,i.__)("Save template","clientcopy-portal")})]})]}),p&&(0,s.jsx)(D.Notice,{status:p.status,onRemove:()=>d(null),children:p.text}),(0,s.jsx)("div",{className:"cc-card",children:(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Template name","clientcopy-portal"),value:t,onChange:e=>x(()=>l(e)),placeholder:(0,i.__)("e.g. 5 Page Business Site","clientcopy-portal")})}),n.map((e,t)=>(0,s.jsx)(X,{item:e,index:t,count:n.length,sections:y,onChange:e=>((e,t)=>x(()=>c(l=>l.map((l,a)=>a===e?t:l))))(t,e),onMove:e=>((e,t)=>x(()=>c(l=>{const a=[...l];return[a[e],a[e+t]]=[a[e+t],a[e]],a})))(t,e),onRemove:()=>(e=>x(()=>c(t=>t.filter((t,l)=>l!==e))))(t)},t)),(0,s.jsxs)(D.Button,{variant:"secondary",onClick:()=>x(()=>c(e=>[...e,J(e.length?e[e.length-1].section_label:"")])),children:["+ ",(0,i.__)("Add item","clientcopy-portal")]})]})}function Z(){const{data:e,error:t,loading:l}=v($),[n,c]=(0,a.useState)(null),[r,o]=(0,a.useState)(null),[p,d]=(0,a.useState)(!1);if((0,a.useEffect)(()=>{e&&c(e)},[e]),t)return(0,s.jsx)(D.Notice,{status:"error",isDismissible:!1,children:B(t)});if(l||!n)return(0,s.jsx)(D.Spinner,{});const _=window.clientcopyAdmin||{},u=e=>t=>c(l=>({...l,[e]:t}));return(0,s.jsxs)("form",{onSubmit:async e=>{e.preventDefault(),d(!0);try{const e={};["reminders_enabled","reminder_cadence_days","reminder_max_count","notify_admin_on_submit","admin_notify_email","notify_client_on_reject","notify_client_on_approve","from_name","allow_publish_writes","show_credit"].forEach(t=>{e[t]=n[t]});const t=await(e=>w("/settings","POST",e))(e);c(e=>({...e,...t})),o({status:"success",text:(0,i.__)("Settings saved.","clientcopy-portal")})}catch(e){o({status:"error",text:B(e)})}d(!1)},className:"cc-form cc-settings",children:[(0,s.jsx)("div",{className:"cc-page-head",children:(0,s.jsx)("h2",{children:(0,i.__)("Settings","clientcopy-portal")})}),r&&(0,s.jsx)(D.Notice,{status:r.status,onRemove:()=>o(null),children:r.text}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Reminders","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Send automatic reminder emails","clientcopy-portal"),help:(0,i.__)("Clients get a reminder for outstanding items once the project due date has passed (or, with no due date, once the interval has passed since creation).","clientcopy-portal"),checked:n.reminders_enabled,onChange:u("reminders_enabled")}),(0,s.jsxs)("div",{className:"cc-row",children:[(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"number",min:"1",max:"60",label:(0,i.__)("Repeat every (days)","clientcopy-portal"),value:n.reminder_cadence_days,onChange:u("reminder_cadence_days")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"number",min:"1",max:"50",label:(0,i.__)("Maximum reminders per project","clientcopy-portal"),value:n.reminder_max_count,onChange:u("reminder_max_count")})]})]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Notifications","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email me when a client submits an item","clientcopy-portal"),checked:n.notify_admin_on_submit,onChange:u("notify_admin_on_submit")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,type:"email",label:(0,i.__)("Notification email","clientcopy-portal"),value:n.admin_notify_email,onChange:u("admin_notify_email")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email the client when changes are requested","clientcopy-portal"),checked:n.notify_client_on_reject,onChange:u("notify_client_on_reject")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Email the client when an item is approved","clientcopy-portal"),checked:!!n.notify_client_on_approve,onChange:u("notify_client_on_approve")}),(0,s.jsx)(D.TextControl,{__nextHasNoMarginBottom:!0,__next40pxDefaultSize:!0,label:(0,i.__)("Sender name","clientcopy-portal"),value:n.from_name,onChange:u("from_name")})]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Client portal and emails","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Show “powered by ClientCopy”","clientcopy-portal"),help:(0,i.__)("Off by default. When on, a small credit line appears at the bottom of the client portal and in client emails.","clientcopy-portal"),checked:!!n.show_credit,onChange:u("show_credit")}),_.proActive?(0,s.jsxs)("p",{className:"cc-muted",children:[(0,i.__)("Logo, colours, portal path and email wording are in ","clientcopy-portal"),(0,s.jsx)("a",{href:_.proUrl,children:(0,i.__)("ClientCopy Pro","clientcopy-portal")}),"."]}):_.learnProUrl?(0,s.jsxs)("p",{className:"cc-muted",children:[(0,i.__)("Want your own logo, colours and email wording? The optional ","clientcopy-portal"),(0,s.jsx)("a",{href:_.learnProUrl,target:"_blank",rel:"noreferrer",children:(0,i.__)("ClientCopy Pro add-on","clientcopy-portal")}),(0,i.__)(" adds them.","clientcopy-portal")]}):null]}),(0,s.jsxs)("div",{className:"cc-card",children:[(0,s.jsx)("h3",{children:(0,i.__)("Writing content to the site","clientcopy-portal")}),(0,s.jsx)(D.ToggleControl,{__nextHasNoMarginBottom:!0,label:(0,i.__)("Allow writing to published content","clientcopy-portal"),help:(0,i.__)("Off by default: approved content is only written to draft, pending, or scheduled pages so nothing changes live by surprise.","clientcopy-portal"),checked:n.allow_publish_writes,onChange:u("allow_publish_writes")})]}),(0,s.jsx)(D.Button,{variant:"primary",type:"submit",isBusy:p,disabled:p,children:(0,i.__)("Save settings","clientcopy-portal")})]})}function ee(){const e=function(){const e=()=>window.location.hash.replace(/^#/,"")||"/",[t,l]=(0,a.useState)(e);return(0,a.useEffect)(()=>{const t=()=>l(e());return window.addEventListener("hashchange",t),()=>window.removeEventListener("hashchange",t)},[]),t}(),[t,l]=(0,a.useState)(0);(0,a.useEffect)(()=>{const e=()=>N().then(e=>l(e.length)).catch(()=>{});return e(),window.addEventListener("clientcopy:queue-changed",e),()=>window.removeEventListener("clientcopy:queue-changed",e)},[e]);const n=e.match(/^\/project\/(\d+)/);let c=(0,s.jsx)(H,{}),r="projects";if(n)c=(0,s.jsx)(G,{id:parseInt(n[1],10)},n[1]);else if(e.startsWith("/review"))c=(0,s.jsx)(E,{}),r="review";else if(e.startsWith("/templates")){const t=e.match(/^\/templates\/(new|\d+)/);c=t?(0,s.jsx)(Q,{id:"new"===t[1]?0:parseInt(t[1],10)},t[1]):(0,s.jsx)(Y,{}),r="templates"}else e.startsWith("/settings")&&(c=(0,s.jsx)(Z,{}),r="settings");const o=[["projects","/",(0,i.__)("Projects","clientcopy-portal")],["review","/review",(0,i.__)("Review","clientcopy-portal")],["templates","/templates",(0,i.__)("Templates","clientcopy-portal")],["settings","/settings",(0,i.__)("Settings","clientcopy-portal")]];return(0,s.jsxs)("div",{className:"cc-app",children:[(0,s.jsxs)("header",{className:"cc-nav",children:[(0,s.jsxs)("h1",{className:"cc-nav__brand",children:[(0,s.jsx)("svg",{className:"cc-logo",viewBox:"0 0 32 32","aria-hidden":"true",focusable:"false",children:(0,s.jsx)("path",{fill:"#4f46e5",d:"M18 2H14A10 10 0 0 0 4 12v8a10 10 0 0 0 10 10h10a4 4 0 0 0 4-4v-4H14a2 2 0 0 1-2-2v-8a2 2 0 0 1 2-2h4zm2 0 8 8h-8z"})}),"ClientCopy"]}),(0,s.jsxs)("nav",{children:[o.map(([e,l,a])=>(0,s.jsxs)("a",{href:`#${l}`,className:r===e?"is-active":"",onClick:e=>{e.preventDefault(),g(l)},children:[a,"review"===e&&t>0&&(0,s.jsx)("span",{className:"cc-nav__count",children:t})]},e)),window.clientcopyAdmin?.docsUrl&&(0,s.jsxs)("a",{className:"cc-nav__docs",href:window.clientcopyAdmin.docsUrl,target:"_blank",rel:"noopener noreferrer",children:[(0,i.__)("Docs","clientcopy-portal"),(0,s.jsx)("span",{"aria-hidden":"true",children:" ↗"})]})]})]}),(0,s.jsx)("main",{className:"cc-main",children:c})]})}const te=document.getElementById("clientcopy-admin-root");te&&(0,a.createRoot)(te).render((0,s.jsx)(ee,{}))}};const t={};function l(a){const i=t[a];if(void 0!==i)return i.exports;const s=t[a]={exports:{}};return e[a](s,s.exports,l),s.exports}l.m=e,(()=>{const e=[];l.O=(t,a,i)=>{if(!a){for(var s=0;s<e.length;s++){let[a,i]=e[s],c=!0;for(var n=0;n<a.length;n++)l.O.j(a[n])?a.splice(n--,1):c=!1;if(c){e.splice(s--,1);const l=i();void 0!==l&&(t=l)}}return t}e.push([a,i])}})(),l.n=e=>{const t=e&&e.__esModule?()=>e.default:()=>e;return l.d(t,{a:t}),t},l.d=(e,t)=>{for(var a in t)l.o(t,a)&&!l.o(e,a)&&Object.defineProperty(e,a,{enumerable:!0,get:t[a]})},l.o=(e,t)=>Object.hasOwn(e,t),(()=>{const e={773:0,641:0};l.O.j=t=>0===e[t];const t=(t,a)=>{let[i,s,n]=a;var c,r,o=0;if(i.some(t=>0!==e[t])){for(c in s)l.o(s,c)&&(l.m[c]=s[c]);if(n)var p=n(l)}for(t&&t(a);o<i.length;o++)r=i[o],l.o(e,r)&&e[r]&&e[r][0](),e[r]=0;return l.O(p)},a=globalThis.webpackChunkclientcopy_portal||=[];a.forEach(t.bind(null,0)),a.push=t.bind(null,a.push.bind(a))})();let a=l.O(void 0,[641],()=>l(639));a=l.O(a)})(); -
clientcopy-portal/tags/2.1.1/clientcopy-portal.php
r3799111 r3799706 4 4 * Plugin URI: https://clientcopy.godhustler90956.workers.dev 5 5 * Description: Stop chasing clients for content. Collect it, approve it, publish it, all inside WordPress. 6 * Version: 2.1. 06 * Version: 2.1.1 7 7 * Requires at least: 6.4 8 8 * Requires PHP: 7.4 … … 16 16 defined( 'ABSPATH' ) || exit; 17 17 18 define( 'CLIENTCOPY_VERSION', '2.1. 0' );18 define( 'CLIENTCOPY_VERSION', '2.1.1' ); 19 19 define( 'CLIENTCOPY_DB_VERSION', '1.1.0' ); 20 20 define( 'CLIENTCOPY_FILE', __FILE__ ); -
clientcopy-portal/tags/2.1.1/includes/class-requests.php
r3799111 r3799706 127 127 public static function set_status( $id, $status ) { 128 128 return self::update( $id, array( 'status' => $status ) ); 129 } 130 131 /** 132 * Change status only if the request is still in the expected one. The single UPDATE is the lock: when two 133 * reviewers decide at the same moment, exactly one of them gets true. 134 */ 135 public static function transition( $id, $from, $to ) { 136 global $wpdb; 137 return 1 === (int) $wpdb->update( DB::table( 'requests' ), array( 'status' => $to ), array( 'id' => (int) $id, 'status' => $from ) ); 129 138 } 130 139 -
clientcopy-portal/tags/2.1.1/includes/class-submissions.php
r3799111 r3799706 29 29 ); 30 30 return $row ? self::cast( $row ) : null; 31 } 32 33 /** 34 * Which version of an item this is: 1 for the first thing the client sent, 2 after the first resubmit, and so on. 35 */ 36 public static function revision( $request_id, $submission_id ) { 37 global $wpdb; 38 return (int) $wpdb->get_var( 39 $wpdb->prepare( 'SELECT COUNT(*) FROM %i WHERE request_id = %d AND submitted_at IS NOT NULL AND id <= %d', DB::table( 'submissions' ), $request_id, $submission_id ) 40 ); 31 41 } 32 42 -
clientcopy-portal/tags/2.1.1/includes/class-workflow.php
r3799111 r3799706 112 112 Submissions::mark_submitted( $sid ); 113 113 Requests::set_status( $request['id'], 'submitted' ); 114 Activity::log( $project['id'], $request['id'], 'client', 'submitted', array( 'label' => $request['label'] ) );114 Activity::log( $project['id'], $request['id'], 'client', 'submitted', array( 'label' => $request['label'], 'submission_id' => (int) $sid, 'revision' => Submissions::revision( $request['id'], $sid ) ) ); 115 115 Projects::sync_status( $project['id'] ); 116 116 … … 122 122 123 123 /** 124 * @param int $submission_id The version the reviewer was looking at. When given, the decision is refused if the 125 * client has sent something newer since, so unseen text is never approved. 124 126 * @return array|\WP_Error Result with 'status' and 'write' keys. 125 127 */ 126 public static function review( array $request, $decision, $note, $user_id ) {128 public static function review( array $request, $decision, $note, $user_id, $submission_id = 0 ) { 127 129 if ( 'submitted' !== $request['status'] ) { 128 130 return new \WP_Error( 'clientcopy_state', __( 'Only submitted items can be reviewed.', 'clientcopy-portal' ), array( 'status' => 409 ) ); … … 132 134 return new \WP_Error( 'clientcopy_state', __( 'No submission found.', 'clientcopy-portal' ), array( 'status' => 409 ) ); 133 135 } 136 if ( $submission_id && (int) $submission_id !== (int) $submission['id'] ) { 137 return new \WP_Error( 'clientcopy_stale', __( 'The client has sent a newer version since you opened this item. Reload the page to review it.', 'clientcopy-portal' ), array( 'status' => 409 ) ); 138 } 139 $revision = Submissions::revision( $request['id'], $submission['id'] ); 140 $ref = array( 'submission_id' => (int) $submission['id'], 'revision' => $revision ); 134 141 $project = Projects::get( $request['project_id'] ); 135 142 $note = sanitize_textarea_field( $note ); … … 139 146 return new \WP_Error( 'clientcopy_invalid', __( 'Add a note so the client knows what to change.', 'clientcopy-portal' ), array( 'status' => 400 ) ); 140 147 } 148 if ( ! Requests::transition( $request['id'], 'submitted', 'rejected' ) ) { 149 return self::already_decided(); 150 } 141 151 Submissions::mark_reviewed( $submission['id'], $user_id, $note ); 142 Requests::set_status( $request['id'], 'rejected' ); 143 Activity::log( $request['project_id'], $request['id'], 'admin', 'rejected', array( 'label' => $request['label'], 'note' => $note ) ); 152 Activity::log( $request['project_id'], $request['id'], 'admin', 'rejected', array( 'label' => $request['label'], 'note' => $note ) + $ref ); 144 153 Projects::sync_status( $request['project_id'] ); 145 154 if ( $project && Settings::get( 'notify_client_on_reject' ) ) { … … 149 158 } 150 159 160 if ( ! Requests::transition( $request['id'], 'submitted', 'approved' ) ) { 161 return self::already_decided(); 162 } 151 163 Submissions::mark_reviewed( $submission['id'], $user_id, $note ); 152 Requests::set_status( $request['id'], 'approved' ); 153 Activity::log( $request['project_id'], $request['id'], 'admin', 'approved', array( 'label' => $request['label'], 'note' => $note ) ); 164 Activity::log( $request['project_id'], $request['id'], 'admin', 'approved', array( 'label' => $request['label'], 'note' => $note ) + $ref ); 154 165 155 166 $write = self::apply( $request, $submission, $user_id ); … … 159 170 } 160 171 return array( 'status' => 'approved', 'write' => $write ); 172 } 173 174 private static function already_decided() { 175 return new \WP_Error( 'clientcopy_state', __( 'Someone else has already decided this item. Reload the page to see the result.', 'clientcopy-portal' ), array( 'status' => 409 ) ); 161 176 } 162 177 -
clientcopy-portal/tags/2.1.1/includes/rest/class-admin-controller.php
r3799111 r3799706 111 111 $out['submission'] = array( 112 112 'id' => $shown['id'], 113 'revision' => Submissions::revision( $req['id'], $shown['id'] ), 113 114 'value' => $is_creds ? '' : ( 'rich_text' === $req['item_type'] ? wp_kses_post( (string) $shown['value'] ) : (string) $shown['value'] ), 114 115 'has_secret' => $is_creds && '' !== (string) $shown['value'], … … 375 376 return new \WP_Error( 'clientcopy_invalid', __( 'Decision must be approve or reject.', 'clientcopy-portal' ), array( 'status' => 400 ) ); 376 377 } 377 $res = Workflow::review( $req, $decision, (string) $r->get_param( 'note' ), get_current_user_id() );378 $res = Workflow::review( $req, $decision, (string) $r->get_param( 'note' ), get_current_user_id(), (int) $r->get_param( 'submission_id' ) ); 378 379 if ( is_wp_error( $res ) ) { 379 380 return $res; -
clientcopy-portal/tags/2.1.1/readme.txt
r3799111 r3799706 5 5 Tested up to: 7.1 6 6 Requires PHP: 7.4 7 Stable tag: 2.1. 07 Stable tag: 2.1.1 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 72 72 == Changelog == 73 73 74 = 2.1.1 = 75 * Fix: approving or requesting changes now applies to the exact version you were reviewing. If the client has sent a newer version since you opened the item (for example after you asked for changes and they resubmitted), the decision is refused with a prompt to reload, so text you have not seen is never written to a page. 76 * Fix: if two people decide the same item at the same moment, only the first decision is applied. 77 * The activity log and the review screen now show which version of an item (version 2, 3 and so on) was submitted, approved or sent back. 78 74 79 = 2.1.0 = 75 80 * New hooks for add-ons: `clientcopy_activity_logged` (fires for every project event) and `clientcopy_project_deleted`. The activity list shows a readable summary for events that add-ons log. -
clientcopy-portal/tags/2.1.1/src/admin/api.js
r3799111 r3799706 20 20 deleteRequest: ( id ) => call( `/requests/${ id }`, 'DELETE' ), 21 21 reorder: ( pid, ids ) => call( `/projects/${ pid }/requests/reorder`, 'POST', { ids } ), 22 review: ( id, decision, note ) => call( `/requests/${ id }/review`, 'POST', { decision, note} ),22 review: ( id, decision, note, submissionId ) => call( `/requests/${ id }/review`, 'POST', { decision, note, submission_id: submissionId } ), 23 23 reapply: ( id ) => call( `/requests/${ id }/reapply`, 'POST' ), 24 24 credentials: ( id ) => call( `/requests/${ id }/credentials`, 'POST' ), -
clientcopy-portal/tags/2.1.1/src/admin/components/ActivityTab.js
r3799111 r3799706 1 import { __ } from '@wordpress/i18n';1 import { __, sprintf } from '@wordpress/i18n'; 2 2 import { Spinner, Notice } from '@wordpress/components'; 3 3 import { api, errorMessage } from '../api'; … … 7 7 const m = a.meta || {}; 8 8 const label = m.label ? `“${ m.label }”` : ''; 9 // Which version of the item the event refers to, shown once an item has been resubmitted. 10 const version = m.revision > 1 ? ` (${ sprintf( /* translators: %d: version number */ __( 'version %d', 'clientcopy-portal' ), m.revision ) })` : ''; 9 11 switch ( a.action ) { 10 12 case 'project_created': return __( 'created the project', 'clientcopy-portal' ); … … 14 16 case 'request_removed': return `${ __( 'removed', 'clientcopy-portal' ) } ${ label }`; 15 17 case 'template_applied': return `${ __( 'applied template', 'clientcopy-portal' ) } “${ m.template }”`; 16 case 'submitted': return `${ __( 'submitted', 'clientcopy-portal' ) } ${ label } `;17 case 'approved': return `${ __( 'approved', 'clientcopy-portal' ) } ${ label } `;18 case 'rejected': return `${ __( 'requested changes on', 'clientcopy-portal' ) } ${ label }${ m.note ? `: “${ m.note }”` : '' }`;18 case 'submitted': return `${ __( 'submitted', 'clientcopy-portal' ) } ${ label }${ version }`; 19 case 'approved': return `${ __( 'approved', 'clientcopy-portal' ) } ${ label }${ version }`; 20 case 'rejected': return `${ __( 'requested changes on', 'clientcopy-portal' ) } ${ label }${ version }${ m.note ? `: “${ m.note }”` : '' }`; 19 21 case 'content_written': return `${ label } → ${ m.field } (#${ m.post_id }): ${ m.message }`; 20 22 case 'write_skipped': return `${ __( 'skipped writing', 'clientcopy-portal' ) } ${ label }: ${ m.message }`; -
clientcopy-portal/tags/2.1.1/src/admin/components/ReviewPanel.js
r3799111 r3799706 1 1 import { useState } from '@wordpress/element'; 2 import { __ } from '@wordpress/i18n';2 import { __, sprintf } from '@wordpress/i18n'; 3 3 import { Button, TextareaControl, Notice } from '@wordpress/components'; 4 4 import { api, errorMessage } from '../api'; … … 77 77 const [ busy, setBusy ] = useState( false ); 78 78 const [ error, setError ] = useState( '' ); 79 const [ stale, setStale ] = useState( false ); 79 80 80 81 if ( ! sub ) { … … 86 87 setError( '' ); 87 88 try { 88 onResult( await api.review( request.id, decision, note ) );89 onResult( await api.review( request.id, decision, note, sub.id ) ); 89 90 setNote( '' ); 90 91 } catch ( e ) { 91 92 setError( errorMessage( e ) ); 93 setStale( !! e && ( e.code === 'clientcopy_stale' || e.code === 'clientcopy_state' ) ); 92 94 } 93 95 setBusy( false ); … … 108 110 return ( 109 111 <div className="cc-review"> 110 { error && <Notice status="error" isDismissible={ false }>{ error }</Notice> } 111 <p className="cc-muted">{ __( 'Submitted', 'clientcopy-portal' ) } { fmtDateTime( sub.submitted_at ) }</p> 112 { error && ( 113 <Notice status="error" isDismissible={ false }> 114 { error } 115 { stale && <> <Button variant="link" onClick={ () => window.location.reload() }>{ __( 'Reload', 'clientcopy-portal' ) }</Button></> } 116 </Notice> 117 ) } 118 <p className="cc-muted"> 119 { sub.revision > 1 && <strong>{ sprintf( /* translators: %d: version number */ __( 'Version %d', 'clientcopy-portal' ), sub.revision ) } · </strong> } 120 { __( 'Submitted', 'clientcopy-portal' ) } { fmtDateTime( sub.submitted_at ) } 121 </p> 112 122 113 123 { request.item_type === 'credentials' && <Credentials request={ request } /> }
Note:
See TracChangeset
for help on using the changeset viewer.