signupDialog.js 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. const html = require('choo/html');
  2. const assets = require('../../common/assets');
  3. const { bytes, platform } = require('../utils');
  4. const { canceledSignup, submittedSignup } = require('../metrics');
  5. module.exports = function(trigger) {
  6. return function(state, emit, close) {
  7. const DAYS = Math.floor(state.LIMITS.MAX_EXPIRE_SECONDS / 86400);
  8. const hidden = platform() === 'android' ? 'hidden' : '';
  9. let submitting = false;
  10. return html`
  11. <send-signup-dialog
  12. class="flex flex-col lg:flex-row justify-center px-8 md:px-24 w-full h-full"
  13. >
  14. <img src="${assets.get('master-logo.svg')}" class="h-16 mt-1 mb-4" />
  15. <section
  16. class="flex flex-col flex-shrink-0 self-center lg:mx-6 lg:max-w-xs"
  17. >
  18. <h1 class="text-3xl font-bold text-center lg:text-left">
  19. ${state.translate('accountBenefitTitle')}
  20. </h1>
  21. <ul
  22. class="leading-normal list-disc text-grey-80 my-2 mt-4 pl-4 md:self-center dark:text-grey-40"
  23. >
  24. <li>
  25. ${state.translate('accountBenefitLargeFiles', {
  26. size: bytes(state.LIMITS.MAX_FILE_SIZE)
  27. })}
  28. </li>
  29. <li>${state.translate('accountBenefitDownloadCount')}</li>
  30. <li>
  31. ${state.translate('accountBenefitTimeLimit', { count: DAYS })}
  32. </li>
  33. <li>${state.translate('accountBenefitSync')}</li>
  34. <li>${state.translate('accountBenefitMoz')}</li>
  35. </ul>
  36. </section>
  37. <section
  38. class="flex flex-col flex-grow m-4 md:self-center md:w-128 lg:max-w-xs"
  39. >
  40. <form onsubmit=${submitEmail} data-no-csrf>
  41. <input
  42. id="email-input"
  43. type="email"
  44. class="${hidden} border rounded-lg w-full px-2 py-1 h-12 mb-3 text-lg text-grey-70 leading-loose dark:bg-grey-80 dark:text-white"
  45. placeholder=${state.translate('emailPlaceholder')}
  46. />
  47. <input
  48. class="btn rounded-lg w-full flex flex-shrink-0 items-center justify-center"
  49. value="${state.translate('signInOnlyButton')}"
  50. title="${state.translate('signInOnlyButton')}"
  51. id="email-submit"
  52. type="submit"
  53. />
  54. </form>
  55. <button
  56. class="my-3 link-blue font-medium"
  57. title="${state.translate('deletePopupCancel')}"
  58. onclick=${cancel}
  59. >
  60. ${state.translate('deletePopupCancel')}
  61. </button>
  62. </section>
  63. </send-signup-dialog>
  64. `;
  65. function emailish(str) {
  66. if (!str) {
  67. return false;
  68. }
  69. // just check if it's the right shape
  70. const a = str.split('@');
  71. return a.length === 2 && a.every(s => s.length > 0);
  72. }
  73. function cancel(event) {
  74. canceledSignup({ trigger });
  75. close(event);
  76. }
  77. function submitEmail(event) {
  78. event.preventDefault();
  79. if (submitting) {
  80. return;
  81. }
  82. submitting = true;
  83. const el = document.getElementById('email-input');
  84. const email = el.value;
  85. submittedSignup({ trigger });
  86. emit('login', emailish(email) ? email : null);
  87. }
  88. };
  89. };