2024-08-22 10:14:32 -05:00
|
|
|
<template>
|
|
|
|
<v-container fluid>
|
|
|
|
<BaseDialog
|
|
|
|
v-model="createDialog"
|
|
|
|
:title="$t('household.create-household')"
|
|
|
|
:icon="$globals.icons.household"
|
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #activator />
|
2024-08-22 10:14:32 -05:00
|
|
|
<v-card-text>
|
2024-12-02 10:14:28 -06:00
|
|
|
<v-form ref="refNewHouseholdForm">
|
|
|
|
<v-select
|
|
|
|
v-if="groups"
|
|
|
|
v-model="createHouseholdForm.data.groupId"
|
|
|
|
:items="groups"
|
2025-06-20 00:09:12 +07:00
|
|
|
item-title="name"
|
2024-12-02 10:14:28 -06:00
|
|
|
item-value="id"
|
2025-06-20 00:09:12 +07:00
|
|
|
variant="filled"
|
|
|
|
:label="$t('household.household-group')"
|
2024-12-02 10:14:28 -06:00
|
|
|
:rules="[validators.required]"
|
|
|
|
/>
|
2025-06-20 00:09:12 +07:00
|
|
|
<AutoForm
|
|
|
|
v-model="createHouseholdForm.data"
|
|
|
|
:update-mode="updateMode"
|
|
|
|
:items="createHouseholdForm.items"
|
|
|
|
/>
|
2024-12-02 10:14:28 -06:00
|
|
|
</v-form>
|
2024-08-22 10:14:32 -05:00
|
|
|
</v-card-text>
|
2024-12-02 10:14:28 -06:00
|
|
|
<template #custom-card-action>
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseButton
|
|
|
|
type="submit"
|
|
|
|
@click="handleCreateSubmit"
|
|
|
|
>
|
|
|
|
{{ $t("general.create") }}
|
|
|
|
</BaseButton>
|
2024-12-02 10:14:28 -06:00
|
|
|
</template>
|
2024-08-22 10:14:32 -05:00
|
|
|
</BaseDialog>
|
|
|
|
|
|
|
|
<BaseDialog
|
|
|
|
v-model="confirmDialog"
|
|
|
|
:title="$t('general.confirm')"
|
|
|
|
color="error"
|
2025-06-20 00:09:12 +07:00
|
|
|
can-confirm
|
2024-08-22 10:14:32 -05:00
|
|
|
@confirm="deleteHousehold(deleteTarget)"
|
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #activator />
|
2024-08-22 10:14:32 -05:00
|
|
|
<v-card-text>
|
|
|
|
{{ $t("general.confirm-delete-generic") }}
|
|
|
|
</v-card-text>
|
|
|
|
</BaseDialog>
|
|
|
|
|
2025-06-20 00:09:12 +07:00
|
|
|
<BaseCardSectionTitle :title="$t('household.household-management')" />
|
2024-08-22 10:14:32 -05:00
|
|
|
<section>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-toolbar
|
|
|
|
flat
|
|
|
|
color="transparent"
|
|
|
|
class="justify-between"
|
|
|
|
>
|
|
|
|
<BaseButton @click="openDialog">
|
|
|
|
{{ $t("general.create") }}
|
|
|
|
</BaseButton>
|
2024-08-22 10:14:32 -05:00
|
|
|
</v-toolbar>
|
|
|
|
|
|
|
|
<v-data-table
|
2025-06-20 00:09:12 +07:00
|
|
|
v-if="headers && households"
|
2024-08-22 10:14:32 -05:00
|
|
|
:headers="headers"
|
2025-06-20 00:09:12 +07:00
|
|
|
:items="households"
|
2024-08-22 10:14:32 -05:00
|
|
|
item-key="id"
|
|
|
|
class="elevation-0"
|
|
|
|
hide-default-footer
|
|
|
|
disable-pagination
|
|
|
|
:search="search"
|
2025-06-20 00:09:12 +07:00
|
|
|
@click:row="($event, { item }) => handleRowClick(item)"
|
2024-08-22 10:14:32 -05:00
|
|
|
>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.users`]="{ item }">
|
|
|
|
{{ item.users?.length }}
|
2024-08-22 10:14:32 -05:00
|
|
|
</template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.group`]="{ item }">
|
2024-08-22 10:14:32 -05:00
|
|
|
{{ item.group }}
|
|
|
|
</template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.webhookEnable`]="{ item }">
|
|
|
|
{{ item.webhooks!.length > 0 ? $t("general.yes") : $t("general.no") }}
|
2024-08-22 10:14:32 -05:00
|
|
|
</template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<template #[`item.actions`]="{ item }">
|
|
|
|
<v-tooltip
|
|
|
|
bottom
|
|
|
|
:disabled="!(item && item.users!.length > 0)"
|
|
|
|
>
|
|
|
|
<template #activator="{ props }">
|
|
|
|
<div v-bind="props">
|
2024-10-22 17:45:21 +02:00
|
|
|
<v-btn
|
2025-06-20 00:09:12 +07:00
|
|
|
:disabled="item && item.users!.length > 0"
|
2024-10-22 17:45:21 +02:00
|
|
|
class="mr-1"
|
|
|
|
icon
|
|
|
|
color="error"
|
2025-06-20 00:09:12 +07:00
|
|
|
variant="text"
|
2025-07-13 15:57:28 +02:00
|
|
|
@click.stop="confirmDialog = true; deleteTarget = item.id"
|
2024-10-22 17:45:21 +02:00
|
|
|
>
|
|
|
|
<v-icon>
|
|
|
|
{{ $globals.icons.delete }}
|
|
|
|
</v-icon>
|
|
|
|
</v-btn>
|
|
|
|
</div>
|
|
|
|
</template>
|
2025-06-20 00:09:12 +07:00
|
|
|
<span>{{ $t("admin.household-delete-note") }}</span>
|
2024-10-22 17:45:21 +02:00
|
|
|
</v-tooltip>
|
2024-08-22 10:14:32 -05:00
|
|
|
</template>
|
|
|
|
</v-data-table>
|
2025-06-20 00:09:12 +07:00
|
|
|
<v-divider />
|
2024-08-22 10:14:32 -05:00
|
|
|
</section>
|
|
|
|
</v-container>
|
|
|
|
</template>
|
|
|
|
|
2025-07-13 15:57:28 +02:00
|
|
|
<script setup lang="ts">
|
2024-08-22 10:14:32 -05:00
|
|
|
import { fieldTypes } from "~/composables/forms";
|
|
|
|
import { useGroups } from "~/composables/use-groups";
|
2024-09-22 09:59:20 -05:00
|
|
|
import { useAdminHouseholds } from "~/composables/use-households";
|
2024-08-22 10:14:32 -05:00
|
|
|
import { validators } from "~/composables/use-validators";
|
2025-06-20 00:09:12 +07:00
|
|
|
import type { HouseholdInDB } from "~/lib/api/types/household";
|
|
|
|
import type { VForm } from "~/types/auto-forms";
|
2024-08-22 10:14:32 -05:00
|
|
|
|
2025-07-13 15:57:28 +02:00
|
|
|
definePageMeta({
|
|
|
|
layout: "admin",
|
|
|
|
});
|
|
|
|
|
|
|
|
const i18n = useI18n();
|
|
|
|
|
|
|
|
useSeoMeta({
|
|
|
|
title: i18n.t("household.manage-households"),
|
|
|
|
});
|
|
|
|
|
|
|
|
const { groups } = useGroups();
|
|
|
|
const { households, deleteHousehold, createHousehold } = useAdminHouseholds();
|
|
|
|
|
|
|
|
const refNewHouseholdForm = ref<VForm | null>(null);
|
|
|
|
|
|
|
|
const createDialog = ref(false);
|
|
|
|
const confirmDialog = ref(false);
|
|
|
|
const deleteTarget = ref<string>("");
|
|
|
|
const search = ref("");
|
|
|
|
const updateMode = ref(false);
|
|
|
|
|
|
|
|
const headers = [
|
|
|
|
{
|
|
|
|
title: i18n.t("household.household"),
|
|
|
|
align: "start",
|
|
|
|
sortable: false,
|
|
|
|
value: "id",
|
|
|
|
},
|
|
|
|
{ title: i18n.t("general.name"), value: "name" },
|
|
|
|
{ title: i18n.t("group.group"), value: "group" },
|
|
|
|
{ title: i18n.t("user.total-users"), value: "users" },
|
|
|
|
{ title: i18n.t("user.webhooks-enabled"), value: "webhookEnable" },
|
|
|
|
{ title: i18n.t("general.delete"), value: "actions" },
|
|
|
|
];
|
|
|
|
|
|
|
|
const createHouseholdForm = reactive({
|
|
|
|
items: [
|
|
|
|
{
|
|
|
|
label: i18n.t("household.household-name"),
|
|
|
|
varName: "name",
|
|
|
|
type: fieldTypes.TEXT,
|
|
|
|
rules: ["required"],
|
|
|
|
},
|
|
|
|
],
|
|
|
|
data: {
|
|
|
|
groupId: "",
|
|
|
|
name: "",
|
2024-08-22 10:14:32 -05:00
|
|
|
},
|
|
|
|
});
|
2025-07-13 15:57:28 +02:00
|
|
|
|
|
|
|
function openDialog() {
|
|
|
|
createDialog.value = true;
|
|
|
|
createHouseholdForm.data.name = "";
|
|
|
|
createHouseholdForm.data.groupId = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
const router = useRouter();
|
|
|
|
|
|
|
|
function handleRowClick(item: HouseholdInDB) {
|
|
|
|
router.push(`/admin/manage/households/${item.id}`);
|
|
|
|
}
|
|
|
|
|
|
|
|
async function handleCreateSubmit() {
|
|
|
|
if (!refNewHouseholdForm.value?.validate()) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
createDialog.value = false;
|
|
|
|
await createHousehold(createHouseholdForm.data);
|
|
|
|
}
|
2024-08-22 10:14:32 -05:00
|
|
|
</script>
|