2021-11-23 18:57:24 -09:00
|
|
|
<template>
|
|
|
|
<v-container fluid>
|
2024-11-12 04:30:08 +01:00
|
|
|
<UserInviteDialog v-model="inviteDialog" />
|
2023-01-07 11:30:45 -08:00
|
|
|
<BaseDialog
|
|
|
|
v-model="deleteDialog"
|
2025-06-20 00:09:12 +07:00
|
|
|
:title="$t('general.confirm')"
|
2023-01-07 11:30:45 -08:00
|
|
|
color="error"
|
2025-06-20 00:09:12 +07:00
|
|
|
can-confirm
|
2023-01-07 11:30:45 -08:00
|
|
|
@confirm="deleteUser(deleteTargetId)"
|
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #activator />
|
2022-12-01 06:26:50 +01:00
|
|
|
|
2023-01-07 11:30:45 -08:00
|
|
|
<v-card-text>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-alert
|
|
|
|
v-if="isUserOwnAccount"
|
|
|
|
type="warning"
|
|
|
|
:text="$t('general.confirm-delete-own-admin-account')"
|
|
|
|
variant="outlined"
|
|
|
|
/>
|
2021-11-25 14:17:02 -09:00
|
|
|
{{ $t("general.confirm-delete-generic") }}
|
|
|
|
</v-card-text>
|
|
|
|
</BaseDialog>
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseCardSectionTitle :title="$t('user.user-management')" />
|
2021-11-23 18:57:24 -09:00
|
|
|
<section>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-toolbar
|
|
|
|
color="transparent"
|
|
|
|
flat
|
|
|
|
class="justify-between"
|
|
|
|
>
|
|
|
|
<BaseButton
|
|
|
|
to="/admin/manage/users/create"
|
|
|
|
class="mr-2"
|
|
|
|
>
|
2021-11-23 18:57:24 -09:00
|
|
|
{{ $t("general.create") }}
|
|
|
|
</BaseButton>
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseButton
|
|
|
|
class="mr-2"
|
|
|
|
color="info"
|
|
|
|
:icon="$globals.icons.link"
|
|
|
|
@click="inviteDialog = true"
|
|
|
|
>
|
2024-11-12 04:30:08 +01:00
|
|
|
{{ $t("group.invite") }}
|
|
|
|
</BaseButton>
|
2022-08-13 13:18:12 -08:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseOverflowButton
|
|
|
|
mode="event"
|
|
|
|
variant="elevated"
|
|
|
|
:items="ACTIONS_OPTIONS"
|
|
|
|
@unlock-all-users="unlockAllUsers"
|
|
|
|
/>
|
2021-11-23 18:57:24 -09:00
|
|
|
</v-toolbar>
|
|
|
|
<v-data-table
|
|
|
|
:headers="headers"
|
|
|
|
:items="users || []"
|
|
|
|
item-key="id"
|
|
|
|
class="elevation-0"
|
|
|
|
elevation="0"
|
|
|
|
hide-default-footer
|
|
|
|
disable-pagination
|
|
|
|
:search="search"
|
2025-06-20 00:09:12 +07:00
|
|
|
@click:row="($event, { item }) => handleRowClick(item)"
|
2021-11-23 18:57:24 -09:00
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.admin`]="{ item }">
|
|
|
|
<v-icon
|
|
|
|
end
|
|
|
|
:color="item.admin ? 'success' : undefined"
|
|
|
|
>
|
2021-11-23 18:57:24 -09:00
|
|
|
{{ item.admin ? $globals.icons.checkboxMarkedCircle : $globals.icons.windowClose }}
|
|
|
|
</v-icon>
|
|
|
|
</template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.actions`]="{ item }">
|
2021-11-25 14:17:02 -09:00
|
|
|
<v-btn
|
|
|
|
icon
|
2025-06-20 00:09:12 +07:00
|
|
|
:disabled="+item.id == 1"
|
2021-11-25 14:17:02 -09:00
|
|
|
color="error"
|
2025-06-20 00:09:12 +07:00
|
|
|
variant="text"
|
2021-11-25 14:17:02 -09:00
|
|
|
@click.stop="
|
|
|
|
deleteDialog = true;
|
2023-01-07 11:30:45 -08:00
|
|
|
deleteTargetId = item.id;
|
|
|
|
"
|
2021-11-25 14:17:02 -09:00
|
|
|
>
|
|
|
|
<v-icon>
|
|
|
|
{{ $globals.icons.delete }}
|
|
|
|
</v-icon>
|
|
|
|
</v-btn>
|
2021-11-23 18:57:24 -09:00
|
|
|
</template>
|
|
|
|
</v-data-table>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-divider />
|
2021-11-23 18:57:24 -09:00
|
|
|
</section>
|
|
|
|
</v-container>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2022-08-13 13:18:12 -08:00
|
|
|
import { useAdminApi } from "~/composables/api";
|
|
|
|
import { alert } from "~/composables/use-toast";
|
2021-11-23 18:57:24 -09:00
|
|
|
import { useUser, useAllUsers } from "~/composables/use-user";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { UserOut } from "~/lib/api/types/user";
|
2024-11-12 04:30:08 +01:00
|
|
|
import UserInviteDialog from "~/components/Domain/User/UserInviteDialog.vue";
|
2021-11-23 18:57:24 -09:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
export default defineNuxtComponent({
|
2024-11-12 04:30:08 +01:00
|
|
|
components: {
|
|
|
|
UserInviteDialog,
|
|
|
|
},
|
2021-11-23 18:57:24 -09:00
|
|
|
setup() {
|
2025-06-20 00:09:12 +07:00
|
|
|
definePageMeta({
|
|
|
|
layout: "admin",
|
|
|
|
});
|
|
|
|
|
2022-08-13 13:18:12 -08:00
|
|
|
const api = useAdminApi();
|
2021-11-23 18:57:24 -09:00
|
|
|
const refUserDialog = ref();
|
2024-11-12 04:30:08 +01:00
|
|
|
const inviteDialog = ref();
|
2025-06-20 00:09:12 +07:00
|
|
|
const $auth = useMealieAuth();
|
2022-12-01 06:26:50 +01:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const user = computed(() => $auth.user.value);
|
2021-11-23 18:57:24 -09:00
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
const i18n = useI18n();
|
|
|
|
const { $globals } = useNuxtApp();
|
2021-11-23 18:57:24 -09:00
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
2023-01-07 11:30:45 -08:00
|
|
|
const isUserOwnAccount = computed(() => {
|
|
|
|
return state.deleteTargetId === user.value?.id;
|
|
|
|
});
|
|
|
|
|
2023-03-21 20:45:27 +01:00
|
|
|
const ACTIONS_OPTIONS = [
|
|
|
|
{
|
|
|
|
text: i18n.t("user.reset-locked-users"),
|
|
|
|
icon: $globals.icons.lock,
|
|
|
|
event: "unlock-all-users",
|
|
|
|
},
|
|
|
|
];
|
|
|
|
|
2021-11-23 18:57:24 -09:00
|
|
|
const state = reactive({
|
2021-11-25 14:17:02 -09:00
|
|
|
deleteDialog: false,
|
2023-01-07 11:30:45 -08:00
|
|
|
deleteTargetId: "",
|
2021-11-23 18:57:24 -09:00
|
|
|
search: "",
|
2024-11-12 04:30:08 +01:00
|
|
|
groups: [],
|
|
|
|
households: [],
|
|
|
|
sendTo: "",
|
2021-11-23 18:57:24 -09:00
|
|
|
});
|
|
|
|
|
|
|
|
const { users, refreshAllUsers } = useAllUsers();
|
2023-01-07 11:30:45 -08:00
|
|
|
const { loading, deleteUser: deleteUserMixin } = useUser(refreshAllUsers);
|
|
|
|
|
|
|
|
function deleteUser(id: string) {
|
|
|
|
deleteUserMixin(id);
|
|
|
|
|
|
|
|
if (isUserOwnAccount.value) {
|
2025-06-20 00:09:12 +07:00
|
|
|
$auth.refresh();
|
2023-01-07 11:30:45 -08:00
|
|
|
}
|
|
|
|
}
|
2021-11-23 18:57:24 -09:00
|
|
|
|
|
|
|
function handleRowClick(item: UserOut) {
|
2022-01-09 07:15:23 +01:00
|
|
|
router.push(`/admin/manage/users/${item.id}`);
|
2021-11-23 18:57:24 -09:00
|
|
|
}
|
|
|
|
|
|
|
|
// ==========================================================
|
|
|
|
// Constants / Non-reactive
|
|
|
|
|
|
|
|
const headers = [
|
|
|
|
{
|
2025-06-20 00:09:12 +07:00
|
|
|
title: i18n.t("user.user-id"),
|
2021-11-23 18:57:24 -09:00
|
|
|
align: "start",
|
|
|
|
value: "id",
|
|
|
|
},
|
2025-06-20 00:09:12 +07:00
|
|
|
{ title: i18n.t("user.username"), value: "username" },
|
|
|
|
{ title: i18n.t("user.full-name"), value: "fullName" },
|
|
|
|
{ title: i18n.t("user.email"), value: "email" },
|
|
|
|
{ title: i18n.t("group.group"), value: "group" },
|
|
|
|
{ title: i18n.t("household.household"), value: "household" },
|
|
|
|
{ title: i18n.t("user.auth-method"), value: "authMethod" },
|
|
|
|
{ title: i18n.t("user.admin"), value: "admin" },
|
|
|
|
{ title: i18n.t("general.delete"), value: "actions", sortable: false, align: "center" },
|
2021-11-23 18:57:24 -09:00
|
|
|
];
|
|
|
|
|
2022-08-13 13:18:12 -08:00
|
|
|
async function unlockAllUsers(): Promise<void> {
|
|
|
|
const { data } = await api.users.unlockAllUsers(true);
|
|
|
|
|
|
|
|
if (data) {
|
|
|
|
const unlocked = data.unlocked ?? 0;
|
|
|
|
|
|
|
|
alert.success(`${unlocked} user(s) unlocked`);
|
|
|
|
refreshAllUsers();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
useSeoMeta({
|
|
|
|
title: i18n.t("sidebar.manage-users"),
|
|
|
|
});
|
|
|
|
|
2021-11-23 18:57:24 -09:00
|
|
|
return {
|
2023-01-07 11:30:45 -08:00
|
|
|
isUserOwnAccount,
|
2022-08-13 13:18:12 -08:00
|
|
|
unlockAllUsers,
|
2021-11-23 18:57:24 -09:00
|
|
|
...toRefs(state),
|
|
|
|
headers,
|
|
|
|
deleteUser,
|
|
|
|
loading,
|
|
|
|
refUserDialog,
|
2024-11-12 04:30:08 +01:00
|
|
|
inviteDialog,
|
2021-11-23 18:57:24 -09:00
|
|
|
users,
|
2022-12-01 06:26:50 +01:00
|
|
|
user,
|
2021-11-23 18:57:24 -09:00
|
|
|
handleRowClick,
|
2023-03-21 20:45:27 +01:00
|
|
|
ACTIONS_OPTIONS,
|
2021-11-23 18:57:24 -09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
head() {
|
|
|
|
return {
|
2025-06-20 00:09:12 +07:00
|
|
|
title: useI18n().t("sidebar.manage-users"),
|
2021-11-23 18:57:24 -09:00
|
|
|
};
|
|
|
|
},
|
|
|
|
});
|
2022-01-09 07:15:23 +01:00
|
|
|
</script>
|