summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/user_callout.js
blob: b9d57cbcad4852d20c90fe3fc502f2a51b0d19f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import Cookies from 'js-cookie';

const USER_CALLOUT_COOKIE = 'user_callout_dismissed';

export default class UserCallout {
  constructor() {
    this.isCalloutDismissed = Cookies.get(USER_CALLOUT_COOKIE);
    this.userCalloutBody = $('.user-callout');
    this.init();
  }

  init() {
    if (!this.isCalloutDismissed || this.isCalloutDismissed === 'false') {
      $('.js-close-callout').on('click', e => this.dismissCallout(e));
    }
  }

  dismissCallout(e) {
    const $currentTarget = $(e.currentTarget);

    Cookies.set(USER_CALLOUT_COOKIE, 'true', { expires: 365 });

    if ($currentTarget.hasClass('close')) {
      this.userCalloutBody.remove();
    }
  }
}