PageSourceSearch

https://royaltrust.jp/assets/Chat-C7eqdDLj.js

js royaltrust.jp collected 2026-10-04 01:52:57 UTC 14,057 bytes, 1 lines download raw bytes

1import{r as i,j as t}from"./vendor-react-Cx3Bz6gM.js";import{j as B,h,q as _,K as N,L as oe,E as W,w as ge,T as me,x as E,t as k,M as ye,N as be,O as je,v as re,P as Se,Q as ve}from"./vendor-firebase-CGQGHW05.js";import{u as we,d as p,a as ke,c as Re,s as Ce}from"./main-BR99q4qQ.js";function ne(r,d){return[r,d].sort().join("_")}function ae(r){return(r||"").replace(/[^a-zA-Z0-9\u3000-\u9FFF\uF900-\uFAFF]/g,"_").substring(0,50)}function ze(r){if(!r)return"";const d=r.toDate?r.toDate():new Date(r),x=new Date;return d.getFullYear()===x.getFullYear()&&d.getMonth()===x.getMonth()&&d.getDate()===x.getDate()?d.toLocaleTimeString("ja-JP",{hour:"2-digit",minute:"2-digit"}):`${d.getMonth()+1}/${d.getDate()} `+d.toLocaleTimeString("ja-JP",{hour:"2-digit",minute:"2-digit"})}function Ae(){const{user:r,profile:d}=we(),[x,I]=i.useState([]),[l,se]=i.useState("general"),[ie,le]=i.useState("全体チャット"),[j,U]=i.useState([]),[m,$]=i.useState(""),[L,q]=i.useState(!1),[y,R]=i.useState({}),[de,ce]=i.useState({}),[c,O]=i.useState(null),[P,C]=i.useState(null),[z,H]=i.useState(!1),K=i.useRef(null),J=i.useRef(null),S=i.useRef(null),[D,pe]=i.useState([]),[M,fe]=i.useState([]);i.useEffect(()=>{(async()=>{try{const[e,o]=await Promise.all([B(h(p,"users")),B(h(p,"allowedEmails"))]);I(e.docs.map(n=>({uid:n.id,...n.data()})).filter(n=>n.uid!==(r==null?void 0:r.uid)));const a=o.docs.map(n=>({id:n.id,...n.data()}));pe(a.filter(n=>n.role==="dealer"&&n.dealerCode)),fe(a.filter(n=>n.role==="salon"&&n.companyName))}catch(e){console.error("ユーザー一覧の取得に失敗:",e)}})()},[r]),i.useEffect(()=>{if(!l)return;const e=_(h(p,"chatRooms",l,"messages"),oe("createdAt","asc"),N(200)),o=W(e,a=>{U(a.docs.map(n=>({id:n.id,...n.data()}))),setTimeout(()=>{var n;(n=K.current)==null||n.scrollIntoView({behavior:"smooth"})},100),r!=null&&r.uid&&T(l,r.uid)});return()=>o()},[l,r]),i.useEffect(()=>{if(!l)return;const e=W(h(p,"chatRooms",l,"readers"),o=>{const a={};o.forEach(n=>{var f,u;const s=n.data();a[n.id]=((u=(f=s.lastRead)==null?void 0:f.toMillis)==null?void 0:u.call(f))||0}),ce(a)});return()=>e()},[l]),i.useEffect(()=>{if(!(r!=null&&r.uid))return;const e=D.map(s=>`dealer_${s.dealerCode}`),o=M.map(s=>`salon_${ae(s.companyName)}_hq`),n=["general","warehouse_chat",...e,...o,...x.map(s=>ne(r.uid,s.uid))].map(s=>{const f=_(h(p,"chatRooms",s,"messages"),oe("createdAt","desc"),N(1));return W(f,async u=>{var g,X,w,ee;if(u.empty)return;const v=((X=(g=u.docs[0].data().createdAt)==null?void 0:g.toMillis)==null?void 0:X.call(g))||0;try{const A=await B(_(h(p,"chatRooms",s,"readers"),ge("uid","==",r.uid),N(1))).catch(()=>null);let te=0;A&&!A.empty&&(te=((ee=(w=A.docs[0].data().lastRead)==null?void 0:w.toMillis)==null?void 0:ee.call(w))||0),v>te&&s!==l?R(F=>({...F,[s]:!0})):R(F=>({...F,[s]:!1}))}catch{}})});return()=>n.forEach(s=>s())},[r,x,l]);async function T(e,o){try{const a=me.now();await E(k(p,"chatRooms",e),{[`_read_${o}`]:a},{merge:!0});const n=k(p,"chatRooms",e,"readers",o);await E(n,{uid:o,lastRead:a},{merge:!0}),R(s=>({...s,[e]:!1}))}catch(a){console.error("既読更新エラー:",a)}}i.useEffect(()=>{!l||!(r!=null&&r.uid)||j.length===0||T(l,r.uid)},[j.length]);const xe=e=>{var a;const o=(a=e.target.files)==null?void 0:a[0];if(o){if(o.size>10*1024*1024){alert("ファイルサイズは10MB以下にしてください"),e.target.value="";return}if(O(o),o.type.startsWith("image/")){const n=new FileReader;n.onload=s=>C(s.target.result),n.readAsDataURL(o)}else C(null)}},Y=()=>{O(null),C(null),S.current&&(S.current.value="")},Z=e=>e<1024?e+"B":e<1024*1024?(e/1024).toFixed(1)+"KB":(e/(1024*1024)).toFixed(1)+"MB",Q=async()=>{var o;const e=m.trim();if(!(!e&&!c)&&!L){try{ke(Re,d,{userMessage:"チャット送信権限がありません。ログインし直してください。"})}catch(a){alert(a.message);return}q(!0),H(!!c);try{let a=null;if(c){const f=Date.now(),u=c.name.replace(/[^a-zA-Z0-9._\-\u3000-\u9FFF]/g,"_"),G=`chat/${l}/${f}_${u}`,v=ye(Ce,G);await be(v,c);const g=await je(v);a={fileName:c.name,fileUrl:g,fileType:c.type,fileSize:c.size}}const n={text:e,uid:r.uid,name:(d==null?void 0:d.name)||r.email,createdAt:re(),...a||{}};await Se(h(p,"chatRooms",l,"messages"),n);const s=e||(a?`📎 ${a.fileName}`:"");await E(k(p,"chatRooms",l),{lastMessage:s,lastMessageAt:re(),lastMessageBy:(d==null?void 0:d.name)||r.email},{merge:!0}),$(""),Y(),(o=J.current)==null||o.focus()}catch(a){console.error(a),alert("送信に失敗しました")}finally{q(!1),H(!1)}}},b=(e,o)=>{se(e),le(o),U([]),r!=null&&r.uid&&T(e,r.uid)},V=e=>e.uid===(r==null?void 0:r.uid),ue=async e=>{if(window.confirm("このメッセージを取り消しますか?"))try{await ve(k(p,"chatRooms",l,"messages",e))}catch(o){console.error(o),alert("取り消しに失敗しました")}},he=e=>{var a,n;if(!V(e))return!1;const o=((n=(a=e.createdAt)==null?void 0:a.toMillis)==null?void 0:n.call(a))||0;return o?Object.entries(de).some(([s,f])=>s!==(r==null?void 0:r.uid)&&f>=o):!1};return t.jsxs("div",{style:{display:"flex",height:"calc(100vh - 64px)",gap:0},children:[t.jsxs("div",{style:{width:"240px",borderRight:"1px solid #e5e7eb",backgroundColor:"#fff",display:"flex",flexDirection:"column",flexShrink:0},children:[t.jsx("div",{style:{padding:"16px",borderBottom:"1px solid #e5e7eb",fontSize:"14px",fontWeight:"bold",color:"#111"},children:"チャット"}),t.jsxs("div",{style:{flex:1,overflow:"auto"},children:[t.jsxs("div",{onClick:()=>b("general","全体チャット"),style:{padding:"12px 16px",cursor:"pointer",backgroundColor:l==="general"?"#eef2ff":"transparent",borderBottom:"1px solid #f3f4f6",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:"600",color:"#111"},children:"📢 全体チャット"}),t.jsx("div",{style:{fontSize:"11px",color:"#888",marginTop:"2px"},children:"全スタッフ共通"})]}),y.general&&t.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",flexShrink:0}})]}),t.jsxs("div",{onClick:()=>b("warehouse_chat","📦 倉庫連絡"),style:{padding:"12px 16px",cursor:"pointer",backgroundColor:l==="warehouse_chat"?"#eef2ff":"transparent",borderBottom:"1px solid #f3f4f6",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsxs("div",{children:[t.jsx("div",{style:{fontSize:"13px",fontWeight:"600",color:"#111"},children:"📦 倉庫連絡"}),t.jsx("div",{style:{fontSize:"11px",color:"#888",marginTop:"2px"},children:"OHC倉庫との業務連絡"})]}),y.warehouse_chat&&t.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",flexShrink:0}})]}),D.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"10px 16px 6px",fontSize:"11px",fontWeight:"600",color:"#888",textTransform:"uppercase"},children:"代理店チャット"}),D.map(e=>{const o=`dealer_${e.dealerCode}`;return t.jsxs("div",{onClick:()=>b(o,e.companyName||e.dealerCode),style:{padding:"10px 16px",cursor:"pointer",backgroundColor:l===o?"#eef2ff":"transparent",borderBottom:"1px solid #f9fafb",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("div",{style:{fontSize:"13px",color:"#333"},children:e.companyName||e.dealerCode}),y[o]&&t.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",flexShrink:0}})]},e.id)})]}),M.length>0&&t.jsxs(t.Fragment,{children:[t.jsx("div",{style:{padding:"10px 16px 6px",fontSize:"11px",fontWeight:"600",color:"#888",textTransform:"uppercase"},children:"サロンチャット"}),M.map(e=>{const o=`salon_${ae(e.companyName)}_hq`;return t.jsxs("div",{onClick:()=>b(o,e.companyName||e.salonName),style:{padding:"10px 16px",cursor:"pointer",backgroundColor:l===o?"#eef2ff":"transparent",borderBottom:"1px solid #f9fafb",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("div",{style:{fontSize:"13px",color:"#333"},children:e.companyName||e.salonName}),y[o]&&t.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",flexShrink:0}})]},e.id)})]}),t.jsx("div",{style:{padding:"10px 16px 6px",fontSize:"11px",fontWeight:"600",color:"#888",textTransform:"uppercase"},children:"ダイレクトメッセージ"}),x.map(e=>
1{const o=ne(r.uid,e.uid);return t.jsxs("div",{onClick:()=>b(o,e.name||e.email),style:{padding:"10px 16px",cursor:"pointer",backgroundColor:l===o?"#eef2ff":"transparent",borderBottom:"1px solid #f9fafb",display:"flex",alignItems:"center",justifyContent:"space-between"},children:[t.jsx("div",{style:{fontSize:"13px",color:"#333"},children:e.name||e.email}),y[o]&&t.jsx("div",{style:{width:"10px",height:"10px",borderRadius:"50%",backgroundColor:"#ef4444",flexShrink:0}})]},e.uid)})]})]}),t.jsxs("div",{style:{flex:1,display:"flex",flexDirection:"column",backgroundColor:"#f9fafb"},children:[t.jsx("div",{style:{padding:"14px 20px",borderBottom:"1px solid #e5e7eb",backgroundColor:"#fff",fontSize:"15px",fontWeight:"bold",color:"#111"},children:ie}),t.jsxs("div",{style:{flex:1,overflow:"auto",padding:"16px 20px"},children:[j.length===0?t.jsx("div",{style:{textAlign:"center",color:"#aaa",marginTop:"80px",fontSize:"13px"},children:"まだメッセージがありません"}):j.map(e=>{var n,s;const o=V(e),a=(e.name||"?")[0];return t.jsxs("div",{style:{marginBottom:"14px",display:"flex",flexDirection:o?"row-reverse":"row",alignItems:"flex-start",gap:"8px"},children:[t.jsx("div",{style:{width:"34px",height:"34px",borderRadius:"50%",backgroundColor:o?"#4f46e5":"#e5e7eb",color:o?"#fff":"#555",display:"flex",alignItems:"center",justifyContent:"center",fontSize:"13px",fontWeight:"bold",flexShrink:0},children:a}),t.jsxs("div",{style:{maxWidth:"65%",display:"flex",flexDirection:"column",alignItems:o?"flex-end":"flex-start"},children:[t.jsx("div",{style:{fontSize:"11px",color:o?"#6366f1":"#888",marginBottom:"3px"},children:e.name}),t.jsxs("div",{style:{display:"flex",flexDirection:o?"row-reverse":"row",alignItems:"center",gap:"6px"},children:[t.jsxs("div",{style:{padding:"10px 14px",borderRadius:o?"16px 16px 4px 16px":"16px 16px 16px 4px",backgroundColor:o?"#4f46e5":"#fff",color:o?"#fff":"#111",fontSize:"14px",lineHeight:"1.5",boxShadow:"0 1px 3px rgba(0,0,0,0.06)",whiteSpace:"pre-wrap",wordBreak:"break-word"},children:[e.fileUrl&&((n=e.fileType)==null?void 0:n.startsWith("image/"))&&t.jsx("a",{href:e.fileUrl,target:"_blank",rel:"noopener noreferrer",style:{display:"block",marginBottom:e.text?"8px":0},children:t.jsx("img",{src:e.fileUrl,alt:e.fileName,style:{maxWidth:"240px",maxHeight:"200px",borderRadius:"8px",cursor:"pointer"}})}),e.fileUrl&&!((s=e.fileType)!=null&&s.startsWith("image/"))&&t.jsxs("a",{href:e.fileUrl,target:"_blank",rel:"noopener noreferrer",style:{display:"flex",alignItems:"center",gap:"8px",padding:"8px 12px",borderRadius:"8px",backgroundColor:o?"rgba(255,255,255,0.15)":"#f3f4f6",textDecoration:"none",color:o?"#fff":"#4f46e5",marginBottom:e.text?"8px":0,fontSize:"13px"},children:[t.jsx("span",{children:"📎"}),t.jsx("span",{style:{flex:1,overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:e.fileName||"ファイル"}),e.fileSize&&t.jsx("span",{style:{fontSize:"11px",opacity:.7,flexShrink:0},children:Z(e.fileSize)})]}),e.text]}),o&&t.jsx("button",{onClick:()=>ue(e.id),style:{background:"#fee2e2",border:"1px solid #fca5a5",color:"#dc2626",cursor:"pointer",fontSize:"11px",fontWeight:"bold",padding:"4px 8px",borderRadius:"6px",lineHeight:1,flexShrink:0,whiteSpace:"nowrap"},children:"取消"})]}),t.jsxs("div",{style:{fontSize:"10px",color:"#bbb",marginTop:"3px",display:"flex",alignItems:"center",gap:"6px"},children:[o&&he(e)&&t.jsx("span",{style:{color:"#4f46e5",fontWeight:"600"},children:"既読"}),ze(e.createdAt)]})]})]},e.id)}),t.jsx("div",{ref:K})]}),c&&t.jsx("div",{style:{padding:"8px 20px 0",backgroundColor:"#fff",borderTop:"1px solid #e5e7eb"},children:t.jsxs("div",{style:{display:"inline-flex",alignItems:"center",gap:"8px",padding:"6px 12px",borderRadius:"8px",backgroundColor:"#f3f4f6",fontSize:"13px",color:"#333"},children:[P?t.jsx("img",{src:P,alt:"",style:{width:"40px",height:"40px",objectFit:"cover",borderRadius:"6px"}}):t.jsx("span",{children:"📎"}),t.jsx("span",{style:{maxWidth:"200px",overflow:"hidden",textOverflow:"ellipsis",whiteSpace:"nowrap"},children:c.name}),t.jsx("span",{style:{fontSize:"11px",color:"#888"},children:Z(c.size)}),t.jsx("button",{onClick:Y,style:{background:"none",border:"none",cursor:"pointer",fontSize:"16px",color:"#999",padding:"0 2px",lineHeight:1},children:"×"})]})}),t.jsxs("div",{style:{padding:"12px 20px",borderTop:c?"none":"1px solid #e5e7eb",backgroundColor:"#fff",display:"flex",gap:"10px",alignItems:"center"},children:[t.jsx("input",{ref:S,type:"file",onChange:xe,className:"hidden",style:{display:"none"},accept:"image/*,.pdf,.doc,.docx,.xls,.xlsx,.csv,.txt,.zip"}),t.jsx("button",{onClick:()=>{var e;return(e=S.current)==null?void 0:e.click()},title:"ファイルを添付",style:{background:"none",border:"1px solid #d1d5db",borderRadius:"10px",padding:"9px 12px",cursor:"pointer",fontSize:"16px",color:"#6b7280",display:"flex",alignItems:"center",flexShrink:0,transition:"background-color 0.2s"},onMouseEnter:e=>e.target.style.backgroundColor="#f3f4f6",onMouseLeave:e=>e.target.style.backgroundColor="transparent",children:"📎"}),t.jsx("input",{ref:J,type:"text",value:m,onChange:e=>$(e.target.value),onKeyDown:e=>{e.key==="Enter"&&!e.shiftKey&&(e.preventDefault(),Q())},placeholder:z?"アップロード中...":"メッセージを入力...",disabled:z,style:{flex:1,padding:"10px 14px",borderRadius:"10px",border:"1px solid #d1d5db",fontSize:"14px",outline:"none"}}),t.jsx("button",{onClick:Q,disabled:!m.trim()&&!c||L,style:{padding:"10px 20px",borderRadius:"10px",border:"none",backgroundColor:m.trim()||c?"#4f46e5":"#d1d5db",color:"#fff",fontSize:"14px",fontWeight:"bold",cursor:m.trim()||c?"pointer":"default",transition:"background-color 0.2s"},children:z?"送信中...":"送信"})]})]})]})}export{Ae 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.