chore: restructure project into backend and frontend folders

- Move all frontend code to frontend/ directory
- Add backend/ with Go project structure (cmd, internal, pkg)
- Add docker-compose.yml for orchestration
This commit is contained in:
Egor Pozharov
2026-04-14 13:14:28 +06:00
parent 11e12f964d
commit 4e0899d3ce
54 changed files with 779 additions and 0 deletions

84
frontend/src/App.tsx Normal file
View File

@@ -0,0 +1,84 @@
import { useState } from 'react';
import { Truck } from 'lucide-react';
import { Dashboard } from './pages/Dashboard';
import { DeliveryListPage } from './pages/DeliveryListPage';
import { DeliveryForm } from './components/delivery/DeliveryForm';
import { useDeliveryStore } from './stores/deliveryStore';
function App() {
const [view, setView] = useState<'dashboard' | 'delivery-list'>('dashboard');
const [selectedDate, setSelectedDate] = useState<string>('');
const [isFormOpen, setIsFormOpen] = useState(false);
const [formDate, setFormDate] = useState<string>('');
const addDelivery = useDeliveryStore(state => state.addDelivery);
const handleDateSelect = (date: string) => {
setSelectedDate(date);
setView('delivery-list');
};
const handleBackToDashboard = () => {
setView('dashboard');
setSelectedDate('');
};
const handleAddDelivery = () => {
const today = new Date().toLocaleDateString('ru-RU').split('.').join('-');
setFormDate(today);
setIsFormOpen(true);
};
const handleFormSubmit = (data: Parameters<typeof addDelivery>[0]) => {
addDelivery(data);
setIsFormOpen(false);
if (data.date !== new Date().toLocaleDateString('ru-RU').split('.').join('-')) {
setSelectedDate(data.date);
setView('delivery-list');
}
};
return (
<div className="min-h-screen bg-[#fbf8fb]">
<header className="sticky top-0 z-40 bg-[#1B263B] text-white shadow-md">
<div className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8">
<div className="flex items-center justify-between h-14">
<div className="flex items-center gap-3">
<div className="p-2 bg-white/10 rounded-lg">
<Truck size={24} className="text-white" />
</div>
<h1 className="text-lg font-semibold hidden sm:block">Delivery Tracker</h1>
</div>
<div className="text-sm text-white/70">
{view === 'dashboard' ? 'Панель управления' : `Доставки на ${selectedDate}`}
</div>
</div>
</div>
</header>
<main className="max-w-7xl mx-auto px-4 sm:px-6 lg:px-8 py-6">
{view === 'dashboard' ? (
<Dashboard
onDateSelect={handleDateSelect}
onAddDelivery={handleAddDelivery}
/>
) : (
<DeliveryListPage
selectedDate={selectedDate}
onBack={handleBackToDashboard}
/>
)}
</main>
<DeliveryForm
isOpen={isFormOpen}
onClose={() => setIsFormOpen(false)}
onSubmit={handleFormSubmit}
defaultDate={formDate}
/>
</div>
);
}
export default App;

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

File diff suppressed because one or more lines are too long

After

Width:  |  Height:  |  Size: 8.5 KiB

View File

@@ -0,0 +1,135 @@
import { MapPin, Phone, Package, Store, Calendar, MessageSquare, CheckCircle2, Circle, CheckSquare } from 'lucide-react';
import type { Delivery } from '../../types';
import { pickupLocationLabels } from '../../types';
import { StatusBadge } from './StatusBadge';
import { Card } from '../ui/Card';
interface DeliveryCardProps {
delivery: Delivery;
onStatusChange: (id: string) => void;
onEdit: (delivery: Delivery) => void;
onDelete: (id: string) => void;
}
export const DeliveryCard = ({ delivery, onStatusChange, onEdit, onDelete }: DeliveryCardProps) => {
const handleAddressClick = () => {
const encodedAddress = encodeURIComponent(delivery.address);
window.open(`https://maps.google.com/?q=${encodedAddress}`, '_blank');
};
const handlePhoneClick = () => {
window.location.href = `tel:${delivery.phone}`;
};
return (
<Card className="relative">
<div className="flex items-start justify-between mb-3">
<div className="flex items-center gap-2">
<StatusBadge
status={delivery.status}
onClick={() => onStatusChange(delivery.id)}
size="md"
/>
</div>
<div className="flex gap-1">
<button
onClick={() => onEdit(delivery)}
className="p-1.5 rounded-md hover:bg-[#f5f3f5] text-[#75777d] transition-colors"
title="Редактировать"
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>
</button>
<button
onClick={() => onDelete(delivery.id)}
className="p-1.5 rounded-md hover:bg-red-50 text-red-500 transition-colors"
title="Удалить"
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
</button>
</div>
</div>
<div className="space-y-2.5">
<div className="flex items-center gap-2 text-sm">
<Calendar size={16} className="text-[#75777d]" />
<span className="text-[#1b1b1d] font-medium">{delivery.date}</span>
</div>
<div className="flex items-center gap-2 text-sm">
<Store size={16} className="text-[#75777d]" />
<span className="text-[#1b1b1d]">{pickupLocationLabels[delivery.pickupLocation]}</span>
</div>
<div className="flex items-center gap-2 text-sm">
<Package size={16} className="text-[#75777d]" />
<span className="text-[#1b1b1d]">{delivery.productName}</span>
</div>
<button
onClick={handleAddressClick}
className="flex items-start gap-2 text-sm w-full text-left hover:bg-[#f5f3f5] -mx-1 px-1 py-0.5 rounded transition-colors"
>
<MapPin size={16} className="text-[#F28C28] mt-0.5 shrink-0" />
<span className="text-[#1B263B] underline decoration-[#F28C28]/30 underline-offset-2">
{delivery.address}
</span>
</button>
<button
onClick={handlePhoneClick}
className="flex items-center gap-2 text-sm w-full text-left hover:bg-[#f5f3f5] -mx-1 px-1 py-0.5 rounded transition-colors"
>
<Phone size={16} className="text-[#16a34a] shrink-0" />
<span className="text-[#16a34a] font-medium">
{delivery.phone}
</span>
</button>
{delivery.additionalPhone && (
<button
onClick={() => window.location.href = `tel:${delivery.additionalPhone}`}
className="flex items-center gap-2 text-sm w-full text-left hover:bg-[#f5f3f5] -mx-1 px-1 py-0.5 rounded transition-colors"
>
<Phone size={16} className="text-[#75777d] shrink-0" />
<span className="text-[#75777d]">
{delivery.additionalPhone}
</span>
</button>
)}
<div className="flex items-center gap-2 text-sm">
<CheckSquare size={16} className={delivery.hasElevator ? 'text-[#16a34a]' : 'text-[#75777d]'} />
<span className="text-[#1b1b1d]">
{delivery.hasElevator ? 'Есть лифт' : 'Нет лифта'}
</span>
</div>
{delivery.comment && (
<div className="flex items-start gap-2 text-sm">
<MessageSquare size={16} className="text-[#75777d] mt-0.5 shrink-0" />
<span className="text-[#45474d]">{delivery.comment}</span>
</div>
)}
</div>
<div className="mt-4 pt-3 border-t border-[#e4e2e4]">
<button
onClick={() => onStatusChange(delivery.id)}
className="w-full flex items-center justify-center gap-2 py-2 rounded-md bg-[#f5f3f5] hover:bg-[#e4e2e4] transition-colors text-sm font-medium text-[#1b1b1d]"
>
{delivery.status === 'new' ? (
<>
<CheckCircle2 size={16} className="text-[#16a34a]" />
Отметить доставленным
</>
) : (
<>
<Circle size={16} className="text-[#F28C28]" />
Вернуть в "Новые"
</>
)}
</button>
</div>
</Card>
);
};

