filebrowser/frontend/src/components/prompts/DeleteUser.vue

90 lines
2.2 KiB
Vue
Raw Normal View History

2024-06-12 19:51:13 +00:00
<template>
<div class="card floating">
<div class="card-content">
<p>Are you sure you want to delete this user?</p>
</div>
<div class="card-action">
<button
class="button button--flat button--grey"
@click="closeHovers"
v-focus
:aria-label="$t('buttons.cancel')"
:title="$t('buttons.cancel')"
>
{{ $t("buttons.cancel") }}
</button>
<button class="button button--flat" @click="deleteUser">
{{ $t("buttons.delete") }}
</button>
</div>
</div>
</template>
<script>
import { users as api } from "@/api";
2024-07-30 17:45:27 +00:00
import { showSuccess,showError } from "@/notify";
2024-06-12 19:51:13 +00:00
import buttons from "@/utils/buttons";
2024-07-30 17:45:27 +00:00
import { state, mutations, getters } from "@/store";
2024-06-12 19:51:13 +00:00
export default {
name: "delete",
computed: {
currentPrompt() {
2024-07-30 17:45:27 +00:00
return getters.currentPrompt();
2024-06-12 19:51:13 +00:00
},
user() {
return this.currentPrompt?.props?.user;
2024-07-30 17:45:27 +00:00
},
2024-06-12 19:51:13 +00:00
},
methods: {
async deleteUser(event) {
event.preventDefault();
try {
await api.remove(this.user.id);
this.$router.push({ path: "/settings/users" });
2024-07-30 17:45:27 +00:00
showSuccess(this.$t("settings.userDeleted"));
2024-06-12 19:51:13 +00:00
} catch (e) {
e.message === "403"
2024-07-30 17:45:27 +00:00
? showError(this.$t("errors.forbidden"), false)
: showError(e);
2024-06-12 19:51:13 +00:00
}
},
2024-07-30 17:45:27 +00:00
closeHovers() {
mutations.closeHovers();
},
2024-06-12 19:51:13 +00:00
submit: async function () {
buttons.loading("delete");
try {
if (!this.isListing) {
await api.remove(this.$route.path);
buttons.success("delete");
this.currentPrompt?.confirm();
this.closeHovers();
return;
}
this.closeHovers();
2024-07-30 17:45:27 +00:00
if (getters.selectedCount() === 0) {
2024-06-12 19:51:13 +00:00
return;
}
let promises = [];
for (let index of this.selected) {
2024-07-30 17:45:27 +00:00
promises.push(api.remove(state.req.items[index].url));
2024-06-12 19:51:13 +00:00
}
await Promise.all(promises);
buttons.success("delete");
2024-07-30 17:45:27 +00:00
mutations.setReload(true); // Handle reload as needed
2024-06-12 19:51:13 +00:00
} catch (e) {
buttons.done("delete");
2024-07-30 17:45:27 +00:00
showError(e);
if (this.isListing) mutations.setReload(true); // Handle reload as needed
2024-06-12 19:51:13 +00:00
}
},
},
};
</script>