2018-10-25 04:07:10 +02:00
|
|
|
const html = require('choo/html');
|
2019-02-08 18:44:21 +01:00
|
|
|
const { bytes, platform } = require('../utils');
|
2019-02-12 20:50:06 +01:00
|
|
|
const { canceledSignup, submittedSignup } = require('../metrics');
|
2018-10-25 04:07:10 +02:00
|
|
|
|
2019-02-12 20:50:06 +01:00
|
|
|
module.exports = function(trigger) {
|
2018-10-25 04:07:10 +02:00
|
|
|
return function(state, emit, close) {
|
2019-02-26 19:39:50 +01:00
|
|
|
const DAYS = Math.floor(state.LIMITS.MAX_EXPIRE_SECONDS / 86400);
|
2019-02-08 18:44:21 +01:00
|
|
|
const hidden = platform() === 'android' ? 'hidden' : '';
|
|
|
|
let submitting = false;
|
2018-10-25 04:07:10 +02:00
|
|
|
return html`
|
2019-01-11 01:22:40 +01:00
|
|
|
<send-signup-dialog class="flex flex-col p-4">
|
2019-02-22 16:42:08 +01:00
|
|
|
<h2 class="font-bold">${state.translate('accountBenefitTitle')}</h3>
|
|
|
|
<ul class="my-2 leading-normal list-reset text-lg mb-8 mt-4">
|
|
|
|
<li>${state.translate('accountBenefitLargeFiles', {
|
2019-02-26 19:39:50 +01:00
|
|
|
size: bytes(state.LIMITS.MAX_FILE_SIZE)
|
2019-02-22 16:42:08 +01:00
|
|
|
})}</li>
|
|
|
|
<li>${state.translate('accountBenefitExpiry')}</li>
|
2019-02-22 21:42:10 +01:00
|
|
|
<li>${state.translate('accountBenefitExpiryTwo', { count: DAYS })}</li>
|
2019-02-22 16:42:08 +01:00
|
|
|
<li>${state.translate('accountBenefitSync')}</li>
|
|
|
|
</ul>
|
2018-10-25 04:07:10 +02:00
|
|
|
<form
|
|
|
|
onsubmit=${submitEmail}
|
|
|
|
data-no-csrf>
|
|
|
|
<input
|
|
|
|
id="email-input"
|
|
|
|
type="text"
|
2019-02-13 20:14:53 +01:00
|
|
|
class="${hidden} border rounded-lg w-full px-2 py-1 h-12 mb-4 text-lg text-grey-darker leading-loose"
|
2019-02-22 21:00:39 +01:00
|
|
|
placeholder=${state.translate('emailEntryPlaceholder')} />
|
2018-10-25 04:07:10 +02:00
|
|
|
<input
|
2019-02-20 19:57:32 +01:00
|
|
|
class="btn rounded-lg w-full flex flex-no-shrink items-center justify-center"
|
|
|
|
value="${state.translate('signInMenuOption')}"
|
2019-02-21 04:59:29 +01:00
|
|
|
title="${state.translate('signInMenuOption')}"
|
2018-10-25 04:07:10 +02:00
|
|
|
id="email-submit"
|
2019-02-08 18:44:21 +01:00
|
|
|
type="submit" />
|
2018-10-25 04:07:10 +02:00
|
|
|
</form>
|
|
|
|
<button
|
2019-02-13 20:14:53 +01:00
|
|
|
class="my-4 text-blue-dark hover:text-blue-darker focus:text-blue-darker font-medium"
|
2018-10-25 04:07:10 +02:00
|
|
|
title="${state.translate('deletePopupCancel')}"
|
2019-02-12 20:50:06 +01:00
|
|
|
onclick=${cancel}>${state.translate('deletePopupCancel')}
|
2018-10-25 04:07:10 +02:00
|
|
|
</button>
|
2019-01-11 01:22:40 +01:00
|
|
|
</send-signup-dialog>`;
|
2018-10-25 04:07:10 +02:00
|
|
|
|
2018-12-21 20:40:52 +01:00
|
|
|
function emailish(str) {
|
|
|
|
if (!str) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// just check if it's the right shape
|
|
|
|
const a = str.split('@');
|
|
|
|
return a.length === 2 && a.every(s => s.length > 0);
|
|
|
|
}
|
|
|
|
|
2019-02-12 20:50:06 +01:00
|
|
|
function cancel(event) {
|
|
|
|
canceledSignup({ trigger });
|
|
|
|
close(event);
|
|
|
|
}
|
|
|
|
|
2018-10-25 04:07:10 +02:00
|
|
|
function submitEmail(event) {
|
|
|
|
event.preventDefault();
|
2019-02-08 18:44:21 +01:00
|
|
|
if (submitting) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
submitting = true;
|
|
|
|
|
2018-10-25 04:07:10 +02:00
|
|
|
const el = document.getElementById('email-input');
|
|
|
|
const email = el.value;
|
2019-02-12 20:50:06 +01:00
|
|
|
submittedSignup({ trigger });
|
2018-12-21 20:40:52 +01:00
|
|
|
emit('login', emailish(email) ? email : null);
|
2018-10-25 04:07:10 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|