diff --git a/frontend/src/components/admin/AddEmployeeModal.vue b/frontend/src/components/admin/AddEmployeeModal.vue index 7f445f5..e11c32b 100644 --- a/frontend/src/components/admin/AddEmployeeModal.vue +++ b/frontend/src/components/admin/AddEmployeeModal.vue @@ -126,6 +126,7 @@ export default { this.isLoading = true try { + console.log('Sending employee data:', this.formData) const response = await axios.post('/api/employees', this.formData, { headers: { Authorization: `Bearer ${localStorage.getItem('admin_token')}`, @@ -136,8 +137,11 @@ export default { } }) + console.log('Response:', response) + if (response.status === 307) { const redirectUrl = response.headers.location + console.log('Redirecting to:', redirectUrl) const finalResponse = await axios.post(redirectUrl, this.formData, { headers: { Authorization: `Bearer ${localStorage.getItem('admin_token')}`, @@ -145,6 +149,8 @@ export default { } }) + console.log('Final response:', finalResponse) + if (finalResponse.status === 200 || finalResponse.status === 201) { this.$emit('employee-added') this.closeModal() diff --git a/frontend/src/components/admin/EmployeesModal.vue b/frontend/src/components/admin/EmployeesModal.vue index 1701e20..30a1b62 100644 --- a/frontend/src/components/admin/EmployeesModal.vue +++ b/frontend/src/components/admin/EmployeesModal.vue @@ -118,8 +118,11 @@ export default { } else { this.employees = response.data } + + console.log('Fetched employees:', this.employees) // Для отладки } catch (error) { console.error('Error fetching employees:', error) + this.employees = [] } }, editEmployee(employee) { @@ -158,11 +161,17 @@ export default { } }, watch: { - isOpen(newVal) { - if (newVal) { - this.fetchEmployees() + isOpen: { + immediate: true, + handler(newVal) { + if (newVal) { + this.fetchEmployees() + } } } + }, + mounted() { + this.fetchEmployees() } } diff --git a/frontend/src/views/admin/AdminDashboardView.vue b/frontend/src/views/admin/AdminDashboardView.vue index 202f190..ab4636d 100644 --- a/frontend/src/views/admin/AdminDashboardView.vue +++ b/frontend/src/views/admin/AdminDashboardView.vue @@ -105,14 +105,33 @@ export default { methods: { async fetchStatistics() { try { - const response = await axios.get('/api/statistics', { + const response = await axios.get('/api/requests/statistics', { headers: { Authorization: `Bearer ${localStorage.getItem('admin_token')}` + }, + validateStatus: function (status) { + return status < 500 } }) - this.statistics = response.data + + if (response.status === 307) { + const redirectUrl = response.headers.location + const finalResponse = await axios.get(redirectUrl, { + headers: { + Authorization: `Bearer ${localStorage.getItem('admin_token')}` + } + }) + this.statistics = finalResponse.data + } else { + this.statistics = response.data + } } catch (error) { console.error('Error fetching statistics:', error) + this.statistics = { + total_requests: 0, + by_status: {}, + by_priority: {} + } } }, handleEmployeeAdded() { @@ -120,6 +139,15 @@ export default { if (this.showEmployeesModal && this.$refs.employeesModal) { this.$refs.employeesModal.fetchEmployees() } + // Также обновляем список, если окно закрыто + if (!this.showEmployeesModal) { + this.showEmployeesModal = true + this.$nextTick(() => { + if (this.$refs.employeesModal) { + this.$refs.employeesModal.fetchEmployees() + } + }) + } } }, async created() {