Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve UX for new households/users #4653

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion frontend/lang/messages/en-US.json
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,8 @@
"admin-group-management": "Admin Group Management",
"admin-group-management-text": "Changes to this group will be reflected immediately.",
"group-id-value": "Group Id: {0}",
"total-households": "Total Households"
"total-households": "Total Households",
"you-must-select-a-group-before-selecting-a-household": "You must select a group before selecting a household"
},
"household": {
"household": "Household",
Expand Down
51 changes: 34 additions & 17 deletions frontend/pages/admin/manage/households/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,29 @@
v-model="createDialog"
:title="$t('household.create-household')"
:icon="$globals.icons.household"
@submit="createHousehold(createHouseholdForm.data)"
>
<template #activator> </template>
<v-card-text>
<v-select
v-if="groups"
v-model="createHouseholdForm.data.groupId"
:items="groups"
rounded
class="rounded-lg"
item-text="name"
item-value="id"
:return-object="false"
filled
:label="$tc('household.household-group')"
:rules="[validators.required]"
/>
<AutoForm v-model="createHouseholdForm.data" :update-mode="updateMode" :items="createHouseholdForm.items" />
<v-form ref="refNewHouseholdForm">
<v-select
v-if="groups"
v-model="createHouseholdForm.data.groupId"
:items="groups"
rounded
class="rounded-lg"
item-text="name"
item-value="id"
:return-object="false"
filled
:label="$tc('household.household-group')"
:rules="[validators.required]"
/>
<AutoForm v-model="createHouseholdForm.data" :update-mode="updateMode" :items="createHouseholdForm.items" />
</v-form>
</v-card-text>
<template #custom-card-action>
<BaseButton type="submit" @click="handleCreateSubmit"> {{ $t("general.create") }} </BaseButton>
</template>
</BaseDialog>

<BaseDialog
Expand Down Expand Up @@ -92,23 +96,26 @@
</template>

<script lang="ts">
import { defineComponent, reactive, toRefs, useContext, useRouter } from "@nuxtjs/composition-api";
import { defineComponent, reactive, ref, toRefs, useContext, useRouter } from "@nuxtjs/composition-api";
import { fieldTypes } from "~/composables/forms";
import { useGroups } from "~/composables/use-groups";
import { useAdminHouseholds } from "~/composables/use-households";
import { validators } from "~/composables/use-validators";
import { HouseholdInDB } from "~/lib/api/types/household";
import { VForm } from "~/types/vuetify";

export default defineComponent({
layout: "admin",
setup() {
const { i18n } = useContext();
const { groups } = useGroups();
const { households, refreshAllHouseholds, deleteHousehold, createHousehold } = useAdminHouseholds();
const refNewHouseholdForm = ref<VForm | null>(null);

const state = reactive({
createDialog: false,
confirmDialog: false,
loading: false,
deleteTarget: 0,
search: "",
headers: [
Expand Down Expand Up @@ -153,14 +160,24 @@ export default defineComponent({
router.push(`/admin/manage/households/${item.id}`);
}

async function handleCreateSubmit() {
if (!refNewHouseholdForm.value?.validate()) {
return;
}

state.createDialog = false;
await createHousehold(state.createHouseholdForm.data);
}

return {
...toRefs(state),
refNewHouseholdForm,
groups,
households,
validators,
refreshAllHouseholds,
deleteHousehold,
createHousehold,
handleCreateSubmit,
openDialog,
handleRowClick,
};
Expand Down
5 changes: 3 additions & 2 deletions frontend/pages/admin/manage/users/create.vue
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<v-card outlined>
<v-card-text>
<v-select
v-if="groups"
v-model="selectedGroupId"
:items="groups"
rounded
Expand All @@ -24,8 +23,8 @@
:rules="[validators.required]"
/>
<v-select
v-if="households"
v-model="newUserData.household"
:disabled="!selectedGroupId"
:items="households"
rounded
class="rounded-lg"
Expand All @@ -34,6 +33,8 @@
:return-object="false"
filled
:label="$t('household.user-household')"
:hint="selectedGroupId ? '' : $tc('group.you-must-select-a-group-before-selecting-a-household')"
persistent-hint
:rules="[validators.required]"
/>
<AutoForm v-model="newUserData" :items="userForm" />
Expand Down
Loading