Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user detail page switching does not take effect #4321

Merged
merged 1 commit into from Jul 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
25 changes: 19 additions & 6 deletions console/src/modules/system/users/layouts/UserProfileLayout.vue
Expand Up @@ -34,6 +34,7 @@ import { useQuery } from "@tanstack/vue-query";
import { useI18n } from "vue-i18n";
import { useFileDialog } from "@vueuse/core";
import { rbacAnnotations } from "@/constants/annotations";
import { onBeforeRouteUpdate } from "vue-router";
const UserAvatarCropper = defineAsyncComponent(
() => import("../components/UserAvatarCropper.vue")
Expand Down Expand Up @@ -69,21 +70,32 @@ const editingModal = ref(false);
const passwordChangeModal = ref(false);
const { params } = useRoute();
const name = ref();
onMounted(() => {
name.value = params.name;
});
// Update name when route change
onBeforeRouteUpdate((to, _, next) => {
name.value = to.params.name;
next();
});
const {
data: user,
isFetching,
isLoading,
refetch,
} = useQuery({
queryKey: ["user-detail", params.name],
queryKey: ["user-detail", name],
queryFn: async () => {
if (params.name === "-") {
if (name.value === "-") {
const { data } = await apiClient.user.getCurrentUserDetail();
return data;
} else {
const { data } = await apiClient.user.getUserDetail({
name: params.name as string,
name: name.value,
});
return data;
}
Expand All @@ -95,10 +107,11 @@ const {
? 1000
: false;
},
enabled: computed(() => !!name.value),
});
const isCurrentUser = computed(() => {
if (params.name === "-") {
if (name.value === "-") {
return true;
}
return (
Expand Down Expand Up @@ -155,7 +168,7 @@ const handleUploadAvatar = () => {
uploadSaving.value = true;
apiClient.user
.uploadUserAvatar({
name: params.name as string,
name: name.value,
file: file,
})
.then(() => {
Expand All @@ -181,7 +194,7 @@ const handleRemoveCurrentAvatar = () => {
onConfirm: async () => {
apiClient.user
.deleteUserAvatar({
name: params.name as string,
name: name.value as string,
})
.then(() => {
refetch();
Expand Down