Skip to content

Commit

Permalink
Fixed bug where users couldn't be created. #147
Browse files Browse the repository at this point in the history
  • Loading branch information
CodeNamedRobin committed Apr 3, 2024
1 parent 136ee25 commit b92a9d7
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 149 deletions.
13 changes: 12 additions & 1 deletion src/utils/validation-schema.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import { toTypedSchema } from "@vee-validate/yup";
import * as yup from "yup";
import { ref } from "vue";

export const userDetailsSchema = toTypedSchema(
yup.object({
firstName: yup.string().required(),
lastName: yup.string().required(),
email: yup.string().email(),
userType: yup.string().required(),
userType: yup.mixed().required(),
isActive: yup.boolean().required().default(true),
ofAge: yup.boolean().required().default(false),
canGoIntoDebt: yup.boolean().required().default(false),
Expand Down Expand Up @@ -37,3 +38,13 @@ export const editPinSchema = toTypedSchema(
pinConfirm: yup.string().required().oneOf([yup.ref('pin')], 'PINs must match'),
})
);

export const userTypes = ref([
{ name: 'MEMBER', value: 1 },
{ name: 'ORGAN', value: 2 },
{ name: 'VOUCHER', value: 3 },
{ name: 'LOCAL_USER', value: 4 },
{ name: 'LOCAL_ADMIN', value: 5 },
{ name: 'INVOICE', value: 6 },
{ name: 'AUTOMATIC_INVOICE', value: 7 },
]);
3 changes: 0 additions & 3 deletions src/views/ProductsContainersView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -252,9 +252,6 @@ const updateRow = async (event: DataTableRowEditSaveEvent) => {
const onImgUpload = async (event: Event, productId: number) => {
const el = (event.target as HTMLInputElement);
if(el == null || el.files == null) return;
console.log('uploading')
console.log(el.files[0])
console.log(productId)
await apiService.products.updateProductImage(productId, el.files[0]);
handleNewProduct();
}
Expand Down
4 changes: 3 additions & 1 deletion src/views/SingleUserView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ import BalanceComponent from "@/components/BalanceComponent.vue";
import { useForm } from "vee-validate";
import apiService from "@/services/ApiService";
import router from "@/router";
import { userDetailsSchema } from "@/utils/validation-schema";
import { userDetailsSchema, userTypes } from "@/utils/validation-schema";
import MutationsTableComponent from "@/components/Mutations/MutationsTableComponent.vue";
import { handleError } from "@/utils/errorUtils";
import { useToast } from "primevue/usetoast";
Expand Down Expand Up @@ -119,6 +119,8 @@ onBeforeMount(async () => {
await router.replace({ path: '/error' });
return;
}
console.error(currentUser.value.type);
console.error(currentUser.value.type);
isLocal.value = currentUser.value.type == "LOCAL_USER";
setValues({
firstName: currentUser.value?.firstName,
Expand Down
265 changes: 121 additions & 144 deletions src/views/UserOverView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,140 +2,128 @@
<div class="page-container">
<div class="page-title">{{ $t('app.User overview') }}</div>
<CardComponent :header="$t('app.User overview')" class="full-width">
<DataTable
v-model:filters="filters"
:value="sortedUsers.length > 0 ? sortedUsers : allUsersWithFullName"
paginator
:rows="10"
:rowsPerPageOptions="[5, 10, 25, 50, 100]"
filterDisplay="menu"
:globalFilterFields="['type', 'firstName', 'lastName', 'fullName']"
lazy
:totalRecords="sortedUsers.length > 0 ? sortedUsers.length : totalRecords"
:loading="loading"
@page="onPage($event)"
@sort="onSort()"
@filter="onFilter()"
>
<template #header>
<div class="flex flex-row gap-2">
<span class="p-input-icon-left search-box">
<i class="pi pi-search" />
<InputText v-model="searchQuery" :placeholder="$t('app.Search')" />
</span>
<span>
<Button @click="visible = true">{{ $t('app.Create') }}</Button>
</span>
</div>
</template>
<Column field="gewisId" header="GEWIS ID" />
<Column field="firstName" :header="$t('c_userTable.firstName')" />
<Column field="lastName" :header="$t('c_userTable.lastName')" />
<Column field="type" :header="$t('c_userTable.Type')" :showFilterMatchModes="false">
<template #filter="{ filterModel, filterCallback }">
<Dropdown
v-model="filterModel.value"
@change="filterCallback()"
:options="userTypes"
:placeholder="$t('c_userTable.Select Type')"
/>
</template>
</Column>
<Column field="active" :showFilterMatchModes="false">
<DataTable
v-model:filters="filters"
:value="sortedUsers.length > 0 ? sortedUsers : allUsersWithFullName"
paginator
:rows="10"
:rowsPerPageOptions="[5, 10, 25, 50, 100]"
filterDisplay="menu"
:globalFilterFields="['type', 'firstName', 'lastName', 'fullName']"
lazy
:totalRecords="sortedUsers.length > 0 ? sortedUsers.length : totalRecords"
:loading="loading"
@page="onPage($event)"
@sort="onSort"
@filter="onFilter"
>
<template #header>
<div class="flex flex-row gap-2 align-items-center">
{{ $t("userDetails.Active") }}
<Checkbox
v-model="isActiveFilter"
@change="onFilter()"
binary
/>
<div class="flex flex-row align-items-center justify-content-between">
<span class="p-input-icon-left">
<i class="pi pi-search" />
<InputText v-model="searchQuery" placeholder="Search..." />
</span>
<Button label="Create" icon="pi pi-plus" @click="visible = true" />
</div>
</template>
</Column>
<Column field="gewisId" header="GEWIS ID" />
<Column field="firstName" :header="$t('c_userTable.firstName')" />
<Column field="lastName" :header="$t('c_userTable.lastName')" />
<Column field="type" :header="$t('c_userTable.Type')" :showFilterMatchModes="false">
<template #filter="{ filterModel, filterCallback }">
<Dropdown
v-model="filterModel.value"
@change="filterCallback()"
:options="userTypes"
:placeholder="$t('c_userTable.Select Type')"
/>
</template>
</Column>
<Column field="active" :showFilterMatchModes="false">
<template #header>
<div class="flex flex-row gap-2 align-items-center">
{{ $t("userDetails.Active") }}
<Checkbox
v-model="isActiveFilter"
@change="onFilter()"
binary
/>
</div>
</template>
</Column>

<Column field="ofAge">
<template #header>
<div class="flex flex-row gap-2 align-items-center">
{{ $t('c_userTable.ofAge') }}
<Checkbox
v-model="ofAgeFilter"
@change="onFilter()"
binary
<Column field="ofAge">
<template #header>
<div class="flex flex-row gap-2 align-items-center">
{{ $t('c_userTable.ofAge') }}
<Checkbox
v-model="ofAgeFilter"
@change="onFilter()"
binary
/>
</div>
</template>
</Column>
<Column
headerStyle="width: 3rem; text-align: center"
bodyStyle="text-align: center; overflow: visible"
>
<template #body="slotProps">
<Button
@click="handleInfoPush(slotProps.data.id)"
type="button"
icon="pi pi-info-circle"
outlined
/>
</template>
</Column>
</DataTable>
<Dialog v-model:visible="visible" modal header="Create User" :style="{ width: '50vw' }" @hide="resetForm">
<form @submit.prevent="handleCreateUser" class="p-fluid">
<div class="field">
<label for="firstName">First Name</label>
<InputText id="firstName" v-model="firstName" v-bind="firstNameAttrs" />
<small class="p-error">{{ errors.firstName }}</small>
</div>
</template>
</Column>
<Column
headerStyle="width: 3rem; text-align: center"
bodyStyle="text-align: center; overflow: visible"
>
<template #body="slotProps">
<Button
@click="handleInfoPush(slotProps.data.id)"
type="button"
icon="pi pi-info-circle"
outlined
/>
</template>
</Column>
</DataTable>
<Dialog
class="w-auto flex w-9"
v-model:visible="visible"
modal
:header="$t('c_userTable.Create User')"
@after-hide="resetForm"
>
<form @submit="handleCreateUser">
<div class="field grid">
<label for="first-name" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('c_userTable.firstName') }}</label>
<div class="col-12 md:col-10">
<InputText v-bind="firstName" id="first-name" />
<span class="error-text">{{ errors.firstName }}</span>
<div class="field">
<label for="lastName">Last Name</label>
<InputText id="lastName" v-model="lastName" v-bind="lastNameAttrs" />
<small class="p-error">{{ errors.lastName }}</small>
</div>
</div>
<div class="field grid">
<label for="last-name" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('c_userTable.lastName') }}</label>
<div class="col-12 md:col-10">
<InputText v-bind="lastName" id="last-name"/>
<span class="error-text">{{ errors.lastName }}</span></div>
</div>
<div class="field grid">
<label for="user-type" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('c_userTable.User Type') }}</label>
<div class="col-12 md:col-10">
<div class="field">
<label for="userType">User Type</label>
<Dropdown
v-bind="userType"
id="userType"
v-model="userType"
v-bind="userTypeAttrs"
:options="userTypes"
:placeholder="$t('c_userTable.Select User Type')"
id="user-type"
optionLabel="name"
placeholder="Select a type"
optionValue="value"
/>
<span class="error-text">{{ errors.userType }}</span></div>
</div>
<div class="field grid">
<label for="email" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('profile.emailAddress') }}</label>
<div class="col-12 md:col-10">
<InputText v-bind="email" id="email"/>
<span class="error-text">{{ errors.email }}</span></div>
</div>
<div class="field grid">
<label for="ofAge" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('profile.ofAge') }}</label>
<div class="col-12 md:col-10">
<Checkbox v-bind="ofAge" id="ofAge"/>
<span class="error-text">{{ errors.ofAge }}</span></div>
</div>
<div class="field grid">
<label for="canGoIntoDebt" class="col-12 mb-2 md:col-2 md:mb-0">{{ $t('profile.canGoIntoDebt') }}</label>
<div class="col-12 md:col-10">
<Checkbox v-bind="canGoIntoDebt" id="canGoIntoDebt"/>
<span class="error-text">{{ errors.canGoIntoDebt }}</span></div>
</div>
<div class="form-row" id="actions">
<Button outlined @click="visible = false">{{ $t('c_confirmationModal.Cancel' )}}</Button>
<Button type="submit">{{ $t('c_confirmationModal.Save' )}}</Button>
</div>
</form>
</Dialog>
<small class="p-error">{{ errors.userType }}</small>
</div>
<div class="field">
<label for="email">Email</label>
<InputText id="email" v-model="email" v-bind="emailAttrs" />
<small class="p-error">{{ errors.email }}</small>
</div>
<div class="field">
<label for="ofAge">Of Age</label>
<Checkbox id="ofAge" v-model="ofAge" v-bind="ofAgeAttrs" binary />
<small class="p-error">{{ errors.ofAge }}</small>
</div>
<div class="field">
<label for="canGoIntoDebt">Can Go Into Debt</label>
<Checkbox id="canGoIntoDebt" v-model="canGoIntoDebt" v-bind="canGoIntoDebtAttrs" binary />
<small class="p-error">{{ errors.canGoIntoDebt }}</small>
</div>
<div class="flex justify-content-end">
<Button label="Cancel" class="p-button-text" @click="visible = false" />
<Button label="Save" class="p-button-outlined" type="submit" />
</div>
</form>
</Dialog>
</CardComponent>
</div>
</template>
Expand All @@ -152,14 +140,14 @@ import Checkbox from "primevue/checkbox";
import Dropdown from 'primevue/dropdown';
import InputText from 'primevue/inputtext';
import router from '@/router';
import { userDetailsSchema } from '@/utils/validation-schema';
import { userDetailsSchema, userTypes } from "@/utils/validation-schema";
import { useForm } from 'vee-validate';
import Fuse from 'fuse.js';
import CardComponent from '@/components/CardComponent.vue';
const userStore = useUserStore();
const searchQuery: Ref<string> = ref('');
const { defineComponentBinds, handleSubmit, errors, resetForm } = useForm({
const { defineField, handleSubmit, errors, resetForm } = useForm({
validationSchema: userDetailsSchema,
});
Expand All @@ -168,12 +156,12 @@ const filters = ref({
type: { value: null, matchMode: FilterMatchMode.EQUALS },
});
const firstName = defineComponentBinds('firstName');
const lastName = defineComponentBinds('lastName');
const userType = defineComponentBinds('userType');
const email = defineComponentBinds('email');
const ofAge = defineComponentBinds('ofAge');
const canGoIntoDebt = defineComponentBinds('canGoIntoDebt');
const [firstName, firstNameAttrs] = defineField('firstName', {});
const [lastName, lastNameAttrs] = defineField('lastName', {});
const [userType, userTypeAttrs] = defineField('userType', {});
const [email, emailAttrs] = defineField('email', {});
const [ofAge, ofAgeAttrs] = defineField('ofAge', {});
const [canGoIntoDebt, canGoIntoDebtAttrs] = defineField('canGoIntoDebt', {});
const isActiveFilter: Ref<boolean> = ref(true);
Expand All @@ -191,19 +179,8 @@ const allUsersWithFullName: Ref<GewisUserResponse[]> = computed(() => {
});
});
const userTypes = [
'MEMBER',
'ORGAN',
'VOUCHER',
'LOCAL_USER',
'LOCAL_ADMIN',
'INVOICE',
'AUTOMATIC_INVOICE'
];
onMounted(() => {
delayedAPICall(0);
});
function debounce(func: (skip: number) => Promise<void>, delay: number): (skip: number) => Promise<void> {
Expand Down Expand Up @@ -262,7 +239,7 @@ const handleCreateUser = handleSubmit(async (values) => {
const createUserRequest: CreateUserRequest = {
firstName: values.firstName,
lastName: values.lastName,
type: userTypes.indexOf(values.userType),
type: values.userType,
email: values.email || '',
ofAge: values.ofAge,
canGoIntoDebt: values.canGoIntoDebt,
Expand Down

0 comments on commit b92a9d7

Please sign in to comment.