index.jsx 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320
  1. import styles from './styles.module.scss';
  2. import {useDispatch, useSelector} from "react-redux";
  3. import {ReactComponent as EmptyAvatar} from '@assets/avatar_empty.svg';
  4. import {getLogoutStatus, getUserInfo, isLogined} from "@features/mainSlice";
  5. import Spring from "@components/Spring";
  6. import {useNavigate} from "react-router-dom";
  7. import {ROUTE_PATH} from "@constants/routes";
  8. import LazyImage from "@components/LazyImage";
  9. import USD from "@assets/lvicon/USD.black.png";
  10. import {numFormatter} from "@utils/helpers";
  11. import SvgIcon from "@components/SvgIcon";
  12. import {ReactComponent as Male} from '@assets/singlesvg/gener/male.svg';
  13. import {ReactComponent as FeMale} from '@assets/singlesvg/gener/female.svg';
  14. import {ReactComponent as GenderIcon} from '@assets/singlesvg/gener/gender.svg';
  15. import {ReactComponent as MobileIcon} from '@assets/singlesvg/mobile.svg';
  16. import {ReactComponent as EmailIcon} from '@assets/singlesvg/email.svg';
  17. import {CopyToClipboard} from 'react-copy-to-clipboard';
  18. import {toast} from "react-toastify";
  19. import ToggleButtonGroup from "@mui/material/ToggleButtonGroup";
  20. import {StyledThemeTabs} from "@layout/Sidebar/styles";
  21. import {useThemeProvider} from "@contexts/themeContext";
  22. import ToggleButton from "@mui/material/ToggleButton";
  23. import {reqChangeInfo, reqLogout} from "@features/api";
  24. import {REQ_STATUS} from "@api/config";
  25. import SmallLoading from "@components/SmallLoading";
  26. import {APP_GENDER, APP_THEME} from "@constants/app";
  27. const i18n=global.i18n;
  28. const UserSettings=()=>{
  29. const isLogin=useSelector(isLogined);
  30. const user=useSelector(getUserInfo);
  31. const logoutStatus=useSelector(getLogoutStatus);
  32. const dispatch = useDispatch();
  33. const navigate=useNavigate();
  34. const {theme, toggleTheme,setIsShowLang} = useThemeProvider();
  35. const renderEmpty=()=>{
  36. return (
  37. <div className={styles.wrap_item}>
  38. <div className={styles.user_info}>
  39. <EmptyAvatar className={styles.avatar_empty}/>
  40. <div className={styles.empty_info}>
  41. <span className={styles.welcome}>
  42. {i18n.t("settings.user_info.welcome")}
  43. </span>
  44. <span className={styles.login_tips}>
  45. {i18n.t("settings.user_info.tips")}
  46. </span>
  47. </div>
  48. </div>
  49. <div className={styles.login_con}>
  50. <button className={`button-gray ${styles.button}`} onClick={()=>{
  51. navigate(ROUTE_PATH.SIGN_IN);
  52. }}>
  53. {i18n.t("sign_in")}
  54. </button>
  55. <button className={`button-green ${styles.button}`} onClick={()=>{
  56. navigate(ROUTE_PATH.SIGN_UP);
  57. }}>
  58. {i18n.t("sign_up")}
  59. </button>
  60. </div>
  61. </div>
  62. )
  63. }
  64. const getPhone=()=>{
  65. let loc=user.RegisterLocation;
  66. let phone=user.Phone;
  67. if (phone.startsWith(loc)){
  68. phone=phone.replace(loc,"");
  69. }
  70. return phone;
  71. }
  72. const getEmail=()=>{
  73. let email=user.Email;
  74. if (email==null||email==""){
  75. return "--";
  76. }
  77. return email;
  78. }
  79. const renderPhone=()=>{
  80. return (
  81. <div className={styles.action_item}>
  82. <div className={styles.action_left}>
  83. <MobileIcon className={styles.icon}></MobileIcon>
  84. <div>{i18n.t("settings.phone")}</div>
  85. </div>
  86. <div className={styles.action_right}>
  87. <div>{"+"+user.RegisterLocation}</div>
  88. <div>{getPhone()}</div>
  89. </div>
  90. </div>
  91. )
  92. }
  93. const renderEmail=()=>{
  94. return (
  95. <div className={styles.action_item}>
  96. <div className={styles.action_left}>
  97. <EmailIcon className={styles.icon}></EmailIcon>
  98. <div>{i18n.t("settings.email")}</div>
  99. </div>
  100. <div className={styles.action_right}>
  101. <div>{getEmail()}</div>
  102. </div>
  103. </div>
  104. )
  105. }
  106. const renderUser=()=>{
  107. let gender=(<></>);
  108. if (user.Gender===APP_GENDER.FEMALE){
  109. gender=(<FeMale className={styles.female}/>);
  110. }
  111. else if (user.Gender===APP_GENDER.MALE){
  112. gender=(<Male className={styles.male}/>);
  113. }
  114. return (
  115. <div className={styles.wrap_item}>
  116. <div className={styles.user_con}>
  117. <div className={styles.user_info}>
  118. <LazyImage wrapperClassName={styles.avatar} src={user.img} alt={"avatar"}></LazyImage>
  119. <div className={`${styles.user_info} ${styles.info}`}>
  120. <div className={styles.info_item}>
  121. <div className={styles.name}>{user.NickName}</div>
  122. {gender}
  123. </div>
  124. <CopyToClipboard text={user.UserID} onCopy={()=>{
  125. toast.success(i18n.t("copy_success"));
  126. }}>
  127. <div className={styles.info_item}>
  128. <div className={styles.text}>{i18n.t("settings.user_info.id")}</div>
  129. <div className={styles.text}>{user.UserID}</div>
  130. <button>
  131. <SvgIcon className={styles.icon_copy} herf={"icon_Copy"}/>
  132. </button>
  133. </div>
  134. </CopyToClipboard>
  135. <div className={styles.info_item}>
  136. <img className={styles.icon_golds} src={USD}/>
  137. <div className={styles.golds}>{global.DOLLAR+""+numFormatter(user.Score)}</div>
  138. </div>
  139. </div>
  140. </div>
  141. <div className={styles.user_edit_con}>
  142. <button className={styles.edit_btn} onClick={()=>{
  143. navigate(ROUTE_PATH.EDIT_PROFILE);
  144. }}>
  145. <SvgIcon className={styles.icon} herf={"icon_Edit"}/>
  146. </button>
  147. </div>
  148. </div>
  149. {/*<div className={styles.card_line}></div>*/}
  150. {/*{renderPhone()}*/}
  151. {/*{renderEmail()}*/}
  152. </div>
  153. )
  154. }
  155. const renderUserInfo=()=>{
  156. return (
  157. <>
  158. {
  159. isLogin?renderUser():renderEmpty()
  160. }
  161. </>
  162. )
  163. }
  164. const renderItemSecurity=()=>{
  165. return (
  166. <>
  167. {
  168. isLogin?(
  169. <button className={styles.action_item} onClick={()=>{
  170. navigate(ROUTE_PATH.EDIT_PWD);
  171. }}>
  172. <div className={styles.action_left}>
  173. <SvgIcon className={styles.icon} herf={"icon_Locked"}></SvgIcon>
  174. <div>{i18n.t("settings.security")}</div>
  175. </div>
  176. <div className={styles.action_right}>
  177. <SvgIcon className={styles.icon} herf={"icon_Arrow"}></SvgIcon>
  178. </div>
  179. </button>
  180. ):(<></>)
  181. }
  182. </>
  183. )
  184. }
  185. const renderItemLang=()=>{
  186. return (
  187. <button className={styles.action_item} onClick={()=>{
  188. setIsShowLang(true);
  189. }}>
  190. <div className={styles.action_left}>
  191. <SvgIcon className={styles.icon} herf={"icon_Language"}></SvgIcon>
  192. <div>{i18n.t("settings.language")}</div>
  193. </div>
  194. <div className={styles.action_right}>
  195. <div>{i18n.getCurrLangName()}</div>
  196. <SvgIcon className={styles.icon} herf={"icon_Arrow"}></SvgIcon>
  197. </div>
  198. </button>
  199. )
  200. }
  201. const handleTheme=(theme)=>{
  202. toggleTheme();
  203. // "DefaultLanguage": "en",
  204. // "ThemeColor": "dark"
  205. if (!isLogin)return;
  206. dispatch(reqChangeInfo({
  207. ThemeColor:theme
  208. }));
  209. }
  210. const renderItemTheme=()=>{
  211. return (
  212. <button className={styles.action_item}>
  213. <div className={styles.action_left}>
  214. <SvgIcon className={styles.icon} herf={"icon_Exchange"}></SvgIcon>
  215. <div>{i18n.t("settings.theme")}</div>
  216. </div>
  217. <div className={styles.action_right}>
  218. <div className={styles.theme_con}>
  219. <ToggleButtonGroup sx={{
  220. display:"flex",
  221. position: "relative",
  222. width:"100%",
  223. height:"100%",
  224. alignItems:"center",
  225. justifyContent:"space-between"
  226. }} exclusive value={theme} onChange={(event, value)=>{
  227. handleTheme(value);
  228. }}>
  229. <div className={styles.theme_bg} style={{left: `${theme === APP_THEME.DARK ? '0%' : '50%'}`}}/>
  230. <ToggleButton sx={{
  231. display:"flex",
  232. position: "relative",
  233. width:"100%",
  234. height:"100%",
  235. alignItems:"center",
  236. justifyContent:"center",
  237. border:"none",
  238. backgroundColor:'transparent !important;',
  239. ".Mui-selected:hover":{
  240. backgroundColor: 'transparent !important;',
  241. }
  242. }} value={APP_THEME.DARK}>
  243. <SvgIcon className={`${styles.theme_icon} ${theme===APP_THEME.DARK?styles.active:''}`} herf={"icon_Dark"}/>
  244. </ToggleButton>
  245. <ToggleButton sx={{
  246. display:"flex",
  247. position: "relative",
  248. width:"100%",
  249. height:"100%",
  250. alignItems:"center",
  251. justifyContent:"center",
  252. border:"none",
  253. backgroundColor:'transparent !important;',
  254. ".Mui-selected:hover":{
  255. backgroundColor: 'transparent !important;',
  256. }
  257. }} value={"light"}>
  258. <SvgIcon className={`${styles.theme_icon} ${theme===APP_THEME.LIGHT?styles.active:''}`} herf={"icon_Light"}/>
  259. </ToggleButton>
  260. </ToggleButtonGroup>
  261. </div>
  262. </div>
  263. </button>
  264. )
  265. }
  266. const renderItemGender=()=>{
  267. return (
  268. <div className={styles.action_item}>
  269. <div className={styles.action_left}>
  270. <GenderIcon className={styles.icon}></GenderIcon>
  271. <div>{i18n.t("settings.gender")}</div>
  272. </div>
  273. <div className={styles.action_right}>
  274. {
  275. user.Gender===APP_GENDER.FEMALE?(<FeMale className={styles.gender}></FeMale>):(<Male className={styles.gender}></Male>)
  276. }
  277. <SvgIcon className={styles.icon} herf={"icon_Arrow"}></SvgIcon>
  278. </div>
  279. </div>
  280. )
  281. }
  282. const renderSetting=()=>{
  283. return (
  284. <div className={`${styles.wrap_item} ${styles.action_wrap}`}>
  285. {renderItemSecurity()}
  286. {renderItemLang()}
  287. {/*{renderItemGender()}*/}
  288. {renderItemTheme()}
  289. </div>
  290. )
  291. }
  292. const renderLogout=()=>{
  293. return (
  294. <>
  295. {
  296. isLogin?(
  297. <button className={`button-gray ${styles.logout}`} onClick={()=>{
  298. if (logoutStatus===REQ_STATUS.LOADING)return;
  299. dispatch(reqLogout());
  300. }}>
  301. {
  302. logoutStatus===REQ_STATUS.LOADING?(<SmallLoading fill={"#fff"} />):(<>{i18n.t("links.log_out")}</>)
  303. }
  304. </button>
  305. ):(<></>)
  306. }
  307. </>
  308. )
  309. }
  310. return (
  311. <div className={styles.container}>
  312. <Spring type="slideUp" className={styles.content}>
  313. {renderUserInfo()}
  314. {renderSetting()}
  315. {renderLogout()}
  316. </Spring>
  317. </div>
  318. )
  319. }
  320. export default UserSettings;