diff --git a/templates/panel/sitekey/add/ts/form/index.ts b/templates/panel/sitekey/add/ts/form/index.ts index 1d39c17f..b2fa2736 100644 --- a/templates/panel/sitekey/add/ts/form/index.ts +++ b/templates/panel/sitekey/add/ts/form/index.ts @@ -25,6 +25,8 @@ import VIEWS from '../../../../../views/v1/routes'; import validateDescription from './validateDescription'; import validateDuration from './validateDuration'; +import createError from '../../../../../components/error'; + const SITE_KEY_FORM_CLASS = 'sitekey-form'; const FORM = document.querySelector(`.${SITE_KEY_FORM_CLASS}`); @@ -53,12 +55,11 @@ const submit = async (e: Event) => { const res = await fetch(formUrl, genJsonPayload(payload)); if (res.ok) { - alert('success'); const data = await res.json(); window.location.assign(VIEWS.listSitekey(data.key)); } else { const err = await res.json(); - alert(`error: ${err.error}`); + createError(err.error); } }; diff --git a/templates/panel/sitekey/add/ts/form/validateDescription.test.ts b/templates/panel/sitekey/add/ts/form/validateDescription.test.ts index 8bd39234..9efbd01e 100644 --- a/templates/panel/sitekey/add/ts/form/validateDescription.test.ts +++ b/templates/panel/sitekey/add/ts/form/validateDescription.test.ts @@ -19,6 +19,8 @@ import validateDescription from './validateDescription'; import {getAddForm, fillDescription} from '../setupTests'; import {mockAlert} from '../../../../../setUpTests'; +import setup from '../../../../../components/error/setUpTests'; + mockAlert(); document.body.innerHTML = getAddForm(); @@ -26,6 +28,7 @@ document.body.innerHTML = getAddForm(); const emptyErr = "can't be empty"; it('validateDescription workds', () => { + document.querySelector('body').appendChild(setup()); try { const event = new Event('submit'); validateDescription(event); diff --git a/templates/panel/sitekey/add/ts/levels/updateLevel.ts b/templates/panel/sitekey/add/ts/levels/updateLevel.ts index a5e855ff..8fc99a26 100644 --- a/templates/panel/sitekey/add/ts/levels/updateLevel.ts +++ b/templates/panel/sitekey/add/ts/levels/updateLevel.ts @@ -19,6 +19,8 @@ import CONST from '../const'; import getLevelFields from './getLevelFields'; import {LEVELS} from './index'; +import createError from '../../../../../components/error'; + /** on-change event handler to update level */ const updateLevel = (e: Event) => { const target = e.target; @@ -41,7 +43,7 @@ const updateLevel = (e: Event) => { const updatedLevel = getLevelFields(level); LEVELS.update(updatedLevel, level); } catch (e) { - alert(e); + createError(e); } }; diff --git a/templates/utils/isBlankString.test.ts b/templates/utils/isBlankString.test.ts index f85262dd..54013e71 100644 --- a/templates/utils/isBlankString.test.ts +++ b/templates/utils/isBlankString.test.ts @@ -18,11 +18,15 @@ import isBlankString from './isBlankString'; import {mockAlert} from '../setUpTests'; + +import setup from '../components/error/setUpTests'; + 'use strict'; mockAlert(); it('getFromUrl workds', () => { + document.querySelector('body').appendChild(setup()); expect(isBlankString('test', 'username')).toBe(false); try { isBlankString(' ', 'username'); diff --git a/templates/utils/isBlankString.ts b/templates/utils/isBlankString.ts index 52c22e14..5589a60e 100644 --- a/templates/utils/isBlankString.ts +++ b/templates/utils/isBlankString.ts @@ -14,6 +14,7 @@ * You should have received a copy of the GNU Affero General Public License * along with this program. If not, see . */ +import createError from '../components/error/'; const isBlankString = (value: string|number, field: string, event?: Event) => { value = value.toString(); @@ -22,7 +23,7 @@ const isBlankString = (value: string|number, field: string, event?: Event) => { event.preventDefault(); } const msg = `${field} can't be empty`; - alert(msg); + createError(msg); throw new Error(msg); } return false;