View File

@@ -0,0 +1,183 @@
import { useState, useEffect } from 'react';
import { Button, Input, Select, Modal } from '../ui';
import type { Delivery, PickupLocation, DeliveryStatus } from '../../types';
import { pickupLocationLabels } from '../../types';
interface DeliveryFormProps {
isOpen: boolean;
onClose: () => void;
onSubmit: (delivery: Omit<Delivery, 'id' | 'createdAt' | 'updatedAt'>) => void;
initialData?: Delivery | null;
defaultDate?: string;
}
const pickupOptions: { value: PickupLocation; label: string }[] = [
{ value: 'warehouse', label: pickupLocationLabels.warehouse },
{ value: 'symbat', label: pickupLocationLabels.symbat },
{ value: 'nursaya', label: pickupLocationLabels.nursaya },
{ value: 'galaktika', label: pickupLocationLabels.galaktika },
];
export const DeliveryForm = ({ isOpen, onClose, onSubmit, initialData, defaultDate }: DeliveryFormProps) => {
const [formData, setFormData] = useState({
date: defaultDate || new Date().toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'warehouse' as PickupLocation,
productName: '',
address: '',
phone: '',
additionalPhone: '',
hasElevator: false,
comment: '',
status: 'new' as DeliveryStatus,
});
useEffect(() => {
if (initialData) {
setFormData({
date: initialData.date,
pickupLocation: initialData.pickupLocation,
productName: initialData.productName,
address: initialData.address,
phone: initialData.phone,
additionalPhone: initialData.additionalPhone || '',
hasElevator: initialData.hasElevator,
comment: initialData.comment,
status: initialData.status,
});
} else if (defaultDate) {
setFormData(prev => ({ ...prev, date: defaultDate }));
}
}, [initialData, defaultDate, isOpen]);
const handleSubmit = (e: React.FormEvent) => {
e.preventDefault();
onSubmit(formData);
if (!initialData) {
setFormData({
date: defaultDate || new Date().toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'warehouse',
productName: '',
address: '',
phone: '',
additionalPhone: '',
hasElevator: false,
comment: '',
status: 'new',
});
}
onClose();
};
const formatDateForInput = (dateStr: string) => {
const [day, month, year] = dateStr.split('-');
return `${year}-${month}-${day}`;
};
const formatDateFromInput = (dateStr: string) => {
const [year, month, day] = dateStr.split('-');
return `${day}-${month}-${year}`;
};
return (
<Modal
isOpen={isOpen}
onClose={onClose}
title={initialData ? 'Редактировать доставку' : 'Новая доставка'}
footer={
<>
<Button variant="ghost" onClick={onClose}>
Отмена
</Button>
<Button type="submit" form="delivery-form">
{initialData ? 'Сохранить' : 'Создать'}
</Button>
</>
}
>
<form id="delivery-form" onSubmit={handleSubmit} className="space-y-4">
<div>
<label className="block text-sm font-medium text-[#1b1b1d] mb-1">
Дата доставки
</label>
<input
type="date"
value={formatDateForInput(formData.date)}
onChange={(e) => setFormData({ ...formData, date: formatDateFromInput(e.target.value) })}
className="w-full px-3 py-2 bg-[#f5f3f5] border border-[#c5c6cd] rounded-md text-[#1b1b1d] focus:outline-none focus:ring-2 focus:ring-[#1B263B] focus:border-transparent transition-colors"
required
/>
</div>
<Select
label="Место загрузки"
value={formData.pickupLocation}
onChange={(e) => setFormData({ ...formData, pickupLocation: e.target.value as PickupLocation })}
options={pickupOptions}
/>
<Input
label="Название товара"
value={formData.productName}
onChange={(e) => setFormData({ ...formData, productName: e.target.value })}
placeholder="Введите название товара"
required
/>
<Input
label="Адрес разгрузки"
value={formData.address}
onChange={(e) => setFormData({ ...formData, address: e.target.value })}
placeholder="ул. Примерная, д. 1"
required
/>
<Input
label="Телефон покупателя"
type="tel"
value={formData.phone}
onChange={(e) => setFormData({ ...formData, phone: e.target.value })}
onFocus={(e) => {
if (!e.target.value) {
setFormData({ ...formData, phone: '+7' });
}
}}
placeholder="+7 (776)-567-89-01"
required
/>
<Input
label="Дополнительный номер телефона"
type="tel"
value={formData.additionalPhone}
onChange={(e) => setFormData({ ...formData, additionalPhone: e.target.value })}
onFocus={(e) => {
if (!e.target.value) {
setFormData({ ...formData, additionalPhone: '+7' });
}
}}
placeholder="+7 (776)-567-89-01"
/>
<div className="flex items-center gap-2">
<input
type="checkbox"
id="hasElevator"
checked={formData.hasElevator}
onChange={(e) => setFormData({ ...formData, hasElevator: e.target.checked })}
className="w-4 h-4 text-[#1B263B] border-[#c5c6cd] rounded focus:ring-[#1B263B]"
/>
<label htmlFor="hasElevator" className="text-sm text-[#1b1b1d]">
Наличие лифта
</label>
</div>
<Input
label="Комментарий"
value={formData.comment}
onChange={(e) => setFormData({ ...formData, comment: e.target.value })}
placeholder="Дополнительная информация..."
/>
</form>
</Modal>
);
};

