From 6a8b34aba475bf8acdbcf37fd0d0c50c2a838a77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Wed, 20 Dec 2023 15:07:44 +0100 Subject: [PATCH 01/13] Revert "AE-1770 Announce the text of Alert" This reverts commit ff648a75dc49d4d7fe9b02f3eeac9732ccbe0069. Maybe it will be better to announce important events more directly Only the changes to Alert.svelte are reverted. The supporting changes elsewhere will stay relevant. --- src/components/FlashMessage/Alert.svelte | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/components/FlashMessage/Alert.svelte b/src/components/FlashMessage/Alert.svelte index 787b6a5ea..689f8bf71 100644 --- a/src/components/FlashMessage/Alert.svelte +++ b/src/components/FlashMessage/Alert.svelte @@ -1,6 +1,4 @@ - flashMessageStore.flush('Yritys')} /> + diff --git a/src/pages/yritys/laatijat.svelte b/src/pages/yritys/laatijat.svelte index f2c920336..fe39eec9e 100644 --- a/src/pages/yritys/laatijat.svelte +++ b/src/pages/yritys/laatijat.svelte @@ -4,7 +4,6 @@ import * as Future from '@Utility/future-utils'; import * as Response from '@Utility/response'; import * as Formats from '@Utility/formats'; - import * as Kayttajat from '@Utility/kayttajat'; import * as api from '@Pages/yritys/yritys-api'; import * as laatijaApi from '@Pages/laatija/laatija-api'; @@ -13,7 +12,7 @@ import * as Yritykset from '@Pages/yritys/yritys-utils'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; import H1 from '@Component/H/H1.svelte'; import Overlay from '@Component/Overlay/Overlay.svelte'; @@ -24,6 +23,7 @@ export let params; const i18n = $_; + const { announceError, announceSuccess } = announcementsForModule('yritys'); let overlay = false; let laatijat = []; @@ -33,9 +33,7 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'yritys', - 'error', + announceError( i18n( Maybe.orSome( 'yritys.messages.load-error', @@ -62,19 +60,10 @@ const detach = id => { Future.fork( - _ => - flashMessageStore.add( - 'yritys', - 'error', - i18n('laatija.yritykset.error.detach-failed') - ), + _ => announceError(i18n('laatija.yritykset.error.detach-failed')), _ => { load(params.id); - flashMessageStore.add( - 'yritys', - 'success', - i18n('laatija.yritykset.success.detach') - ); + announceSuccess(i18n('laatija.yritykset.success.detach')); }, laatijaApi.deleteLaatijaYritys(fetch, id, params.id) ); @@ -82,19 +71,10 @@ const accept = id => Future.fork( - _ => - flashMessageStore.add( - 'yritys', - 'error', - i18n('yritys.laatijat.accept.error') - ), + _ => announceError(i18n('yritys.laatijat.accept.error')), _ => { load(params.id); - flashMessageStore.add( - 'yritys', - 'success', - i18n('yritys.laatijat.accept.success') - ); + announceSuccess(i18n('yritys.laatijat.accept.success')); }, api.putAcceptedLaatijaYritys(fetch, id, params.id) ); diff --git a/src/pages/yritys/new-yritys.svelte b/src/pages/yritys/new-yritys.svelte index 3d0c550ed..1aa14fcf8 100644 --- a/src/pages/yritys/new-yritys.svelte +++ b/src/pages/yritys/new-yritys.svelte @@ -11,11 +11,11 @@ import Spinner from '@Component/Spinner/Spinner'; import YritysForm from '@Pages/yritys/yritys-form'; import * as YritysUtils from '@Pages/yritys/yritys-utils'; - import { flashMessageStore } from '@/stores'; import * as api from '@Pages/yritys/yritys-api'; import * as Locales from '@Language/locale-utils'; import * as kayttajaApi from '@Pages/kayttaja/kayttaja-api'; + import { announcementsForModule } from '@Utility/announce'; let overlay = false; let dirty = false; @@ -27,13 +27,13 @@ yritys = YritysUtils.emptyYritys; }; + const { announceError, announceSuccess } = announcementsForModule('yritys'); + const submit = R.compose( Future.fork( response => { overlay = false; - flashMessageStore.add( - 'yritys', - 'error', + announceError( Locales.uniqueViolationMessage( $_, response, @@ -42,11 +42,7 @@ ); }, ({ id }) => { - flashMessageStore.addPersist( - 'yritys', - 'success', - $_('yritys.messages.save-success') - ); + announceSuccess($_('yritys.messages.save-success')); dirty = false; replace(`/yritys/${id}`); } @@ -61,11 +57,7 @@ Future.fork( () => { overlay = false; - flashMessageStore.add( - 'yritys', - 'error', - $_('yritys.messages.load-error') - ); + announceError($_('yritys.messages.load-error')); }, response => { resources = Maybe.Some(response); diff --git a/src/pages/yritys/yritykset.svelte b/src/pages/yritys/yritykset.svelte index 1bcbd4792..257a92175 100644 --- a/src/pages/yritys/yritykset.svelte +++ b/src/pages/yritys/yritykset.svelte @@ -7,7 +7,7 @@ import * as qs from 'qs'; import { replace, location, querystring } from 'svelte-spa-router'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; import { _ } from '@Language/i18n'; import { push } from '@Component/Router/router'; @@ -20,6 +20,7 @@ import Checkbox from '@Component/Checkbox/Checkbox'; const i18n = $_; + const { announceError } = announcementsForModule('yritys'); let yritykset = []; let overlay = true; @@ -27,12 +28,7 @@ Future.fork( _ => { - flashMessageStore.add( - 'yritys', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); - + announceError(i18n('yritykset.messages.load-error')); overlay = false; }, response => { diff --git a/src/pages/yritys/yritys-form.svelte b/src/pages/yritys/yritys-form.svelte index 8c3c72dce..ccf544cbb 100644 --- a/src/pages/yritys/yritys-form.svelte +++ b/src/pages/yritys/yritys-form.svelte @@ -22,7 +22,7 @@ import Confirm from '@Component/Confirm/Confirm'; import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let submit; export let cancel; @@ -37,6 +37,8 @@ const setDirty = _ => { dirty = true; }; + const { announceError, clearAnnouncements } = + announcementsForModule('yritys'); $: schema = YritysUtils.schema(yritys.maa); @@ -124,15 +126,11 @@ on:change={setDirty} on:submit|preventDefault={event => { if (isValidForm(yritys)) { - flashMessageStore.flush(); + clearAnnouncements(); submit(yritys); } else { Validation.blurForm(event.target); - flashMessageStore.add( - 'yritys', - 'error', - i18n('yritys.messages.validation-error') - ); + announceError(i18n('yritys.messages.validation-error')); } }}>
From ff12f2cfedfdcd030182613af63236a2bcda0647 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Thu, 21 Dec 2023 15:44:02 +0100 Subject: [PATCH 07/13] AE-1770 Use announce module in aineistoasiakas pages --- src/pages/aineistoasiakas/index.svelte | 6 +++--- .../new-aineistoasiakas.svelte | 20 ++++++------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/src/pages/aineistoasiakas/index.svelte b/src/pages/aineistoasiakas/index.svelte index 6ba04f7d7..72362b31f 100644 --- a/src/pages/aineistoasiakas/index.svelte +++ b/src/pages/aineistoasiakas/index.svelte @@ -4,16 +4,16 @@ import NewAineistoasiakas from './new-aineistoasiakas'; import FlashMessage from '@Component/FlashMessage/FlashMessage'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; const prefix = '/aineistoasiakas'; const routes = { '/new': NewAineistoasiakas }; + const { clearAnnouncements } = announcementsForModule('aineistoasiakas'); - flashMessageStore.flush('aineistoasiakas')} /> + diff --git a/src/pages/aineistoasiakas/new-aineistoasiakas.svelte b/src/pages/aineistoasiakas/new-aineistoasiakas.svelte index bcf6cc458..822507b21 100644 --- a/src/pages/aineistoasiakas/new-aineistoasiakas.svelte +++ b/src/pages/aineistoasiakas/new-aineistoasiakas.svelte @@ -6,7 +6,7 @@ import * as Response from '@Utility/response'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; import { push } from '@Component/Router/router'; import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; @@ -20,6 +20,8 @@ const i18n = $_; const i18nRoot = 'aineistoasiakas.new'; + const { announceError, announceSuccess } = + announcementsForModule('aineistoasiakas'); let resources = Maybe.None(); const emptyKayttaja = { @@ -52,9 +54,7 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'kayttaja', - 'error', + announceError( Locales.uniqueViolationMessage( i18n, response, @@ -63,11 +63,7 @@ ); }, response => { - flashMessageStore.add( - 'kayttaja', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); overlay = false; dirty = false; push('/kayttaja/' + response.id); @@ -80,11 +76,7 @@ $: Future.fork( response => { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); resources = Maybe.None(); overlay = false; }, From 8295972c3db97907767549096ec3c1c459cfdfd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Thu, 21 Dec 2023 16:20:26 +0100 Subject: [PATCH 08/13] AE-1770 Use announce module in laatija pages --- src/pages/laatija/index.svelte | 5 +-- src/pages/laatija/laatija-form.svelte | 13 ++++---- src/pages/laatija/laatijat.svelte | 10 +++--- src/pages/laatija/new-laatija.svelte | 13 +++----- .../upload/laatija-upload-droparea.svelte | 10 ++---- .../laatija/upload/laatija-upload.svelte | 24 +++++--------- src/pages/laatija/yritykset.svelte | 33 +++++-------------- 7 files changed, 37 insertions(+), 71 deletions(-) diff --git a/src/pages/laatija/index.svelte b/src/pages/laatija/index.svelte index a65b6dd02..e82ec5c3f 100644 --- a/src/pages/laatija/index.svelte +++ b/src/pages/laatija/index.svelte @@ -8,7 +8,7 @@ import NotFound from '@Pages/not-found/not-found'; import FlashMessage from '@Component/FlashMessage/FlashMessage'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; const prefix = '/laatija'; const routes = { @@ -18,9 +18,10 @@ '/:id/yritykset': Yritykset, '*': NotFound }; + const { clearAnnouncements } = announcementsForModule('Laatija'); - flashMessageStore.flush('Laatija')} /> + diff --git a/src/pages/laatija/laatija-form.svelte b/src/pages/laatija/laatija-form.svelte index 492a6fc2a..be47021f5 100644 --- a/src/pages/laatija/laatija-form.svelte +++ b/src/pages/laatija/laatija-form.svelte @@ -23,7 +23,7 @@ import * as LaatijaSchema from './schema'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'laatija'; @@ -103,15 +103,14 @@ let form; const validateAndSubmit = _ => { + const { announceError, clearAnnouncements } = + announcementsForModule(errorModule); + if (Validation.isValidForm(schema)(laatija)) { - flashMessageStore.flush(); + clearAnnouncements(); submit(laatija); } else { - flashMessageStore.add( - errorModule, - 'error', - i18n('laatija.messages.validation-error') - ); + announceError(i18n('laatija.messages.validation-error')); Validation.blurForm(form); } }; diff --git a/src/pages/laatija/laatijat.svelte b/src/pages/laatija/laatijat.svelte index 208f778a0..f9927ec24 100644 --- a/src/pages/laatija/laatijat.svelte +++ b/src/pages/laatija/laatijat.svelte @@ -18,7 +18,6 @@ import { replace, location, querystring } from 'svelte-spa-router'; import { locale, _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import Input from '@Component/Input/Input'; import Datepicker from '@Component/Input/Datepicker.svelte'; @@ -28,20 +27,19 @@ import Label from '@Component/Label/Label.svelte'; import Overlay from '@Component/Overlay/Overlay.svelte'; import Spinner from '@Component/Spinner/Spinner.svelte'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'laatijat'; + const { announceError, announceSuccess, clearAnnouncements } = + announcementsForModule('Laatija'); let resources = Maybe.None(); let overlay = true; // Load all page resources Future.fork( response => { - flashMessageStore.add( - 'Laatija', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); overlay = false; }, response => { diff --git a/src/pages/laatija/new-laatija.svelte b/src/pages/laatija/new-laatija.svelte index 4b464c1dd..16b85fad0 100644 --- a/src/pages/laatija/new-laatija.svelte +++ b/src/pages/laatija/new-laatija.svelte @@ -17,11 +17,12 @@ import Overlay from '@Component/Overlay/Overlay'; import Spinner from '@Component/Spinner/Spinner'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; import { _ } from '@Language/i18n'; const i18n = $_; const i18nRoot = 'laatija'; + const { announceError, announceSuccess } = announcementsForModule('Laatija'); let overlay = true; let dirty = false; @@ -88,9 +89,7 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'Laatija', - 'error', + announceError( Locales.uniqueViolationMessage( i18n, response, @@ -99,11 +98,7 @@ ); }, response => { - flashMessageStore.addPersist( - 'Laatija', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); overlay = false; dirty = false; Router.push('/kayttaja/' + response.id); diff --git a/src/pages/laatija/upload/laatija-upload-droparea.svelte b/src/pages/laatija/upload/laatija-upload-droparea.svelte index 58fa70a24..69e78b87a 100644 --- a/src/pages/laatija/upload/laatija-upload-droparea.svelte +++ b/src/pages/laatija/upload/laatija-upload-droparea.svelte @@ -4,21 +4,17 @@ import FileDropArea from '@Component/FileDropArea/FileDropArea'; import * as LaatijaUploadUtils from './laatija-upload-utils'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let laatijat; export let files = []; const i18n = $_; + const { announceError } = announcementsForModule('Laatija'); $: R.compose( Future.fork( - _ => - flashMessageStore.add( - 'Laatija', - 'error', - i18n('errors.file-read-error') - ), + _ => announceError(i18n('errors.file-read-error')), result => (laatijat = result) ), R.map(LaatijaUploadUtils.deserialize), diff --git a/src/pages/laatija/upload/laatija-upload.svelte b/src/pages/laatija/upload/laatija-upload.svelte index 39c51482b..5a19b86db 100644 --- a/src/pages/laatija/upload/laatija-upload.svelte +++ b/src/pages/laatija/upload/laatija-upload.svelte @@ -12,7 +12,7 @@ import * as LaatijaUploadUtils from './laatija-upload-utils'; import Button from '@Component/Button/Button'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; import * as LocaleUtils from '@Language/locale-utils'; import * as laatijaApi from '@Pages/laatija/laatija-api'; @@ -23,6 +23,8 @@ const i18n = $_; const i18nRoot = 'laatija.upload'; + const { announceError, announceSuccess, clearAnnouncements } = + announcementsForModule('Laatija'); let overlay = false; @@ -35,11 +37,7 @@ $: Future.fork( response => { toggleOverlay(false); - flashMessageStore.add( - 'Laatija', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); }, response => { toggleOverlay(false); @@ -71,15 +69,11 @@ response, Response.errorKey(i18nRoot, 'save', response) ); - flashMessageStore.add('Laatija', 'error', msg); + announceError(msg); }, _ => { toggleOverlay(false); - flashMessageStore.add( - 'Laatija', - 'success', - i18n(i18nRoot + '.messages.save-success') - ); + announceSuccess(i18n(i18nRoot + '.messages.save-success')); laatijat = []; } ), @@ -121,7 +115,7 @@ )(model); $: if (errors.length) { - flashMessageStore.add('Laatija', 'error', R.join(' | ', errors)); + announceError(R.join(' | ', errors)); } @@ -178,11 +172,11 @@
{ - flashMessageStore.flush('Laatija'); + clearAnnouncements(); submit(model); }} on:reset|preventDefault={_ => { - flashMessageStore.flush('Laatija'); + clearAnnouncements(); files = []; laatijat = []; }}> diff --git a/src/pages/laatija/yritykset.svelte b/src/pages/laatija/yritykset.svelte index d2174a047..9d8547ad9 100644 --- a/src/pages/laatija/yritykset.svelte +++ b/src/pages/laatija/yritykset.svelte @@ -25,11 +25,12 @@ import * as laatijaApi from './laatija-api'; import * as yritysApi from '@Pages/yritys/yritys-api'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; + const { announceError, announceSuccess } = announcementsForModule('Laatija'); let newLaatijaYritys = Either.Right(Maybe.None()); let laatijaYritykset = []; @@ -40,19 +41,10 @@ const detach = index => { Future.fork( - _ => - flashMessageStore.add( - 'Laatija', - 'error', - i18n('laatija.yritykset.error.detach-failed') - ), + _ => announceError(i18n('laatija.yritykset.error.detach-failed')), _ => { load(params.id); - flashMessageStore.add( - 'Laatija', - 'success', - i18n('laatija.yritykset.success.detach') - ); + announceSuccess(i18n('laatija.yritykset.success.detach')); }, laatijaApi.deleteLaatijaYritys( fetch, @@ -93,7 +85,7 @@ toggleOverlay(true); return Future.fork( _ => { - flashMessageStore.add('Laatija', 'error', i18n('errors.load-error')); + announceError(i18n('errors.load-error')); toggleOverlay(false); }, response => { @@ -125,21 +117,12 @@ Maybe.toEither(R.applyTo('laatija.yritykset.error.select-yritys')) ) .leftMap(R.applyTo(i18n)) - .cata(flashMessageStore.add('Laatija', 'error'), yritys => { + .cata(announceError, yritys => { Future.fork( - _ => - flashMessageStore.add( - 'Laatija', - 'error', - i18n('laatija.yritykset.error.attach-failed') - ), + _ => announceError(i18n('laatija.yritykset.error.attach-failed')), _ => { load(params.id); - flashMessageStore.add( - 'Laatija', - 'success', - i18n('laatija.yritykset.success.attach') - ); + announceSuccess(i18n('laatija.yritykset.success.attach')); }, laatijaApi.putLaatijaYritys(fetch, params.id, yritys.id) ); From 4e5f6d2bfda90a8e80b3a6eb9bcf93eb19947daf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Fri, 22 Dec 2023 11:56:49 +0100 Subject: [PATCH 09/13] AE-1770 Use announce module in kayttaja pages --- .../kayttaja/aineistoasiakas-form.svelte | 12 +++++----- src/pages/kayttaja/existing-kayttaja.svelte | 22 +++++-------------- src/pages/kayttaja/history.svelte | 6 +++-- src/pages/kayttaja/index.svelte | 6 +++-- src/pages/kayttaja/kayttaja-form.svelte | 12 +++++----- src/pages/kayttaja/kayttajat.svelte | 9 +++----- src/pages/kayttaja/new-kayttaja.svelte | 19 +++++----------- 7 files changed, 32 insertions(+), 54 deletions(-) diff --git a/src/pages/kayttaja/aineistoasiakas-form.svelte b/src/pages/kayttaja/aineistoasiakas-form.svelte index c0aec3dcc..5c3d48638 100644 --- a/src/pages/kayttaja/aineistoasiakas-form.svelte +++ b/src/pages/kayttaja/aineistoasiakas-form.svelte @@ -8,7 +8,6 @@ import * as Locales from '@Language/locale-utils'; import * as Formats from '@Utility/formats'; - import { flashMessageStore } from '@/stores'; import { locale, _ } from '@Language/i18n'; import ApiKey from './api-key.svelte'; @@ -19,6 +18,7 @@ import Select from '@Component/Select/Select2'; import Datepicker from '@Component/Input/Datepicker'; import * as Parsers from '@Utility/parsers'; + import { announcementsForModule } from '@Utility/announce'; /* * Note: kayttaja.rooli :: Maybe[Id] @@ -35,6 +35,8 @@ const i18n = $_; const i18nRoot = 'kayttaja'; + const { announceError, clearAnnouncements } = + announcementsForModule('kayttaja'); const schema = Schema.Aineistoasiakas; const aineistoPermitSchema = Schema.aineistolupa; @@ -55,14 +57,10 @@ let form; const saveKayttaja = _ => { if (isValidForm(kayttaja) && isValidAineisto(kayttajaAineistot)) { - flashMessageStore.flush(); + clearAnnouncements(); submit(R.evolve({ rooli: Maybe.get }, kayttaja), kayttajaAineistot); } else { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n('kayttaja.messages.validation-error') - ); + announceError(i18n('kayttaja.messages.validation-error')); Validation.blurForm(form); } }; diff --git a/src/pages/kayttaja/existing-kayttaja.svelte b/src/pages/kayttaja/existing-kayttaja.svelte index a237d6422..08d4e3d9d 100644 --- a/src/pages/kayttaja/existing-kayttaja.svelte +++ b/src/pages/kayttaja/existing-kayttaja.svelte @@ -8,7 +8,7 @@ import * as Laatija from '@Pages/laatija/laatija'; import { _ } from '@Language/i18n'; - import { flashMessageStore, idTranslateStore } from '@/stores'; + import { idTranslateStore } from '@/stores'; import * as GeoApi from '@Utility/api/geo-api'; import * as LaatijaApi from '@Pages/laatija/laatija-api'; @@ -24,11 +24,13 @@ import H1 from '@Component/H/H1.svelte'; import LastLogin from './last-login.svelte'; import Verification from './verification.svelte'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; const i18nRoot = 'kayttaja'; + const { announceError, announceSuccess } = announcementsForModule('kayttaja'); let resources = Maybe.None(); let overlay = true; @@ -46,18 +48,10 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'kayttaja', - 'error', - errorMessage(type, response) - ); + announceError(errorMessage(type, response)); }, _ => { - flashMessageStore.add( - 'kayttaja', - 'success', - i18n(`${type}.messages.save-success`) - ); + announceSuccess(i18n(`${type}.messages.save-success`)); load(params); onSuccessfulSave(); overlay = false; @@ -124,11 +118,7 @@ ); Future.fork( response => { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); resources = Maybe.None(); overlay = false; }, diff --git a/src/pages/kayttaja/history.svelte b/src/pages/kayttaja/history.svelte index ec0b5f4a3..b34741bdf 100644 --- a/src/pages/kayttaja/history.svelte +++ b/src/pages/kayttaja/history.svelte @@ -10,19 +10,21 @@ import * as laatijaApi from '@Pages/laatija/laatija-api'; import * as GeoApi from '@Utility/api/geo-api'; import * as LaskutusApi from '@Utility/api/laskutus-api'; - import { flashMessageStore } from '@/stores'; import Overlay from '@Component/Overlay/Overlay.svelte'; import Spinner from '@Component/Spinner/Spinner.svelte'; import H2 from '@Component/H/H2'; import KayttajaHistoryTable from './history-table'; import LaatijaHistoryTable from '@Pages/laatija/history-table'; + import { announcementsForModule } from '@Utility/announce'; export let params; $: id = params.id; const i18n = $_; + const { announceError } = announcementsForModule('kayttaja'); + let overlay = true; let resources = Maybe.None(); @@ -37,7 +39,7 @@ ) ); - flashMessageStore.add('ohje', 'error', msg); + announceError(msg); overlay = false; }, response => { diff --git a/src/pages/kayttaja/index.svelte b/src/pages/kayttaja/index.svelte index ff59978ae..2b19bb943 100644 --- a/src/pages/kayttaja/index.svelte +++ b/src/pages/kayttaja/index.svelte @@ -7,7 +7,9 @@ import History from '@Pages/kayttaja/history'; import FlashMessage from '@Component/FlashMessage/FlashMessage'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; + + const { clearAnnouncements } = announcementsForModule('kayttaja'); const prefix = '/kayttaja'; const routes = { @@ -18,7 +20,7 @@ }; - flashMessageStore.flush('kayttaja')} /> + diff --git a/src/pages/kayttaja/kayttaja-form.svelte b/src/pages/kayttaja/kayttaja-form.svelte index 6b2a1a314..531e40bdd 100644 --- a/src/pages/kayttaja/kayttaja-form.svelte +++ b/src/pages/kayttaja/kayttaja-form.svelte @@ -6,7 +6,6 @@ import * as Validation from '@Utility/validation'; import * as Locales from '@Language/locale-utils'; - import { flashMessageStore } from '@/stores'; import { locale, _ } from '@Language/i18n'; import H2 from '@Component/H/H2'; @@ -14,6 +13,7 @@ import Input from '@Component/Input/Input'; import Checkbox from '@Component/Checkbox/Checkbox.svelte'; import Select from '@Component/Select/Select.svelte'; + import { announcementsForModule } from '@Utility/announce'; /* * Note: kayttaja.rooli :: Maybe[Id] @@ -29,6 +29,8 @@ const i18n = $_; const i18nRoot = 'kayttaja'; + const { announceError, clearAnnouncements } = + announcementsForModule('kayttaja'); const schema = Schema.Kayttaja; $: virtuSchema = Schema.virtuSchema(kayttaja); @@ -66,14 +68,10 @@ let form; const saveKayttaja = _ => { if (isValidForm(kayttaja)) { - flashMessageStore.flush(); + clearAnnouncements(); submit(R.evolve({ rooli: Maybe.get }, kayttaja)); } else { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n('kayttaja.messages.validation-error') - ); + announceError(i18n('kayttaja.messages.validation-error')); Validation.blurForm(form); } }; diff --git a/src/pages/kayttaja/kayttajat.svelte b/src/pages/kayttaja/kayttajat.svelte index a141fabdb..e3fb94a8d 100644 --- a/src/pages/kayttaja/kayttajat.svelte +++ b/src/pages/kayttaja/kayttajat.svelte @@ -9,7 +9,6 @@ import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as LaatijaApi from '@Pages/laatija/laatija-api'; - import { flashMessageStore } from '@/stores'; import { _, locale } from '@Language/i18n'; import { push } from '@Component/Router/router'; @@ -17,20 +16,18 @@ import H1 from '@Component/H/H1.svelte'; import H2 from '@Component/H/H2.svelte'; import Link from '../../components/Link/Link.svelte'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'kayttajat'; + const { announceError } = announcementsForModule('kayttaja'); let resources = Maybe.None(); let overlay = true; Future.fork( response => { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); overlay = false; }, response => { diff --git a/src/pages/kayttaja/new-kayttaja.svelte b/src/pages/kayttaja/new-kayttaja.svelte index e9b7aa776..0eaba0d55 100644 --- a/src/pages/kayttaja/new-kayttaja.svelte +++ b/src/pages/kayttaja/new-kayttaja.svelte @@ -5,7 +5,6 @@ import * as Response from '@Utility/response'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import { push } from '@Component/Router/router'; import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; @@ -15,9 +14,11 @@ import Spinner from '@Component/Spinner/Spinner'; import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; import H1 from '@Component/H/H1.svelte'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'kayttaja.new'; + const { announceError, announceSuccess } = announcementsForModule('kayttaja'); let resources = Maybe.None(); const emptyKayttaja = { @@ -43,9 +44,7 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'kayttaja', - 'error', + announceError( Locales.uniqueViolationMessage( i18n, response, @@ -54,11 +53,7 @@ ); }, response => { - flashMessageStore.add( - 'kayttaja', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); overlay = false; dirty = false; push('/kayttaja/' + response.id); @@ -69,11 +64,7 @@ $: Future.fork( response => { - flashMessageStore.add( - 'kayttaja', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); resources = Maybe.None(); overlay = false; }, From 62035ae8b6f27f5642e298dd0dc0d2f39715f811 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Fri, 22 Dec 2023 12:54:26 +0100 Subject: [PATCH 10/13] AE-1770 Use announce module in energiatodistus pages --- .../EnergiatodistusForm.svelte | 18 +++++++-------- .../energiatodistus/ToolBar/toolbar.svelte | 14 +++++------- .../energiatodistus/energiatodistukset.svelte | 12 +++++----- .../energiatodistus-haku.svelte | 17 +++++--------- .../energiatodistus-resolver.svelte | 5 +++-- .../existing-energiatodistus.svelte | 22 +++++-------------- src/pages/energiatodistus/index.svelte | 8 +++---- .../energiatodistus/korvaavuus/ehdotus.svelte | 7 +++--- .../korvaavuus/korvaava.svelte | 9 +++----- .../korvaavuus/korvattu.svelte | 10 +++------ src/pages/energiatodistus/liitteet.svelte | 22 +++++-------------- .../energiatodistus/muutoshistoria.svelte | 6 +++-- .../new-energiatodistus.svelte | 22 +++++-------------- src/pages/energiatodistus/viestit.svelte | 14 +++++------- src/utils/announce.js | 8 ++++++- 15 files changed, 75 insertions(+), 119 deletions(-) diff --git a/src/pages/energiatodistus/EnergiatodistusForm.svelte b/src/pages/energiatodistus/EnergiatodistusForm.svelte index 94631d847..633d0c2d3 100644 --- a/src/pages/energiatodistus/EnergiatodistusForm.svelte +++ b/src/pages/energiatodistus/EnergiatodistusForm.svelte @@ -33,8 +33,7 @@ import ToolBar from './ToolBar/toolbar'; import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; - import { flashMessageStore } from '@/stores'; - import * as Validation from '@Utility/validation'; + import { announcementsForModule } from '@Utility/announce'; export let version; export let energiatodistus; @@ -48,6 +47,9 @@ export let submit; export let title = ''; + const { announceError, clearAnnouncements } = + announcementsForModule('Energiatodistus'); + const required = energiatodistus => energiatodistus['bypass-validation-limits'] ? validation.requiredBypass @@ -113,9 +115,7 @@ R.map(R.nth(0)) )(invalidProperties); - flashMessageStore.add( - 'Energiatodistus', - 'error', + announceError( $_('energiatodistus.messages.validation-error') + invalidTxt ); @@ -125,7 +125,7 @@ const showKorvausErrorMessage = R.forEach( R.compose( - flashMessageStore.add('Energiatodistus', 'error'), + announceError, $_, R.concat('energiatodistus.korvaavuus.validation.') ) @@ -141,7 +141,7 @@ ); if (R.isEmpty(invalid) && korvausError.isNone()) { - flashMessageStore.flush(); + clearAnnouncements(); submit(energiatodistus, (...args) => { dirty = false; onSuccessfulSave(...args); @@ -164,9 +164,7 @@ R.map(Inputs.propertyLabel($_)) )(missing); - flashMessageStore.add( - 'Energiatodistus', - 'error', + announceError( $_('energiatodistus.messages.validation-required-error') + missingTxt ); diff --git a/src/pages/energiatodistus/ToolBar/toolbar.svelte b/src/pages/energiatodistus/ToolBar/toolbar.svelte index c8cc997e3..fc4e174c1 100644 --- a/src/pages/energiatodistus/ToolBar/toolbar.svelte +++ b/src/pages/energiatodistus/ToolBar/toolbar.svelte @@ -19,8 +19,8 @@ import * as Toolbar from './toolbar-utils'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import * as Response from '@Utility/response'; + import { announcementsForModule } from '@Utility/announce'; export let energiatodistus; export let inputLanguage = 'fi'; @@ -30,6 +30,8 @@ export let valvonta = { ongoing: false, pending: false }; const i18n = $_; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); const version = energiatodistus.versio; const id = Maybe.fromNull(energiatodistus.id); @@ -87,20 +89,14 @@ Future.fork( response => { pendingExecution = false; - flashMessageStore.add( - 'Energiatodistus', - 'error', + announceError( i18n(Response.errorKey404('energiatodistus', name, response)) ); }, _ => { onSuccess(); pendingExecution = false; - flashMessageStore.add( - 'Energiatodistus', - 'success', - i18n(`energiatodistus.messages.${name}-success`) - ); + announceSuccess(i18n(`energiatodistus.messages.${name}-success`)); }, operation(fetch, version, Maybe.get(id)) ); diff --git a/src/pages/energiatodistus/energiatodistukset.svelte b/src/pages/energiatodistus/energiatodistukset.svelte index c961302fc..e5960d91d 100644 --- a/src/pages/energiatodistus/energiatodistukset.svelte +++ b/src/pages/energiatodistus/energiatodistukset.svelte @@ -20,7 +20,6 @@ import qs from 'qs'; import { _, locale } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import { push } from '@Component/Router/router'; import H1 from '@Component/H/H1'; @@ -36,8 +35,11 @@ import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as ValvontaApi from '@Pages/valvonta-oikeellisuus/valvonta-api'; import * as GeoApi from '@Utility/api/geo-api'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); let overlay = true; let failure = false; @@ -66,7 +68,7 @@ Maybe.orSome(defaultKey, Response.localizationKey(response)) ); - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); }; const loadError = showError('energiatodistus.messages.load-error'); @@ -89,11 +91,7 @@ id )(energiatodistukset); - flashMessageStore.add( - 'Energiatodistus', - 'success', - i18n('energiatodistukset.messages.delete-success') - ); + announceSuccess(i18n('energiatodistukset.messages.delete-success')); nextPageCallback(1); }, api.deleteEnergiatodistus(fetch, versio, id) diff --git a/src/pages/energiatodistus/energiatodistus-haku/energiatodistus-haku.svelte b/src/pages/energiatodistus/energiatodistus-haku/energiatodistus-haku.svelte index a8c0c2139..ce1a7cb83 100644 --- a/src/pages/energiatodistus/energiatodistus-haku/energiatodistus-haku.svelte +++ b/src/pages/energiatodistus/energiatodistus-haku/energiatodistus-haku.svelte @@ -4,8 +4,6 @@ import qs from 'qs'; import * as R from 'ramda'; - import { flashMessageStore } from '@/stores'; - import * as Maybe from '@Utility/maybe-utils'; import * as Either from '@Utility/either-utils'; import * as Future from '@Utility/future-utils'; @@ -23,6 +21,7 @@ import Radio from '@Component/Radio/Radio'; import { _ } from '@Language/i18n'; + import { announcementsForModule } from '@Utility/announce'; export let where; export let keyword; @@ -36,6 +35,8 @@ ? EtHakuSchema.paakayttajaSchema : EtHakuSchema.laatijaSchema; + const { announceWarning } = announcementsForModule('Energiatodistus'); + let laatijat = Maybe.None(); Future.fork( @@ -187,11 +188,7 @@ await tick(); form.dispatchEvent(new Event('change')); } else { - flashMessageStore.add( - 'energiatodistus', - 'warn', - 'Hakukriteerin poistamisessa tapahtui virhe.' - ); + announceWarning('Hakukriteerin poistamisessa tapahtui virhe.'); } }}> cancel @@ -215,11 +212,7 @@ form.dispatchEvent(new Event('change')); R.last([...form.querySelectorAll('input:not(.hidden)')]).focus(); } else { - flashMessageStore.add( - 'energiatodistus', - 'warn', - 'Hakukriteerin lisäyksessä tapahtui virhe.' - ); + announceWarning('Hakukriteerin lisäyksessä tapahtui virhe.'); } }} /> diff --git a/src/pages/energiatodistus/energiatodistus-resolver.svelte b/src/pages/energiatodistus/energiatodistus-resolver.svelte index 5d7eb970f..b607ca2fc 100644 --- a/src/pages/energiatodistus/energiatodistus-resolver.svelte +++ b/src/pages/energiatodistus/energiatodistus-resolver.svelte @@ -6,15 +6,16 @@ import * as EtApi from '@Pages/energiatodistus/energiatodistus-api'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import * as Response from '@Utility/response'; import { replace, location } from 'svelte-spa-router'; import Spinner from '@Component/Spinner/Spinner'; + import { announcementsForModule } from '@Utility/announce'; export let params; + const { announceError } = announcementsForModule('Energiatodistus'); let overlay = true; Future.fork( @@ -28,7 +29,7 @@ ) ); overlay = false; - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); }, energiatodistus => { replace( diff --git a/src/pages/energiatodistus/existing-energiatodistus.svelte b/src/pages/energiatodistus/existing-energiatodistus.svelte index 8af8628ea..2e1aa18be 100644 --- a/src/pages/energiatodistus/existing-energiatodistus.svelte +++ b/src/pages/energiatodistus/existing-energiatodistus.svelte @@ -18,12 +18,14 @@ import Overlay from '@Component/Overlay/Overlay'; import Spinner from '@Component/Spinner/Spinner'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; const i18nRoot = 'energiatodistus'; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); let resources = Maybe.None(); let overlay = true; @@ -42,20 +44,12 @@ if (R.pathEq(['body', 'type'], 'missing-value', response)) { showMissingProperties(response.body.missing); } else { - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n(Response.errorKey(i18nRoot, 'save', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'save', response))); } }, () => { toggleOverlay(false); - flashMessageStore.add( - 'Energiatodistus', - 'success', - $_('energiatodistus.messages.save-success') - ); + announceSuccess($_('energiatodistus.messages.save-success')); onSuccessfulSave(); } ), @@ -72,11 +66,7 @@ Future.fork( response => { toggleOverlay(false); - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); }, response => { resources = Maybe.Some(response); diff --git a/src/pages/energiatodistus/index.svelte b/src/pages/energiatodistus/index.svelte index bd23fe864..281abf225 100644 --- a/src/pages/energiatodistus/index.svelte +++ b/src/pages/energiatodistus/index.svelte @@ -1,6 +1,5 @@ - flashMessageStore.flush('Energiatodistus')} /> +
diff --git a/src/pages/energiatodistus/korvaavuus/ehdotus.svelte b/src/pages/energiatodistus/korvaavuus/ehdotus.svelte index 352876e62..845f48f3b 100644 --- a/src/pages/energiatodistus/korvaavuus/ehdotus.svelte +++ b/src/pages/energiatodistus/korvaavuus/ehdotus.svelte @@ -7,8 +7,7 @@ import * as Kayttajat from '@Utility/kayttajat'; import * as Validation from '@Utility/validation'; - import { _, locale } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { _ } from '@Language/i18n'; import Spinner from '@Component/Spinner/Spinner'; import Link from '@Component/Link/Link.svelte'; @@ -17,6 +16,7 @@ import * as EnergiatodistusApi from '../energiatodistus-api'; import * as ET from '../energiatodistus-utils'; + import { announcementsForModule } from '@Utility/announce'; export let energiatodistus; export let postinumerot; @@ -26,6 +26,7 @@ const i18n = $_; const i18nRoot = 'energiatodistus.korvaavuus'; + const { announceError } = announcementsForModule('Energiatodistus'); let loading = false; let korvattavat = []; @@ -48,7 +49,7 @@ ) ); - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); loading = false; }, response => { diff --git a/src/pages/energiatodistus/korvaavuus/korvaava.svelte b/src/pages/energiatodistus/korvaavuus/korvaava.svelte index 67265922f..bf9157d5b 100644 --- a/src/pages/energiatodistus/korvaavuus/korvaava.svelte +++ b/src/pages/energiatodistus/korvaavuus/korvaava.svelte @@ -13,13 +13,14 @@ import * as Maybe from '@Utility/maybe-utils'; import * as Future from '@Utility/future-utils'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let korvaavaEnergiatodistusId = Maybe.None(); export let whoami; export let postinumerot; const i18n = $_; + const { announceError } = announcementsForModule('Energiatodistus'); let overlay = false; @@ -34,11 +35,7 @@ _ => { overlay = false; korvaavaEnergiatodistus = Maybe.None(); - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n('energiatodistus.messages.load-error') - ); + announceError(i18n('energiatodistus.messages.load-error')); }, response => { overlay = false; diff --git a/src/pages/energiatodistus/korvaavuus/korvattu.svelte b/src/pages/energiatodistus/korvaavuus/korvattu.svelte index 3743ef097..38287917c 100644 --- a/src/pages/energiatodistus/korvaavuus/korvattu.svelte +++ b/src/pages/energiatodistus/korvaavuus/korvattu.svelte @@ -9,8 +9,6 @@ import EtTable from './energiatodistus-table'; import EnergiatodistusKorvausEhdotus from './ehdotus'; - import { flashMessageStore } from '@/stores'; - import * as EtApi from '../energiatodistus-api'; import * as Korvaus from './korvaus'; @@ -19,6 +17,7 @@ import * as Maybe from '@Utility/maybe-utils'; import * as Future from '@Utility/future-utils'; import * as Parsers from '@Utility/parsers'; + import { announcementsForModule } from '@Utility/announce'; export let energiatodistus; export let whoami; @@ -27,6 +26,7 @@ export let dirty; const i18n = $_; + const { announceError } = announcementsForModule('Energiatodistus'); const enabled = (Kayttajat.isLaatija(whoami) && @@ -66,11 +66,7 @@ _ => { searching = false; updated = true; - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n('energiatodistus.messages.load-error') - ); + announceError(i18n('energiatodistus.messages.load-error')); }, response => { searching = false; diff --git a/src/pages/energiatodistus/liitteet.svelte b/src/pages/energiatodistus/liitteet.svelte index 56b32a05d..0d01e20e4 100644 --- a/src/pages/energiatodistus/liitteet.svelte +++ b/src/pages/energiatodistus/liitteet.svelte @@ -7,14 +7,16 @@ import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import Liitteet from '@Component/liitteet/liitteet.svelte'; import Overlay from '@Component/Overlay/Overlay'; import Spinner from '@Component/Spinner/Spinner'; + import { announcementsForModule } from '@Utility/announce'; const i18nRoot = 'energiatodistus.liitteet'; const i18n = $_; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); export let params; let overlay = true; @@ -25,11 +27,7 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); overlay = false; }, response => { @@ -50,19 +48,11 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n(Response.errorKey404(i18nRoot, key, response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, key, response))); overlay = false; }, _ => { - flashMessageStore.add( - 'Energiatodistus', - 'success', - i18n(`${i18nRoot}.messages.${key}-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.${key}-success`)); load(params); }, liiteFuture(liite) diff --git a/src/pages/energiatodistus/muutoshistoria.svelte b/src/pages/energiatodistus/muutoshistoria.svelte index 098ea635b..76f1d05a2 100644 --- a/src/pages/energiatodistus/muutoshistoria.svelte +++ b/src/pages/energiatodistus/muutoshistoria.svelte @@ -9,7 +9,6 @@ import * as api from '@Pages/energiatodistus/energiatodistus-api'; import * as kayttajaApi from '@Pages/kayttaja/kayttaja-api'; - import { flashMessageStore } from '@/stores'; import { _ } from '@Language/i18n'; import H1 from '@Component/H/H1'; @@ -17,9 +16,12 @@ import Overlay from '@Component/Overlay/Overlay'; import Link from '@Component/Link/Link.svelte'; import * as Inputs from '@Pages/energiatodistus/inputs'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'energiatodistus.muutoshistoria'; + const { announceError } = announcementsForModule('Energiatodistus'); + export let params; let resources = Maybe.None(); @@ -73,7 +75,7 @@ ) ); - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); overlay = false; }, response => { diff --git a/src/pages/energiatodistus/new-energiatodistus.svelte b/src/pages/energiatodistus/new-energiatodistus.svelte index 81ec993b9..8858f1f95 100644 --- a/src/pages/energiatodistus/new-energiatodistus.svelte +++ b/src/pages/energiatodistus/new-energiatodistus.svelte @@ -19,12 +19,14 @@ import * as laatijaApi from '@Pages/laatija/laatija-api'; import * as laskutusApi from '@Utility/api/laskutus-api'; - import { flashMessageStore } from '@/stores'; import * as Response from '@Utility/response'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; const i18nRoot = 'energiatodistus'; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); let overlay = false; @@ -62,19 +64,11 @@ Future.fork( response => { toggleOverlay(false); - flashMessageStore.add( - 'Energiatodistus', - 'save', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); }, ({ id }) => { toggleOverlay(false); - flashMessageStore.addPersist( - 'Energiatodistus', - 'success', - $_('energiatodistus.messages.save-success') - ); + announceSuccess($_('energiatodistus.messages.save-success')); onSuccessfulSave(); replace(`/energiatodistus/${params.version}/${id}`); } @@ -101,11 +95,7 @@ Future.fork( response => { toggleOverlay(false); - flashMessageStore.add( - 'Energiatodistus', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); }, response => { resources = Maybe.Some(response); diff --git a/src/pages/energiatodistus/viestit.svelte b/src/pages/energiatodistus/viestit.svelte index 263e4d1c1..5be021d6d 100644 --- a/src/pages/energiatodistus/viestit.svelte +++ b/src/pages/energiatodistus/viestit.svelte @@ -5,7 +5,6 @@ import * as Response from '@Utility/response'; import { loc } from 'svelte-spa-router'; - import { flashMessageStore } from '@/stores'; import { _ } from '@Language/i18n'; import * as ViestiApi from '@Pages/viesti/viesti-api'; @@ -16,8 +15,11 @@ import H1 from '@Component/H/H1.svelte'; import Link from '@Component/Link/Link.svelte'; import Viestiketju from '@Pages/viesti/viestiketju'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; + const { announceError, announceSuccess } = + announcementsForModule('Energiatodistus'); export let params; @@ -35,7 +37,7 @@ ) ); - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); overlay = false; }, response => { @@ -68,15 +70,11 @@ Response.localizationKey(response) ) ); - flashMessageStore.add('Energiatodistus', 'error', msg); + announceError(msg); overlay = false; }, _ => { - flashMessageStore.add( - 'Energiatodistus', - 'success', - i18n(`viesti.all.messages.update-success`) - ); + announceSuccess(i18n(`viesti.all.messages.update-success`)); overlay = false; load(params); } diff --git a/src/utils/announce.js b/src/utils/announce.js index 5363fdf96..e7f50591b 100644 --- a/src/utils/announce.js +++ b/src/utils/announce.js @@ -11,10 +11,16 @@ const announceError = module => msg => { flashMessageStore.add(module, 'error', msg); }; +const annouceWarning = module => msg => { + announceAssertively(msg); + flashMessageStore.add(module, 'warn', msg); +}; + const flush = module => () => flashMessageStore.flush(module); export const announcementsForModule = module => ({ - announceSuccess: announceSuccess(module), announceError: announceError(module), + announceSuccess: announceSuccess(module), + announceWarning: annouceWarning(module), clearAnnouncements: flush(module) }); From 9a664b8ea8a49929535d58b9fa8829b32ae5c569 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Fri, 22 Dec 2023 13:15:30 +0100 Subject: [PATCH 11/13] AE-1770 Use announce module in VO pages --- .../existing-toimenpide.svelte | 15 ++++++------ src/pages/valvonta-oikeellisuus/index.svelte | 9 ++++--- .../new-toimenpide-dialog.svelte | 9 +++---- .../new-toimenpide.svelte | 15 ++++++------ .../valvonta-oikeellisuus/note-dialog.svelte | 9 +++---- .../toimenpide-form.svelte | 16 +++---------- .../valvonta-oikeellisuus/valvonnat.svelte | 9 +++---- .../valvonta-oikeellisuus/valvonta.svelte | 15 ++++++------ .../virhetypes/index.svelte | 24 +++++++------------ .../virhetypes/type-form.svelte | 10 +++----- src/pages/valvonta/deadline-dialog.svelte | 10 ++++---- 11 files changed, 54 insertions(+), 87 deletions(-) diff --git a/src/pages/valvonta-oikeellisuus/existing-toimenpide.svelte b/src/pages/valvonta-oikeellisuus/existing-toimenpide.svelte index ea636f3ab..44b6e33ef 100644 --- a/src/pages/valvonta-oikeellisuus/existing-toimenpide.svelte +++ b/src/pages/valvonta-oikeellisuus/existing-toimenpide.svelte @@ -4,7 +4,6 @@ import * as Future from '@Utility/future-utils'; import * as Response from '@Utility/response'; - import { flashMessageStore } from '@/stores'; import * as Router from '@Component/Router/router'; import * as Links from './links'; @@ -21,11 +20,15 @@ import Spinner from '@Component/Spinner/Spinner.svelte'; import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; import ToimenpideForm from './toimenpide-form.svelte'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; const i18nRoot = 'valvonta.oikeellisuus.toimenpide'; + const { announceError, announceSuccess } = announcementsForModule( + 'valvonta-oikeellisuus' + ); let resources = Maybe.None(); let dirty = false; @@ -46,7 +49,7 @@ Future.fork( response => { const msg = errorMessage('load', response); - flashMessageStore.add('valvonta-oikeellisuus', 'error', msg); + announceError(msg); overlay = false; }, response => { @@ -72,15 +75,11 @@ Future.fork( response => { const msg = errorMessage(key, response); - flashMessageStore.add('valvonta-oikeellisuus', 'error', msg); + announceError(msg); overlay = false; }, _ => { - flashMessageStore.addPersist( - 'valvonta-oikeellisuus', - 'success', - i18n(`${i18nRoot}.messages.${key}-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.${key}-success`)); successCallback(); }, future diff --git a/src/pages/valvonta-oikeellisuus/index.svelte b/src/pages/valvonta-oikeellisuus/index.svelte index 08abb9623..624317d2f 100644 --- a/src/pages/valvonta-oikeellisuus/index.svelte +++ b/src/pages/valvonta-oikeellisuus/index.svelte @@ -9,7 +9,11 @@ import NotFound from '@Pages/not-found/not-found'; import FlashMessage from '@Component/FlashMessage/FlashMessage'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; + + const { clearAnnouncements } = announcementsForModule( + 'valvonta-oikeellisuus' + ); const prefix = '/valvonta/oikeellisuus'; const routes = { @@ -22,8 +26,7 @@ }; - flashMessageStore.flush('valvonta-oikeellisuus')} /> + diff --git a/src/pages/valvonta-oikeellisuus/new-toimenpide-dialog.svelte b/src/pages/valvonta-oikeellisuus/new-toimenpide-dialog.svelte index fcb92de35..6747e66c1 100644 --- a/src/pages/valvonta-oikeellisuus/new-toimenpide-dialog.svelte +++ b/src/pages/valvonta-oikeellisuus/new-toimenpide-dialog.svelte @@ -17,15 +17,16 @@ import Textarea from '@Component/Textarea/Textarea'; import Datepicker from '@Component/Input/Datepicker'; - import { flashMessageStore } from '@/stores'; import Dialog from '@Component/dialog/dialog'; import Select from '@Component/Select/Select.svelte'; import * as Validation from '@Utility/validation'; import Radio from '@Component/Radio/Radio'; import Fieldset from '@Component/Fieldset/Fieldset'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.oikeellisuus.toimenpide'; + const { announceSuccess } = announcementsForModule('valvonta-oikeellisuus'); export let id; export let templatesByType; @@ -64,11 +65,7 @@ }, _ => { publishPending = false; - flashMessageStore.add( - 'valvonta-oikeellisuus', - 'success', - i18n(`${i18nRoot}.messages.publish-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.publish-success`)); reload(); }, Toimenpiteet.isAnomaly(toimenpide) diff --git a/src/pages/valvonta-oikeellisuus/new-toimenpide.svelte b/src/pages/valvonta-oikeellisuus/new-toimenpide.svelte index bd9ff6875..aec1db26a 100644 --- a/src/pages/valvonta-oikeellisuus/new-toimenpide.svelte +++ b/src/pages/valvonta-oikeellisuus/new-toimenpide.svelte @@ -4,7 +4,6 @@ import * as Future from '@Utility/future-utils'; import * as Response from '@Utility/response'; - import { flashMessageStore } from '@/stores'; import * as Router from '@Component/Router/router'; import * as Toimenpiteet from './toimenpiteet'; @@ -20,9 +19,13 @@ import Spinner from '@Component/Spinner/Spinner.svelte'; import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; import ToimenpideForm from './toimenpide-form.svelte'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18nRoot = 'valvonta.oikeellisuus.toimenpide'; + const { announceError, announceSuccess } = announcementsForModule( + 'valvonta-oikeellisuus' + ); let resources = Maybe.None(); let dirty = false; @@ -37,7 +40,7 @@ Response.localizationKey(response) ); - flashMessageStore.add('viesti', 'error', msg); + announceError(msg); overlay = false; }, response => { @@ -61,15 +64,11 @@ Response.localizationKey(response) ) ); - flashMessageStore.add('valvonta-oikeellisuus', 'error', msg); + announceError(msg); overlay = false; }, response => { - flashMessageStore.add( - 'valvonta-oikeellisuus', - 'success', - $_(`${i18nRoot}.messages.add-success`) - ); + announceSuccess($_(`${i18nRoot}.messages.add-success`)); dirty = false; Router.replace(Links.toimenpide(response, params)); } diff --git a/src/pages/valvonta-oikeellisuus/note-dialog.svelte b/src/pages/valvonta-oikeellisuus/note-dialog.svelte index c4a795d5b..bb0866db3 100644 --- a/src/pages/valvonta-oikeellisuus/note-dialog.svelte +++ b/src/pages/valvonta-oikeellisuus/note-dialog.svelte @@ -10,12 +10,13 @@ import { _ } from '@Language/i18n'; import Textarea from '@Component/Textarea/Textarea'; - import { flashMessageStore } from '@/stores'; import * as Validation from '@Utility/validation'; import Dialog from '@Component/dialog/dialog'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.oikeellisuus.note'; + const { announceSuccess } = announcementsForModule('valvonta-oikeellisuus'); export let id; export let note; @@ -42,11 +43,7 @@ }, _ => { addPending = false; - flashMessageStore.add( - 'valvonta-oikeellisuus', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); reload(); }, ValvontaApi.postNote(id, note) diff --git a/src/pages/valvonta-oikeellisuus/toimenpide-form.svelte b/src/pages/valvonta-oikeellisuus/toimenpide-form.svelte index b56821398..a0223a215 100644 --- a/src/pages/valvonta-oikeellisuus/toimenpide-form.svelte +++ b/src/pages/valvonta-oikeellisuus/toimenpide-form.svelte @@ -1,11 +1,6 @@ - flashMessageStore.flush('valvonta-kaytto')} /> + diff --git a/src/pages/valvonta-kaytto/kohde-form.svelte b/src/pages/valvonta-kaytto/kohde-form.svelte index 18ce7f38b..77b7d0ca8 100644 --- a/src/pages/valvonta-kaytto/kohde-form.svelte +++ b/src/pages/valvonta-kaytto/kohde-form.svelte @@ -23,13 +23,14 @@ import Link from '@Component/Link/Link.svelte'; import Spinner from '@Component/Spinner/Spinner'; - import { flashMessageStore } from '@/stores'; import Autocomplete from '../../components/Autocomplete/Autocomplete.svelte'; import * as etApi from '@Pages/energiatodistus/energiatodistus-api'; import * as ValvontaApi from './valvonta-api'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.kaytto.kohde'; + const { announceError } = announcementsForModule('valvonta-kaytto'); export let kohde; export let ilmoituspaikat; @@ -54,9 +55,7 @@ Future.fork( response => { showRakennustunnusSpinner = false; - flashMessageStore.add( - 'valvonta-kaytto', - 'error', + announceError( i18n(Response.errorKey(i18nRoot, 'find-rakennustunnus', response)) ); }, @@ -81,11 +80,7 @@ if (Validation.isValidForm(schema)(kohde)) { save(kohde); } else { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(`${i18nRoot}.messages.validation-error`) - ); + announceError(i18n(`${i18nRoot}.messages.validation-error`)); Validation.blurForm(form); } }; diff --git a/src/pages/valvonta-kaytto/kohde.svelte b/src/pages/valvonta-kaytto/kohde.svelte index 326f8a456..0c92b5aa0 100644 --- a/src/pages/valvonta-kaytto/kohde.svelte +++ b/src/pages/valvonta-kaytto/kohde.svelte @@ -5,8 +5,7 @@ import * as Response from '@Utility/response'; import { push } from '@Component/Router/router'; - import { _, locale } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { _ } from '@Language/i18n'; import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as ValvontaApi from './valvonta-api'; @@ -19,11 +18,14 @@ import DirtyConfirmation from '@Component/Confirm/dirty.svelte'; import KohdeForm from './kohde-form'; import Osapuolet from './osapuolet.svelte'; + import { announcementsForModule } from '@Utility/announce'; export let params; const i18n = $_; const i18nRoot = 'valvonta.kaytto.kohde'; + const { announceError, announceSuccess } = + announcementsForModule('valvonta-kaytto'); let overlay = true; let dirtyKohde = false; @@ -36,11 +38,7 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); overlay = false; }, response => { @@ -68,19 +66,11 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey404(i18nRoot, action, response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, action, response))); overlay = false; }, _ => { - flashMessageStore.add( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.${action}-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.${action}-success`)); overlay = false; successCallback(); }, diff --git a/src/pages/valvonta-kaytto/new-osapuoli.svelte b/src/pages/valvonta-kaytto/new-osapuoli.svelte index 5c8fa744d..c4e5104fa 100644 --- a/src/pages/valvonta-kaytto/new-osapuoli.svelte +++ b/src/pages/valvonta-kaytto/new-osapuoli.svelte @@ -14,17 +14,20 @@ import H1 from '@Component/H/H1.svelte'; import HenkiloForm from './henkilo-form.svelte'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import * as GeoApi from '@Utility/api/geo-api'; import * as ValvontaApi from '@Pages/valvonta-kaytto/valvonta-api'; import YritysForm from '@Pages/valvonta-kaytto/yritys-form'; + import { announcementsForModule } from '@Utility/announce'; export let params; export let type; const i18n = $_; const i18nRoot = 'valvonta.kaytto.osapuoli'; + const { announceError, announceSuccess } = + announcementsForModule('valvonta-kaytto'); + const types = { henkilo: { form: HenkiloForm, @@ -50,11 +53,7 @@ Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); overlay = false; }, response => { @@ -72,19 +71,11 @@ R.compose( Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey(i18nRoot, 'add', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'add', response))); overlay = false; }, response => { - flashMessageStore.addPersist( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); dirty = false; push(osapuoliType.link({ id: params['valvonta-id'] }, response)); } diff --git a/src/pages/valvonta-kaytto/new-toimenpide-dialog.svelte b/src/pages/valvonta-kaytto/new-toimenpide-dialog.svelte index 01d81430e..7bf0a8975 100644 --- a/src/pages/valvonta-kaytto/new-toimenpide-dialog.svelte +++ b/src/pages/valvonta-kaytto/new-toimenpide-dialog.svelte @@ -21,7 +21,6 @@ import Textarea from '@Component/Textarea/Textarea'; import Datepicker from '@Component/Input/Datepicker'; import Input from '@Component/Input/Input'; - import { flashMessageStore } from '@/stores'; import Select from '@Component/Select/Select'; import OsapuoletTable from './toimenpide-osapuolet-table.svelte'; @@ -29,9 +28,11 @@ import DecisionOrderActualDecisionSubView from './new-decision-order-actual-decision-toimenpide'; import PenaltyDecisionActualDecisionSubView from './new-penalty-decision-actual-decision-toimenpide'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.kaytto.toimenpide'; + const { announceSuccess } = announcementsForModule('valvonta-kaytto'); export let id; export let templatesByType; @@ -83,11 +84,7 @@ publishPending = false; }, _ => { - flashMessageStore.add( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.publish-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.publish-success`)); publishPending = false; reload(); }, diff --git a/src/pages/valvonta-kaytto/new-valvonta.svelte b/src/pages/valvonta-kaytto/new-valvonta.svelte index f23096207..c92240bc2 100644 --- a/src/pages/valvonta-kaytto/new-valvonta.svelte +++ b/src/pages/valvonta-kaytto/new-valvonta.svelte @@ -11,14 +11,17 @@ import H1 from '@Component/H/H1.svelte'; import KohdeForm from './kohde-form'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import * as api from './valvonta-api'; import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as GeoApi from '@Utility/api/geo-api'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.kaytto.kohde'; + const { announceError, announceSuccess } = + announcementsForModule('valvonta-kaytto'); + const emptyKohde = _ => ({ rakennustunnus: Maybe.None(), katuosoite: '', @@ -42,11 +45,7 @@ Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'load', response))); overlay = false; }, response => { @@ -65,19 +64,11 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey(i18nRoot, 'add', response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, 'add', response))); overlay = false; }, response => { - flashMessageStore.addPersist( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); dirty = false; push('/valvonta/kaytto/' + response.id + '/kohde'); }, diff --git a/src/pages/valvonta-kaytto/note-dialog.svelte b/src/pages/valvonta-kaytto/note-dialog.svelte index a4dd37f79..570f89add 100644 --- a/src/pages/valvonta-kaytto/note-dialog.svelte +++ b/src/pages/valvonta-kaytto/note-dialog.svelte @@ -11,11 +11,12 @@ import Button from '@Component/Button/Button'; import Textarea from '@Component/Textarea/Textarea'; - import { flashMessageStore } from '@/stores'; import * as Validation from '@Utility/validation'; + import { announcementsForModule } from '@Utility/announce'; const i18n = $_; const i18nRoot = 'valvonta.kaytto.note'; + const { announceSuccess } = announcementsForModule('valvonta-kaytto'); export let id; export let note; @@ -40,11 +41,7 @@ error = Maybe.Some(msg); }, _ => { - flashMessageStore.add( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.add-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.add-success`)); reload(); }, ValvontaApi.postNote(id, note) diff --git a/src/pages/valvonta-kaytto/osapuoli.svelte b/src/pages/valvonta-kaytto/osapuoli.svelte index b5bf29ff9..857f4e78f 100644 --- a/src/pages/valvonta-kaytto/osapuoli.svelte +++ b/src/pages/valvonta-kaytto/osapuoli.svelte @@ -15,16 +15,19 @@ import HenkiloForm from './henkilo-form.svelte'; import YritysForm from './yritys-form.svelte'; import { _ } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; import * as GeoApi from '@Utility/api/geo-api'; import * as ValvontaApi from '@Pages/valvonta-kaytto/valvonta-api'; + import { announcementsForModule } from '@Utility/announce'; export let params; export let type; const i18n = $_; const i18nRoot = 'valvonta.kaytto.osapuoli'; + const { announceError, announceSuccess } = + announcementsForModule('valvonta-kaytto'); + const types = { henkilo: { name: henkilo => `${henkilo.etunimi} ${henkilo.sukunimi}`, @@ -56,7 +59,7 @@ Response.localizationKey(response) ); - flashMessageStore.add('valvonta-kaytto', 'error', msg); + announceError(msg); overlay = false; }, response => { @@ -77,19 +80,11 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey(i18nRoot, key, response)) - ); + announceError(i18n(Response.errorKey(i18nRoot, key, response))); overlay = false; }, _ => { - flashMessageStore.add( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.${key}-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.${key}-success`)); dirty = false; overlay = false; successCallback(); diff --git a/src/pages/valvonta-kaytto/valvonnat.svelte b/src/pages/valvonta-kaytto/valvonnat.svelte index 017b82c9b..db35f7bce 100644 --- a/src/pages/valvonta-kaytto/valvonnat.svelte +++ b/src/pages/valvonta-kaytto/valvonnat.svelte @@ -22,7 +22,6 @@ import * as kayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as geoApi from '@Utility/api/geo-api'; - import { flashMessageStore } from '@/stores'; import { _, locale } from '@Language/i18n'; import * as Locales from '@Language/locale-utils'; @@ -38,6 +37,7 @@ import Input from '@Component/Input/Input'; import * as ValvontaApi from '@Pages/valvonta-kaytto/valvonta-api'; import * as Selects from '@Component/Select/select-util'; + import { announcementsForModule } from '@Utility/announce'; let resources = Maybe.None(); let overlay = true; @@ -45,6 +45,7 @@ const pageSize = 50; const i18n = $_; const i18nRoot = 'valvonta.kaytto.all'; + const { announceError } = announcementsForModule('valvonta-kaytto'); let textCancel = () => {}; @@ -121,7 +122,7 @@ ) ); - flashMessageStore.add('valvonta-kaytto', 'error', msg); + announceError(msg); overlay = false; }, response => { diff --git a/src/pages/valvonta-kaytto/valvonta.svelte b/src/pages/valvonta-kaytto/valvonta.svelte index 0d24f213b..5544b5836 100644 --- a/src/pages/valvonta-kaytto/valvonta.svelte +++ b/src/pages/valvonta-kaytto/valvonta.svelte @@ -4,8 +4,7 @@ import * as Response from '@Utility/response'; import * as Maybe from '@Utility/maybe-utils'; - import { _, locale } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { _ } from '@Language/i18n'; import * as KayttajaApi from '@Pages/kayttaja/kayttaja-api'; import * as ValvontaApi from './valvonta-api'; @@ -22,11 +21,14 @@ import Note from './note.svelte'; import * as versionApi from '@Component/Version/version-api'; import { isProduction } from '@Utility/config-utils'; + import { announcementsForModule } from '@Utility/announce'; const TOIMENPIDETYPES_ALLOWED_IN_PRODUCTION = [0, 1, 2, 3, 4, 5]; const i18n = $_; const i18nRoot = 'valvonta.kaytto.valvonta'; + const { announceError, announceSuccess } = + announcementsForModule('valvonta-kaytto'); export let params; let resources = Maybe.None(); @@ -39,11 +41,7 @@ Future.fork( response => { overlay = false; - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey404(i18nRoot, 'load', response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, 'load', response))); }, response => { resources = Maybe.Some(response); @@ -91,19 +89,11 @@ overlay = true; Future.fork( response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(Response.errorKey404(i18nRoot, key, response)) - ); + announceError(i18n(Response.errorKey404(i18nRoot, key, response))); overlay = false; }, response => { - flashMessageStore.add( - 'valvonta-kaytto', - 'success', - i18n(`${i18nRoot}.messages.${key}-success`) - ); + announceSuccess(i18n(`${i18nRoot}.messages.${key}-success`)); overlay = false; successCallback(response); }, diff --git a/src/pages/valvonta-kaytto/yritys-form.svelte b/src/pages/valvonta-kaytto/yritys-form.svelte index 52c2e7d50..524bd250f 100644 --- a/src/pages/valvonta-kaytto/yritys-form.svelte +++ b/src/pages/valvonta-kaytto/yritys-form.svelte @@ -14,7 +14,7 @@ import ContactDetails from './contact-details-form.svelte'; import { _, locale } from '@Language/i18n'; - import { flashMessageStore } from '@/stores'; + import { announcementsForModule } from '@Utility/announce'; export let osapuoli; export let roolit; @@ -27,6 +27,8 @@ const i18n = $_; const i18nRoot = 'valvonta.kaytto.osapuoli'; + const { announceError } = announcementsForModule('valvonta-kaytto'); + let form; $: schema = Schema.appendPostinumeroValidatorForCountry( @@ -42,11 +44,7 @@ if (Validation.isValidForm(schema)(osapuoli)) { save(osapuoli); } else { - flashMessageStore.add( - 'valvonta-kaytto', - 'error', - i18n(`${i18nRoot}.messages.validation-error`) - ); + announceError(i18n(`${i18nRoot}.messages.validation-error`)); Validation.blurForm(form); } }; From 24aa0ebd0a1df4797388392cb8c91986e1ff6d84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Joonas=20Saraj=C3=A4rvi?= Date: Wed, 27 Dec 2023 13:27:55 +0100 Subject: [PATCH 13/13] AE-1770 Clear validationResult when valid --- src/components/Input/InputContainer.svelte | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/components/Input/InputContainer.svelte b/src/components/Input/InputContainer.svelte index d2b5e0aa1..b574a01bf 100644 --- a/src/components/Input/InputContainer.svelte +++ b/src/components/Input/InputContainer.svelte @@ -37,6 +37,10 @@ $: validate = value => { valid = true; + validationResult = { + type: '', + message: '' + }; v.validateModelValue(warnValidators, value).forEachLeft(error => { valid = false;