Add znzt module
Deploy Manager App / deploy (push) Failing after 19s
Details
Deploy Manager App / deploy (push) Failing after 19s
Details
This commit is contained in:
parent
d4b20990e1
commit
054638ed0d
|
|
@ -4,9 +4,13 @@ import {
|
|||
LoadingOverlay, Select, TextInput, HoverCard, ActionIcon, Stack, Textarea, Checkbox
|
||||
} from '@mantine/core'
|
||||
import { notifications } from '@mantine/notifications'
|
||||
import { IconDeviceFloppy, IconLock, IconSettings, IconSearch, IconFilter, IconUserSearch, IconRefresh, IconArrowLeft } from '@tabler/icons-react'
|
||||
import {
|
||||
IconDeviceFloppy, IconLock, IconSettings, IconSearch,
|
||||
IconFilter, IconUserSearch, IconRefresh, IconArrowLeft,
|
||||
IconFileExport, IconPaperclip, IconExternalLink
|
||||
} from '@tabler/icons-react'
|
||||
import { useVirtualizer } from '@tanstack/react-virtual'
|
||||
import { useNavigate, useParams } from 'react-router-dom' // 👈 Добавили для роутинга
|
||||
import { useNavigate, useParams } from 'react-router-dom'
|
||||
import { monthlyOrdersApi } from "../api/monthlyOrders.ts"
|
||||
import type { FrontendOrderMatrix, MonthlyOrderClient, NomenclatureItem } from "../types/orders.ts"
|
||||
|
||||
|
|
@ -56,16 +60,16 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
|
||||
const tableContainerRef = useRef<HTMLDivElement>(null);
|
||||
|
||||
// 🟢 Логика Аналитика
|
||||
// Логика Аналитика
|
||||
const navigate = useNavigate();
|
||||
const { id } = useParams();
|
||||
const targetManagerId = id ? Number(id) : undefined;
|
||||
const isReadOnly = !!targetManagerId; // Если смотрим чужую, то только чтение
|
||||
const isReadOnly = !!targetManagerId;
|
||||
|
||||
const loadData = async (ignoreDraft = false) => {
|
||||
try {
|
||||
setLoading(true)
|
||||
const res = await monthlyOrdersApi.getMatrix(targetManagerId) // 👈 Передаем ID, если есть
|
||||
const res = await monthlyOrdersApi.getMatrix(targetManagerId)
|
||||
const matrix = res.data
|
||||
setData(matrix)
|
||||
|
||||
|
|
@ -84,7 +88,6 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}
|
||||
})
|
||||
|
||||
// Черновик не загружаем, если мы Аналитик (isReadOnly = true)
|
||||
const draft = localStorage.getItem(DRAFT_KEY);
|
||||
const draftTime = localStorage.getItem(DRAFT_TIME_KEY);
|
||||
|
||||
|
|
@ -103,8 +106,6 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}
|
||||
} catch (err: any) {
|
||||
const errorMsg = err.response?.data?.error_description || 'Ошибка загрузки';
|
||||
|
||||
// 🟢 Если бэкенд требует ID менеджера, значит зашел аналитик -> Редирект на дашборд!
|
||||
if (errorMsg.includes('аналитику необходимо передать manager_id')) {
|
||||
navigate('/analyst');
|
||||
return;
|
||||
|
|
@ -115,9 +116,8 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}
|
||||
}
|
||||
|
||||
useEffect(() => { loadData() }, [targetManagerId]) // 👈 Перезагружаем при смене ID
|
||||
useEffect(() => { loadData() }, [targetManagerId])
|
||||
|
||||
// Автосохранение черновика (только если не аналитик!)
|
||||
useEffect(() => {
|
||||
if (loading || saving || isReadOnly) return;
|
||||
|
||||
|
|
@ -130,7 +130,7 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}, [editableOrders, data, loading, saving, isReadOnly]);
|
||||
|
||||
const handleQuantityChange = useCallback((clientName: string, nom: NomenclatureItem, qty: number | null) => {
|
||||
if (isReadOnly) return; // Блокировка
|
||||
if (isReadOnly) return;
|
||||
setEditableOrders(prev => {
|
||||
const currentOrder = prev[clientName];
|
||||
const items = [...(currentOrder.items || [])];
|
||||
|
|
@ -147,17 +147,18 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
}, [isReadOnly]);
|
||||
|
||||
const updateClientMeta = useCallback((clientName: string, field: keyof MonthlyOrderClient, value: string | null) => {
|
||||
if (isReadOnly) return; // Блокировка
|
||||
if (isReadOnly) return;
|
||||
setEditableOrders(prev => ({
|
||||
...prev, [clientName]: { ...prev[clientName], [field]: value }
|
||||
}))
|
||||
}, [isReadOnly]);
|
||||
|
||||
|
||||
const handleSave = async () => {
|
||||
if (isReadOnly) return;
|
||||
for (const [clientName, order] of Object.entries(editableOrders)) {
|
||||
if (order.items && order.items.length > 0 && !order.manager_comment?.trim()) {
|
||||
return notifications.show({ title: 'Внимание', message: `Укажите комментарий для клиента "${clientName}"!`, color: 'yellow' })
|
||||
if (!order.manager_comment || order.manager_comment.trim() === '') {
|
||||
return notifications.show({ title: 'Внимание', message: `Комментарий обязателен для клиента "${clientName}"!`, color: 'yellow' })
|
||||
}
|
||||
}
|
||||
try {
|
||||
|
|
@ -243,13 +244,11 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
if (loading) return <LoadingOverlay visible />
|
||||
if (!data) return <Text ta="center">Нет данных</Text>
|
||||
|
||||
// Общий флаг отключения элементов
|
||||
const inputsDisabled = data.is_locked || isReadOnly;
|
||||
|
||||
return (
|
||||
<Box display="flex" style={{ flexDirection: 'column', flexGrow: 1, overflow: 'hidden' }}>
|
||||
|
||||
{/* 🟢 Кнопка возврата для аналитика */}
|
||||
{isReadOnly && (
|
||||
<Group mb="sm">
|
||||
<Button variant="subtle" leftSection={<IconArrowLeft size={16} />} onClick={() => navigate('/analyst')}>
|
||||
|
|
@ -313,27 +312,28 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
</Group>
|
||||
</Stack>
|
||||
|
||||
{/* Если Аналитик — прячем кнопки управления данными */}
|
||||
{!isReadOnly && (
|
||||
data.is_locked ? (
|
||||
<Badge color="red" size="lg" leftSection={<IconLock size={14} />}>Прием закрыт</Badge>
|
||||
) : (
|
||||
<Group align="center" gap="md">
|
||||
{draftSavedAt && (
|
||||
<Text size="xs" c="dimmed">
|
||||
Локальный черновик:<br/>
|
||||
<Text span fw={500} c="gray.7">{formatMSKTime(draftSavedAt)} (МСК)</Text>
|
||||
</Text>
|
||||
)}
|
||||
<Button variant="default" onClick={handleResetDraft} leftSection={<IconRefresh size={16} />}>
|
||||
Сбросить черновик
|
||||
</Button>
|
||||
<Button onClick={handleSave} loading={saving} leftSection={<IconDeviceFloppy size={16} />}>
|
||||
Сохранить в базу
|
||||
</Button>
|
||||
</Group>
|
||||
)
|
||||
)}
|
||||
<Group align="center" gap="md">
|
||||
{!isReadOnly && (
|
||||
data.is_locked ? (
|
||||
<Badge color="red" size="lg" leftSection={<IconLock size={14} />}>Прием закрыт</Badge>
|
||||
) : (
|
||||
<>
|
||||
{draftSavedAt && (
|
||||
<Text size="xs" c="dimmed">
|
||||
Локальный черновик:<br/>
|
||||
<Text span fw={500} c="gray.7">{formatMSKTime(draftSavedAt)} (МСК)</Text>
|
||||
</Text>
|
||||
)}
|
||||
<Button variant="default" onClick={handleResetDraft} leftSection={<IconRefresh size={16} />}>
|
||||
Сбросить черновик
|
||||
</Button>
|
||||
<Button onClick={handleSave} loading={saving} leftSection={<IconDeviceFloppy size={16} />}>
|
||||
Сохранить в базу
|
||||
</Button>
|
||||
</>
|
||||
)
|
||||
)}
|
||||
</Group>
|
||||
</Group>
|
||||
|
||||
<Paper withBorder shadow="sm" style={{ flexGrow: 1, display: 'flex', flexDirection: 'column', overflow: 'hidden' }}>
|
||||
|
|
@ -349,21 +349,47 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
const clientName = c.google_data.name;
|
||||
const branch = c.google_data.branch;
|
||||
const order = editableOrders[clientName];
|
||||
const hasOrderItems = order?.items && order.items.length > 0;
|
||||
const isCommentMissing = hasOrderItems && (!order.manager_comment || order.manager_comment.trim() === '');
|
||||
|
||||
// Проверка обязательности комментария
|
||||
const hasComment = !!order?.manager_comment && order.manager_comment.trim() !== '';
|
||||
|
||||
return (
|
||||
<Table.Th key={clientName} w={240} style={{ textAlign: 'center', verticalAlign: 'top', padding: '10px 8px' }}>
|
||||
<Group justify="center" gap={4} wrap="nowrap" mb={2}>
|
||||
<Text size="sm" fw={600} style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.2 }}>
|
||||
<Group justify="space-between" align="center" mb={2} wrap="nowrap">
|
||||
<Text size="sm" fw={600} style={{ whiteSpace: 'normal', wordBreak: 'break-word', lineHeight: 1.2, flex: 1 }}>
|
||||
{clientName}
|
||||
</Text>
|
||||
<ClientSettingsPopover
|
||||
clientName={clientName}
|
||||
order={order}
|
||||
updateClientMeta={updateClientMeta}
|
||||
isLocked={inputsDisabled} // 👈 Передаем флаг блокировки
|
||||
/>
|
||||
|
||||
<Group gap={4} wrap="nowrap">
|
||||
{/* Скрытый инпут для прикрепления файла-скрина */}
|
||||
<input
|
||||
type="file"
|
||||
id={`file-${clientName}`}
|
||||
style={{ display: 'none' }}
|
||||
onChange={(e) => {
|
||||
const file = e.target.files?.[0];
|
||||
if (file) {
|
||||
notifications.show({ title: 'Файл выбран', message: `Скрин для ${clientName}: ${file.name}`, color: 'blue' });
|
||||
}
|
||||
}}
|
||||
/>
|
||||
<ActionIcon
|
||||
variant="light"
|
||||
color={order?.files && order.files.length > 0 ? "teal" : "gray"}
|
||||
size="sm"
|
||||
title="Прикрепить скрин подтверждения заказа"
|
||||
onClick={() => document.getElementById(`file-${clientName}`)?.click()}
|
||||
>
|
||||
<IconPaperclip size={14} />
|
||||
</ActionIcon>
|
||||
|
||||
<ClientSettingsPopover
|
||||
clientName={clientName}
|
||||
order={order}
|
||||
updateClientMeta={updateClientMeta}
|
||||
isLocked={inputsDisabled}
|
||||
/>
|
||||
</Group>
|
||||
</Group>
|
||||
|
||||
{branch && (
|
||||
|
|
@ -380,15 +406,20 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
|
||||
<Textarea
|
||||
size="xs"
|
||||
placeholder={hasOrderItems && !isReadOnly ? "Обязательный коммент *" : "Комментарий..."}
|
||||
disabled={inputsDisabled} // 👈 Блокируем коммент для аналитика
|
||||
placeholder="Комментарий (обязательно) *"
|
||||
disabled={inputsDisabled}
|
||||
value={order?.manager_comment || ''}
|
||||
onChange={e => updateClientMeta(clientName, 'manager_comment', e.currentTarget.value)}
|
||||
autosize
|
||||
minRows={1}
|
||||
maxRows={3}
|
||||
error={!isReadOnly && isCommentMissing} // Ошибку аналитику тоже не светим
|
||||
error={!hasComment}
|
||||
/>
|
||||
{!hasComment && (
|
||||
<Text size="10px" c="red" mt={2} ta="left">
|
||||
Заполните комментарий для разблокировки
|
||||
</Text>
|
||||
)}
|
||||
</Table.Th>
|
||||
)
|
||||
})}
|
||||
|
|
@ -427,12 +458,18 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
|
||||
{filteredClients.map(c => {
|
||||
const clientName = c.google_data.name;
|
||||
const item = editableOrders[clientName]?.items?.find(i => i.nomenclature_name === nom.name);
|
||||
const order = editableOrders[clientName];
|
||||
const hasComment = !!order?.manager_comment && order.manager_comment.trim() !== '';
|
||||
|
||||
// Блокируем инпуты номенклатуры, если дедлайн/чтение ИЛИ не заполнен комментарий
|
||||
const isNomenclatureDisabled = inputsDisabled || !hasComment;
|
||||
|
||||
const item = order?.items?.find(i => i.nomenclature_name === nom.name);
|
||||
return (
|
||||
<Table.Td key={clientName} align="center">
|
||||
<CellInput
|
||||
initialValue={item?.quantity || null}
|
||||
disabled={inputsDisabled} // 👈 Блокируем инпуты
|
||||
disabled={isNomenclatureDisabled}
|
||||
onCommit={(val) => handleQuantityChange(clientName, nom, val)}
|
||||
/>
|
||||
</Table.Td>
|
||||
|
|
@ -455,7 +492,6 @@ export default function OrdersPage({ onError }: { onError: (msg: string) => void
|
|||
)
|
||||
}
|
||||
|
||||
// Меню параметров (отключается, если isLocked = true)
|
||||
function ClientSettingsPopover({ clientName, order, updateClientMeta, isLocked }: any) {
|
||||
return (
|
||||
<HoverCard width={300} position="bottom" withArrow shadow="md" openDelay={200} closeDelay={300}>
|
||||
|
|
|
|||
Loading…
Reference in New Issue