PageSourceSearch

https://socialprotection.org/assets/SubmitLandingContent.page-5Ukq0lFt.js

js socialprotection.org collected 2026-10-02 02:19:23 UTC 10,813 bytes, 1 lines download raw bytes

1import{r as o,u as y,an as M,l as k,aA as W,o as X,aV as Z,j as e,aZ as J,C as b,aY as Q,Y as ee,aj as $,ao as S,B as R,O as te,a as ae,aD as se,aE as ne,aF as le,aH as F,ap as _,aq as I,at as H,az as E,ay as oe,bp as ie,t as V,aC as re,n as ce,G as de}from"./index-o5lM5yTX.js";import{A as me}from"./adminPanel.layout-DDhd51rE.js";import{I as ue,F as ge}from"./index-DNAe_WUB.js";import{C as xe}from"./constants-Bd4S2aX1.js";import{f as Y}from"./utils-DdlWp_wr.js";import{c as he}from"./schema-DK27P7I1.js";import"./index-C6Ti8Rhb.js";import"./index-CJI3Rj1b.js";import"./index-BPiK-QmS.js";import"./index-BnuIbuXj.js";import"./circle-chevron-left-BhuBogxm.js";import"./index-DIzhP4Rd.js";import"./index-SE51wN4R.js";import"./progress-oEpeedka.js";import"./pencil-CuMtTy_y.js";import"./constants-N7EXd0zj.js";import"./chevron-right-9LrqCSP2.js";const pe=({disabled:m=!1,selectedId:c,setSelectedId:u})=>{const[s,a]=o.useState(null),[x,h]=o.useState(!1),[d,i]=o.useState(""),[n,t]=o.useState([]),[r,j]=o.useState(0),{t:l}=y("AdminPanel"),v=o.useRef(null),{landingSection:A}=M(),{f:w,loading:G}=k(),L=o.useRef(null),P=W(d,300),{filterOptions:D}=X(g=>g.state),z=Y(D,"event"),q=Y(D,"webinar"),B=o.useCallback(async()=>{var N,C,f,O;if(!c)return;const g={page:0,search:"",scope:"All content",sorting:{field:"published_at",order:"desc"}},{response:p}=await w({apiModule:"content",url:"/search/results",method:"post",data:{...g,filters:{id:[c]}}});(C=(N=p==null?void 0:p.data)==null?void 0:N.results)!=null&&C[0]&&a((O=(f=p==null?void 0:p.data)==null?void 0:f.results)==null?void 0:O[0])},[c,w]),K=o.useCallback(async()=>{var p,N;L.current&&L.current.abort();const g=new AbortController;if(L.current=g,P){const C={page:0,limit:5,filters:{...A==="upcoming_events"&&{[xe]:[z,q].filter(Boolean)}},search:P,scope:"All content",sorting:{field:"published_at",order:"desc"}},{response:f}=await w({apiModule:"content",url:"/search/results",method:"post",signal:g.signal,data:C});(p=f==null?void 0:f.data)!=null&&p.results&&t(((N=f==null?void 0:f.data)==null?void 0:N.results)||[])}else t([])},[z,q,P,A,w]);o.useEffect(()=>{K()},[K]);const T=o.useCallback(g=>{v.current&&!v.current.contains(g.target)&&h(!1)},[]);o.useEffect(()=>(document.addEventListener("mousedown",T),()=>{document.removeEventListener("mousedown",T)}),[T]),o.useEffect(()=>{c&&!s&&B()},[B,s,c]);const U=Z(n);return e.jsxs(e.Fragment,{children:[e.jsxs("div",{ref:v,className:b("border-dorian relative flex w-full items-center rounded-lg border pr-3.5",x&&d?"border-b-none border-primary rounded-b-none transition-all":"border-dorian"),children:[e.jsx("input",{disabled:m,onFocus:()=>h(!0),value:d,onChange:({target:{value:g}})=>i(g),className:"flex-1 rounded-lg px-3.5 py-2.5 text-sm font-normal focus:outline-none",placeholder:l(A==="upcoming_events"?"searchForAnEvent":"searchForAContent")}),x&&!!d&&e.jsx("div",{className:b("scrollbar border-primary absolute top-10 z-40 -mt-[5px] -ml-px max-h-[80svh] w-[calc(100%+2px)] flex-col gap-2 overflow-y-auto rounded-lg rounded-t-none border bg-white px-5 py-5 shadow-lg transition-all",x?"flex":"hidden"),children:e.jsx(J,{canSeeAllResults:!1,searchValue:d,searchResults:n,grouppedSearchResults:U,loadingSearchResults:G,focusedIndex:r,setFocusedIndex:j,resetSearchToShow:()=>{},setSearchToShow:()=>{},openInlineFilter:void 0,onSetSearch:()=>{},selectedInlineFilters:{},setSelectedInlineFilters:()=>{},selectedIds:s!=null&&s.id?[s==null?void 0:s.id]:[],onSelectResult:g=>{u(g.id),a(g),h(!1)}})}),e.jsx(Q,{className:"text-light_slate h-5"})]}),s&&e.jsx(fe,{disabled:m,data:s,onRemove:()=>{u(null),a(null)}})]})},fe=({disabled:m=!1,data:c,onRemove:u})=>{const{headline:s}=ee(c);return e.jsxs("div",{onClick:()=>!m&&u(),className:b("bg-cloud border-dorian flex items-center rounded-lg border px-2 py-1",m?"cursor-default":"cursor-pointer"),children:[e.jsx("span",{className:"line-clamp-1 flex-auto text-sm",children:s}),!m&&e.jsx($,{className:"h-4 w-4 shrink-0"})]})},be=S.object({id:S.number().nullable().optional(),object_id:S.number().min(1,{message:"requiredError"}),custom_title:S.string().min(1,{message:"requiredError"}),custom_image:he,section:S.string().min(1,{message:"requiredError"}),is_visible:S.boolean()}),je={object_id:0,custom_title:"",section:"carousel",is_visible:!1},ve=({onSelect:m})=>
1{const[c,u]=o.useState(!1),[s,a]=o.useState([]),{f:x,loading:h}=k(),{t:d}=y("AdminPanel"),i=o.useCallback(async()=>{const{response:n}=await x({apiModule:"content",method:"get",url:"/admin/banner-images"});n!=null&&n.data&&a(n.data)},[x]);return o.useEffect(()=>{c&&s.length===0&&i()},[c,s.length,i]),c?e.jsxs("div",{className:"border-dorian mt-2 rounded-lg border p-4",children:[e.jsxs("div",{className:"mb-3 flex items-center justify-between",children:[e.jsx("span",{className:"text-sm font-semibold",children:d("imageLibrary")}),e.jsx("button",{type:"button",onClick:()=>u(!1),children:e.jsx($,{className:"text-light_slate h-4 w-4"})})]}),h?e.jsx("div",{className:"grid grid-cols-3 gap-3",children:Array.from({length:6}).map((n,t)=>e.jsx(te,{className:"aspect-video rounded-md"},t))}):s.length===0?e.jsx("p",{className:"text-light_slate text-sm",children:d("noImagesInLibrary")}):e.jsx("div",{className:"grid grid-cols-3 gap-3",children:s.map(n=>e.jsx("button",{type:"button",className:b("group relative overflow-hidden rounded-md border transition-all hover:ring-2 hover:ring-offset-1","border-dorian hover:ring-primary"),onClick:()=>{m({id:n.file.id,url:n.file.url,name:n.file.name}),u(!1)},children:e.jsx("img",{src:n.file.url,alt:n.file.name||n.file.caption,className:"aspect-video w-full object-cover"})},n.id))})]}):e.jsxs(R,{type:"button",variant:"outlined",size:"xs",className:"border-primary text-primary mt-2 w-fit",onClick:()=>u(!0),children:[e.jsx(ue,{className:"mr-1.5 h-4 w-4"}),d("browseImageLibrary")]})},Se=({defaultValues:m})=>{const{landingSection:c,id:u}=M(),s=ae(),{t:a}=y("AdminPanel"),{t:x}=y("SubmitContent"),{f:h,loading:d}=k(),i=se({resolver:ne(be),defaultValues:{...je,section:c}}),n=async t=>{var v;const r={...t,object_id:t.object_id,custom_image:(v=t.custom_image)==null?void 0:v.id,section:c},j=V({variant:"default",title:x("submittingContent"),description:x("pleaseWait"),duration:1/0,action:e.jsx(re,{})}),{error:l}=await h({apiModule:"content",method:r!=null&&r.id?"patch":"post",url:`/admin/landing-items${u?`/${u}`:""}`,data:r});j.dismiss(),l||(V({variant:"success",title:a("success"),description:a("contentSubmittedSuccessfully")}),s("/admin-panel/content-review/landing-page"))};return o.useEffect(()=>{m&&i.reset({...m,section:c})},[m,i,c]),e.jsx(le,{...i,children:e.jsxs("form",{className:"flex flex-col gap-6",onSubmit:i.handleSubmit(n),children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-light_slate text-lg/5 whitespace-nowrap",children:a("contentDetails")}),e.jsx("div",{className:"bg-dorian h-px w-full"})]}),e.jsxs("div",{className:"flex flex-wrap gap-6",children:[e.jsxs("div",{className:"flex min-w-54 flex-1 flex-col gap-6",children:[e.jsx(F,{control:i.control,name:"object_id",disabled:d,render:({field:t,fieldState:{error:r}})=>e.jsxs(_,{className:"flex flex-col gap-1.5",children:[e.jsx("div",{className:"flex flex-col gap-1",children:e.jsx(I,{htmlFor:t.name,className:b("text-base",r!=null&&r.message?"text-red-500":"text-black"),children:a("content")})}),e.jsx(H,{children:e.jsx(pe,{disabled:d||!!i.watch("id"),selectedId:t.value,setSelectedId:t.onChange})}),e.jsx(E,{translateFunc:a})]})}),e.jsx(F,{name:"custom_title",control:i.control,disabled:d,render:({field:t,fieldState:{error:r}})=>e.jsxs(_,{className:"flex flex-col gap-1.5",children:[e.jsx(I,{htmlFor:t.name,className:b("text-base",r!=null&&r.message?"text-red-500":"text-dark_grey"),children:a(t.name)}),e.jsx(oe,{...t,placeholder:a(t.name),className:"border-dorian"}),e.jsx(E,{translateFunc:a})]})})]}),e.jsx(F,{control:i.control,name:"custom_image",disabled:d,render:({field:t,fieldState:{error:r}})=>{var j;return e.jsxs(_,{className:"flex min-w-54 flex-1 flex-col gap-1.5",children:[e.jsxs("div",{className:"flex flex-col gap-1",children:[e.jsx(I,{htmlFor:t.name,className:b("text-base",r!=null&&r.message?"text-red-500":"text-black"),children:a(t.name)}),e.jsx("p",{className:"text-light_slate text-sm",children:a("custom_image_description")})]}
1),e.jsxs(H,{children:[e.jsx(ge,{disabled:d,uploadedFile:t.value,acceptedFormats:{"image/png":[".png"],"image/jpeg":[".jpg",".jpeg"]},resourceType:"online-tool",maxSizeMb:5,afterUploadFile:l=>{l&&(l!=null&&l.fileId)&&(i.clearErrors(t.name),t.onChange({id:l==null?void 0:l.fileId,url:(l==null?void 0:l.url)??"",name:(l==null?void 0:l.fileName)??""}))},canAddCaption:!0,caption:((j=t==null?void 0:t.value)==null?void 0:j.caption)??"",requiredDimensions:{type:"min",height:500,width:500}}),c==="carousel"&&e.jsx(ve,{onSelect:l=>{i.clearErrors(t.name),t.onChange({id:l.id,url:l.url,name:l.name})}})]}),e.jsx(E,{translateFunc:a})]})}})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("h3",{className:"text-light_slate text-lg/5 whitespace-nowrap",children:a("visibilitySettings")}),e.jsx("div",{className:"bg-dorian h-px w-full"})]}),e.jsx(F,{name:"is_visible",control:i.control,disabled:d,render:({field:t})=>e.jsxs(_,{children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(ie,{id:t.name,checked:t.value,onCheckedChange:r=>t.onChange(r)}),e.jsx(I,{htmlFor:t.name,className:b("text-base font-normal"),children:a("showInLandingPageHighlights")})]}),e.jsx(E,{translateFunc:a})]})}),e.jsxs("div",{className:"flex justify-end gap-4",children:[e.jsx(R,{variant:"outlined",size:"xs",className:"border-primary text-primary",onClick:()=>s(-1),children:a("cancel")}),e.jsx(R,{size:"xs",type:"submit",children:a("saveChanges")})]})]})})},Ne=[{titleKey:"heroContent",value:"carousel"},{titleKey:"featuredContent",value:"featured"},{titleKey:"upcomingEvents",value:"upcoming_events"}];function Be(){var n;const[m,c]=o.useState(null),{landingSection:u,id:s}=M(),{t:a}=y("AdminPanel");ce((m?m.custom_title+" | ":"")+a("landingPage")+" | "+a("adminPanel"));const{f:x,loading:h}=k(),d=o.useCallback(async()=>{if(!s)return;const{response:t}=await x({apiModule:"content",url:`/admin/landing-items/${s}`,method:"get"});t!=null&&t.data&&c(t.data)},[x,s]);o.useEffect(()=>{d()},[d]);const i=((n=Ne.find(t=>t.value===u))==null?void 0:n.titleKey)||"heroContent";return h?e.jsx(de,{}):e.jsx(me,{canReturn:!0,title:a(s?"editThe":"addA")+" "+a(i),description:a(i+"Description"),breadcrumbPaths:[{label:a("adminArea"),link:"/admin-panel"},{label:a("contentManagement"),link:"/admin-panel/content-review"},{label:a("landingPage"),link:"/admin-panel/content-review/landing-page"},{label:a(s?"editThe":"addA")+" "+a(i)}],children:e.jsx(Se,{defaultValues:m||void 0})})}export{Be as default};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.