File indexing completed on 2025-01-26 05:27:59
0001 import React , {useEffect, useState, useRef, useContext} from 'react' 0002 import SwitchItem from './function/SwitchItem'; 0003 import {MetaheaderContext} from '../contexts/MetaheaderContext'; 0004 0005 const UserLoginMenuContainer = (props) => { 0006 const {state} = useContext(MetaheaderContext); 0007 const [dropdownClass, setDropdownClass] = useState(''); 0008 const toggleEl = useRef(null); 0009 const [gitlabLink, setGitlabLink] = useState(state.gitlabUrl+"/dashboard/issues?assignee_id="); 0010 0011 useEffect(() => { 0012 document.addEventListener('mousedown',handleClick, false); 0013 return () => { 0014 0015 document.removeEventListener('mousedown',handleClick, false); 0016 }; 0017 },[dropdownClass]) 0018 0019 useEffect(() => { 0020 //componentDidMount 0021 /* 0022 Axios.get(state.gitlabUrl+"/api/v4/users?username="+state.user.username) 0023 .then(result => { 0024 setGitlabLink(gitlabLink+result.data[0].id); 0025 }) 0026 */ 0027 loadData(); 0028 },[]); 0029 0030 const loadData = async () => { 0031 const data = await fetch(`${state.gitlabUrl}/api/v4/users?username=${state.user.username}`); 0032 const items = await data.json(); 0033 setGitlabLink(gitlabLink+items[0].id); 0034 } 0035 0036 const handleClick= e => { 0037 let cls = ""; 0038 if (toggleEl.current.contains(e.target)){ 0039 if (dropdownClass === "open"){ 0040 if (e.target.className === "th-icon" || e.target.className === "btn btn-default dropdown-toggle"){ 0041 cls = ""; 0042 } else { 0043 cls = "open"; 0044 } 0045 } else { 0046 cls = "open"; 0047 } 0048 } 0049 setDropdownClass(cls); 0050 } 0051 0052 let sitethemeSwitchDisplay; 0053 if (state.isAdmin === true){ 0054 sitethemeSwitchDisplay = ( 0055 <li className="user-settings-item"> 0056 <span className="user-settings-item-title">Theme</span> 0057 <SwitchItem 0058 onSwitchStyle={e => props.onSwitchStyle(e)} 0059 onSwitchStyleChecked={props.siteTheme === "content-theme-dark" ? true : false} 0060 /> 0061 <span className="user-settings-item-title">dark</span> 0062 </li> 0063 ) 0064 } 0065 0066 return ( 0067 <li id="user-login-menu-container" ref={toggleEl}> 0068 <div className={"user-dropdown " + dropdownClass}> 0069 <button 0070 className="btn btn-default dropdown-toggle" 0071 type="button" 0072 id="userLoginDropdown"> 0073 <img className="th-icon" src={state.user.avatar}/> 0074 </button> 0075 <ul className="dropdown-menu dropdown-menu-right"> 0076 <li id="user-info-menu-item"> 0077 <div id="user-info-section"> 0078 <div className="user-avatar"> 0079 <div className="no-avatar-user-letter"> 0080 <img src={state.user.avatar}/> 0081 </div> 0082 </div> 0083 <div className="user-details"> 0084 <ul> 0085 <li id="user-details-username"><b>{state.user.username}</b></li> 0086 <li id="user-details-email">{state.user.mail}</li> 0087 </ul> 0088 </div> 0089 </div> 0090 </li> 0091 0092 <li id="user-menu" className="buttons user-info-payout"> 0093 <ul className="payout"> 0094 <li><a href={state.baseUrlStore + "/u/" + state.user.username + "/products"}><div className="icon"></div>Products</a></li> 0095 <li><a href={state.gitlabUrl+"/dashboard/projects"}><div className="icon"></div>Projects</a></li> 0096 <li><a href={gitlabLink}><div className="icon"></div>Issues</a></li> 0097 </ul> 0098 </li> 0099 0100 <li id="user-menu-products" className="buttons user-info-payout"> 0101 <ul className="payout"> 0102 <li><a href={state.baseUrlStore+"/product/add"}><div className="icon iconAdd"></div>Add Product</a></li> 0103 <li><a href={state.baseUrlStore+"/my-favourites"}><div className="icon iconFav"></div>My Favourites</a></li> 0104 </ul> 0105 </li> 0106 0107 <li id="user-info-payout" className="buttons user-info-payout"> 0108 <ul className="payout"> 0109 <li><a href={state.baseUrlStore+'/u/'+state.user.username+'/payout'}><div className="icon"></div>My Payout</a></li> 0110 <li><a href={state.baseUrlStore+'/u/'+state.user.username+'/funding'}><div className="icon"></div>My Funding</a></li> 0111 </ul> 0112 </li> 0113 0114 {sitethemeSwitchDisplay} 0115 <li className="user-settings-item"> 0116 <span className="user-settings-item-title">Metaheader</span> 0117 <SwitchItem 0118 onSwitchStyle={e => props.onSwitchMetaHeaderStyle(e)} 0119 onSwitchStyleChecked={props.metamenuTheme === "metamenu-theme-dark" ? true : false} 0120 /> 0121 <span className="user-settings-item-title">dark</span> 0122 </li> 0123 0124 <li className="buttons"> 0125 <a href={state.baseUrl + "/settings/"} className="btn btn-default btn-metaheader"><span>Settings</span></a> 0126 <a href={state.baseUrl + "/settings/profile"} className="btn btn-default btn-metaheader"><span>Profile</span></a> 0127 <a href={state.logoutUrl} className="btn btn-default pull-right btn-metaheader"><span>Logout</span></a> 0128 </li> 0129 0130 </ul> 0131 </div> 0132 </li> 0133 ) 0134 } 0135 0136 export default UserLoginMenuContainer