Skip to content

Commit

Permalink
Merge pull request #133 from moevm/128-fix-admin-workers-page
Browse files Browse the repository at this point in the history
128-fix-admin-workers-page
  • Loading branch information
D1mitrii authored Dec 23, 2024
2 parents 2286ec5 + 69bb05d commit ca094d8
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 10 deletions.
2 changes: 1 addition & 1 deletion backend/internal/models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type User struct {
UserCredentials `bson:",inline"`
UserInfo `bson:",inline"`
Addresses []*AddressWithTimestamp `json:"addresses,omitempty" bson:"addresses,omitempty"`
OrdersCount int `json:"orders_count,omitempty" bson:"orders_count,omitempty"`
OrdersCount int `json:"orders_count,omitempty" bson:"orders_count"`
UserType string `json:"user_type" bson:"user_type"`
Timestamp `json:",inline" bson:",inline"`
}
Expand Down
41 changes: 36 additions & 5 deletions frontend/src/components/admin/AdminWorkersSettingsPage.vue
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,29 @@ import WorkerItem from '../../ui/uikit/items/WorkerItem.vue'
import { filterWorkers } from '../../api/request'
import { FilterWorkers } from '../../api/models/filterWorkers'
const isCorrectCreateForm = ref<boolean>(false);
const rules = {
required: (value: any) => {
if (
newWorker.value.name &&
newWorker.value.surname &&
newWorker.value.phone_number &&
newWorker.value.password
) {
isCorrectCreateForm.value = true;
} else {
isCorrectCreateForm.value = false;
}
return !!value || 'Поле является обязательным'
},
email: (value: any) => {
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailRegex.test(value)) {
isCorrectCreateForm.value = false;
}
return emailRegex.test(value) || 'Введите корректный email'
},
}
const maxOrdersWorker = ref<number | null>(null);
const maxOrders = computed(() => maxOrdersWorker.value ?? 0);
Expand Down Expand Up @@ -93,9 +116,9 @@ async function fetchWorkersList() {
created_at: user.created_at,
updated_at: user.updated_at
}));
console.log('Workers:', workers.value);
if (maxOrdersWorker.value === null) {
maxOrdersWorker.value = Math.max(...workers.value.map(worker => worker.orders_count));
maxOrdersWorker.value = Math.max(...workers.value.map(worker => isNaN(worker.orders_count) ? 0 : worker.orders_count));
}
} catch (error) {
console.error("Failed to fetch workers list:", error);
Expand Down Expand Up @@ -135,7 +158,9 @@ async function handleCreateWorkerUser() {
}
function handleSearch(): void {
toggleDropdown()
if (isOpen.value) {
isOpen.value = false;
}
const filterParams = { ...filterWorker.value };
if (filterParams.created_at_begin) {
filterParams.created_at_begin = formatToRFC3339(filterParams.created_at_begin, false);
Expand Down Expand Up @@ -166,7 +191,6 @@ function handleSearch(): void {
}
function clearFilters() {
fetchWorkersList();
filterWorker.value = {
name: '',
surname: '',
Expand All @@ -179,6 +203,7 @@ function clearFilters() {
created_at_end: '',
};
ordersRange.value = [0, maxOrders.value];
fetchWorkersList();
}
onMounted(() => {
Expand Down Expand Up @@ -208,7 +233,7 @@ onMounted(() => {
<h3>Фильтры</h3>
<ActionButton
text="Очистить"
type="clear"
type="button"
color="#394cc2"
@click.stop="clearFilters"
></ActionButton>
Expand Down Expand Up @@ -288,12 +313,14 @@ onMounted(() => {
placeholder="Введите имя"
type="text"
label="Имя"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="newWorker.surname"
placeholder="Введите фамилию"
type="text"
label="Фамилия"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="newWorker.patronymic"
Expand All @@ -306,18 +333,21 @@ onMounted(() => {
placeholder="Введите телефон"
type="phonenumber"
label="Номер телефона"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="newWorker.email"
placeholder="Введите почту"
type="email"
label="Почта"
:rules="[rules.required, rules.email]"
></InputTextField>
<InputTextField
v-model="newWorker.password"
placeholder="Введите пароль"
type="password"
label="Пароль"
:rules="[rules.required]"
></InputTextField>
</template>
<template #footer>
Expand All @@ -334,6 +364,7 @@ onMounted(() => {
variant="flat"
color="#394cc2"
@click="handleCreateWorkerUser"
:disabled="!isCorrectCreateForm"
></ActionButton>
</template>
</Dialog>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/ui/model/textfield.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@ type TextField = {
class?: string,
placeholder?: string,
type?: string,
label: string
label: string,
rules?: any,
}

export default TextField;
4 changes: 3 additions & 1 deletion frontend/src/ui/uikit/inputs/InputTextField.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const props = withDefaults(defineProps<TextField>(), {
id: undefined,
class: undefined,
placeholder: undefined,
type: undefined
type: undefined,
rules: undefined,
})
</script>

Expand All @@ -19,6 +20,7 @@ const props = withDefaults(defineProps<TextField>(), {
rounded="xl"
:type="props.type"
:label="props.label"
:rules="props.rules"
clearable
>
<slot
Expand Down
33 changes: 31 additions & 2 deletions frontend/src/ui/uikit/items/WorkerItem.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,29 @@ import Dialog from '../Dialog.vue'
const emit = defineEmits(['update-worker']);
const isCorrectUpdateForm = ref<boolean>(false);
const rules = {
required: (value: any) => {
if (
editWorker.value.name &&
editWorker.value.surname &&
editWorker.value.phone_number
) {
isCorrectUpdateForm.value = true;
} else {
isCorrectUpdateForm.value = false;
}
return !!value || 'Поле является обязательным'
},
email: (value: any) => {
const emailRegex = /^[a-zA-Z0-9._-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$/;
if (!emailRegex.test(value)) {
isCorrectUpdateForm.value = false;
}
return emailRegex.test(value) || 'Введите корректный email'
},
}
const props = defineProps<{
worker: {
id: string;
Expand Down Expand Up @@ -98,8 +121,9 @@ function formatDate(date: Date) {
<template>
<div class="worker-item">
<p>{{ props.worker.surname }} {{ props.worker.name }} {{ props.worker.patronymic }}</p>
<p>email: {{ props.worker.email }}</p>
<p>Выполнено заказов: {{ props.worker.orders_count }}</p>
<p>E-mail: {{ props.worker.email }}</p>
<p>Номер телефона: {{ props.worker.phone_number }}</p>
<p>Выполнено заказов: {{ isNaN(props.worker.orders_count) ? 0 : props.worker.orders_count }}</p>
<p>На сервисе с {{ formatDate(new Date(props.worker.created_at)) }} года</p>
<div class="worker-edit">
<ActionButton
Expand All @@ -123,12 +147,14 @@ function formatDate(date: Date) {
placeholder="Введите имя"
type="text"
label="Имя"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="editWorker.surname"
placeholder="Введите фамилию"
type="text"
label="Фамилия"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="editWorker.patronymic"
Expand All @@ -141,12 +167,14 @@ function formatDate(date: Date) {
placeholder="Введите телефон"
type="phonenumber"
label="Номер телефона"
:rules="[rules.required]"
></InputTextField>
<InputTextField
v-model="editWorker.email"
placeholder="Введите почту"
type="email"
label="Почта"
:rules="[rules.required, rules.email]"
></InputTextField>
<InputTextField
v-model="editWorker.password"
Expand Down Expand Up @@ -176,6 +204,7 @@ function formatDate(date: Date) {
variant="flat"
color="#394cc2"
@click="handleUpdateWorker"
:disabled="!isCorrectUpdateForm"
></ActionButton>
</template>
</Dialog>
Expand Down

0 comments on commit ca094d8

Please sign in to comment.