Skip to content

Commit cd4d176

Browse files
committed
fix/qg-270: исправлено сохранение черновиков в случае ошибки отправки формы записи журнала
1 parent aeda3c2 commit cd4d176

4 files changed

Lines changed: 9 additions & 4 deletions

File tree

app/src/main/kotlin/pro/azhidkov/platform/spring/http/ResponseEntityExt.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ package pro.azhidkov.platform.spring.http
33
import org.springframework.http.ResponseEntity
44

55

6-
fun hxRedirect(path: String): ResponseEntity<Unit> {
6+
fun hxRedirect(path: String, vararg headers: Pair<String, String>): ResponseEntity<Unit> {
77
return ResponseEntity.ok()
88
.header("HX-Redirect", path)
9+
.headers { headers.forEach { (key, value) -> it.add(key, value) } }
910
.build()
1011
}
1112

app/src/main/kotlin/pro/qyoga/app/therapist/clients/journal/edit_entry/create/CreateJournalEntryPageController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ class CreateJournalEntryPageController(
6868

6969
return when {
7070
result.isSuccess ->
71-
hxRedirect("/therapist/clients/$clientId/journal")
71+
hxRedirect("/therapist/clients/$clientId/journal", "HX-Trigger" to "formSaved")
7272

7373
result.isFailureOf<DuplicatedDate>() -> {
7474
val ex = result.exceptionOrNull() as DuplicatedDate

app/src/main/kotlin/pro/qyoga/app/therapist/clients/journal/edit_entry/edit/EditJournalEntryPageController.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class EditJournalEntryPageController(
4747
): Any {
4848
try {
4949
editJournalEntry(ClientRef.to(clientId), entryId, editJournalEntryRq, principal)
50-
return hxRedirect("/therapist/clients/$clientId/journal")
50+
return hxRedirect("/therapist/clients/$clientId/journal", "HX-Trigger" to "formSaved")
5151
} catch (ex: DuplicatedDate) {
5252
return EditJournalEntryPageModel(
5353
ex.duplicatedEntry.clientRef,

app/src/main/resources/templates/therapist/clients/client-add_journal_entry-fragment.html

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,11 @@
7272
});
7373
});
7474

75+
document.body.addEventListener('formSaved', function () {
76+
console.debug('Form saved successfully, resetting local storage');
77+
resetLocalState();
78+
});
79+
7580
</script>
7681

7782
<input
@@ -136,7 +141,6 @@
136141
</div>
137142
<div class="col-6 col-sm-auto text-center">
138143
<button
139-
@click="resetLocalState()"
140144
class="btn btn-outline-success"
141145
name="confirmButton"
142146
style="min-width: 110px;">

0 commit comments

Comments
 (0)