diff --git a/components/logistic/Logistic.tsx b/components/logistic/Logistic.tsx index 69cfdc1..e6a8ae3 100644 --- a/components/logistic/Logistic.tsx +++ b/components/logistic/Logistic.tsx @@ -8,7 +8,7 @@ import { Table } from "antd" import { useRouter } from "next/router" import { useEffect, useState } from "react" import DateRangePickerComponent from "../DateRangePicker" -import { logisticColumns, LogisticDataType, logisticStatusFilters, ShippingByStatus } from "./columns" +import { logisticColumns, LogisticDataType, logisticStatusFilters, ShippingByStatus } from "./logistic-columns" const initialValue = () => ({ created: [], diff --git a/components/logistic/Columns.tsx b/components/logistic/logistic-cell.tsx similarity index 55% rename from components/logistic/Columns.tsx rename to components/logistic/logistic-cell.tsx index f569b8a..b8a2820 100644 --- a/components/logistic/Columns.tsx +++ b/components/logistic/logistic-cell.tsx @@ -1,11 +1,15 @@ import { Shipping } from "@/interfaces/Shipping" -import { formatDate, formatLocation } from "@/utils" import { Divider, Tag } from "antd" -import { ColumnsType } from "antd/es/table" -import Link from "next/link" import { statusMap } from "../Status" +import { ShippingByStatus } from "./logistic-columns" import styled from "styled-components" +import Link from "next/link" +import { formatDate, formatLocation } from "@/utils" +interface CellContentProps { + data: ShippingByStatus + expand: boolean +} export const SmallTag = styled.div<{ $status: string }>` @@ -21,67 +25,32 @@ export const SmallTag = styled.div<{ $status: string }>` font-size: 11px; ` -export interface LogisticDataType { - key: string - contentType: string - push2hot: ShippingByStatus - hot2frez: ShippingByStatus - frez2hot: ShippingByStatus - hot2lahta: ShippingByStatus - expand: boolean +const generateToolTip = (shipping: Shipping) => { + const from = formatLocation(shipping.from) + const to = formatLocation(shipping.to) + const tooltip = [ + `${from} → ${to}`, + `${shipping.contentType} ${shipping.count} шт.`, + `${statusMap.get(shipping.status)!.label} ${statusTime(shipping)}` + ].join('\n') + return tooltip } -export interface ShippingByStatus { - recieved: Shipping[], - created: Shipping[], - sended: Shipping[], +const statusTime = (shipping: Shipping) => { + switch (shipping.status) { + case 'created': + return formatDate(shipping.createdAt) + case 'sended': + return formatDate(shipping.sendedAt) + case 'recieved': + return formatDate(shipping.recievedAt) + default: + return '-' + } } -export const logisticColumns: ColumnsType = [ - { - title: 'Контент', - dataIndex: 'contentType', - key: 'contentType', - align: 'center', - }, - { - title: 'Пушкино → Хотьково', - dataIndex: 'push2hot', - key: 'push2hot', - align: 'center', - render: (value, record, index) => , - }, - { - title: 'Хотьково → Фрезеровка', - dataIndex: 'hot2frez', - key: 'hot2frez', - align: 'center', - render: (value, record, index) => , - }, - { - title: 'Фрезеровка → Хотьково', - dataIndex: 'frez2hot', - key: 'frez2hot', - align: 'center', - render: (value, record, index) => , - }, - { - title: 'Хотьково → Лахта', - dataIndex: 'hot2lahta_created', - key: 'hot2lahta_created', - align: 'center', - render: (value, record, index) => , - }, -] - - -interface CellContentProps { - data: ShippingByStatus - expand: boolean -} - -const ShippingTotal = (props: CellContentProps): JSX.Element => { +export default function ShippingTotal(props: CellContentProps): JSX.Element { const { data, expand } = props @@ -132,54 +101,3 @@ const ShippingTotal = (props: CellContentProps): JSX.Element => { } -const generateToolTip = (shipping: Shipping) => { - const from = formatLocation(shipping.from) - const to = formatLocation(shipping.to) - const tooltip = [ - `${from} → ${to}`, - `${shipping.contentType} ${shipping.count} шт.`, - `${statusMap.get(shipping.status)!.label} ${statusTime(shipping)}` - ].join('\n') - return tooltip -} - -const statusTime = (shipping: Shipping) => { - switch (shipping.status) { - case 'created': - return formatDate(shipping.createdAt) - case 'sended': - return formatDate(shipping.sendedAt) - case 'recieved': - return formatDate(shipping.recievedAt) - default: - return '-' - } -} - -export const logisticStatusFilters = [ - { - key: `push2hot`, - filter: (shipping: Shipping) => - shipping.from === '1 — Пушкино' && - shipping.to === '2 — Хотьково', - }, - { - key: `hot2lahta`, - filter: (shipping: Shipping) => - shipping.from === '2 — Хотьково' && - shipping.to === '4 — Лахта', - }, - { - key: `hot2frez`, - filter: (shipping: Shipping) => - shipping.from === '2 — Хотьково' && - shipping.to === '3 — Фрезеровка', - }, - { - key: `frez2hot`, - filter: (shipping: Shipping) => - shipping.from === '3 — Фрезеровка' && - shipping.to === '2 — Хотьково', - }, -] - diff --git a/components/logistic/logistic-columns.tsx b/components/logistic/logistic-columns.tsx new file mode 100644 index 0000000..f78d7f1 --- /dev/null +++ b/components/logistic/logistic-columns.tsx @@ -0,0 +1,84 @@ +import { Shipping } from "@/interfaces/Shipping" +import { ColumnsType } from "antd/es/table" +import ShippingTotal from "./logistic-cell" + +export interface LogisticDataType { + key: string + contentType: string + push2hot: ShippingByStatus + hot2frez: ShippingByStatus + frez2hot: ShippingByStatus + hot2lahta: ShippingByStatus + expand: boolean +} + +export interface ShippingByStatus { + recieved: Shipping[], + created: Shipping[], + sended: Shipping[], +} + +export const logisticColumns: ColumnsType = [ + { + title: 'Контент', + dataIndex: 'contentType', + key: 'contentType', + align: 'center', + }, + { + title: 'Пушкино → Хотьково', + dataIndex: 'push2hot', + key: 'push2hot', + align: 'center', + render: (value, record, index) => , + }, + { + title: 'Хотьково → Фрезеровка', + dataIndex: 'hot2frez', + key: 'hot2frez', + align: 'center', + render: (value, record, index) => , + }, + { + title: 'Фрезеровка → Хотьково', + dataIndex: 'frez2hot', + key: 'frez2hot', + align: 'center', + render: (value, record, index) => , + }, + { + title: 'Хотьково → Лахта', + dataIndex: 'hot2lahta_created', + key: 'hot2lahta_created', + align: 'center', + render: (value, record, index) => , + }, +] + +export const logisticStatusFilters = [ + { + key: `push2hot`, + filter: (shipping: Shipping) => + shipping.from === '1 — Пушкино' && + shipping.to === '2 — Хотьково', + }, + { + key: `hot2lahta`, + filter: (shipping: Shipping) => + shipping.from === '2 — Хотьково' && + shipping.to === '4 — Лахта', + }, + { + key: `hot2frez`, + filter: (shipping: Shipping) => + shipping.from === '2 — Хотьково' && + shipping.to === '3 — Фрезеровка', + }, + { + key: `frez2hot`, + filter: (shipping: Shipping) => + shipping.from === '3 — Фрезеровка' && + shipping.to === '2 — Хотьково', + }, +] + diff --git a/components/summary/columns.tsx b/components/summary/summary-columns.tsx similarity index 100% rename from components/summary/columns.tsx rename to components/summary/summary-columns.tsx diff --git a/components/summary/summary.tsx b/components/summary/summary.tsx index 248ecc6..e4a85c3 100644 --- a/components/summary/summary.tsx +++ b/components/summary/summary.tsx @@ -10,7 +10,7 @@ import { Shipping } from "@/interfaces/Shipping"; import { User } from "@/interfaces/UserInterface"; import { useRouter } from "next/router"; import { Table } from "antd"; -import { Summary, SummaryByLocation, SummaryByType, summaryColumns, SummaryData, SummaryDataType } from "./columns"; +import { Summary, SummaryByLocation, SummaryByType, summaryColumns, SummaryData, SummaryDataType } from "./summary-columns"; export const LocationSummary = (): JSX.Element => {