View File

@@ -0,0 +1,139 @@
import { useState } from 'react';
import { Plus, LayoutGrid, Table as TableIcon } from 'lucide-react';
import { DeliveryCard } from './DeliveryCard';
import { DeliveryRow } from './DeliveryRow';
import { Button } from '../ui/Button';
import type { Delivery } from '../../types';
interface DeliveryListProps {
deliveries: Delivery[];
onStatusChange: (id: string) => void;
onEdit: (delivery: Delivery) => void;
onDelete: (id: string) => void;
onAdd: () => void;
date: string;
}
export const DeliveryList = ({ deliveries, onStatusChange, onEdit, onDelete, onAdd, date }: DeliveryListProps) => {
const [viewMode, setViewMode] = useState<'kanban' | 'table'>('kanban');
const newDeliveries = deliveries.filter(d => d.status === 'new');
const deliveredDeliveries = deliveries.filter(d => d.status === 'delivered');
return (
<div className="space-y-4">
<div className="flex items-center justify-between">
<h2 className="text-xl font-semibold text-[#1b1b1d]">
Доставки на {date}
</h2>
<div className="flex items-center gap-2">
<div className="flex bg-[#f0edef] rounded-lg p-1">
<button
onClick={() => setViewMode('kanban')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${
viewMode === 'kanban' ? 'bg-white shadow-sm text-[#1b1b1d]' : 'text-[#75777d] hover:text-[#1b1b1d]'
}`}
>
<LayoutGrid size={16} />
<span className="hidden sm:inline">Канбан</span>
</button>
<button
onClick={() => setViewMode('table')}
className={`flex items-center gap-1.5 px-3 py-1.5 rounded-md text-sm font-medium transition-colors ${
viewMode === 'table' ? 'bg-white shadow-sm text-[#1b1b1d]' : 'text-[#75777d] hover:text-[#1b1b1d]'
}`}
>
<TableIcon size={16} />
<span className="hidden sm:inline">Таблица</span>
</button>
</div>
<Button onClick={onAdd} size="sm">
<Plus size={16} className="mr-1" />
<span className="hidden sm:inline">Добавить</span>
</Button>
</div>
</div>
{deliveries.length === 0 ? (
<div className="text-center py-12 bg-[#f5f3f5] rounded-lg">
<p className="text-[#75777d]">Нет доставок на эту дату</p>
<Button onClick={onAdd} variant="ghost" className="mt-2">
Создать первую доставку
</Button>
</div>
) : viewMode === 'kanban' ? (
<div className="grid grid-cols-1 md:grid-cols-2 gap-4">
<div className="space-y-3">
<div className="flex items-center justify-between">
<h3 className="font-medium text-[#1b1b1d] flex items-center gap-2">
<span className="w-2 h-2 rounded-full bg-[#F28C28]"></span>
Новые
<span className="text-sm text-[#75777d] font-normal">({newDeliveries.length})</span>
</h3>
</div>
<div className="space-y-3">
{newDeliveries.map(delivery => (
<DeliveryCard
key={delivery.id}
delivery={delivery}
onStatusChange={onStatusChange}
onEdit={onEdit}
onDelete={onDelete}
/>
))}
</div>
</div>
<div className="space-y-3">
<div className="flex items-center justify-between">
<h3 className="font-medium text-[#1b1b1d] flex items-center gap-2">
<span className="w-2 h-2 rounded-full bg-[#16a34a]"></span>
Доставлено
<span className="text-sm text-[#75777d] font-normal">({deliveredDeliveries.length})</span>
</h3>
</div>
<div className="space-y-3">
{deliveredDeliveries.map(delivery => (
<DeliveryCard
key={delivery.id}
delivery={delivery}
onStatusChange={onStatusChange}
onEdit={onEdit}
onDelete={onDelete}
/>
))}
</div>
</div>
</div>
) : (
<div className="overflow-x-auto">
<table className="w-full bg-white rounded-lg shadow-sm border border-[#e4e2e4]">
<thead className="bg-[#f5f3f5]">
<tr className="text-left text-xs font-semibold text-[#75777d] uppercase tracking-wider">
<th className="px-4 py-3">Статус</th>
<th className="px-4 py-3">Дата</th>
<th className="px-4 py-3">Загрузка</th>
<th className="px-4 py-3">Товар</th>
<th className="px-4 py-3">Адрес</th>
<th className="px-4 py-3">Телефон</th>
<th className="px-4 py-3">Комментарий</th>
<th className="px-4 py-3">Действия</th>
</tr>
</thead>
<tbody className="divide-y divide-[#e4e2e4]">
{deliveries.map(delivery => (
<DeliveryRow
key={delivery.id}
delivery={delivery}
onStatusChange={onStatusChange}
onEdit={onEdit}
onDelete={onDelete}
/>
))}
</tbody>
</table>
</div>
)}
</div>
);
};

View File

@@ -0,0 +1,78 @@
import { MapPin, Phone } from 'lucide-react';
import type { Delivery } from '../../types';
import { pickupLocationLabels } from '../../types';
import { StatusBadge } from './StatusBadge';
interface DeliveryRowProps {
delivery: Delivery;
onStatusChange: (id: string) => void;
onEdit: (delivery: Delivery) => void;
onDelete: (id: string) => void;
}
export const DeliveryRow = ({ delivery, onStatusChange, onEdit, onDelete }: DeliveryRowProps) => {
const handleAddressClick = (e: React.MouseEvent) => {
e.stopPropagation();
const encodedAddress = encodeURIComponent(delivery.address);
window.open(`https://maps.google.com/?q=${encodedAddress}`, '_blank');
};
const handlePhoneClick = (e: React.MouseEvent) => {
e.stopPropagation();
window.location.href = `tel:${delivery.phone}`;
};
return (
<tr className="hover:bg-[#f5f3f5] transition-colors border-b border-[#e4e2e4] last:border-b-0">
<td className="px-4 py-3">
<StatusBadge
status={delivery.status}
onClick={() => onStatusChange(delivery.id)}
size="sm"
/>
</td>
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{delivery.date}</td>
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{pickupLocationLabels[delivery.pickupLocation]}</td>
<td className="px-4 py-3 text-sm text-[#1b1b1d]">{delivery.productName}</td>
<td className="px-4 py-3">
<button
onClick={handleAddressClick}
className="flex items-center gap-1.5 text-sm text-[#1B263B] hover:text-[#F28C28] transition-colors text-left"
>
<MapPin size={14} />
<span className="max-w-[200px] truncate">{delivery.address}</span>
</button>
</td>
<td className="px-4 py-3">
<button
onClick={handlePhoneClick}
className="flex items-center gap-1.5 text-sm text-[#16a34a] hover:underline transition-colors"
>
<Phone size={14} />
{delivery.phone}
</button>
</td>
<td className="px-4 py-3 text-sm text-[#45474d] max-w-[200px] truncate">
{delivery.comment || '-'}
</td>
<td className="px-4 py-3">
<div className="flex items-center gap-1">
<button
onClick={() => onEdit(delivery)}
className="p-1.5 rounded-md hover:bg-[#e4e2e4] text-[#75777d] transition-colors"
title="Редактировать"
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M17 3a2.828 2.828 0 1 1 4 4L7.5 20.5 2 22l1.5-5.5L17 3z"/></svg>
</button>
<button
onClick={() => onDelete(delivery.id)}
className="p-1.5 rounded-md hover:bg-red-50 text-red-500 transition-colors"
title="Удалить"
>
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round"><path d="M3 6h18"/><path d="M19 6v14c0 1-1 2-2 2H7c-1 0-2-1-2-2V6"/><path d="M8 6V4c0-1 1-2 2-2h4c1 0 2 1 2 2v2"/></svg>
</button>
</div>
</td>
</tr>
);
};

View File

@@ -0,0 +1,34 @@
import type { DeliveryStatus } from '../../types';
import { statusLabels } from '../../types';
interface StatusBadgeProps {
status: DeliveryStatus;
onClick?: () => void;
size?: 'sm' | 'md' | 'lg';
}
export const StatusBadge = ({ status, onClick, size = 'md' }: StatusBadgeProps) => {
const baseStyles = 'inline-flex items-center justify-center font-medium rounded-full transition-colors';
const variants = {
new: 'bg-[#ffdcc3] text-[#6e3900]',
delivered: 'bg-[#dcfce7] text-[#166534]',
};
const sizes = {
sm: 'px-2 py-0.5 text-xs',
md: 'px-3 py-1 text-sm',
lg: 'px-4 py-2 text-base',
};
const clickableStyles = onClick ? 'cursor-pointer hover:opacity-80 active:scale-95' : '';
return (
<span
className={`${baseStyles} ${variants[status]} ${sizes[size]} ${clickableStyles}`}
onClick={onClick}
>
{statusLabels[status]}
</span>
);
};

View File

@@ -0,0 +1,39 @@
import type { ButtonHTMLAttributes, ReactNode } from 'react';
interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
variant?: 'primary' | 'secondary' | 'tertiary' | 'ghost';
size?: 'sm' | 'md' | 'lg';
children: ReactNode;
}
export const Button = ({
variant = 'primary',
size = 'md',
children,
className = '',
...props
}: ButtonProps) => {
const baseStyles = 'inline-flex items-center justify-center font-medium rounded-md transition-colors focus:outline-none focus:ring-2 focus:ring-offset-2 disabled:opacity-50 disabled:cursor-not-allowed';
const variants = {
primary: 'bg-[#1B263B] text-white hover:bg-[#2a3a52] focus:ring-[#1B263B]',
secondary: 'bg-[#f0edef] text-[#1b1b1d] hover:bg-[#e4e2e4] focus:ring-[#75777d]',
tertiary: 'bg-[#F28C28] text-white hover:bg-[#d97a1f] focus:ring-[#F28C28]',
ghost: 'bg-transparent text-[#1b1b1d] hover:bg-[#f5f3f5] focus:ring-[#75777d]',
};
const sizes = {
sm: 'px-3 py-1.5 text-sm',
md: 'px-4 py-2 text-base',
lg: 'px-6 py-3 text-lg',
};
return (
<button
className={`${baseStyles} ${variants[variant]} ${sizes[size]} ${className}`}
{...props}
>
{children}
</button>
);
};

