Added menthly order page
Deploy Frontend / build-and-deploy (push) Successful in 3m29s
Details
Deploy Frontend / build-and-deploy (push) Successful in 3m29s
Details
This commit is contained in:
parent
ecefa9a694
commit
95e0ad3fcd
File diff suppressed because it is too large
Load Diff
|
|
@ -21,6 +21,7 @@ import FlowTreePage from "@/pages/flowNodes/FlowTreePage.tsx"
|
|||
import FlowTreeGuidePage from './pages/flowNodes/FlowTreeGuidePage'
|
||||
import NotificationsPage from "@/pages/notifications/NotificationsPage.tsx"
|
||||
import AdminLogsPage from './pages/adminLogs/AdminLogsPage'
|
||||
import MonthlyOrdersSettingsPage from "@/pages/monthlyOrders/MonthlyOrdersSettingsPage.tsx";
|
||||
|
||||
const Placeholder = ({ title }: { title: string }) => (
|
||||
<div style={{ padding: 40 }}>
|
||||
|
|
@ -58,6 +59,7 @@ function App() {
|
|||
<Route path="/approval-dash" element={<Dashboard />} />
|
||||
<Route path="/nodes" element={<FlowTreePage />} />
|
||||
<Route path="/users" element={<UsersPage />} />
|
||||
<Route path="/monthly-orders-settings" element={<MonthlyOrdersSettingsPage />} />
|
||||
<Route path="/departments" element={<DepartmentsPage />} />
|
||||
<Route path="/roles" element={<RolesPage />} />
|
||||
<Route path="/approvals" element={<ApprovalsPage />} />
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ export interface CreateAdminRequest {
|
|||
name?: string
|
||||
is_root?: boolean
|
||||
is_observer?: boolean // 🆕
|
||||
is_analyst?: boolean
|
||||
telegram_id?: number // 🆕
|
||||
}
|
||||
|
||||
|
|
@ -22,6 +23,7 @@ export interface UpdateAdminRequest {
|
|||
is_blocked?: boolean
|
||||
is_root?: boolean
|
||||
is_observer?: boolean // 🆕
|
||||
is_analyst?: boolean
|
||||
telegram_id?: number | null // 🆕
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,10 @@
|
|||
import apiClient from './client'
|
||||
import type { MonthlyOrderSetting } from '@/types/api'
|
||||
|
||||
export const monthlyOrdersApi = {
|
||||
getSettings: () =>
|
||||
apiClient.get<MonthlyOrderSetting>('/monthly-orders/settings'),
|
||||
|
||||
saveSettings: (data: MonthlyOrderSetting) =>
|
||||
apiClient.post<{status: string}>('/monthly-orders/settings', data),
|
||||
}
|
||||
|
|
@ -18,7 +18,7 @@ import {
|
|||
IconCheck,
|
||||
IconBellRinging,
|
||||
IconBlocks,
|
||||
IconHistory,
|
||||
IconHistory, IconChartBar,
|
||||
} from '@tabler/icons-react'
|
||||
import { useLocation, useNavigate } from 'react-router-dom'
|
||||
import { useAuth } from '@/hooks/useAuth'
|
||||
|
|
@ -36,6 +36,13 @@ const menuItems: MenuItem[] = [
|
|||
{ label: 'Администраторы', icon: IconUserCog, path: '/admins', adminOnly: true },
|
||||
{ label: 'Уведомления', icon: IconBellRinging, path: '/notifications', adminOnly: true },
|
||||
{ label: 'Журнал действий', icon: IconHistory, path: '/logs', adminOnly: true },
|
||||
{
|
||||
label: 'Заказы на месяц',
|
||||
icon: IconChartBar,
|
||||
path: '/monthly-orders-settings',
|
||||
adminOnly: true, // Скрываем от наблюдателей
|
||||
// Если нужно скрыть от менеджеров, можно добавить флаг analystOnly: true и фильтровать
|
||||
},
|
||||
{
|
||||
label: 'Система согласований',
|
||||
icon: IconFileCheck,
|
||||
|
|
@ -164,6 +171,7 @@ function MenuItemLink({ item, level }: { item: MenuItem; level: number }) {
|
|||
export default function Sidebar() {
|
||||
const { user } = useAuth()
|
||||
const isObserver = user?.is_observer === true
|
||||
const isAnalyst = user?.is_analyst === true || user?.is_root === true
|
||||
|
||||
// 🆕 Фильтруем меню в зависимости от роли
|
||||
const filteredMenuItems = useMemo(
|
||||
|
|
|
|||
|
|
@ -0,0 +1,39 @@
|
|||
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query'
|
||||
import { monthlyOrdersApi } from '@/api/monthlyOrders'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import type { MonthlyOrderSetting } from '@/types/api'
|
||||
|
||||
export const MO_SETTINGS_QUERY_KEY = 'mo-settings'
|
||||
|
||||
export function useMonthlyOrderSettings() {
|
||||
return useQuery({
|
||||
queryKey: [MO_SETTINGS_QUERY_KEY],
|
||||
queryFn: async () => {
|
||||
const response = await monthlyOrdersApi.getSettings()
|
||||
return response.data
|
||||
},
|
||||
})
|
||||
}
|
||||
|
||||
export function useSaveMonthlyOrderSettings() {
|
||||
const queryClient = useQueryClient()
|
||||
|
||||
return useMutation({
|
||||
mutationFn: (data: MonthlyOrderSetting) => monthlyOrdersApi.saveSettings(data),
|
||||
onSuccess: () => {
|
||||
queryClient.invalidateQueries({ queryKey: [MO_SETTINGS_QUERY_KEY] })
|
||||
notifications.show({
|
||||
title: 'Успешно',
|
||||
message: 'Настройки заказов на месяц сохранены',
|
||||
color: 'green',
|
||||
})
|
||||
},
|
||||
onError: (error: any) => {
|
||||
notifications.show({
|
||||
title: 'Ошибка',
|
||||
message: error.response?.data?.error_description || 'Не удалось сохранить настройки',
|
||||
color: 'red',
|
||||
})
|
||||
},
|
||||
})
|
||||
}
|
||||
|
|
@ -24,7 +24,7 @@ import {
|
|||
IconLockOpen,
|
||||
IconPencil,
|
||||
IconShield,
|
||||
IconUser,
|
||||
IconUser, IconChartBar,
|
||||
} from '@tabler/icons-react'
|
||||
import { modals } from '@mantine/modals'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
|
|
@ -263,14 +263,19 @@ export default function AdminsPage() {
|
|||
ROOT
|
||||
</Badge>
|
||||
)}
|
||||
{admin.is_analyst && (
|
||||
<Badge size="xs" color="grape" variant="filled" leftSection={<IconChartBar size={10} />}>
|
||||
Аналитик
|
||||
</Badge>
|
||||
)}
|
||||
{admin.is_observer && (
|
||||
<Badge size="xs" color="blue" variant="filled" leftSection={<IconUser size={10} />}>
|
||||
Наблюдатель
|
||||
</Badge>
|
||||
)}
|
||||
{!isAdminRoot && !admin.is_observer && (
|
||||
{!isAdminRoot && !admin.is_observer && !admin.is_analyst && (
|
||||
<Badge size="xs" color="gray" variant="light">
|
||||
Админ
|
||||
Менеджер / Админ
|
||||
</Badge>
|
||||
)}
|
||||
</Group>
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ import {
|
|||
Select,
|
||||
} from '@mantine/core'
|
||||
import { useForm } from '@mantine/form'
|
||||
import { IconCheck, IconCopy, IconKey, IconAlertCircle, IconShield, IconUser } from '@tabler/icons-react'
|
||||
import {IconCheck, IconCopy, IconKey, IconAlertCircle, IconShield, IconUser, IconChartBar} from '@tabler/icons-react'
|
||||
import { useCreateAdmin } from '@/features/admins/hooks/useAdmins'
|
||||
import { useUsers } from '@/features/users/hooks/useUsers'
|
||||
import type { Admin } from '@/types/api'
|
||||
|
|
@ -37,6 +37,7 @@ export default function CreateAdminModal({ opened, onClose }: CreateAdminModalPr
|
|||
name: '',
|
||||
is_root: false,
|
||||
is_observer: false,
|
||||
is_analyst: false,
|
||||
telegram_id: null as number | null,
|
||||
},
|
||||
validate: {
|
||||
|
|
@ -75,6 +76,7 @@ export default function CreateAdminModal({ opened, onClose }: CreateAdminModalPr
|
|||
login: values.login,
|
||||
name: values.name || undefined,
|
||||
is_root: values.is_root,
|
||||
is_analyst: values.is_analyst,
|
||||
is_observer: values.is_observer,
|
||||
telegram_id: values.is_observer ? values.telegram_id! : undefined,
|
||||
})
|
||||
|
|
@ -196,6 +198,22 @@ export default function CreateAdminModal({ opened, onClose }: CreateAdminModalPr
|
|||
/>
|
||||
</Paper>
|
||||
|
||||
<Paper withBorder p="md" bg={form.values.is_analyst ? 'grape.0' : 'gray.0'}>
|
||||
<Switch
|
||||
label={
|
||||
<Group gap="xs">
|
||||
<IconChartBar size={16} color="grape" />
|
||||
<Text fw={600}>Аналитик (Заказы)</Text>
|
||||
</Group>
|
||||
}
|
||||
description="Имеет доступ к настройкам и просмотру всех заказов на месяц."
|
||||
checked={form.values.is_analyst}
|
||||
onChange={(e) => form.setFieldValue('is_analyst', e.currentTarget.checked)}
|
||||
color="grape"
|
||||
disabled={form.values.is_root || form.values.is_observer}
|
||||
/>
|
||||
</Paper>
|
||||
|
||||
<Paper withBorder p="md" bg={form.values.is_observer ? 'blue.0' : 'gray.0'}>
|
||||
<Switch
|
||||
label={
|
||||
|
|
@ -212,7 +230,7 @@ export default function CreateAdminModal({ opened, onClose }: CreateAdminModalPr
|
|||
/>
|
||||
</Paper>
|
||||
|
||||
{form.values.is_observer && (
|
||||
{form.values.is_observer || form.values.is_observer && (
|
||||
<Select
|
||||
label="Telegram-аккаунт"
|
||||
placeholder="Выберите пользователя"
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ export default function EditAdminModal({ admin, opened, onClose }: EditAdminModa
|
|||
name: '',
|
||||
is_root: false,
|
||||
is_observer: false,
|
||||
is_analyst: false,
|
||||
telegram_id: null as number | null,
|
||||
},
|
||||
validate: {
|
||||
|
|
@ -79,6 +80,7 @@ export default function EditAdminModal({ admin, opened, onClose }: EditAdminModa
|
|||
id: admin.id,
|
||||
name: values.name || undefined,
|
||||
is_root: values.is_root,
|
||||
is_analyst: values.is_analyst,
|
||||
is_observer: values.is_observer,
|
||||
telegram_id: values.is_observer ? values.telegram_id! : null,
|
||||
})
|
||||
|
|
|
|||
|
|
@ -0,0 +1,88 @@
|
|||
import { useEffect } from 'react'
|
||||
import { Box, Button, Group, NumberInput, Paper, Stack, Title, Text } from '@mantine/core'
|
||||
import { DateTimePicker } from '@mantine/dates'
|
||||
import { useForm } from '@mantine/form'
|
||||
import { useMonthlyOrderSettings, useSaveMonthlyOrderSettings } from '@/features/monthlyOrders/hooks/useMonthlyOrderSettings'
|
||||
import dayjs from 'dayjs'
|
||||
import { IconDeviceFloppy } from '@tabler/icons-react'
|
||||
|
||||
interface SettingsFormValues {
|
||||
deadline_date: Date | null
|
||||
assembly_time_days: number
|
||||
}
|
||||
|
||||
export default function MonthlyOrdersSettingsPage() {
|
||||
const { data: currentSettings, isLoading } = useMonthlyOrderSettings()
|
||||
const { mutate: saveSettings, isPending } = useSaveMonthlyOrderSettings()
|
||||
|
||||
const form = useForm<SettingsFormValues>({
|
||||
initialValues: {
|
||||
deadline_date: null,
|
||||
assembly_time_days: 3,
|
||||
},
|
||||
validate: {
|
||||
deadline_date: (value) => (!value ? 'Укажите граничную дату и время' : null),
|
||||
assembly_time_days: (value) => (value < 0 ? 'Срок не может быть отрицательным' : null),
|
||||
},
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
if (currentSettings) {
|
||||
form.setValues({
|
||||
deadline_date: currentSettings.deadline_date ? new Date(currentSettings.deadline_date) : null,
|
||||
assembly_time_days: currentSettings.assembly_time_days || 3,
|
||||
})
|
||||
}
|
||||
}, [currentSettings])
|
||||
|
||||
const handleSubmit = (values: SettingsFormValues) => {
|
||||
saveSettings({
|
||||
deadline_date: values.deadline_date ? dayjs(values.deadline_date).format() : null,
|
||||
assembly_time_days: values.assembly_time_days,
|
||||
})
|
||||
}
|
||||
|
||||
if (isLoading) return <Text>Загрузка...</Text>
|
||||
|
||||
return (
|
||||
<Box>
|
||||
<Title order={2} mb="lg">Настройки: Заказ товаров на месяц</Title>
|
||||
|
||||
<Paper withBorder shadow="sm" p="md" radius="md" maw={500}>
|
||||
<form onSubmit={form.onSubmit(handleSubmit)}>
|
||||
<Stack gap="md">
|
||||
<Text c="dimmed" size="sm">
|
||||
Эти настройки применяются к текущему месяцу. Заказы открываются автоматически 15-го числа и закрываются в указанную дату.
|
||||
</Text>
|
||||
|
||||
<DateTimePicker
|
||||
label="Граничная дата и время (Дедлайн)"
|
||||
description="После этого времени менеджеры не смогут редактировать заказы, и они отправятся на согласование."
|
||||
placeholder="Выберите дату и время"
|
||||
valueFormat="DD.MM.YYYY HH:mm"
|
||||
withSeconds={false}
|
||||
{...form.getInputProps('deadline_date')}
|
||||
/>
|
||||
|
||||
<NumberInput
|
||||
label="Срок сборки заказа (дней)"
|
||||
description="Отображается у менеджеров при формировании заказа."
|
||||
min={0}
|
||||
{...form.getInputProps('assembly_time_days')}
|
||||
/>
|
||||
|
||||
<Group justify="flex-end" mt="md">
|
||||
<Button
|
||||
type="submit"
|
||||
loading={isPending}
|
||||
leftSection={<IconDeviceFloppy size={18} />}
|
||||
>
|
||||
Сохранить настройки
|
||||
</Button>
|
||||
</Group>
|
||||
</Stack>
|
||||
</form>
|
||||
</Paper>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
|
@ -54,9 +54,10 @@ export interface Admin {
|
|||
login: string
|
||||
name?: string
|
||||
is_root?: boolean
|
||||
is_observer?: boolean // 🆕
|
||||
telegram_id?: number // 🆕
|
||||
telegram_user?: User // 🆕
|
||||
is_observer?: boolean
|
||||
telegram_id?: number
|
||||
telegram_user?: User
|
||||
is_analyst?: boolean
|
||||
created_at?: string
|
||||
last_login?: string
|
||||
last_ip_login?: string
|
||||
|
|
@ -331,4 +332,14 @@ export interface Notification {
|
|||
updated_at?: string
|
||||
sent_at?: string
|
||||
recipients?: NotificationRecipient[]
|
||||
}
|
||||
|
||||
export interface MonthlyOrderSetting {
|
||||
id?: number
|
||||
month?: number
|
||||
year?: number
|
||||
deadline_date: string | null
|
||||
assembly_time_days: number
|
||||
created_at?: string
|
||||
updated_at?: string
|
||||
}
|
||||
Loading…
Reference in New Issue