Skip to content

Commit

Permalink
Merge pull request #5165 from ruibaby/refactor/pat-creation-modal
Browse files Browse the repository at this point in the history
refactor: logic of pat creation modal
  • Loading branch information
JohnNiang authored Jan 11, 2024
2 parents 5f0ac9f + 9f2bed7 commit 5c00d9f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { useI18n } from "vue-i18n";
const queryClient = useQueryClient();
const { t } = useI18n();
const visible = defineModel({ type: Boolean, default: false });
const emit = defineEmits<{
(event: "close"): void;
}>();
const modal = ref();
const formState = ref<
Omit<PersonalAccessToken, "spec"> & {
spec: PatSpec;
Expand Down Expand Up @@ -71,7 +72,6 @@ const {
},
onSuccess(data) {
queryClient.invalidateQueries({ queryKey: ["personal-access-tokens"] });
visible.value = false;
emit("close");
setTimeout(() => {
Expand Down Expand Up @@ -100,7 +100,7 @@ const { copy } = useClipboard({

<template>
<VModal
v-model:visible="visible"
ref="modal"
:width="700"
:title="$t('core.uc_profile.pat.creation_modal.title')"
@close="emit('close')"
Expand Down Expand Up @@ -246,7 +246,7 @@ const { copy } = useClipboard({
:text="$t('core.common.buttons.submit')"
@submit="$formkit.submit('pat-creation-form')"
/>
<VButton @click="visible = false">
<VButton @click="modal.close()">
{{ $t("core.common.buttons.cancel_and_shortcut") }}
</VButton>
</VSpace>
Expand Down
25 changes: 3 additions & 22 deletions console/uc-src/modules/profile/tabs/PersonalAccessTokens.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import { apiClient } from "@/utils/api-client";
import type { PersonalAccessToken } from "@halo-dev/api-client";
import { useQuery } from "@tanstack/vue-query";
import PersonalAccessTokenCreationModal from "../components/PersonalAccessTokenCreationModal.vue";
import { nextTick } from "vue";
import PersonalAccessTokenListItem from "../components/PersonalAccessTokenListItem.vue";
const {
Expand All @@ -32,28 +31,11 @@ const {
},
});
// fixme: Refactor VModal component to simplify the code
// use v-if to control the visibility of the modal
const creationModal = ref(false);
const creationModalVisible = ref(false);
function handleOpenCreationModal() {
creationModal.value = true;
nextTick(() => {
creationModalVisible.value = true;
});
}
function onCreationModalClose() {
creationModalVisible.value = false;
setTimeout(() => {
creationModal.value = false;
}, 200);
}
</script>
<template>
<div v-if="pats?.length" class="my-5 flex justify-end">
<VButton type="secondary" @click="handleOpenCreationModal">
<VButton type="secondary" @click="creationModal = true">
<template #icon>
<IconAddCircle class="h-full w-full" />
</template>
Expand All @@ -73,7 +55,7 @@ function onCreationModalClose() {
<VButton @click="refetch">
{{ $t("core.common.buttons.refresh") }}
</VButton>
<VButton type="primary" @click="handleOpenCreationModal">
<VButton type="primary" @click="creationModal = true">
<template #icon>
<IconAddCircle class="h-full w-full" />
</template>
Expand All @@ -97,7 +79,6 @@ function onCreationModalClose() {

<PersonalAccessTokenCreationModal
v-if="creationModal"
v-model="creationModalVisible"
@close="onCreationModalClose"
@close="creationModal = false"
/>
</template>

0 comments on commit 5c00d9f

Please sign in to comment.