View File

@@ -0,0 +1,22 @@
import type { ReactNode } from 'react';
interface CardProps {
children: ReactNode;
className?: string;
padding?: 'none' | 'sm' | 'md' | 'lg';
}
export const Card = ({ children, className = '', padding = 'md' }: CardProps) => {
const paddings = {
none: '',
sm: 'p-3',
md: 'p-4',
lg: 'p-6',
};
return (
<div className={`bg-white rounded-lg shadow-sm border border-[#e4e2e4] ${paddings[padding]} ${className}`}>
{children}
</div>
);
};

View File

@@ -0,0 +1,25 @@
import type { InputHTMLAttributes } from 'react';
interface InputProps extends InputHTMLAttributes<HTMLInputElement> {
label?: string;
error?: string;
}
export const Input = ({ label, error, className = '', ...props }: InputProps) => {
return (
<div className="w-full">
{label && (
<label className="block text-sm font-medium text-[#1b1b1d] mb-1">
{label}
</label>
)}
<input
className={`w-full px-3 py-2 bg-[#f5f3f5] border border-[#c5c6cd] rounded-md text-[#1b1b1d] placeholder-[#75777d] focus:outline-none focus:ring-2 focus:ring-[#1B263B] focus:border-transparent transition-colors ${className}`}
{...props}
/>
{error && (
<p className="mt-1 text-sm text-red-600">{error}</p>
)}
</div>
);
};

