1import{j as a,S as Y,p as pe,s as y}from"./main-CMViuH_f.js";import{R as u,e as ue,d as Re,u as fe}from"./vendor-react-Bjxsyr_G.js";import{C as Ee,D as ge}from"./vendor-redux-CkTbKByD.js";import{C as v}from"./ControlPanel-Dm3LeJij.js";import{c as be,d as he,e as Ae}from"./referralsApi-CqeHkfwH.js";import{c as z,a as A,b as J}from"./vendor-forms-Chlqk9RW.js";import{f as D}from"./customRules-BTBheOdu.js";import{u as xe}from"./usePanelFormValidation-aCfZ2sNc.js";import{v as B}from"./AccountLogs-CEv-JIFv.js";import{f as t}from"./formStyles-MU_CFwXq.js";import{I as F}from"./Input-BBroo5uU.js";import{f as Se,a as Ne}from"./dateUtils-Cn8z919x.js";import{u as k}from"./vendor-i18n-CmmgQqfv.js";import{R as _e}from"./RadioButton-CFYRGN7p.js";import{i as Ce}from"./permissions-CCOu_b7F.js";import{C as Le}from"./AccountLogs-CF_I4HXW.js";import"./TransformAffiliateResponse-Dl1Ei_ej.js";import"./validation-CmgQtWDq.js";import"./TableData-rsaJzmAi.js";import"./useMediaQuery-Bzu3CIqR.js";import"./formatDate-C6Vg3jtv.js";const je=z().shape({promo_code:A().max(255),login_enabled:J(),username:A().when("login_enabled",{is:!0,then:e=>e.required().max(255),otherwise:e=>e.nullable()}),password:A().when("login_enabled",{is:!0,then:e=>e.required().min(8).max(255),otherwise:e=>e.nullable()}),name:D.specificName(),type:A().required(),belongs_to:A().required(),status:A().required(),comment:D.comment()}),Fe=z().shape({promo_code:A().max(255),login_enabled:J(),username:A().when("login_enabled",{is:!0,then:e=>e.required().max(255),otherwise:e=>e.nullable()}),password:A().when("login_enabled",{is:!0,then:e=>e.min(8).max(255),otherwise:e=>e.nullable()}),name:D.specificName(),type:A().required(),belongs_to:A().required(),status:A().required(),comment:D.comment()}),Te=je,U={id:"",promo_code:"",registration_date:"",login_enabled:!1,username:"",password:""},V={name:"",type:""},G={belongs_to:"",status:""},ye="",X={account:["promo_code","login_enabled","username","password"],referralInfo:["name","type"],assigned:["belongs_to","status"],comments:["comment"]},ve=Object.keys(X).reduce((e,o)=>(e[o]=!1,e),{});({...U,...V,...G});const Ie={promo_code:"REFERRALS.PROMO_CODE",registration_date:"REFERRALS.REGISTRATION_DATE",login_enabled:"REFERRALS.ACTIVATE_LOGIN",username:"REFERRALS.USERNAME",password:"REFERRALS.PASSWORD",name:"REFERRALS.REFERRAL_NAME",type:"MARKETING.TYPE",belongs_to:"REFERRALS.ASSIGNED_TO",status:"REFERRALS.REFERRAL_STATUS",comment:"REFERRALS.COMMENTS"},Oe=(e,o={})=>{if(!e||typeof e!="object")return null;const{accountInitialValues:l={},referralInfoInitialValues:d={},assignedInitialValues:n={}}=o;return{account:{...l,id:e.id||"",promo_code:e.promo_code||"",registration_date:e.created_at||e.registration_date||"",login_enabled:!!e.login_enabled,username:e.username||"",password:""},referralInfo:{...d,name:e.name||"",type:e.type||""},assigned:{...n,belongs_to:e.belongs_to||"",status:e.status||n.status},comments:e.comment||"",activityLog:e.activity_log||[]}};function we({value:e,onChange:o,disabled:l=!1,isEdit:d=!1,errors:n={}}){const{t:s}=k(),c=S=>R=>o==null?void 0:o({...e,[S]:R&&R.target?R.target.value:R}),b=()=>{o==null||o({...e,login_enabled:!e.login_enabled})};return a.jsxs(a.Fragment,{children:[d?a.jsx("div",{className:"col-span-12 sm:col-span-6 lg:col-span-3",children:a.jsx(F,{label:s?s("REFERRALS.REFERRAL_ID"):"Referral ID",value:e.id,onChange:()=>{},variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:!0})}):null,a.jsxs("div",{className:"col-span-12 sm:col-span-6 lg:col-span-3",children:[a.jsx(F,{label:s?s("REFERRALS.PROMO_CODE"):"Promo code",value:e.promo_code,onChange:c("promo_code"),variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:l,error:n.promo_code}),d?null:a.jsx("a",{href:"/how-to-activate-promo-codes.pdf",download:!0,className:`inline-block mt-2 ${t.linkRed}`,children:s?s("REFERRALS.HOW_TO_ACTIVATE_PROMO_CODE"):"How to activate promo code?"})]}),a.jsx("div",{className:"col-span-12 sm:col-span-6 lg:col-span-3",children:a.jsx(F,{label:s?s("REFERRALS.REGISTRATION_DATE"):"Registration date",value:Se(e.registration_date,Ne()),onChange:()=>{},variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:!0})}),d?a.jsx("div",{className:"hidden lg:block lg:col-span-3"}):null,a.jsx("div",{className:"col-span-12 mt-2",children:a.jsxs("label",{className:"inline-flex items-center cursor-pointer",children:[a.jsx("input",{type:"checkbox",checked:!!e.login_enabled,onChange:b,disabled:l,className:"w-4 h-4 accent-green-600 mr-2"}),a.jsx("span",{className:t.label,children:s?s("REFERRALS.ACTIVATE_LOGIN"):"Activate login"})]})}),e.login_enabled?a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"col-span-12 sm:col-span-6 lg:col-span-4",children:a.jsx(F,{label:s?s("REFERRALS.USERNAME"):"Username",value:e.username,onChange:c("username"),variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:l,error:n.username})}),a.jsx("div",{className:"col-span-12 sm:col-span-6 lg:col-span-4",children:a.jsx(F,{label:s?s("REFERRALS.PASSWORD"):"Password",value:e.password,onChange:c("password"),variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:l,error:n.password,type:"password"})})]}):null]})}const Me=()=>[{id:"ads_services",name:"Ads Services"},{id:"influencers",name:"Influencers"},{id:"paid_pr",name:"Paid PR"},{id:"supportive_sites",name:"Supportive sites"},{id:"meta",name:"Meta"},{id:"sponsorships",name:"Sponsorships"}],De=e=>{const o=Me(),l=Number(e&&typeof e=="object"?e.id:e);return!Number.isNaN(l)&&[2,3,4].includes(l)&&o.push({id:"promotion",name:"Promotion type"}),o};
1function ke({value:e,onChange:o,disabled:l=!1,errors:d={},onFieldBlur:n}){const{t:s}=k(),c=parseInt(localStorage.getItem("market_id")||"",10)||null,b=u.useMemo(()=>De(c).map(g=>({id:g.id,name:g.name})),[c]),S=R=>g=>o==null?void 0:o({...e,[R]:g&&g.target?g.target.value:g});return a.jsxs(a.Fragment,{children:[a.jsx("div",{className:"col-span-12 min-[600px]:col-span-6",children:a.jsx(F,{label:s?s("REFERRALS.REFERRAL_NAME"):"Referral Name",value:e.name,onChange:S("name"),onBlur:()=>n&&n("name"),variant:"outlined",labelClassName:t.label,noLabelBottomMargin:!0,inputClassName:t.input,disabled:l,error:d.name})}),a.jsxs("div",{className:"col-span-12 min-[600px]:col-span-6",onBlur:()=>n&&n("type"),children:[a.jsx(Y,{items:b,value:e.type,onChange:R=>S("type")(R),labels:{placeholder:s?s("REFERRALS.CHOOSE_REFERRAL_TYPE"):"Choose referral type"},buttonClassName:`w-full mt-5 ${t.selectBtn} ${d.type?"border-[var(--mdn-red-d2)] border-2":""}`,className:"w-full",disabled:l,placeholderClassName:"text-[var(--mdn-text-38)]"}),d.type&&a.jsx("p",{className:t.errorMessage,children:d.type})]}),a.jsx("div",{className:"hidden lg:block lg:col-span-6"})]})}const Pe=[{value:"active",labelKey:"AFFILIATES.APPROVED",fallback:"Active"},{value:"suspended",labelKey:"REFERRALS.SUSPENDED",fallback:"Suspended"}];function Be({value:e,onChange:o,managers:l=[],disabled:d=!1,errors:n={},onFieldBlur:s}){const{t:c}=k(),b=Ee(i=>{var _;return(_=i.auth)==null?void 0:_.user}),S=Ce(b),R="var(--mdn-red-d2)",g=u.useMemo(()=>({belongs_to:(e==null?void 0:e.belongs_to)??"",status:(e==null?void 0:e.status)??""}),[e]),C=u.useMemo(()=>(Array.isArray(l)?l:[]).map(i=>({id:i.id??i.value??"",name:i.name||i.full_name||i.username||String(i.id||i)})),[l]),I=(i,_)=>o==null?void 0:o({...g,[i]:_});return a.jsxs(a.Fragment,{children:[S&&a.jsxs("div",{className:"col-span-12 sm:col-span-6",onBlur:()=>s&&s("belongs_to"),children:[a.jsxs("label",{className:`block ${t.label} mb-1 ${n.belongs_to?"text-[var(--mdn-red-d2)]":""}`,children:[c?c("REFERRALS.ASSIGNED_TO"):"Assigned to",":"]}),a.jsx(Y,{items:C,value:g.belongs_to,onChange:i=>I("belongs_to",i),labels:{placeholder:c?c("REFERRALS.CHOOSE_MANAGER"):"Choose manager"},buttonClassName:`w-full ${t.selectBtn} ${n.belongs_to?"border-[var(--mdn-red-d2)] border-2":""}`,className:"w-full",searchable:!0,showSearchBox:!0,typeToOpen:!0,inputAsTrigger:!0,disabled:d,placeholderClassName:"text-[var(--mdn-text-38)]"}),n.belongs_to&&a.jsx("p",{className:t.errorMessage,children:n.belongs_to})]}),a.jsxs("div",{className:"col-span-12 sm:col-span-6",onBlur:()=>s&&s("status"),children:[a.jsx("div",{className:"flex flex-col gap-3",children:Pe.map(i=>a.jsx(_e,{name:"referral_status",label:c?c(i.labelKey):i.fallback,value:i.value,checked:g.status===i.value,onChange:_=>I("status",_.target.value),disabled:d,error:!!n.status,style:n.status?{color:R}:void 0},i.value))}),n.status&&a.jsx("p",{className:t.errorMessage,children:n.status})]}),a.jsx("div",{className:"hidden lg:block lg:col-span-3"})]})}function Ue({value:e="",onChange:o,disabled:l=!1,placeholder:d="",errors:n={}}){const s=!!n.comment;return a.jsxs("div",{className:"col-span-12",children:[a.jsx("textarea",{value:e,onChange:c=>o==null?void 0:o(c.target.value),className:s?t.textareaError:t.textarea,disabled:l,placeholder:d,maxLength:255}),s&&a.jsx("p",{className:t.errorMessage,children:n.comment})]})}function ia(){const{t:e}=k(),o=ue(),l=Re(),d=fe(),n=ge(),s=(o==null?void 0:o.id)??null,c=!!s&&!String(d.pathname).includes("/referrals/show/"),b=!!s&&String(d.pathname).includes("/referrals/show/"),S=!s,{data:R,isFetching:g,error:C}=be(s,{skip:!s}),{data:I}=pe({section:"Referrals"}),[i,{isLoading:_}]=he(),[Z,{isLoading:ee}]=Ae(),[m,$]=u.useState(U),[f,H]=u.useState(V),[p,q]=u.useState(G),[x,K]=u.useState(ye),[ae,se]=u.useState([]);u.useEffect(()=>{const r=Oe(R,{accountInitialValues:U,referralInfoInitialValues:V,assignedInitialValues:G});r&&($(r.account),H(r.referralInfo),q(r.assigned),K(r.comments),se(r.activityLog))},[R]),u.useEffect(()=>{if(!s)return;(C==null?void 0:C.status)===404&&(n(y({notification:"REFERRALS.NOT_FOUND",notificationColor:"red",forTranslation:!0})),l("/referrals"))},[s,C,n,l]);const te=c?Fe:Te,{errors:O,panelErrors:w,validateField:N,validateForm:ne}=xe({schema:te,labelKeys:Ie,PANEL_FIELDS:X,initialPanelErrors:ve}),oe=u.useCallback(r=>{$(r),B(m,r,N,L=>({...L,...f,...p,comment:x}
1))},[m,f,p,x,N]),le=u.useCallback(r=>{H(r),B(f,r,N,L=>({...m,...L,...p,comment:x}))},[m,f,p,x,N]),re=u.useCallback(r=>{q(r),B(p,r,N,L=>({...m,...f,...L,comment:x}))},[m,f,p,x,N]),ie=u.useCallback(r=>{K(r),N("comment",{...m,...f,...p,comment:r})},[m,f,p,N]),W=u.useCallback(r=>{N(r,{...m,...f,...p,comment:x})},[m,f,p,x,N]),ce=()=>l(-1),me=async r=>{var Q;if(r.preventDefault(),b||!await ne({...m,...f,...p,comment:x}))return;const T={name:f.name,type:f.type,belongs_to:p.belongs_to?p.belongs_to:null,status:p.status,comment:x,login_enabled:!!m.login_enabled};m.promo_code&&(T.promo_code=m.promo_code),m.login_enabled&&(T.username=m.username,m.password&&(T.password=m.password));try{if(c){const E=await Z({...T,id:s}).unwrap(),h=((E==null?void 0:E.message)||"").toUpperCase();n(y({notification:h,notificationColor:"green",forTranslation:!0}))}else{const E=await i(T).unwrap(),h=((E==null?void 0:E.message)||"").toUpperCase();n(y({notification:h,notificationColor:"green",forTranslation:!0}))}l("/referrals")}catch(E){const h=E==null?void 0:E.data;if(h!=null&&h.errors){const j=Object.keys(h.errors)[0],P=((Q=h.errors[j])==null?void 0:Q[0])||"";n(y({notification:`${j.toUpperCase()}: ${P}`,notificationColor:"red",forTranslation:!1}))}else{const j=(h==null?void 0:h.message)||(E==null?void 0:E.error)||"REFERRALS.SAVE_FAILED",P=typeof j=="string"&&j.includes(".");n(y({notification:j,notificationColor:"red",forTranslation:P}))}}},de=b?e?e("REFERRALS.SHOW_REFERRAL"):"Show referral":c?e?e("REFERRALS.EDIT_REFERRAL"):"Edit referral":e?e("REFERRALS.ADD_NEW_REFERRAL"):"Add new referral",M=!b;return a.jsxs("div",{className:"px-4 pb-4 pt-[6px] md:px-6 md:pb-6 md:pt-[14px]",children:[a.jsx("div",{className:"mb-4",children:a.jsx("h1",{className:"uppercase font-normal text-[14.4px] text-[var(--mdn-text-87)]",children:de})}),a.jsxs("form",{onSubmit:me,children:[a.jsx(v,{title:e?e("REFERRALS.ACCOUNT_DETAILS"):"Account details",headerContainerClassName:t.panelHeader,titleClassName:t.panelTitle,collapsible:!0,defaultExpanded:!0,hasError:w.account,children:a.jsx(we,{value:m,onChange:oe,isEdit:!!s,disabled:!M,errors:O})}),a.jsx(v,{title:e?e("REFERRALS.REFERRAL_INFO"):"Referral info",headerContainerClassName:t.panelHeader,titleClassName:t.panelTitle,collapsible:!0,defaultExpanded:S,hasError:w.referralInfo,children:a.jsx(ke,{value:f,onChange:le,disabled:!M,errors:O,onFieldBlur:W})}),a.jsx(v,{title:a.jsxs("div",{className:"grid grid-cols-12 min-sm:gap-8",children:[a.jsx("span",{className:"col-span-12 sm:col-span-6 max-sm:pt-2",children:e?e("REFERRALS.ASSIGNED_TO"):"Permissions type"}),a.jsx("span",{className:"col-span-12 sm:col-span-6 max-sm:pb-2",children:e?e("REFERRALS.REFERRAL_STATUS"):"Affiliate status"})]}),headerContainerClassName:t.panelHeader,titleClassName:t.panelTitle,collapsible:!0,defaultExpanded:S,hasError:w.assigned,children:a.jsx(Be,{value:p,onChange:re,managers:I||[],disabled:!M,errors:O,onFieldBlur:W})}),a.jsx(v,{title:e?e("REFERRALS.COMMENTS"):"Comments",headerContainerClassName:t.panelHeader,titleClassName:t.panelTitle,collapsible:!0,defaultExpanded:S,hasError:w.comments,children:a.jsx(Ue,{value:x,onChange:ie,disabled:!M,errors:O})}),s?a.jsx(v,{title:e?e("AFFILIATES.ACCOUNT_LOGS"):"Account logs",headerContainerClassName:t.panelHeader,titleClassName:t.panelTitle,collapsible:!0,defaultExpanded:!1,children:a.jsx(Le,{logs:ae})}):null,a.jsxs("div",{className:"flex flex-wrap items-center justify-end gap-3 mt-6",children:[a.jsx("button",{type:"button",onClick:ce,className:t.btnCancel,children:e?e(b?"REFERRALS.BACK":"REFERRALS.CANCEL"):b?"Back":"Cancel"}),b?null:a.jsx("button",{type:"submit",disabled:_||ee||g,className:t.btnSave,children:e?e("REFERRALS.SAVE"):"Save"})]})]})]})}export{ia 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.