implemented submission guard for promotion form
This commit is contained in:
@@ -31,8 +31,12 @@ const { handleSubmit, errors, values, resetForm, setFieldValue, submitCount } =
|
|||||||
validateOnMount: false,
|
validateOnMount: false,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
const submitting = ref(false);
|
||||||
|
|
||||||
const submitForm = handleSubmit(
|
const submitForm = handleSubmit(
|
||||||
async (vals) => {
|
async (vals) => {
|
||||||
|
if (submitting.value) return;
|
||||||
|
submitting.value = true;
|
||||||
try {
|
try {
|
||||||
let output = vals;
|
let output = vals;
|
||||||
output.promotions.map(p => p.start_date = new Date(p.start_date).toISOString())
|
output.promotions.map(p => p.start_date = new Date(p.start_date).toISOString())
|
||||||
@@ -42,6 +46,8 @@ const submitForm = handleSubmit(
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
submitError.value = error;
|
submitError.value = error;
|
||||||
console.error(error);
|
console.error(error);
|
||||||
|
} finally {
|
||||||
|
submitting.value = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -281,7 +287,12 @@ function setAllToday() {
|
|||||||
</VeeField>
|
</VeeField>
|
||||||
<div class="flex flex-col items-end gap-2">
|
<div class="flex flex-col items-end gap-2">
|
||||||
<div class="h-6" />
|
<div class="h-6" />
|
||||||
<Button type="submit" class="w-min">Submit</Button>
|
<Button type="submit" form="trainingForm" :disabled="submitting" class="w-35">
|
||||||
|
<span class="flex items-center gap-2" v-if="submitting">
|
||||||
|
<Spinner></Spinner> Submitting…
|
||||||
|
</span>
|
||||||
|
<span v-else>Submit</span>
|
||||||
|
</Button>
|
||||||
<p v-if="submitError" class="text-destructive">{{ submitError }}</p>
|
<p v-if="submitError" class="text-destructive">{{ submitError }}</p>
|
||||||
<div v-else class="h-6 flex justify-end">
|
<div v-else class="h-6 flex justify-end">
|
||||||
<p v-if="submitCount > 0 && errors.promotions && typeof errors.promotions === 'string'"
|
<p v-if="submitCount > 0 && errors.promotions && typeof errors.promotions === 'string'"
|
||||||
|
|||||||
Reference in New Issue
Block a user