|
80 | 80 |
|
81 | 81 | <!-- Modal for Form -->
|
82 | 82 | <Modal :show="showModal" @close="showModal = false">
|
83 |
| - <Form :submitAction="submitForm" buttonText="Generate Image" :errors="errors" /> |
| 83 | + <Form :submitAction="submitForm" buttonText="Generate Image" :errors="errors" :isProgressing="isProgressing" /> |
84 | 84 | </Modal>
|
85 | 85 |
|
86 | 86 | <!-- Modal for Viewing Image -->
|
@@ -121,7 +121,6 @@ const showModal = ref(false);
|
121 | 121 | const showImageModal = ref(false);
|
122 | 122 | const selectedImage = ref(null);
|
123 | 123 | const errors = ref({});
|
124 |
| -const isProgressing = ref(false); |
125 | 124 |
|
126 | 125 | const truncate = (text, length) => {
|
127 | 126 | if (text.length <= length) {
|
@@ -170,22 +169,28 @@ const openImageModal = (image) => {
|
170 | 169 | showImageModal.value = true;
|
171 | 170 | };
|
172 | 171 |
|
| 172 | +const isProgressing = ref(false); |
| 173 | +
|
173 | 174 | const submitForm = (formData) => {
|
| 175 | + isProgressing.value = true; |
174 | 176 | router.post(route("images.store"), formData, {
|
175 | 177 | preserveScroll: true,
|
176 | 178 | onSuccess: () => {
|
177 | 179 | showModal.value = false;
|
178 |
| - getRequestCount(); // Update request count after form submission |
| 180 | + isProgressing.value = false; |
| 181 | + getRequestCount(); |
179 | 182 | },
|
180 | 183 | onError: (error) => {
|
181 |
| - if (error.response.status === 429) { |
182 |
| - Swal.fire( |
183 |
| - "Error!", |
184 |
| - error.response.data.message, |
185 |
| - "error" |
186 |
| - ); |
| 184 | + isProgressing.value = false; |
| 185 | + if (error.response) { |
| 186 | + if (error.response.status === 429) { |
| 187 | + Swal.fire("Error!", error.response.data.message, "error"); |
| 188 | + } else { |
| 189 | + errors.value = error.response.data.errors; |
| 190 | + } |
187 | 191 | } else {
|
188 |
| - errors.value = error.response.data.errors; |
| 192 | + Swal.fire("Error!", "Ocurrió un error inesperado. Por favor, intenta nuevamente.", "error"); |
| 193 | + console.error("Error sin respuesta:", error); |
189 | 194 | }
|
190 | 195 | },
|
191 | 196 | });
|
|
0 commit comments