Initial commit
This commit is contained in:
39
.gitignore
vendored
Normal file
39
.gitignore
vendored
Normal file
@@ -0,0 +1,39 @@
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
pnpm-debug.log*
|
||||
lerna-debug.log*
|
||||
|
||||
node_modules
|
||||
dist
|
||||
dist-ssr
|
||||
*.local
|
||||
|
||||
# Environment files
|
||||
.env
|
||||
.env.local
|
||||
.env.*.local
|
||||
|
||||
# Testing
|
||||
coverage
|
||||
.nyc_output
|
||||
|
||||
# Cache
|
||||
.cache
|
||||
.temp
|
||||
.tmp
|
||||
*.tsbuildinfo
|
||||
|
||||
# Editor directories and files
|
||||
.vscode/*
|
||||
!.vscode/extensions.json
|
||||
.idea
|
||||
.DS_Store
|
||||
*.suo
|
||||
*.ntvs*
|
||||
*.njsproj
|
||||
*.sln
|
||||
*.sw?
|
||||
73
README.md
Normal file
73
README.md
Normal file
@@ -0,0 +1,73 @@
|
||||
# React + TypeScript + Vite
|
||||
|
||||
This template provides a minimal setup to get React working in Vite with HMR and some ESLint rules.
|
||||
|
||||
Currently, two official plugins are available:
|
||||
|
||||
- [@vitejs/plugin-react](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react) uses [Oxc](https://oxc.rs)
|
||||
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/)
|
||||
|
||||
## React Compiler
|
||||
|
||||
The React Compiler is not enabled on this template because of its impact on dev & build performances. To add it, see [this documentation](https://react.dev/learn/react-compiler/installation).
|
||||
|
||||
## Expanding the ESLint configuration
|
||||
|
||||
If you are developing a production application, we recommend updating the configuration to enable type-aware lint rules:
|
||||
|
||||
```js
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
|
||||
// Remove tseslint.configs.recommended and replace with this
|
||||
tseslint.configs.recommendedTypeChecked,
|
||||
// Alternatively, use this for stricter rules
|
||||
tseslint.configs.strictTypeChecked,
|
||||
// Optionally, add this for stylistic rules
|
||||
tseslint.configs.stylisticTypeChecked,
|
||||
|
||||
// Other configs...
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
|
||||
You can also install [eslint-plugin-react-x](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-x) and [eslint-plugin-react-dom](https://github.com/Rel1cx/eslint-react/tree/main/packages/plugins/eslint-plugin-react-dom) for React-specific lint rules:
|
||||
|
||||
```js
|
||||
// eslint.config.js
|
||||
import reactX from 'eslint-plugin-react-x'
|
||||
import reactDom from 'eslint-plugin-react-dom'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
// Other configs...
|
||||
// Enable lint rules for React
|
||||
reactX.configs['recommended-typescript'],
|
||||
// Enable lint rules for React DOM
|
||||
reactDom.configs.recommended,
|
||||
],
|
||||
languageOptions: {
|
||||
parserOptions: {
|
||||
project: ['./tsconfig.node.json', './tsconfig.app.json'],
|
||||
tsconfigRootDir: import.meta.dirname,
|
||||
},
|
||||
// other options...
|
||||
},
|
||||
},
|
||||
])
|
||||
```
|
||||
23
eslint.config.js
Normal file
23
eslint.config.js
Normal file
@@ -0,0 +1,23 @@
|
||||
import js from '@eslint/js'
|
||||
import globals from 'globals'
|
||||
import reactHooks from 'eslint-plugin-react-hooks'
|
||||
import reactRefresh from 'eslint-plugin-react-refresh'
|
||||
import tseslint from 'typescript-eslint'
|
||||
import { defineConfig, globalIgnores } from 'eslint/config'
|
||||
|
||||
export default defineConfig([
|
||||
globalIgnores(['dist']),
|
||||
{
|
||||
files: ['**/*.{ts,tsx}'],
|
||||
extends: [
|
||||
js.configs.recommended,
|
||||
tseslint.configs.recommended,
|
||||
reactHooks.configs.flat.recommended,
|
||||
reactRefresh.configs.vite,
|
||||
],
|
||||
languageOptions: {
|
||||
ecmaVersion: 2020,
|
||||
globals: globals.browser,
|
||||
},
|
||||
},
|
||||
])
|
||||
17
index.html
Normal file
17
index.html
Normal file
@@ -0,0 +1,17 @@
|
||||
<!doctype html>
|
||||
<html lang="ru">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
|
||||
<link rel="manifest" href="/manifest.json" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
|
||||
<meta name="theme-color" content="#1B263B" />
|
||||
<meta name="apple-mobile-web-app-capable" content="yes" />
|
||||
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
|
||||
<title>Delivery Tracker</title>
|
||||
</head>
|
||||
<body>
|
||||
<div id="root"></div>
|
||||
<script type="module" src="/src/main.tsx"></script>
|
||||
</body>
|
||||
</html>
|
||||
35
package.json
Normal file
35
package.json
Normal file
@@ -0,0 +1,35 @@
|
||||
{
|
||||
"name": "delivery-tracker",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "vite",
|
||||
"build": "tsc -b && vite build",
|
||||
"lint": "eslint .",
|
||||
"preview": "vite preview"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/vite": "^4.2.2",
|
||||
"date-fns": "^4.1.0",
|
||||
"lucide-react": "^1.7.0",
|
||||
"react": "^19.2.4",
|
||||
"react-dom": "^19.2.4",
|
||||
"tailwindcss": "^4.2.2",
|
||||
"zustand": "^5.0.12"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^9.39.4",
|
||||
"@types/node": "^24.12.0",
|
||||
"@types/react": "^19.2.14",
|
||||
"@types/react-dom": "^19.2.3",
|
||||
"@vitejs/plugin-react": "^6.0.1",
|
||||
"eslint": "^9.39.4",
|
||||
"eslint-plugin-react-hooks": "^7.0.1",
|
||||
"eslint-plugin-react-refresh": "^0.5.2",
|
||||
"globals": "^17.4.0",
|
||||
"typescript": "~5.9.3",
|
||||
"typescript-eslint": "^8.57.0",
|
||||
"vite": "^8.0.1"
|
||||
}
|
||||
}
|
||||
1
public/favicon.svg
Normal file
1
public/favicon.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 9.3 KiB |
24
public/icons.svg
Normal file
24
public/icons.svg
Normal file
@@ -0,0 +1,24 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<symbol id="bluesky-icon" viewBox="0 0 16 17">
|
||||
<g clip-path="url(#bluesky-clip)"><path fill="#08060d" d="M7.75 7.735c-.693-1.348-2.58-3.86-4.334-5.097-1.68-1.187-2.32-.981-2.74-.79C.188 2.065.1 2.812.1 3.251s.241 3.602.398 4.13c.52 1.744 2.367 2.333 4.07 2.145-2.495.37-4.71 1.278-1.805 4.512 3.196 3.309 4.38-.71 4.987-2.746.608 2.036 1.307 5.91 4.93 2.746 2.72-2.746.747-4.143-1.747-4.512 1.702.189 3.55-.4 4.07-2.145.156-.528.397-3.691.397-4.13s-.088-1.186-.575-1.406c-.42-.19-1.06-.395-2.741.79-1.755 1.24-3.64 3.752-4.334 5.099"/></g>
|
||||
<defs><clipPath id="bluesky-clip"><path fill="#fff" d="M.1.85h15.3v15.3H.1z"/></clipPath></defs>
|
||||
</symbol>
|
||||
<symbol id="discord-icon" viewBox="0 0 20 19">
|
||||
<path fill="#08060d" d="M16.224 3.768a14.5 14.5 0 0 0-3.67-1.153c-.158.286-.343.67-.47.976a13.5 13.5 0 0 0-4.067 0c-.128-.306-.317-.69-.476-.976A14.4 14.4 0 0 0 3.868 3.77C1.546 7.28.916 10.703 1.231 14.077a14.7 14.7 0 0 0 4.5 2.306q.545-.748.965-1.587a9.5 9.5 0 0 1-1.518-.74q.191-.14.372-.293c2.927 1.369 6.107 1.369 8.999 0q.183.152.372.294-.723.437-1.52.74.418.838.963 1.588a14.6 14.6 0 0 0 4.504-2.308c.37-3.911-.63-7.302-2.644-10.309m-9.13 8.234c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.894 0 1.614.82 1.599 1.82.001 1-.705 1.82-1.6 1.82m5.91 0c-.878 0-1.599-.82-1.599-1.82 0-.998.705-1.82 1.6-1.82.893 0 1.614.82 1.599 1.82 0 1-.706 1.82-1.6 1.82"/>
|
||||
</symbol>
|
||||
<symbol id="documentation-icon" viewBox="0 0 21 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="m15.5 13.333 1.533 1.322c.645.555.967.833.967 1.178s-.322.623-.967 1.179L15.5 18.333m-3.333-5-1.534 1.322c-.644.555-.966.833-.966 1.178s.322.623.966 1.179l1.534 1.321"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M17.167 10.836v-4.32c0-1.41 0-2.117-.224-2.68-.359-.906-1.118-1.621-2.08-1.96-.599-.21-1.349-.21-2.848-.21-2.623 0-3.935 0-4.983.369-1.684.591-3.013 1.842-3.641 3.428C3 6.449 3 7.684 3 10.154v2.122c0 2.558 0 3.838.706 4.726q.306.383.713.671c.76.536 1.79.64 3.581.66"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M3 10a2.78 2.78 0 0 1 2.778-2.778c.555 0 1.209.097 1.748-.047.48-.129.854-.503.982-.982.145-.54.048-1.194.048-1.749a2.78 2.78 0 0 1 2.777-2.777"/>
|
||||
</symbol>
|
||||
<symbol id="github-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M9.356 1.85C5.05 1.85 1.57 5.356 1.57 9.694a7.84 7.84 0 0 0 5.324 7.44c.387.079.528-.168.528-.376 0-.182-.013-.805-.013-1.454-2.165.467-2.616-.935-2.616-.935-.349-.91-.864-1.143-.864-1.143-.71-.48.051-.48.051-.48.787.051 1.2.805 1.2.805.695 1.194 1.817.857 2.268.649.064-.507.27-.857.49-1.052-1.728-.182-3.545-.857-3.545-3.87 0-.857.31-1.558.8-2.104-.078-.195-.349-1 .077-2.078 0 0 .657-.208 2.14.805a7.5 7.5 0 0 1 1.946-.26c.657 0 1.328.092 1.946.26 1.483-1.013 2.14-.805 2.14-.805.426 1.078.155 1.883.078 2.078.502.546.799 1.247.799 2.104 0 3.013-1.818 3.675-3.558 3.87.284.247.528.714.528 1.454 0 1.052-.012 1.896-.012 2.156 0 .208.142.455.528.377a7.84 7.84 0 0 0 5.324-7.441c.013-4.338-3.48-7.844-7.773-7.844" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
<symbol id="social-icon" viewBox="0 0 20 20">
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M12.5 6.667a4.167 4.167 0 1 0-8.334 0 4.167 4.167 0 0 0 8.334 0"/>
|
||||
<path fill="none" stroke="#aa3bff" stroke-linecap="round" stroke-linejoin="round" stroke-width="1.35" d="M2.5 16.667a5.833 5.833 0 0 1 8.75-5.053m3.837.474.513 1.035c.07.144.257.282.414.309l.93.155c.596.1.736.536.307.965l-.723.73a.64.64 0 0 0-.152.531l.207.903c.164.715-.213.991-.84.618l-.872-.52a.63.63 0 0 0-.577 0l-.872.52c-.624.373-1.003.094-.84-.618l.207-.903a.64.64 0 0 0-.152-.532l-.723-.729c-.426-.43-.289-.864.306-.964l.93-.156a.64.64 0 0 0 .412-.31l.513-1.034c.28-.562.735-.562 1.012 0"/>
|
||||
</symbol>
|
||||
<symbol id="x-icon" viewBox="0 0 19 19">
|
||||
<path fill="#08060d" fill-rule="evenodd" d="M1.893 1.98c.052.072 1.245 1.769 2.653 3.77l2.892 4.114c.183.261.333.48.333.486s-.068.089-.152.183l-.522.593-.765.867-3.597 4.087c-.375.426-.734.834-.798.905a1 1 0 0 0-.118.148c0 .01.236.017.664.017h.663l.729-.83c.4-.457.796-.906.879-.999a692 692 0 0 0 1.794-2.038c.034-.037.301-.34.594-.675l.551-.624.345-.392a7 7 0 0 1 .34-.374c.006 0 .93 1.306 2.052 2.903l2.084 2.965.045.063h2.275c1.87 0 2.273-.003 2.266-.021-.008-.02-1.098-1.572-3.894-5.547-2.013-2.862-2.28-3.246-2.273-3.266.008-.019.282-.332 2.085-2.38l2-2.274 1.567-1.782c.022-.028-.016-.03-.65-.03h-.674l-.3.342a871 871 0 0 1-1.782 2.025c-.067.075-.405.458-.75.852a100 100 0 0 1-.803.91c-.148.172-.299.344-.99 1.127-.304.343-.32.358-.345.327-.015-.019-.904-1.282-1.976-2.808L6.365 1.85H1.8zm1.782.91 8.078 11.294c.772 1.08 1.413 1.973 1.425 1.984.016.017.241.02 1.05.017l1.03-.004-2.694-3.766L7.796 5.75 5.722 2.852l-1.039-.004-1.039-.004z" clip-rule="evenodd"/>
|
||||
</symbol>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 4.9 KiB |
21
public/manifest.json
Normal file
21
public/manifest.json
Normal file
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Delivery Tracker",
|
||||
"short_name": "Deliveries",
|
||||
"description": "Система контроля доставок мебели",
|
||||
"start_url": "/",
|
||||
"display": "standalone",
|
||||
"background_color": "#fbf8fb",
|
||||
"theme_color": "#1B263B",
|
||||
"icons": [
|
||||
{
|
||||
"src": "/icon-192x192.png",
|
||||
"sizes": "192x192",
|
||||
"type": "image/png"
|
||||
},
|
||||
{
|
||||
"src": "/icon-512x512.png",
|
||||
"sizes": "512x512",
|
||||
"type": "image/png"
|
||||
}
|
||||
]
|
||||
}
|
||||
84
src/App.tsx
Normal file
84
src/App.tsx
Normal 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;
|
||||
BIN
src/assets/hero.png
Normal file
BIN
src/assets/hero.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 44 KiB |
1
src/assets/vite.svg
Normal file
1
src/assets/vite.svg
Normal file
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 8.5 KiB |
135
src/components/delivery/DeliveryCard.tsx
Normal file
135
src/components/delivery/DeliveryCard.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
183
src/components/delivery/DeliveryForm.tsx
Normal file
183
src/components/delivery/DeliveryForm.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
139
src/components/delivery/DeliveryList.tsx
Normal file
139
src/components/delivery/DeliveryList.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
78
src/components/delivery/DeliveryRow.tsx
Normal file
78
src/components/delivery/DeliveryRow.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
34
src/components/delivery/StatusBadge.tsx
Normal file
34
src/components/delivery/StatusBadge.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
39
src/components/ui/Button.tsx
Normal file
39
src/components/ui/Button.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
22
src/components/ui/Card.tsx
Normal file
22
src/components/ui/Card.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
25
src/components/ui/Input.tsx
Normal file
25
src/components/ui/Input.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
44
src/components/ui/Modal.tsx
Normal file
44
src/components/ui/Modal.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
37
src/components/ui/Select.tsx
Normal file
37
src/components/ui/Select.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
5
src/components/ui/index.ts
Normal file
5
src/components/ui/index.ts
Normal 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';
|
||||
83
src/hooks/useWebSocket.ts
Normal file
83
src/hooks/useWebSocket.ts
Normal 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
src/index.css
Normal file
34
src/index.css
Normal 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
src/main.tsx
Normal file
21
src/main.tsx
Normal 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>,
|
||||
)
|
||||
220
src/pages/Dashboard.tsx
Normal file
220
src/pages/Dashboard.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
115
src/pages/DeliveryListPage.tsx
Normal file
115
src/pages/DeliveryListPage.tsx
Normal 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>
|
||||
);
|
||||
};
|
||||
83
src/stores/deliveryStore.ts
Normal file
83
src/stores/deliveryStore.ts
Normal 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,
|
||||
}
|
||||
)
|
||||
);
|
||||
30
src/types/index.ts
Normal file
30
src/types/index.ts
Normal 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: 'Доставлено',
|
||||
};
|
||||
59
src/utils/mockData.ts
Normal file
59
src/utils/mockData.ts
Normal 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',
|
||||
},
|
||||
];
|
||||
28
tsconfig.app.json
Normal file
28
tsconfig.app.json
Normal file
@@ -0,0 +1,28 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"useDefineForClassFields": true,
|
||||
"lib": ["ES2023", "DOM", "DOM.Iterable"],
|
||||
"module": "ESNext",
|
||||
"types": ["vite/client"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
"jsx": "react-jsx",
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
7
tsconfig.json
Normal file
7
tsconfig.json
Normal file
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"files": [],
|
||||
"references": [
|
||||
{ "path": "./tsconfig.app.json" },
|
||||
{ "path": "./tsconfig.node.json" }
|
||||
]
|
||||
}
|
||||
26
tsconfig.node.json
Normal file
26
tsconfig.node.json
Normal file
@@ -0,0 +1,26 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||
"target": "ES2023",
|
||||
"lib": ["ES2023"],
|
||||
"module": "ESNext",
|
||||
"types": ["node"],
|
||||
"skipLibCheck": true,
|
||||
|
||||
/* Bundler mode */
|
||||
"moduleResolution": "bundler",
|
||||
"allowImportingTsExtensions": true,
|
||||
"verbatimModuleSyntax": true,
|
||||
"moduleDetection": "force",
|
||||
"noEmit": true,
|
||||
|
||||
/* Linting */
|
||||
"strict": true,
|
||||
"noUnusedLocals": true,
|
||||
"noUnusedParameters": true,
|
||||
"erasableSyntaxOnly": true,
|
||||
"noFallthroughCasesInSwitch": true,
|
||||
"noUncheckedSideEffectImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
15
vite.config.ts
Normal file
15
vite.config.ts
Normal file
@@ -0,0 +1,15 @@
|
||||
import { defineConfig } from 'vite'
|
||||
import react from '@vitejs/plugin-react'
|
||||
import tailwindcss from '@tailwindcss/vite'
|
||||
|
||||
// https://vite.dev/config/
|
||||
export default defineConfig({
|
||||
plugins: [react(), tailwindcss()],
|
||||
server: {
|
||||
allowedHosts: ['delivery.loca.lt', '.loca.lt'],
|
||||
// hmr: {
|
||||
// host: 'delivery.loca.lt', // Use the hostname provided by localtunnel
|
||||
// port: 443, // Use HTTPS port
|
||||
// },
|
||||
},
|
||||
})
|
||||
Reference in New Issue
Block a user