Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Feature/ae 1770 announce module #990

Merged
merged 13 commits into from
Jan 2, 2024
4 changes: 0 additions & 4 deletions src/components/FlashMessage/Alert.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<script>
import { announceAssertively } from '@Utility/announce';

export let type;
export let text;
export let close = () => {};
Expand All @@ -10,8 +8,6 @@
warn: 'warning',
success: 'check_circle_outline'
}[type];

$: announceAssertively(text);
</script>

<style type="text/postcss">
Expand Down
17 changes: 0 additions & 17 deletions src/components/Router/router.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,7 @@
import * as Router from 'svelte-spa-router';

import { flashMessageStore } from '@/stores';

export const replace = Router.replace;

export const pop = Router.pop;

export const push = Router.push;

export const replaceFlushFlashMessages = route => {
flashMessageStore.flush();
Router.replace(route);
};

export const popFlushFlashMessages = route => {
flashMessageStore.flush();
Router.pop(route);
};

export const pushFlushFlashMessages = route => {
flashMessageStore.flush();
Router.push(route);
};
13 changes: 6 additions & 7 deletions src/components/liitteet/liitteet.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import * as Links from './links';

import { _ } from '@Language/i18n';
import { flashMessageStore } from '@/stores';
import { announcementsForModule } from '@Utility/announce';

import H2 from '@Component/H/H2';
import FileDropArea from '@Component/FileDropArea/FileDropArea';
Expand Down Expand Up @@ -50,18 +50,17 @@
}

const submit = event => {
const { announceError, clearAnnouncements } =
announcementsForModule(flashModule);

if (isValidForm(newLink)) {
flashMessageStore.flush();
clearAnnouncements();
liiteApi.addLink(newLink);
resetForm();
Validation.unblurForm(event.target);
} else {
Validation.blurForm(event.target);
flashMessageStore.add(
flashModule,
'error',
i18n(i18nRoot + '.messages.add-link.validation')
);
announceError(i18n(i18nRoot + '.messages.add-link.validation'));
}
};

Expand Down
6 changes: 3 additions & 3 deletions src/pages/aineistoasiakas/index.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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');
</script>

<svelte:window
on:hashchange={_ => flashMessageStore.flush('aineistoasiakas')} />
<svelte:window on:hashchange={clearAnnouncements} />

<Router {routes} {prefix} />
<FlashMessage module={'aineistoasiakas'} />
20 changes: 6 additions & 14 deletions src/pages/aineistoasiakas/new-aineistoasiakas.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -20,6 +20,8 @@

const i18n = $_;
const i18nRoot = 'aineistoasiakas.new';
const { announceError, announceSuccess } =
announcementsForModule('aineistoasiakas');

let resources = Maybe.None();
const emptyKayttaja = {
Expand Down Expand Up @@ -52,9 +54,7 @@
Future.fork(
response => {
overlay = false;
flashMessageStore.add(
'kayttaja',
'error',
announceError(
Locales.uniqueViolationMessage(
i18n,
response,
Expand All @@ -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);
Expand All @@ -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;
},
Expand Down
18 changes: 8 additions & 10 deletions src/pages/energiatodistus/EnergiatodistusForm.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -48,6 +47,9 @@
export let submit;
export let title = '';

const { announceError, clearAnnouncements } =
announcementsForModule('Energiatodistus');

const required = energiatodistus =>
energiatodistus['bypass-validation-limits']
? validation.requiredBypass
Expand Down Expand Up @@ -113,9 +115,7 @@
R.map(R.nth(0))
)(invalidProperties);

flashMessageStore.add(
'Energiatodistus',
'error',
announceError(
$_('energiatodistus.messages.validation-error') + invalidTxt
);

Expand All @@ -125,7 +125,7 @@

const showKorvausErrorMessage = R.forEach(
R.compose(
flashMessageStore.add('Energiatodistus', 'error'),
announceError,
$_,
R.concat('energiatodistus.korvaavuus.validation.')
)
Expand All @@ -141,7 +141,7 @@
);

if (R.isEmpty(invalid) && korvausError.isNone()) {
flashMessageStore.flush();
clearAnnouncements();
submit(energiatodistus, (...args) => {
dirty = false;
onSuccessfulSave(...args);
Expand All @@ -164,9 +164,7 @@
R.map(Inputs.propertyLabel($_))
)(missing);

flashMessageStore.add(
'Energiatodistus',
'error',
announceError(
$_('energiatodistus.messages.validation-required-error') + missingTxt
);

Expand Down
14 changes: 5 additions & 9 deletions src/pages/energiatodistus/ToolBar/toolbar.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
Expand Down Expand Up @@ -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))
);
Expand Down
12 changes: 5 additions & 7 deletions src/pages/energiatodistus/energiatodistukset.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand Down Expand Up @@ -66,7 +68,7 @@
Maybe.orSome(defaultKey, Response.localizationKey(response))
);

flashMessageStore.add('Energiatodistus', 'error', msg);
announceError(msg);
};

const loadError = showError('energiatodistus.messages.load-error');
Expand All @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -36,6 +35,8 @@
? EtHakuSchema.paakayttajaSchema
: EtHakuSchema.laatijaSchema;

const { announceWarning } = announcementsForModule('Energiatodistus');

let laatijat = Maybe.None();

Future.fork(
Expand Down Expand Up @@ -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
Expand All @@ -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.');
}
}} />
</div>
Expand Down
5 changes: 3 additions & 2 deletions src/pages/energiatodistus/energiatodistus-resolver.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -28,7 +29,7 @@
)
);
overlay = false;
flashMessageStore.add('Energiatodistus', 'error', msg);
announceError(msg);
},
energiatodistus => {
replace(
Expand Down
Loading
Loading