1
0
mirror of https://github.com/flarum/core.git synced 2025-07-10 11:26:24 +02:00
Files
php-flarum/js/src/forum/utils/alertEmailConfirmation.js
David Wheatley d268894e61 chore: 1.2 JS clean-up (#3214)
* fix: `extend.ts` TS error

* docs: fix incorrect JS docblocks

* chore: simplify some code

* chore: remove usages of prefixed JS function

* chore: consistent empty return types

* chore: format

* fix: typing errors

* chore: remove unneeded `@public` docblock modifiers

* Apply suggestions from code review

* Update js/src/forum/utils/slidable.js

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>

* Apply suggestions from code review

Co-authored-by: Alexander Skvortsov <38059171+askvortsov1@users.noreply.github.com>
2021-12-27 18:58:18 +00:00

70 lines
1.9 KiB
JavaScript

import Alert from '../../common/components/Alert';
import Button from '../../common/components/Button';
import icon from '../../common/helpers/icon';
import Component from '../../common/Component';
/**
* Shows an alert if the user has not yet confirmed their email address.
*
* @param {import('../ForumApplication').default} app
*/
export default function alertEmailConfirmation(app) {
const user = app.session.user;
if (!user || user.isEmailConfirmed()) return;
class ResendButton extends Component {
oninit(vnode) {
super.oninit(vnode);
this.loading = false;
this.sent = false;
}
view() {
return (
<Button class="Button Button--link" onclick={this.onclick.bind(this)} loading={this.loading} disabled={this.sent}>
{this.sent
? [icon('fas fa-check'), ' ', app.translator.trans('core.forum.user_email_confirmation.sent_message')]
: app.translator.trans('core.forum.user_email_confirmation.resend_button')}
</Button>
);
}
onclick() {
this.loading = true;
m.redraw();
app
.request({
method: 'POST',
url: app.forum.attribute('apiUrl') + '/users/' + user.id() + '/send-confirmation',
})
.then(() => {
this.loading = false;
this.sent = true;
m.redraw();
})
.catch(() => {
this.loading = false;
m.redraw();
});
}
}
class ContainedAlert extends Alert {
view(vnode) {
const vdom = super.view(vnode);
return { ...vdom, children: [<div className="container">{vdom.children}</div>] };
}
}
m.mount($('<div/>').insertBefore('#content')[0], {
view: () => (
<ContainedAlert dismissible={false} controls={[<ResendButton />]}>
{app.translator.trans('core.forum.user_email_confirmation.alert_message', { email: <strong>{user.email()}</strong> })}
</ContainedAlert>
),
});
}