Skip to content

Commit

Permalink
refactor: add support to reset update email form
Browse files Browse the repository at this point in the history
  • Loading branch information
KabinKhandThakuri committed Jan 7, 2025
1 parent 5916e7b commit 163c67e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
9 changes: 8 additions & 1 deletion packages/vue-form/src/components/Form.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<template>
<Form class="form" @submit="onSubmit">
<Form ref="dzangolabVueForm" class="form" @submit="onSubmit">
<slot></slot>
</Form>
</template>
Expand All @@ -12,10 +12,17 @@ export default {

<script setup lang="ts">
import { Form } from "vee-validate";
import { ref } from "vue";
const emit = defineEmits(["submit"]);
const dzangolabVueForm = ref();
const onSubmit = (data: object) => {
emit("submit", data);
};
defineExpose({
resetForm: () => dzangolabVueForm.value?.resetForm(),
});
</script>
9 changes: 7 additions & 2 deletions packages/vue-user/src/components/profile/UpdateEmailForm.vue
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<template>
<Form @submit="onSubmit">
<Form ref="dzangolabVueUpdateEmail" @submit="onSubmit">
<Email
:error-messages="errorMessages"
:label="t('user.profile.accountInfo.newEmail')"
name="email"
/>

<FormActions :loading="loading" />
<FormActions
:loading="loading"
@cancel="dzangolabVueUpdateEmail.resetForm()"
/>
</Form>
</template>

Expand Down Expand Up @@ -41,6 +44,7 @@ const errorMessages = {
required: t("user.profile.accountInfo.messages.email"),
};
const dzangolabVueUpdateEmail = ref();
const loading = ref<boolean>(false);
const onSubmit = async (data: UpdateEmailFormData) => {
Expand Down Expand Up @@ -105,6 +109,7 @@ const onSubmit = async (data: UpdateEmailFormData) => {
}
}
dzangolabVueUpdateEmail.value?.resetForm();
loading.value = false;
} catch (error) {
emitter.emit("notify", {
Expand Down

0 comments on commit 163c67e

Please sign in to comment.