View File

@@ -0,0 +1,44 @@
import { X } from 'lucide-react';
import type { ReactNode } from 'react';
interface ModalProps {
isOpen: boolean;
onClose: () => void;
title: string;
children: ReactNode;
footer?: ReactNode;
}
export const Modal = ({ isOpen, onClose, title, children, footer }: ModalProps) => {
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-50 overflow-y-auto">
<div className="flex min-h-full items-center justify-center p-4 text-center">
<div
className="fixed inset-0 bg-black/30 transition-opacity"
onClick={onClose}
/>
<div className="relative transform overflow-hidden rounded-lg bg-white text-left shadow-xl transition-all w-full max-w-lg">
<div className="flex items-center justify-between border-b border-[#e4e2e4] px-4 py-3">
<h3 className="text-lg font-semibold text-[#1b1b1d]">{title}</h3>
<button
onClick={onClose}
className="rounded-full p-1 hover:bg-[#f5f3f5] transition-colors"
>
<X size={20} className="text-[#75777d]" />
</button>
</div>
<div className="px-4 py-4">
{children}
</div>
{footer && (
<div className="border-t border-[#e4e2e4] px-4 py-3 flex justify-end gap-2">
{footer}
</div>
)}
</div>
</div>
</div>
);
};

View File

@@ -0,0 +1,37 @@
import type { SelectHTMLAttributes } from 'react';
interface SelectOption {
value: string;
label: string;
}
interface SelectProps extends SelectHTMLAttributes<HTMLSelectElement> {
label?: string;
options: SelectOption[];
error?: string;
}
export const Select = ({ label, options, error, className = '', ...props }: SelectProps) => {
return (
<div className="w-full">
{label && (
<label className="block text-sm font-medium text-[#1b1b1d] mb-1">
{label}
</label>
)}
<select
className={`w-full px-3 py-2 bg-[#f5f3f5] border border-[#c5c6cd] rounded-md text-[#1b1b1d] focus:outline-none focus:ring-2 focus:ring-[#1B263B] focus:border-transparent transition-colors ${className}`}
{...props}
>
{options.map((option) => (
<option key={option.value} value={option.value}>
{option.label}
</option>
))}
</select>
{error && (
<p className="mt-1 text-sm text-red-600">{error}</p>
)}
</div>
);
};

View File

@@ -0,0 +1,5 @@
export { Button } from './Button';
export { Card } from './Card';
export { Modal } from './Modal';
export { Input } from './Input';
export { Select } from './Select';

View File

@@ -0,0 +1,83 @@
import { useEffect, useCallback } from 'react';
import { useDeliveryStore } from '../stores/deliveryStore';
import type { Delivery } from '../types';
type WebSocketEvent =
| { type: 'delivery.created'; payload: Delivery }
| { type: 'delivery.updated'; payload: Delivery }
| { type: 'delivery.deleted'; payload: { id: string } };
type EventHandler = (event: WebSocketEvent) => void;
class MockWebSocket {
private handlers: EventHandler[] = [];
private isConnected = false;
connect() {
this.isConnected = true;
console.log('WebSocket connected (mock)');
}
disconnect() {
this.isConnected = false;
console.log('WebSocket disconnected (mock)');
}
subscribe(handler: EventHandler) {
this.handlers.push(handler);
return () => {
this.handlers = this.handlers.filter((h) => h !== handler);
};
}
emit(event: WebSocketEvent) {
if (!this.isConnected) return;
this.handlers.forEach((handler) => handler(event));
}
simulateIncomingEvent(event: WebSocketEvent) {
this.emit(event);
}
}
const mockWebSocket = new MockWebSocket();
export const useWebSocket = () => {
const { addDelivery, updateDelivery, deleteDelivery } = useDeliveryStore();
useEffect(() => {
mockWebSocket.connect();
const unsubscribe = mockWebSocket.subscribe((event) => {
switch (event.type) {
case 'delivery.created':
addDelivery(event.payload);
break;
case 'delivery.updated':
updateDelivery(event.payload.id, event.payload);
break;
case 'delivery.deleted':
deleteDelivery(event.payload.id);
break;
}
});
return () => {
unsubscribe();
mockWebSocket.disconnect();
};
}, [addDelivery, updateDelivery, deleteDelivery]);
const sendEvent = useCallback((event: WebSocketEvent) => {
mockWebSocket.emit(event);
}, []);
return { sendEvent, isConnected: true };
};
export const simulateIncomingDelivery = (delivery: Delivery) => {
mockWebSocket.simulateIncomingEvent({
type: 'delivery.created',
payload: delivery,
});
};

