Skip to content

Commit 676c63f

Browse files
committed
Update prompt validation rules and enhance form submission handling in ImageRequest and Index components
1 parent dee8235 commit 676c63f

File tree

2 files changed

+16
-11
lines changed

2 files changed

+16
-11
lines changed

app/Http/Requests/ImageRequest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public function rules(): array
2323
{
2424
return [
2525
'model' => ['required', 'string', 'in:dall-e-2,dall-e-3'],
26-
'prompt' => ['required', 'string', 'min:12', 'max:300'],
26+
'prompt' => ['required', 'string', 'min:8', 'max:300'],
2727
'style' => ['required', 'string', 'in:realistic,anime,cartoon,futuristic,abstract'],
2828
'size' => ['required', 'string', 'in:256x256,512x512,1024x1024,1024x1792,1792x1024'],
2929
'quality' => ['string', 'in:standard,hd'],

resources/js/Pages/Images/Index.vue

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@
8080

8181
<!-- Modal for Form -->
8282
<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" />
8484
</Modal>
8585

8686
<!-- Modal for Viewing Image -->
@@ -121,7 +121,6 @@ const showModal = ref(false);
121121
const showImageModal = ref(false);
122122
const selectedImage = ref(null);
123123
const errors = ref({});
124-
const isProgressing = ref(false);
125124
126125
const truncate = (text, length) => {
127126
if (text.length <= length) {
@@ -170,22 +169,28 @@ const openImageModal = (image) => {
170169
showImageModal.value = true;
171170
};
172171
172+
const isProgressing = ref(false);
173+
173174
const submitForm = (formData) => {
175+
isProgressing.value = true;
174176
router.post(route("images.store"), formData, {
175177
preserveScroll: true,
176178
onSuccess: () => {
177179
showModal.value = false;
178-
getRequestCount(); // Update request count after form submission
180+
isProgressing.value = false;
181+
getRequestCount();
179182
},
180183
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+
}
187191
} 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);
189194
}
190195
},
191196
});

0 commit comments

Comments
 (0)