From 01affca1daf523758c06f78dc559754570eb7e96 Mon Sep 17 00:00:00 2001 From: axolotle Date: Fri, 29 Dec 2023 15:59:07 +0100 Subject: [PATCH] edit: remove submit button disabled state --- components/SubmitButton.vue | 21 ++++----------------- components/UserInfoForm.vue | 9 ++++----- components/UserPasswordForm.vue | 5 ++--- components/YForm.vue | 2 +- 4 files changed, 11 insertions(+), 26 deletions(-) diff --git a/components/SubmitButton.vue b/components/SubmitButton.vue index c9328a1..473cc18 100644 --- a/components/SubmitButton.vue +++ b/components/SubmitButton.vue @@ -18,33 +18,20 @@ const attrs = computed(() => { props.loading === true ? props.loadingIcon || 'loading' : props.loading === false - ? 'thumb-up' - : props.icon, + ? 'thumb-up' + : props.icon, iconClass: props.loading ? 'animate-spin' : '', ...baseAttrs, } }) const onClick = (e: MouseEvent) => { - if (props.loading !== null) { + if (props.loading) { e.preventDefault() } } - - diff --git a/components/UserInfoForm.vue b/components/UserInfoForm.vue index 282f1ba..526e567 100644 --- a/components/UserInfoForm.vue +++ b/components/UserInfoForm.vue @@ -9,7 +9,7 @@ import type { Feedback } from '@/composables/form' const { t } = useI18n() const user = await useUser() -const loading: Ref = ref(false) +const loading: Ref = ref(false) const feedback: Ref = ref(null) const { handleSubmit, setFieldError, resetForm, meta } = useForm({ @@ -29,9 +29,8 @@ const { handleSubmit, setFieldError, resetForm, meta } = useForm({ watch( () => meta.value.dirty, (value) => { - // remove loading and feedback on edition + // remove global feedback on edition if (value) { - loading.value = null feedback.value = null } }, @@ -49,7 +48,7 @@ const onSubmit = handleSubmit(async (form) => { if (error.value) { // Reset form dirty state but keep previous values - resetForm({ values: form }) + resetForm({ values: { ...form, mail: user.value.mail } }) const errData = error.value.data let message @@ -67,7 +66,7 @@ const onSubmit = handleSubmit(async (form) => { } else if (data.value) { Object.assign(user.value, data) resetForm({ - values: data.value, + values: { ...data.value, mail: user.value.mail }, }) feedback.value = { variant: 'success', diff --git a/components/UserPasswordForm.vue b/components/UserPasswordForm.vue index fc736b9..b48a847 100644 --- a/components/UserPasswordForm.vue +++ b/components/UserPasswordForm.vue @@ -7,7 +7,7 @@ import type { Feedback } from '@/composables/form' const { t } = useI18n() -const loading: Ref = ref(false) +const loading: Ref = ref(false) const feedback: Ref = ref(null) const { handleSubmit, setFieldError, resetForm, meta } = useForm({ @@ -37,9 +37,8 @@ const { handleSubmit, setFieldError, resetForm, meta } = useForm({ watch( () => meta.value.dirty, (value) => { - // remove loading and feedback on edition + // remove global feedback on edition if (value) { - loading.value = null feedback.value = null } }, diff --git a/components/YForm.vue b/components/YForm.vue index eb34bd8..0bd5158 100644 --- a/components/YForm.vue +++ b/components/YForm.vue @@ -3,7 +3,7 @@ import type { Feedback } from '@/composables/form' withDefaults( defineProps<{ - loading: boolean | null + loading: boolean feedback?: Feedback submitVariant?: 'success' | 'warning' | 'error' }>(),