34
frontend/src/index.css Normal file
View File

@@ -0,0 +1,34 @@
@import "tailwindcss";
@theme {
--color-primary: #1B263B;
--color-primary-container: #051125;
--color-tertiary: #F28C28;
--color-surface: #fbf8fb;
--color-surface-container: #f0edef;
--color-surface-container-low: #f5f3f5;
--color-surface-container-high: #eae7e9;
--color-on-surface: #1b1b1d;
--color-outline: #75777d;
--color-outline-variant: #c5c6cd;
--color-success: #16a34a;
--font-sans: 'Inter', system-ui, sans-serif;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: var(--font-sans);
background-color: var(--color-surface);
color: var(--color-on-surface);
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
#root {
min-height: 100vh;
width: 100%;
}

21
frontend/src/main.tsx Normal file
View File

@@ -0,0 +1,21 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import './index.css'
import App from './App.tsx'
import { mockDeliveries } from './utils/mockData'
import { useDeliveryStore } from './stores/deliveryStore'
// Seed mock data if no data exists
const stored = localStorage.getItem('delivery-tracker-data')
if (!stored) {
const store = useDeliveryStore.getState()
mockDeliveries.forEach(delivery => {
store.addDelivery(delivery)
})
}
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

View File

@@ -0,0 +1,220 @@
import { useState } from 'react';
import { Plus, Printer, ChevronRight, CalendarDays } from 'lucide-react';
import { format, startOfMonth, endOfMonth, eachDayOfInterval, isToday } from 'date-fns';
import { ru } from 'date-fns/locale';
import { useDeliveryStore } from '../stores/deliveryStore';
import { Button } from '../components/ui/Button';
import { Card } from '../components/ui/Card';
interface DashboardProps {
onDateSelect: (date: string) => void;
onAddDelivery: () => void;
}
export const Dashboard = ({ onDateSelect, onAddDelivery }: DashboardProps) => {
const deliveries = useDeliveryStore(state => state.deliveries);
const [currentMonth, setCurrentMonth] = useState(new Date());
const monthStart = startOfMonth(currentMonth);
const monthEnd = endOfMonth(currentMonth);
const days = eachDayOfInterval({ start: monthStart, end: monthEnd });
const getCountForDate = (date: Date) => {
const dateStr = format(date, 'dd-MM-yyyy');
return deliveries.filter(d => d.date === dateStr).length;
};
const handlePrintDay = (date: Date) => {
const dateStr = format(date, 'dd-MM-yyyy');
const dayDeliveries = deliveries.filter(d => d.date === dateStr);
const printWindow = window.open('', '_blank');
if (!printWindow) return;
const html = `
<!DOCTYPE html>
<html>
<head>
<title>Доставки на ${format(date, 'dd MMMM yyyy', { locale: ru })}</title>
<style>
body { font-family: system-ui, sans-serif; margin: 20px; }
h1 { font-size: 18px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid #ddd; }
th { font-weight: 600; background: #f5f5f5; }
.status-new { background: #ffdcc3; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
.status-delivered { background: #dcfce7; padding: 2px 8px; border-radius: 12px; font-size: 12px; }
</style>
</head>
<body>
<h1>Доставки на ${format(date, 'dd MMMM yyyy', { locale: ru })}</h1>
<table>
<tr>
<th>Статус</th>
<th>Загрузка</th>
<th>Товар</th>
<th>Адрес</th>
<th>Телефон</th>
<th>Комментарий</th>
</tr>
${dayDeliveries.map(d => `
<tr>
<td><span class="status-${d.status}">${d.status === 'new' ? 'Новое' : 'Доставлено'}</span></td>
<td>${d.pickupLocation === 'warehouse' ? 'Склад' : d.pickupLocation === 'symbat' ? 'Сымбат' : d.pickupLocation === 'nursaya' ? 'Нурсая' : 'Галактика'}</td>
<td>${d.productName}</td>
<td>${d.address}</td>
<td>${d.phone}</td>
<td>${d.comment || '-'}</td>
</tr>
`).join('')}
</table>
</body>
</html>
`;
printWindow.document.write(html);
printWindow.document.close();
printWindow.print();
};
const navigateMonth = (direction: 'prev' | 'next') => {
setCurrentMonth(prev => {
const newDate = new Date(prev);
newDate.setMonth(prev.getMonth() + (direction === 'next' ? 1 : -1));
return newDate;
});
};
return (
<div className="space-y-6">
<div className="flex items-center justify-between">
<div>
<h1 className="text-2xl font-bold text-[#1b1b1d]">Панель управления</h1>
<p className="text-[#75777d] mt-1">Выберите дату для просмотра доставок</p>
</div>
<Button onClick={onAddDelivery}>
<Plus size={18} className="mr-2" />
Новая доставка
</Button>
</div>
<Card className="p-6">
<div className="flex items-center justify-between mb-6">
<h2 className="text-lg font-semibold text-[#1b1b1d] flex items-center gap-2">
<CalendarDays size={20} className="text-[#1B263B]" />
{format(currentMonth, 'MMMM yyyy', { locale: ru })}
</h2>
<div className="flex gap-2">
<Button variant="ghost" size="sm" onClick={() => navigateMonth('prev')}>
</Button>
<Button
variant="ghost"
size="sm"
onClick={() => setCurrentMonth(new Date())}
>
Сегодня
</Button>
<Button variant="ghost" size="sm" onClick={() => navigateMonth('next')}>
</Button>
</div>
</div>
<div className="grid grid-cols-7 gap-1 mb-2">
{['Пн', 'Вт', 'Ср', 'Чт', 'Пт', 'Сб', 'Вс'].map(day => (
<div key={day} className="text-center text-xs font-medium text-[#75777d] py-2">
{day}
</div>
))}
</div>
<div className="grid grid-cols-7 gap-1">
{days.map((day) => {
const count = getCountForDate(day);
const isTodayDate = isToday(day);
return (
<button
key={day.toISOString()}
onClick={() => onDateSelect(format(day, 'dd-MM-yyyy'))}
className={`
relative p-3 rounded-lg text-left transition-all min-h-[80px]
${isTodayDate ? 'bg-[#1B263B] text-white' : 'hover:bg-[#f5f3f5]'}
${!isTodayDate && count > 0 ? 'bg-[#ffdcc3]/30' : ''}
`}
>
<div className={`text-sm font-medium ${isTodayDate ? 'text-white' : 'text-[#1b1b1d]'}`}>
{format(day, 'd')}
</div>
{count > 0 && (
<div className={`mt-1 text-[10px] truncate w-full ${isTodayDate ? 'text-white/80' : 'text-[#F28C28]'}`}>
{count} {count === 1 ? 'доставка' : count < 5 ? 'доставки' : 'доставок'}
</div>
)}
</button>
);
})}
</div>
</Card>
<div className="space-y-3">
<h3 className="font-semibold text-[#1b1b1d]">Ближайшие даты с доставками</h3>
{days
.filter(day => getCountForDate(day) > 0)
.slice(0, 7)
.map(day => {
const count = getCountForDate(day);
return (
<Card key={day.toISOString()} className="flex items-center justify-between p-4">
<div className="flex items-center gap-4">
<div className="text-center min-w-[60px]">
<div className="text-2xl font-bold text-[#1B263B]">
{format(day, 'd')}
</div>
<div className="text-xs text-[#75777d] uppercase">
{format(day, 'MMM', { locale: ru })}
</div>
</div>
<div>
<div className="font-medium text-[#1b1b1d]">
{count} {count === 1 ? 'доставка' : count < 5 ? 'доставки' : 'доставок'}
</div>
<div className="text-sm text-[#75777d]">
{format(day, 'EEEE', { locale: ru })}
</div>
</div>
</div>
<div className="flex items-center gap-2">
<Button
variant="ghost"
size="sm"
onClick={() => handlePrintDay(day)}
>
<Printer size={16} />
</Button>
<Button
variant="secondary"
size="sm"
onClick={() => onDateSelect(format(day, 'dd-MM-yyyy'))}
>
Открыть
<ChevronRight size={16} className="ml-1" />
</Button>
</div>
</Card>
);
})}
{days.filter(day => getCountForDate(day) > 0).length === 0 && (
<Card className="p-8 text-center">
<p className="text-[#75777d]">Нет запланированных доставок</p>
<Button onClick={onAddDelivery} variant="ghost" className="mt-2">
Создать первую доставку
</Button>
</Card>
)}
</div>
</div>
);
};

