From 69bb05df55220f2645f0b90b76b61b1cda6cba8c Mon Sep 17 00:00:00 2001 From: unknown Date: Mon, 23 Dec 2024 18:29:58 +0300 Subject: [PATCH] fix: workers page --- backend/internal/models/user.go | 2 +- .../admin/AdminWorkersSettingsPage.vue | 41 ++++++++++++++++--- frontend/src/ui/model/textfield.ts | 3 +- .../src/ui/uikit/inputs/InputTextField.vue | 4 +- frontend/src/ui/uikit/items/WorkerItem.vue | 33 ++++++++++++++- 5 files changed, 73 insertions(+), 10 deletions(-) diff --git a/backend/internal/models/user.go b/backend/internal/models/user.go index aaaea66..12d160b 100644 --- a/backend/internal/models/user.go +++ b/backend/internal/models/user.go @@ -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"` } diff --git a/frontend/src/components/admin/AdminWorkersSettingsPage.vue b/frontend/src/components/admin/AdminWorkersSettingsPage.vue index 3339f3f..1e9677d 100644 --- a/frontend/src/components/admin/AdminWorkersSettingsPage.vue +++ b/frontend/src/components/admin/AdminWorkersSettingsPage.vue @@ -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(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(null); const maxOrders = computed(() => maxOrdersWorker.value ?? 0); @@ -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); @@ -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); @@ -166,7 +191,6 @@ function handleSearch(): void { } function clearFilters() { - fetchWorkersList(); filterWorker.value = { name: '', surname: '', @@ -179,6 +203,7 @@ function clearFilters() { created_at_end: '', }; ordersRange.value = [0, maxOrders.value]; + fetchWorkersList(); } onMounted(() => { @@ -208,7 +233,7 @@ onMounted(() => {

Фильтры

@@ -288,12 +313,14 @@ onMounted(() => { placeholder="Введите имя" type="text" label="Имя" + :rules="[rules.required]" > { placeholder="Введите телефон" type="phonenumber" label="Номер телефона" + :rules="[rules.required]" > diff --git a/frontend/src/ui/model/textfield.ts b/frontend/src/ui/model/textfield.ts index 4b5d737..96124cd 100644 --- a/frontend/src/ui/model/textfield.ts +++ b/frontend/src/ui/model/textfield.ts @@ -3,7 +3,8 @@ type TextField = { class?: string, placeholder?: string, type?: string, - label: string + label: string, + rules?: any, } export default TextField; \ No newline at end of file diff --git a/frontend/src/ui/uikit/inputs/InputTextField.vue b/frontend/src/ui/uikit/inputs/InputTextField.vue index c73feca..d48322f 100644 --- a/frontend/src/ui/uikit/inputs/InputTextField.vue +++ b/frontend/src/ui/uikit/inputs/InputTextField.vue @@ -6,7 +6,8 @@ const props = withDefaults(defineProps(), { id: undefined, class: undefined, placeholder: undefined, - type: undefined + type: undefined, + rules: undefined, }) @@ -19,6 +20,7 @@ const props = withDefaults(defineProps(), { rounded="xl" :type="props.type" :label="props.label" + :rules="props.rules" clearable > (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; @@ -98,8 +121,9 @@ function formatDate(date: Date) {