2020-01-30 13:08:57 -05:00
|
|
|
import Vue from 'vue';
|
2022-02-01 16:12:02 -05:00
|
|
|
import { setCookie, parseBoolean } from '~/lib/utils/common_utils';
|
|
|
|
|
2020-01-30 13:08:57 -05:00
|
|
|
import DismissibleAlert from '~/vue_shared/components/dismissible_alert.vue';
|
|
|
|
|
2021-12-18 07:13:19 -05:00
|
|
|
const getCookieExpirationPeriod = (expirationPeriod) => {
|
|
|
|
const defaultExpirationPeriod = 30;
|
|
|
|
const alertExpirationPeriod = Number(expirationPeriod);
|
|
|
|
|
|
|
|
return !expirationPeriod || Number.isNaN(alertExpirationPeriod)
|
|
|
|
? defaultExpirationPeriod
|
|
|
|
: alertExpirationPeriod;
|
|
|
|
};
|
|
|
|
|
2020-12-23 16:10:24 -05:00
|
|
|
const mountVueAlert = (el) => {
|
2020-01-30 13:08:57 -05:00
|
|
|
const props = {
|
|
|
|
html: el.innerHTML,
|
|
|
|
};
|
|
|
|
const attrs = {
|
|
|
|
...el.dataset,
|
|
|
|
dismissible: parseBoolean(el.dataset.dismissible),
|
|
|
|
};
|
2021-12-18 07:13:19 -05:00
|
|
|
const { dismissCookieName, dismissCookieExpire } = el.dataset;
|
2020-01-30 13:08:57 -05:00
|
|
|
|
|
|
|
return new Vue({
|
|
|
|
el,
|
2021-12-18 07:13:19 -05:00
|
|
|
render(createElement) {
|
|
|
|
return createElement(DismissibleAlert, {
|
|
|
|
props,
|
|
|
|
attrs,
|
|
|
|
on: {
|
|
|
|
alertDismissed() {
|
|
|
|
if (!dismissCookieName) {
|
|
|
|
return;
|
|
|
|
}
|
2022-02-01 16:12:02 -05:00
|
|
|
setCookie(dismissCookieName, true, {
|
2021-12-18 07:13:19 -05:00
|
|
|
expires: getCookieExpirationPeriod(dismissCookieExpire),
|
|
|
|
});
|
|
|
|
},
|
|
|
|
},
|
|
|
|
});
|
2020-01-30 13:08:57 -05:00
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
export default () => [...document.querySelectorAll('.js-vue-alert')].map(mountVueAlert);
|