Merge pull request #5168 from ruibaby/refactor/email-verify-modal

refactor: logic of email verify modal
pull/5181/head
John Niang 2024-01-11 14:55:11 +08:00 committed by GitHub
commit 0462a4808c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 6 additions and 24 deletions

View File

@ -2,7 +2,7 @@
import { Toast, VButton, VSpace } from "@halo-dev/components"; import { Toast, VButton, VSpace } from "@halo-dev/components";
import { VModal } from "@halo-dev/components"; import { VModal } from "@halo-dev/components";
import { nextTick, onMounted, ref } from "vue"; import { ref } from "vue";
import { useMutation, useQueryClient } from "@tanstack/vue-query"; import { useMutation, useQueryClient } from "@tanstack/vue-query";
import { apiClient } from "@/utils/api-client"; import { apiClient } from "@/utils/api-client";
import { useUserStore } from "@/stores/user"; import { useUserStore } from "@/stores/user";
@ -19,24 +19,7 @@ const emit = defineEmits<{
(event: "close"): void; (event: "close"): void;
}>(); }>();
// fixme: refactor VModal component const modal = ref();
const shouldRender = ref(false);
const visible = ref(false);
onMounted(() => {
shouldRender.value = true;
nextTick(() => {
visible.value = true;
});
});
function onClose() {
visible.value = false;
setTimeout(() => {
shouldRender.value = false;
emit("close");
}, 200);
}
// count down // count down
const timer = ref(0); const timer = ref(0);
@ -111,7 +94,7 @@ const { mutate: verifyEmail, isLoading: isVerifying } = useMutation({
); );
queryClient.invalidateQueries({ queryKey: ["user-detail"] }); queryClient.invalidateQueries({ queryKey: ["user-detail"] });
fetchCurrentUser(); fetchCurrentUser();
onClose(); modal.value.close();
}, },
}); });
@ -122,14 +105,13 @@ function handleVerify(data: { code: string }) {
<template> <template>
<VModal <VModal
v-if="shouldRender" ref="modal"
v-model:visible="visible"
:title=" :title="
currentUser?.spec.emailVerified currentUser?.spec.emailVerified
? $t('core.uc_profile.email_verify_modal.titles.modify') ? $t('core.uc_profile.email_verify_modal.titles.modify')
: $t('core.uc_profile.email_verify_modal.titles.verify') : $t('core.uc_profile.email_verify_modal.titles.verify')
" "
@close="onClose" @close="emit('close')"
> >
<FormKit <FormKit
id="email-verify-form" id="email-verify-form"
@ -175,7 +157,7 @@ function handleVerify(data: { code: string }) {
> >
{{ $t("core.common.buttons.verify") }} {{ $t("core.common.buttons.verify") }}
</VButton> </VButton>
<VButton @click="emit('close')"> <VButton @click="modal.close()">
{{ $t("core.common.buttons.close_and_shortcut") }} {{ $t("core.common.buttons.close_and_shortcut") }}
</VButton> </VButton>
</VSpace> </VSpace>