View File

@@ -0,0 +1,115 @@
import { useState } from 'react';
import { ArrowLeft, Filter } from 'lucide-react';
import { useDeliveryStore } from '../stores/deliveryStore';
import { DeliveryList as DeliveryListComponent } from '../components/delivery/DeliveryList';
import { DeliveryForm } from '../components/delivery/DeliveryForm';
import { Button } from '../components/ui/Button';
import { Select } from '../components/ui/Select';
import type { Delivery, PickupLocation } from '../types';
import { pickupLocationLabels } from '../types';
interface DeliveryListPageProps {
selectedDate: string;
onBack: () => void;
}
export const DeliveryListPage = ({ selectedDate, onBack }: DeliveryListPageProps) => {
const deliveries = useDeliveryStore(state => state.deliveries);
const toggleStatus = useDeliveryStore(state => state.toggleStatus);
const deleteDelivery = useDeliveryStore(state => state.deleteDelivery);
const updateDelivery = useDeliveryStore(state => state.updateDelivery);
const addDelivery = useDeliveryStore(state => state.addDelivery);
const [isFormOpen, setIsFormOpen] = useState(false);
const [editingDelivery, setEditingDelivery] = useState<Delivery | null>(null);
const [pickupFilter, setPickupFilter] = useState<PickupLocation | 'all'>('all');
const dayDeliveries = deliveries.filter(d => d.date === selectedDate);
const filteredDeliveries = pickupFilter === 'all'
? dayDeliveries
: dayDeliveries.filter(d => d.pickupLocation === pickupFilter);
const pickupOptions: { value: PickupLocation | 'all'; label: string }[] = [
{ value: 'all', label: 'Все места загрузки' },
{ value: 'warehouse', label: pickupLocationLabels.warehouse },
{ value: 'symbat', label: pickupLocationLabels.symbat },
{ value: 'nursaya', label: pickupLocationLabels.nursaya },
{ value: 'galaktika', label: pickupLocationLabels.galaktika },
];
const handleStatusChange = (id: string) => {
toggleStatus(id);
};
const handleEdit = (delivery: Delivery) => {
setEditingDelivery(delivery);
setIsFormOpen(true);
};
const handleDelete = (id: string) => {
if (confirm('Удалить эту доставку?')) {
deleteDelivery(id);
}
};
const handleSubmit = (data: Omit<Delivery, 'id' | 'createdAt' | 'updatedAt'>) => {
if (editingDelivery) {
updateDelivery(editingDelivery.id, data);
} else {
addDelivery(data);
}
setEditingDelivery(null);
};
const handleAdd = () => {
setEditingDelivery(null);
setIsFormOpen(true);
};
const handleCloseForm = () => {
setIsFormOpen(false);
setEditingDelivery(null);
};
return (
<div className="space-y-4">
<div className="flex items-center justify-between flex-wrap gap-4">
<div className="flex items-center gap-4">
<Button variant="ghost" size="sm" onClick={onBack}>
<ArrowLeft size={18} className="mr-1" />
Назад
</Button>
<div className="flex items-center gap-2 text-sm text-[#75777d]">
<Filter size={16} />
<span>Всего: {filteredDeliveries.length}</span>
</div>
</div>
<div className="w-48">
<Select
label=""
value={pickupFilter}
onChange={(e) => setPickupFilter(e.target.value as PickupLocation | 'all')}
options={pickupOptions}
/>
</div>
</div>
<DeliveryListComponent
deliveries={filteredDeliveries}
onStatusChange={handleStatusChange}
onEdit={handleEdit}
onDelete={handleDelete}
onAdd={handleAdd}
date={selectedDate}
/>
<DeliveryForm
isOpen={isFormOpen}
onClose={handleCloseForm}
onSubmit={handleSubmit}
initialData={editingDelivery}
defaultDate={selectedDate}
/>
</div>
);
};

