1
0
Fork 0
mirror of https://github.com/mealie-recipes/mealie.git synced 2025-07-23 23:29:41 +02:00
mealie/frontend/pages/admin/manage/households/[id].vue

140 lines
3.7 KiB
Vue
Raw Permalink Normal View History

2024-08-22 10:14:32 -05:00
<template>
<v-container
v-if="household"
class="narrow-container"
>
2024-08-22 10:14:32 -05:00
<BasePageTitle>
<template #header>
<v-img
width="100%"
max-height="125"
max-width="125"
:src="require('~/static/svgs/manage-group-settings.svg')"
/>
</template>
<template #title>
{{ $t('household.admin-household-management') }}
2024-08-22 10:14:32 -05:00
</template>
{{ $t('household.admin-household-management-text') }}
</BasePageTitle>
<AppToolbar back />
2024-08-22 10:14:32 -05:00
<v-card-text> {{ $t('household.household-id-value', [household.id]) }} </v-card-text>
<v-form
v-if="!userError"
ref="refHouseholdEditForm"
@submit.prevent="handleSubmit"
>
<v-card variant="outlined" style="border-color: lightgrey;">
2024-08-22 10:14:32 -05:00
<v-card-text>
<v-select
v-if="groups"
v-model="household.groupId"
disabled
:items="groups"
variant="solo-filled"
flat
item-title="name"
2024-08-22 10:14:32 -05:00
item-value="id"
:return-object="false"
:label="$t('group.user-group')"
2024-08-22 10:14:32 -05:00
:rules="[validators.required]"
/>
<v-text-field
v-model="household.name"
variant="solo-filled"
flat
2024-08-22 10:14:32 -05:00
:label="$t('household.household-name')"
:rules="[validators.required]"
/>
<HouseholdPreferencesEditor
v-if="household.preferences"
v-model="household.preferences"
variant="solo-filled"
flat
/>
2024-08-22 10:14:32 -05:00
</v-card-text>
</v-card>
<div class="d-flex pa-2">
<BaseButton
type="submit"
edit
class="ml-auto"
>
{{ $t("general.update") }}
</BaseButton>
2024-08-22 10:14:32 -05:00
</div>
</v-form>
</v-container>
</template>
<script lang="ts">
import HouseholdPreferencesEditor from "~/components/Domain/Household/HouseholdPreferencesEditor.vue";
import { useGroups } from "~/composables/use-groups";
import { useAdminApi } from "~/composables/api";
2024-08-22 10:14:32 -05:00
import { alert } from "~/composables/use-toast";
import { validators } from "~/composables/use-validators";
export default defineNuxtComponent({
2024-08-22 10:14:32 -05:00
components: {
HouseholdPreferencesEditor,
2024-08-22 10:14:32 -05:00
},
setup() {
definePageMeta({
layout: "admin",
});
2024-08-22 10:14:32 -05:00
const route = useRoute();
const i18n = useI18n();
2024-08-22 10:14:32 -05:00
const { groups } = useGroups();
const householdId = computed(() => route.params.id as string);
2024-08-22 10:14:32 -05:00
// ==============================================
// New User Form
const refHouseholdEditForm = ref<VForm | null>(null);
const adminApi = useAdminApi();
2024-08-22 10:14:32 -05:00
const userError = ref(false);
const { data: household } = useAsyncData(`get-household-${householdId.value}`, async () => {
if (!householdId.value) {
return null;
}
const { data, error } = await adminApi.households.getOne(householdId.value);
2024-08-22 10:14:32 -05:00
if (error?.response?.status === 404) {
alert.error(i18n.t("user.user-not-found"));
2024-08-22 10:14:32 -05:00
userError.value = true;
}
return data;
}, { watch: [householdId] });
2024-08-22 10:14:32 -05:00
async function handleSubmit() {
if (!refHouseholdEditForm.value?.validate() || household.value === null) {
return;
}
const { response, data } = await adminApi.households.updateOne(household.value.id, household.value);
2024-08-22 10:14:32 -05:00
if (response?.status === 200 && data) {
household.value = data;
alert.success(i18n.t("settings.settings-updated"));
}
else {
alert.error(i18n.t("settings.settings-update-failed"));
2024-08-22 10:14:32 -05:00
}
}
return {
groups,
household,
validators,
userError,
refHouseholdEditForm,
handleSubmit,
};
},
});
</script>