Skip to content

Commit

Permalink
fix user count not updated on front-end when creating new users (#2823)
Browse files Browse the repository at this point in the history
  • Loading branch information
ildyria authored Dec 17, 2024
1 parent 82909d7 commit 842aec9
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
4 changes: 4 additions & 0 deletions resources/js/components/forms/users/CreateEditUser.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { useLycheeStateStore } from "@/stores/LycheeState";
import { storeToRefs } from "pinia";
import Textarea from "../basic/Textarea.vue";
import SETag from "@/components/icons/SETag.vue";
import UsersService from "@/services/users-service";
const lycheeStore = useLycheeStateStore();
const { is_se_preview_enabled, is_se_enabled } = storeToRefs(lycheeStore);
Expand Down Expand Up @@ -120,6 +121,9 @@ function createUser() {
quota_kb.value = "0";
toast.add({ severity: "success", summary: "Success", detail: "User created", life: 3000 });
emits("refresh");
// Clear user count as it is cachable.
UsersService.clearCount();
})
.catch((e) => {
toast.add({ severity: "error", summary: "Error", detail: e.response.data.message, life: 3000 });
Expand Down
9 changes: 8 additions & 1 deletion resources/js/services/users-service.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import axios, { type AxiosResponse } from "axios";
import Constants from "./constants";
import { AxiosCacheInstance } from "axios-cache-interceptor";

const UsersService = {
clearCount(): void {
const axiosWithCache = axios as unknown as AxiosCacheInstance;
axiosWithCache.storage.remove("users::count");
},

count(): Promise<AxiosResponse<number>> {
return axios.get(`${Constants.getApiUrl()}Users::count`, { data: {} });
const requester = axios as unknown as AxiosCacheInstance;
return requester.get(`${Constants.getApiUrl()}Users::count`, { data: {}, id: "users::count" });
},

get(): Promise<AxiosResponse<App.Http.Resources.Models.LightUserResource[]>> {
Expand Down
5 changes: 5 additions & 0 deletions resources/js/views/Users.vue
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import { useToast } from "primevue/usetoast";
import { storeToRefs } from "pinia";
import { useLycheeStateStore } from "@/stores/LycheeState";
import OpenLeftMenu from "@/components/headers/OpenLeftMenu.vue";
import UsersService from "@/services/users-service";
const lycheeStore = useLycheeStateStore();
lycheeStore.init();
Expand All @@ -98,6 +99,10 @@ function load() {
function deleteUser(id: number) {
UserManagementService.delete({ id: id }).then(() => {
toast.add({ severity: "success", summary: "Success", detail: "User deleted" });
// Clear user count as it is cachable.
UsersService.clearCount();
load();
});
}
Expand Down

0 comments on commit 842aec9

Please sign in to comment.