Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AE-2072 Announce errors in new-toimenpide-dialog #8

Merged
merged 1 commit into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 37 additions & 19 deletions etp-front/src/pages/valvonta-kaytto/new-toimenpide-dialog.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import DecisionOrderActualDecisionSubView from './new-decision-order-actual-decision-toimenpide';
import PenaltyDecisionActualDecisionSubView from './new-penalty-decision-actual-decision-toimenpide';
import { announcementsForModule } from '@Utility/announce';
import { announceAssertively } from '@Utility/aria-live';

const i18n = $_;
const i18nRoot = 'valvonta.kaytto.toimenpide';
Expand All @@ -51,6 +52,15 @@

let form;
let error = Maybe.None();

// setError is used instead of the more common announceError from
// @Utility/announce, because the visual error needs a mechanism
// different from the common route through FlashMessage
const setError = er => {
error = er;
R.forEach(announceAssertively, R.map(R.prop('message'), error));
};

let publishPending = false;
let previewPending = false;

Expand All @@ -75,12 +85,14 @@
publishPending = true;
Future.fork(
response => {
error = Maybe.Some({
mayBypassAsha:
Toimenpiteet.isCloseCase(toimenpide) &&
ValvontaApi.isAshaFailure(response),
message: i18n(Response.errorKey(i18nRoot, 'publish', response))
});
setError(
Maybe.Some({
mayBypassAsha:
Toimenpiteet.isCloseCase(toimenpide) &&
ValvontaApi.isAshaFailure(response),
message: i18n(Response.errorKey(i18nRoot, 'publish', response))
})
);
publishPending = false;
},
_ => {
Expand All @@ -91,10 +103,12 @@
ValvontaApi.postToimenpide(id, toimenpide)
);
} else {
error = Maybe.Some({
mayBypassAsha: false,
message: $_(`${i18nRoot}.messages.validation-error`)
});
setError(
Maybe.Some({
mayBypassAsha: false,
message: $_(`${i18nRoot}.messages.validation-error`)
})
);
Validation.blurForm(form);
}
};
Expand All @@ -111,24 +125,28 @@
previewPending = true;
Future.fork(
response => {
error = Maybe.Some({
message: i18n(Response.errorKey(i18nRoot, 'preview', response)),
mayBypassAsha: false
});
setError(
Maybe.Some({
message: i18n(Response.errorKey(i18nRoot, 'preview', response)),
mayBypassAsha: false
})
);
previewPending = false;
},
response => {
previewPending = false;
error = Maybe.None();
setError(Maybe.None());
Response.openBlob(response);
},
api
);
} else {
error = Maybe.Some({
message: $_(`${i18nRoot}.messages.validation-error`),
mayBypassAsha: false
});
setError(
Maybe.Some({
message: $_(`${i18nRoot}.messages.validation-error`),
mayBypassAsha: false
})
);
Validation.blurForm(form);
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import Radio from '@Component/Radio/Radio';
import Fieldset from '@Component/Fieldset/Fieldset';
import { announcementsForModule } from '@Utility/announce';
import { announceAssertively } from '@Utility/aria-live';

const i18n = $_;
const i18nRoot = 'valvonta.oikeellisuus.toimenpide';
Expand All @@ -36,6 +37,14 @@
let form;
let error = Maybe.None();

// setError is used instead of the more common announceError from
// @Utility/announce, because the visual error needs a mechanism
// different from the common route through FlashMessage
const setError = er => {
error = er;
R.forEach(announceAssertively, error);
};

const text = R.compose(i18n, Toimenpiteet.i18nKey);

let publishPending = false;
Expand All @@ -61,7 +70,7 @@
Response.localizationKey(response)
)
);
error = Maybe.Some(msg);
setError(Maybe.Some(msg));
},
_ => {
publishPending = false;
Expand All @@ -73,7 +82,7 @@
: ValvontaApi.postToimenpide(id, toimenpide)
);
} else {
error = Maybe.Some($_(`${i18nRoot}.messages.validation-error`));
setError(Maybe.Some($_(`${i18nRoot}.messages.validation-error`)));
Validation.blurForm(form);
}
};
Expand All @@ -90,17 +99,17 @@
Response.localizationKey(response)
)
);
error = Maybe.Some(msg);
setError(Maybe.Some(msg));
},
response => {
previewPending = false;
error = Maybe.None();
setError(Maybe.None());
Response.openBlob(response);
},
ValvontaApi.previewToimenpide(id, toimenpide)
);
} else {
error = Maybe.Some($_(`${i18nRoot}.messages.validation-error`));
setError(Maybe.Some($_(`${i18nRoot}.messages.validation-error`)));
Validation.blurForm(form);
}
};
Expand Down
Loading