WShare.jsx 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. import MuiDrawer from '@mui/material/Drawer';
  2. import styles from "./styles.module.scss";
  3. import {ReactComponent as ShareIcon} from '@assets/singlesvg/share.svg';
  4. import icon_fb from "@assets/share/facebook.png";
  5. import icon_ws from "@assets/share/WhatsApp.png";
  6. import icon_tg from "@assets/share/telegram.png";
  7. import icon_twitter from "@assets/share/Twitter.png";
  8. import icon_email from "@assets/share/email.png";
  9. import icon_svg_ws from "@assets/share/whatsappsvg.svg";
  10. import icon_sms from "@assets/share/sms.png";
  11. import {useSelector} from "react-redux";
  12. import {getNumbers, getShareUrl, getTotalAmount} from "@features/turnplateSlice";
  13. import {formatCash, stringFormat} from "@utils/helpers";
  14. import {CopyToClipboard} from "react-copy-to-clipboard/lib/Component";
  15. import {toast} from "react-toastify";
  16. import {useState} from "react";
  17. const i18n=global.i18n;
  18. const WShare=({open,onClose})=>{
  19. const shareUrl=useSelector(getShareUrl);
  20. const amount=useSelector(getTotalAmount);
  21. const numbers=useSelector(getNumbers);
  22. const shareTitle=stringFormat(i18n.t("turnplate.share_box.share_title"),[global.DOLLAR,formatCash(amount,0)]);
  23. const shareText=stringFormat(i18n.t("turnplate.share_box.share_text"),[global.DOLLAR,formatCash(amount,0)]);
  24. const [waPhoneIndex,setWaPhoneIndex]=useState(-1);
  25. const shareMore=()=>{
  26. try {
  27. navigator.share ? navigator.share({
  28. title: shareTitle,
  29. url: shareUrl,
  30. text: shareText
  31. }) : shareFb()
  32. } catch (t) {
  33. shareFb()
  34. }
  35. }
  36. const shareFb=()=>{
  37. if (global.isIOS){
  38. let url="fb://share/?link="+shareUrl;
  39. window.open(url);
  40. }
  41. else
  42. {
  43. let url="https://www.facebook.com/sharer/sharer.php?u="+shareUrl+"&t=" + encodeURIComponent(shareText);
  44. window.open(url);
  45. }
  46. }
  47. const shareWa=()=>{
  48. let url="whatsapp://send?text=" + encodeURIComponent(shareText) + encodeURIComponent("\n\n" + shareUrl) + "&via=lopscoop";
  49. window.open(url);
  50. }
  51. const shareTG=()=>{
  52. let url="https://t.me/share/url?url=" + encodeURIComponent(shareUrl) + "&text=" + encodeURIComponent(shareText);
  53. window.open(url);
  54. }
  55. const shareTw=()=>{
  56. let url="https://twitter.com/intent/tweet?text" + encodeURIComponent(shareText) + "&url=" + encodeURIComponent(shareUrl);
  57. window.open(url);
  58. }
  59. const shareEmail=()=>{
  60. let url="mailto:?body=" + encodeURIComponent(shareText + " " + shareUrl);
  61. window.open(url);
  62. }
  63. const shareWaMore=()=>{
  64. if (numbers.length>0){
  65. let windex=waPhoneIndex+1;
  66. if (windex>=numbers.length)windex=0;
  67. setWaPhoneIndex(windex);
  68. let phone=numbers[windex];
  69. let url="whatsapp://send?phone=+" + phone + "&text=" + encodeURIComponent("Responda OK,".concat(shareText, ".")) + encodeURIComponent("\n\n" + shareUrl) + "&via=lopscoop";
  70. window.open(url);
  71. }
  72. }
  73. const shareSms=()=>{
  74. let text="";
  75. let smsCode="";
  76. if (global.isIOS){
  77. text="&body="+shareText+" "+shareUrl;
  78. smsCode="/open?addresses="+numbers.join(", ");
  79. }
  80. else
  81. {
  82. text="?body=" + encodeURIComponent(shareText) + " " + encodeURIComponent(shareUrl);
  83. smsCode=numbers.join(", ")+ ";";
  84. }
  85. let url="sms:" + smsCode + text;
  86. window.open(url);
  87. }
  88. const renderIcons=()=>{
  89. return (
  90. <div className={styles.share_icon_con}>
  91. <button className={styles.icon_btn} onClick={shareMore}>
  92. <div className={`${styles.icon} ${styles.more}`}>
  93. <ShareIcon className={styles.s_icon}></ShareIcon>
  94. </div>
  95. <div>{i18n.t("turnplate.share_box.btn_more")}</div>
  96. </button>
  97. <button className={styles.icon_btn} onClick={shareFb}>
  98. <div className={`${styles.icon}`}>
  99. <img src={icon_fb}/>
  100. </div>
  101. <div>{i18n.t("turnplate.share_box.btn_facebook")}</div>
  102. </button>
  103. <button className={styles.icon_btn} onClick={shareWa}>
  104. <div className={`${styles.icon}`}>
  105. <img src={icon_ws}/>
  106. </div>
  107. <div>{i18n.t("turnplate.share_box.btn_whatsapp")}</div>
  108. </button>
  109. <button className={styles.icon_btn} onClick={shareTG}>
  110. <div className={`${styles.icon}`}>
  111. <img src={icon_tg}/>
  112. </div>
  113. <div>{i18n.t("turnplate.share_box.btn_telegram")}</div>
  114. </button>
  115. <button className={styles.icon_btn} onClick={shareTw}>
  116. <div className={`${styles.icon}`}>
  117. <img src={icon_twitter}/>
  118. </div>
  119. <div>{i18n.t("turnplate.share_box.btn_twitter")}</div>
  120. </button>
  121. <button className={styles.icon_btn} onClick={shareEmail}>
  122. <div className={`${styles.icon}`}>
  123. <img src={icon_email}/>
  124. </div>
  125. <div>{i18n.t("turnplate.share_box.btn_email")}</div>
  126. </button>
  127. </div>
  128. )
  129. }
  130. const renderShareUrl=()=>{
  131. return (
  132. <CopyToClipboard text={shareUrl} onCopy={()=>{
  133. toast.success(i18n.t("copy_success"));
  134. }}>
  135. <button className={styles.share_url_con}>
  136. {shareUrl}
  137. <div className={styles.copy}>{i18n.t("turnplate.share_box.btn_copy")}</div>
  138. </button>
  139. </CopyToClipboard>
  140. )
  141. }
  142. const renderRandomPlayers=()=>{
  143. return (
  144. <div className={styles.share_random_con}>
  145. <div className={styles.content}>
  146. {
  147. numbers.map((item,index)=>{
  148. return (
  149. <div key={index} className={`${styles.item} ${index<=waPhoneIndex?styles.active:''}`}>{item}</div>
  150. )
  151. })
  152. }
  153. </div>
  154. <div className={styles.btn_con}>
  155. <button className={styles.btn_send} onClick={shareWaMore}>
  156. <div className={styles.text_con}>
  157. <div>{i18n.t("turnplate.share_box.send_title")}</div>
  158. <div className={styles.text_app}>
  159. <div>{i18n.t("turnplate.share_box.send_on")}</div>
  160. <div className={styles.name}>{i18n.t("turnplate.share_box.btn_whatsapp")}</div>
  161. </div>
  162. </div>
  163. <img className={styles.icon} src={icon_svg_ws}/>
  164. </button>
  165. <button className={styles.btn_send} onClick={shareSms}>
  166. <img className={styles.icon} src={icon_sms}/>
  167. <div className={styles.text_con}>
  168. <div>{i18n.t("turnplate.share_box.send_title")}</div>
  169. <div className={styles.text_app}>
  170. <div className={styles.name}>{i18n.t("turnplate.share_box.btn_sms")}</div>
  171. </div>
  172. </div>
  173. </button>
  174. </div>
  175. </div>
  176. )
  177. }
  178. const renderShare=()=>{
  179. return (
  180. <div className={styles.container}>
  181. <div className={styles.title}>{i18n.t("turnplate.share_box.title_1")}</div>
  182. {renderIcons()}
  183. {renderShareUrl()}
  184. <div className={styles.title}>{i18n.t("turnplate.share_box.title_2")}</div>
  185. {renderRandomPlayers()}
  186. </div>
  187. )
  188. }
  189. return (
  190. <MuiDrawer open={open}
  191. anchor={"bottom"}
  192. sx={{
  193. zIndex:"1400",
  194. "& .MuiDrawer-paper": {
  195. height: "60%",
  196. boxSizing: "border-box",
  197. overflow:'visible !important',
  198. backgroundColor:'var(--standard);',
  199. boxShadow:'var(--widget-shadow);',
  200. borderTopLeftRadius:'1rem',
  201. borderTopRightRadius:'1rem'
  202. },
  203. }}
  204. variant="temporary"
  205. onClose={()=>{
  206. if (onClose)onClose();
  207. }}>
  208. {renderShare()}
  209. </MuiDrawer>
  210. )
  211. }
  212. export default WShare;