|
19 | 19 | return {}; |
20 | 20 | })(); |
21 | 21 |
|
| 22 | + const MESSAGE_TYPE_INFO = 'info'; |
| 23 | + const MESSAGE_TYPE_DANGER = 'danger'; |
| 24 | + const MESSAGE_TYPE_ERROR = 'error'; |
| 25 | + const MESSAGE_TYPE_SUCCESS = 'success'; |
| 26 | +
|
22 | 27 | let formContainer; |
23 | 28 | let region; |
24 | 29 | let formHidden = $state(true); |
|
27 | 32 |
|
28 | 33 | let messageTimeout = null; |
29 | 34 | let message = $state(''); |
30 | | - let messageType = $state('info'); |
| 35 | + let messageType = $state(MESSAGE_TYPE_INFO); |
31 | 36 | const messageHideDelay = config.messageHideDelay ?? 0; |
32 | 37 |
|
33 | 38 | const t = (text) => config.messages?.[text] ?? text + ' (missing translation)'; |
34 | 39 |
|
35 | | - const showMessage = (msg, type = 'info') => { |
| 40 | + const showMessage = (msg, type = MESSAGE_TYPE_INFO) => { |
36 | 41 | if (messageTimeout) { |
37 | 42 | clearTimeout(messageTimeout); |
38 | 43 | } |
|
75 | 80 |
|
76 | 81 | const submitForm = async (target) => { |
77 | 82 | // https://developer.mozilla.org/en-US/docs/Web/API/HTMLFormElement#instance_methods |
78 | | - // @todo This does not actually validate the form elements! |
79 | 83 | const isValid = form.reportValidity(); |
80 | 84 | if (isValid) { |
81 | 85 | const data = {}; |
|
97 | 101 | data.image = image; |
98 | 102 | } catch (error) { |
99 | 103 | console.error(error); |
100 | | - showMessage('Error taking screenshot', 'danger'); |
| 104 | + showMessage('Error taking screenshot', MESSAGE_TYPE_DANGER); |
101 | 105 | } |
102 | 106 |
|
103 | 107 | const formData = new FormData(form); |
|
136 | 140 | .then((response) => { |
137 | 141 | if (201 === response.status) { |
138 | 142 | hideForm(true); |
139 | | - showMessage(t('Feedback created'), 'success'); |
| 143 | + showMessage(t('Feedback created'), MESSAGE_TYPE_SUCCESS); |
140 | 144 | } else { |
141 | 145 | response |
142 | 146 | .json() |
143 | 147 | .then((data) => |
144 | | - showMessage('Error creating feedback: ' + JSON.stringify(data), 'danger') |
| 148 | + showMessage('Error creating feedback: ' + JSON.stringify(data), MESSAGE_TYPE_DANGER) |
145 | 149 | ) |
146 | | - .catch((error) => showMessage('Error creating feedback: ' + error, 'danger')); |
| 150 | + .catch((error) => |
| 151 | + showMessage('Error creating feedback: ' + error, MESSAGE_TYPE_DANGER) |
| 152 | + ); |
147 | 153 | } |
148 | 154 | }) |
149 | | - .catch((reason) => showMessage(reason, 'error')); |
| 155 | + .catch((reason) => showMessage(reason, MESSAGE_TYPE_ERROR)); |
150 | 156 | } |
151 | 157 | }; |
152 | 158 |
|
|
192 | 198 |
|
193 | 199 | <div data-capture="exclude"> |
194 | 200 | {#if message} |
195 | | - <div class="tidy-feedback-message-wrapper container position-fixed top"> |
| 201 | + <div class="tidy-feedback-message-wrapper container position-fixed top-0"> |
196 | 202 | <row class="row"> |
197 | 203 | <div class="col-md-6 offset-md-3 mt-3"> |
198 | 204 | <div |
199 | | - class="tidy-feedback-message alert alert-{messageType} alert-dismissible" |
| 205 | + class={[ |
| 206 | + 'tidy-feedback-message', |
| 207 | + 'alert', |
| 208 | + 'alert-dismissible', |
| 209 | + { |
| 210 | + 'alert-info': MESSAGE_TYPE_INFO === messageType, |
| 211 | + 'alert-danger': MESSAGE_TYPE_DANGER === messageType, |
| 212 | + 'alert-error': MESSAGE_TYPE_ERROR === messageType, |
| 213 | + 'alert-sucess': MESSAGE_TYPE_SUCCESS === messageType |
| 214 | + } |
| 215 | + ]} |
200 | 216 | role="alert" |
201 | 217 | > |
202 | 218 | {message} |
|
0 commit comments