View File

@@ -0,0 +1,83 @@
import { create } from 'zustand';
import { persist } from 'zustand/middleware';
import type { Delivery } from '../types';
interface DeliveryState {
deliveries: Delivery[];
addDelivery: (delivery: Omit<Delivery, 'id' | 'createdAt' | 'updatedAt'>) => void;
updateDelivery: (id: string, updates: Partial<Delivery>) => void;
deleteDelivery: (id: string) => void;
toggleStatus: (id: string) => void;
getDeliveriesByDate: (date: string) => Delivery[];
getDeliveriesByDateRange: (startDate: string, endDate: string) => Delivery[];
getDeliveryCountsByDate: () => Record<string, number>;
}
const STORAGE_KEY = 'delivery-tracker-data';
export const useDeliveryStore = create<DeliveryState>()(
persist(
(set, get) => ({
deliveries: [],
addDelivery: (delivery) => {
const now = Date.now();
const newDelivery: Delivery = {
...delivery,
id: crypto.randomUUID(),
createdAt: now,
updatedAt: now,
};
set((state) => ({
deliveries: [...state.deliveries, newDelivery],
}));
},
updateDelivery: (id, updates) => {
set((state) => ({
deliveries: state.deliveries.map((d) =>
d.id === id ? { ...d, ...updates, updatedAt: Date.now() } : d
),
}));
},
deleteDelivery: (id) => {
set((state) => ({
deliveries: state.deliveries.filter((d) => d.id !== id),
}));
},
toggleStatus: (id) => {
set((state) => ({
deliveries: state.deliveries.map((d) =>
d.id === id
? { ...d, status: d.status === 'new' ? 'delivered' : 'new', updatedAt: Date.now() }
: d
),
}));
},
getDeliveriesByDate: (date) => {
return get().deliveries.filter((d) => d.date === date);
},
getDeliveriesByDateRange: (startDate, endDate) => {
return get().deliveries.filter((d) => {
const date = d.date;
return date >= startDate && date <= endDate;
});
},
getDeliveryCountsByDate: () => {
const counts: Record<string, number> = {};
get().deliveries.forEach((d) => {
counts[d.date] = (counts[d.date] || 0) + 1;
});
return counts;
},
}),
{
name: STORAGE_KEY,
}
)
);

View File

@@ -0,0 +1,30 @@
export type PickupLocation = 'warehouse' | 'symbat' | 'nursaya' | 'galaktika';
export type DeliveryStatus = 'new' | 'delivered';
export interface Delivery {
id: string;
date: string; // DD-MM-YYYY
pickupLocation: PickupLocation;
productName: string;
address: string;
phone: string;
additionalPhone?: string;
hasElevator: boolean;
comment: string;
status: DeliveryStatus;
createdAt: number;
updatedAt: number;
}
export const pickupLocationLabels: Record<PickupLocation, string> = {
warehouse: 'Склад',
symbat: 'Сымбат',
nursaya: 'Нурсая',
galaktika: 'Галактика',
};
export const statusLabels: Record<DeliveryStatus, string> = {
new: 'Новое',
delivered: 'Доставлено',
};

View File

@@ -0,0 +1,59 @@
import type { Delivery } from '../types';
export const mockDeliveries: Omit<Delivery, 'id' | 'createdAt' | 'updatedAt'>[] = [
{
date: new Date().toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'symbat',
productName: 'Диван прямой Милан',
address: 'ул. Ленина, д. 10, кв. 25',
phone: '+7 (771)-123-45-67',
additionalPhone: '',
hasElevator: true,
comment: 'Доставить после 18:00',
status: 'new',
},
{
date: new Date().toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'warehouse',
productName: 'Шкаф двухдверный',
address: 'ул. Гагарина, д. 5, офис 304',
phone: '+7 (777)-234-56-78',
additionalPhone: '+7 (702)-111-22-33',
hasElevator: false,
comment: 'Предварительно позвонить',
status: 'new',
},
{
date: new Date(Date.now() + 86400000).toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'nursaya',
productName: 'Стол обеденный + 4 стула',
address: 'пр. Мира, д. 15',
phone: '+7 (705)-345-67-89',
additionalPhone: '',
hasElevator: true,
comment: '',
status: 'new',
},
{
date: new Date(Date.now() - 86400000).toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'galaktika',
productName: 'Матрас ортопедический 160x200',
address: 'ул. Пушкина, д. 20',
phone: '+7 (701)-456-78-90',
additionalPhone: '',
hasElevator: false,
comment: 'Доставлено успешно',
status: 'delivered',
},
{
date: new Date(Date.now() + 172800000).toLocaleDateString('ru-RU').split('.').join('-'),
pickupLocation: 'warehouse',
productName: 'Кресло реклайнер',
address: 'ул. Чехова, д. 8, кв. 12',
phone: '+7 (776)-567-89-01',
additionalPhone: '',
hasElevator: true,
comment: 'Подъезд с торца',
status: 'new',
},
];