Files
Rasadyar_FrontEnd/build/assets/ProvinceSendMessage-CZGfVdJQ.js
2026-01-19 15:40:45 +03:30

113 lines
10 KiB
JavaScript

import{cj as M,j as u,s as f,T as k,ck as N,bs as h,$ as W,ak as b,ag as S,av as z,aw as _,ax as G,b as w,ar as T,bj as O,am as I,B as L}from"./mui-vendor-CkIVaoQP.js";import{j as R,G as n,u as V,c as U,M as j,A as H,S as c,L as q,h as K,hV as J,b4 as Q,N as X}from"./index-CeyyVc1v.js";import{r as o}from"./react-vendor-CmFgShSM.js";import{a as Y,f as B,u as D}from"./redux-vendor-B7uoacJt.js";import{I as Z,f as uu}from"./toBase64-BzgTOHsW.js";import{d as eu}from"./Check-CRb6laYC.js";import{d as ru}from"./Close-_jAEIgMD.js";import{M as tu}from"./MessagesSenders-Y1Gaf5ab.js";import"./PublishedWithChanges-C8kvr_m4.js";import"./Delete-C5MyLelE.js";const au=Y("PROVINCE_SEND_MESSAGE",async r=>{const{data:t,status:s}=await R.post("user_message/",r);return{data:t,status:s}}),su=f("div")(({theme:r})=>`
color: ${r.palette.mode==="dark"?"rgba(255,255,255,0.65)":"rgba(0,0,0,.85)"};
font-size: 14px;
`),nu=f("label")`
padding: 0 0 4px;
line-height: 1.5;
display: block;
`,lu=f("div")(({theme:r})=>`
width: 300px;
border: 1px solid ${r.palette.mode==="dark"?"#434343":"#d9d9d9"};
background-color: ${r.palette.mode==="dark"?"#141414":"#fff"};
border-radius: 4px;
padding: 1px;
display: flex;
flex-wrap: wrap;
&:hover {
border-color: ${r.palette.mode==="dark"?"#177ddc":"#40a9ff"};
}
&.focused {
border-color: ${r.palette.mode==="dark"?"#177ddc":"#40a9ff"};
box-shadow: 0 0 0 2px rgba(24, 144, 255, 0.2);
}
& input {
background-color: ${r.palette.mode==="dark"?"#141414":"#fff"};
color: ${r.palette.mode==="dark"?"rgba(255,255,255,0.65)":"rgba(0,0,0,.85)"};
height: 30px;
box-sizing: border-box;
padding: 4px 6px;
width: 0;
min-width: 30px;
flex-grow: 1;
border: 0;
margin: 0;
outline: 0;
}
`);function $(r){const{label:t,onDelete:s,...e}=r;return u.jsxs("div",{...e,children:[u.jsx("span",{children:t}),u.jsx(ru,{onClick:s})]})}$.propTypes={label:h.string.isRequired,onDelete:h.func.isRequired};const iu=f($)(({theme:r})=>`
display: flex;
align-items: center;
height: 24px;
margin: 2px;
line-height: 22px;
background-color: ${r.palette.mode==="dark"?"rgba(255,255,255,0.08)":"#fafafa"};
border: 1px solid ${r.palette.mode==="dark"?"#303030":"#e8e8e8"};
border-radius: 2px;
box-sizing: content-box;
padding: 0 4px 0 10px;
outline: 0;
overflow: hidden;
&:focus {
border-color: ${r.palette.mode==="dark"?"#177ddc":"#40a9ff"};
background-color: ${r.palette.mode==="dark"?"#003b57":"#e6f7ff"};
}
& span {
overflow: hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
& svg {
font-size: 12px;
cursor: pointer;
padding: 4px;
}
`),ou=f("ul")(({theme:r})=>`
width: 300px;
margin: 2px 0 0;
padding: 0;
position: absolute;
list-style: none;
background-color: ${r.palette.mode==="dark"?"#141414":"#fff"};
overflow: auto;
max-height: 250px;
border-radius: 4px;
box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
z-index: 1;
& li {
padding: 5px 12px;
display: flex;
& span {
flex-grow: 1;
}
& svg {
color: transparent;
}
}
& li[aria-selected='true'] {
background-color: ${r.palette.mode==="dark"?"#2b2b2b":"#fafafa"};
font-weight: 600;
& svg {
color: #1890ff;
}
}
& li.${N.focused} {
background-color: ${r.palette.mode==="dark"?"#003b57":"#e6f7ff"};
cursor: pointer;
& svg {
color: currentColor;
}
}
`);function P({title:r,options:t,defualtValueIndex:s,onChange:e}){const{getInputLabelProps:A,getInputProps:p,getTagProps:v,getListboxProps:x,getOptionProps:g,groupedOptions:m,value:C,focused:y,setAnchorEl:E}=M({id:"customized-hook-demo",multiple:!0,options:t,getOptionLabel:l=>l.title});return o.useEffect(()=>{e(C)},[C]),u.jsx(n,{children:u.jsxs(su,{children:[u.jsx(nu,{...A(),children:u.jsx(k,{varinat:"body1",children:r})}),u.jsxs(lu,{style:{width:"275px",minHeight:"56px"},ref:E,className:y?"focused":"",children:[C.map((l,d)=>u.jsx(k,{variant:"body2",children:u.jsx(iu,{label:l==null?void 0:l.title,...v({index:d})})},l.id+d)),u.jsx("input",{...p()})]}),m.length>0?u.jsx(ou,{style:{position:"inherit",width:"275px"},...x(),children:m.map((l,d)=>u.jsx("li",{...g({option:l,index:d}),children:u.jsxs(n,{container:!0,children:[u.jsx(k,{variant:"body2",children:l.title}),u.jsx(eu,{fontSize:"small"})]})},l.id+d))}):null]})})}P.propTypes={title:h.string,defualtValueIndex:h.any,options:h.any,onChange:h.any};function du(r){let t;switch(r){case"شهرستان":t="CityOperator";break;case"مرغدار":t="Poultry";break;case"دامپزشک":t="VetFarm";break;case"راننده":t="Driver";break;case"کشتارگاه":t="KillHouse";break;case"پشتیبانی امور دام":t="LiveStockSupport";break;case"مالی":t="ProvinceFinancial";break;case"ادمین کل":t="SuperAdmin";break;case"پخش کننده":t="Dispenser";break}return t}const cu=48,pu=8,hu={PaperProps:{style:{maxHeight:cu*4.5+pu,width:250}}},xu=["شهرستان","دامپزشک","راننده","مرغدار","کشتارگاه","مالی"];function gu(r,t,s){return{fontWeight:t.indexOf(r)===-1?s.typography.fontWeightRegular:s.typography.fontWeightMedium}}const Cu=()=>{const[r,t]=o.useState([]),{provinceUsers:s}=B(a=>a.provinceSlice);o.useEffect(()=>{t(s.map(a=>{const i=a.profile.fullname?a.profile.fullname:`${a.profile.firstName} ${a.profile.lastName}`;return{id:a.profile.key,title:`${i}`}}))},[]);const e=V({initialValues:{description:"",linkText:"",heading:"",link:"",usersList:[]},validationSchema:U({description:j().required("لطفا پیغام خود را بنویسید!").typeError("لطفا فیلد را پر کنید!"),heading:j().required("لطفا عنوان پیغام خود را بنویسید!").typeError("لطفا فیلد را پر کنید!"),link:j().typeError("لطفا فیلد را پر کنید!"),linkText:j().typeError("لطفا فیلد را پر کنید!")})});o.useEffect(()=>{e.validateForm()},[]);const A=W(),[p,v]=o.useState([]),x=D(),[g]=o.useContext(H),[m,C]=o.useState([]),[y,E]=o.useState([]),l=(a,i)=>{E(a.map(F=>uu(F.data_url))),C(a)},d=a=>{const{target:{value:i}}=a;v(typeof i=="string"?i.split(","):i)};return u.jsx(u.Fragment,{children:u.jsx(n,{justifyContent:"center",children:u.jsxs(n,{container:!0,justifyContent:"center",xs:12,sm:12,md:8,lg:8,gap:c.SMALL,direction:"column",children:[u.jsx(n,{children:u.jsx(b,{fullWidth:!0,id:"heading",label:"عنوان",variant:"outlined",value:e.values.heading,error:e.touched.heading?!!e.errors.heading:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.heading&&e.errors.heading?e.errors.heading:null})}),u.jsx(n,{justifyContent:"center",children:u.jsx(b,{fullWidth:!0,id:"description",label:"توضیحات",multiline:!0,rows:5,variant:"outlined",sx:{width:"100%",height:"100%"},value:e.values.description,error:e.touched.description?!!e.errors.description:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.description&&e.errors.description?e.errors.description:null})}),u.jsx(n,{children:u.jsxs(S,{fullWidth:!0,children:[u.jsx(z,{children:"ارسال پیام بر اساس نقش"}),u.jsx(_,{id:"demo-multiple-chip",multiple:!0,value:p,onChange:d,input:u.jsx(O,{label:"ارسال پیام بر اساس نقش",id:"select-multiple-chip"}),renderValue:a=>u.jsx(w,{sx:{display:"flex",flexWrap:"wrap",gap:.5},children:a.map(i=>u.jsx(T,{label:i},i))}),MenuProps:hu,children:xu.map(a=>u.jsx(G,{value:a,label:a,style:gu(a,p,A),children:a},a))})]})}),u.jsx(n,{children:u.jsx(S,{fullWidth:!0,children:u.jsx(n,{children:u.jsx(P,{options:r,title:"انتخاب کاربر",onChange:a=>{const i=a.map(F=>F.id);e.setFieldValue("usersList",i)}})})})}),u.jsx(n,{children:u.jsx(Z,{onChange:l,images:m,maxNumber:5,title:"تصاویر ضمیمه"})}),u.jsx(n,{m:c.SMALL,children:u.jsx(I,{children:u.jsx(T,{label:"پیوند"})})}),u.jsx(n,{children:u.jsx(b,{fullWidth:!0,size:"small",id:"linkText",label:"متن توضیح پیوند",variant:"outlined",value:e.values.linkText,error:e.touched.linkText?!!e.errors.linkText:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.linkText&&e.errors.linkText?e.errors.linkText:null})}),u.jsx(n,{children:u.jsx(b,{fullWidth:!0,size:"small",id:"link",label:"لینک",variant:"outlined",value:e.values.link,error:e.touched.link?!!e.errors.link:null,onChange:e.handleChange,onBlur:e.handleBlur,helperText:e.touched.link&&e.errors.link?e.errors.link:null})}),u.jsx(n,{mb:c.SMALL,children:u.jsx(L,{fullWidth:!0,disabled:!e.isValid,size:"large",variant:"contained",onClick:()=>{p.length?(x(q()),x(au({roles:p.map(a=>du(a)),users:e.values.usersList,heading:e.values.heading,message:e.values.description,link_text:e.values.linkText,link:e.values.link,image:y})).then(a=>{a.error?g({vertical:"top",horizontal:"center",msg:"مشکلی پیش آمده است",severity:"error"}):g({vertical:"top",horizontal:"center",msg:"پیغام با موفقیت فرستاده شد.",severity:"success"})}),x(K())):g({vertical:"top",horizontal:"center",msg:"لطفا کاربر هدف را انتخاب کنید.",severity:"error"})},children:"ارسال پیغام"})})]})})})},Tu=()=>{const r=D(),{senderMessages:t}=B(s=>s.messageSlice);return o.useEffect(()=>{r(J()),r(Q())},[]),u.jsx(u.Fragment,{children:u.jsx(w,{display:"flex",justifyContent:"center",children:u.jsxs(n,{container:!0,direction:"column",justifyContent:"center",xs:12,sm:12,md:10,lg:10,my:c.MEDIUM,children:[u.jsx(n,{container:!0,mt:c.MEDIUM,children:u.jsx(L,{className:"first-step",variant:"contained",onClick:()=>{r(X({title:"ارسال پیام جدید",right:!(window.innerWidth<=600),bottom:window.innerWidth<=600,content:u.jsx(Cu,{})}))},children:"ثبت پیام جدید"})}),u.jsx(I,{children:u.jsx(T,{size:"small",label:"پیام های استان"})}),!(t!=null&&t.length)&&u.jsx(n,{mt:c.SMALL,children:u.jsx(k,{variant:"body1",color:"primary",children:"در حال حاضر پیامی جهت نمایش وجود ندارد!"})}),u.jsx(n,{p:c.SMALL,children:t==null?void 0:t.map((s,e)=>[u.jsx(tu,{number:e,heading:s.heading,message:s.message,link:s.link,linkText:s.linkText,image:s.image,time:s.time},e)])})]})})})};export{Tu as default};