feat: add initial implementation of Kitchen CRM with authentication and dashboard features

- Create global styles and theme management
- Implement app shell layout with sidebar navigation
- Add authentication layout and pages for login and registration
- Develop dashboard page with placeholder content
- Introduce routing guards for guest-only and authenticated routes
- Set up Zustand for state management of authentication and theme
- Create API types and structures for CRM entities
- Configure Vite with PWA support and Tailwind CSS
This commit is contained in:
Artem Kashaev 2025-12-01 12:29:02 +05:00
parent c58a08bc9c
commit ede064cc11
76 changed files with 19882 additions and 1 deletions

27
.gitignore vendored
View File

@ -161,3 +161,30 @@ cython_debug/
#.idea/ #.idea/
task.instructions.md task.instructions.md
frontend.instructions.md
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*
node_modules
dist
dist-ssr
*.local
# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?

View File

@ -0,0 +1 @@
npx lint-staged

73
frontend/README.md Normal file
View 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 [Babel](https://babeljs.io/) (or [oxc](https://oxc.rs) when used in [rolldown-vite](https://vite.dev/guide/rolldown)) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## 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...
},
},
])
```

View File

@ -0,0 +1 @@
if('serviceWorker' in navigator) navigator.serviceWorker.register('/dev-sw.js?dev-sw', { scope: '/', type: 'classic' })

View File

105
frontend/dev-dist/sw.js Normal file
View File

@ -0,0 +1,105 @@
/**
* Copyright 2018 Google Inc. All Rights Reserved.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* http://www.apache.org/licenses/LICENSE-2.0
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
// If the loader is already loaded, just stop.
if (!self.define) {
let registry = {};
// Used for `eval` and `importScripts` where we can't get script URL by other means.
// In both cases, it's safe to use a global var because those functions are synchronous.
let nextDefineUri;
const singleRequire = (uri, parentUri) => {
uri = new URL(uri + ".js", parentUri).href;
return registry[uri] || (
new Promise(resolve => {
if ("document" in self) {
const script = document.createElement("script");
script.src = uri;
script.onload = resolve;
document.head.appendChild(script);
} else {
nextDefineUri = uri;
importScripts(uri);
resolve();
}
})
.then(() => {
let promise = registry[uri];
if (!promise) {
throw new Error(`Module ${uri} didnt register its module`);
}
return promise;
})
);
};
self.define = (depsNames, factory) => {
const uri = nextDefineUri || ("document" in self ? document.currentScript.src : "") || location.href;
if (registry[uri]) {
// Module is already loading or loaded.
return;
}
let exports = {};
const require = depUri => singleRequire(depUri, uri);
const specialDeps = {
module: { uri },
exports,
require
};
registry[uri] = Promise.all(depsNames.map(
depName => specialDeps[depName] || require(depName)
)).then(deps => {
factory(...deps);
return exports;
});
};
}
define(['./workbox-c5fd805d'], (function (workbox) { 'use strict';
self.skipWaiting();
workbox.clientsClaim();
/**
* The precacheAndRoute() method efficiently caches and responds to
* requests for URLs in the manifest.
* See https://goo.gl/S9QRab
*/
workbox.precacheAndRoute([{
"url": "suppress-warnings.js",
"revision": "d41d8cd98f00b204e9800998ecf8427e"
}, {
"url": "index.html",
"revision": "0.h29q0vck9ug"
}], {});
workbox.cleanupOutdatedCaches();
workbox.registerRoute(new workbox.NavigationRoute(workbox.createHandlerBoundToURL("index.html"), {
allowlist: [/^\/$/]
}));
workbox.registerRoute(({
url
}) => url.pathname.startsWith("/api"), new workbox.NetworkFirst({
"cacheName": "api-cache",
"networkTimeoutSeconds": 5,
plugins: [new workbox.ExpirationPlugin({
maxEntries: 50,
maxAgeSeconds: 900
})]
}), 'GET');
workbox.registerRoute(({
request
}) => request.destination === "document", new workbox.NetworkFirst(), 'GET');
}));

File diff suppressed because it is too large Load Diff

58
frontend/eslint.config.js Normal file
View File

@ -0,0 +1,58 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import simpleImportSort from 'eslint-plugin-simple-import-sort'
import tailwindcss from 'eslint-plugin-tailwindcss'
import tseslint from 'typescript-eslint'
import { defineConfig } from 'eslint/config'
const tsconfigRootDir = new URL('.', import.meta.url).pathname
export default defineConfig([
{
ignores: ['dist', 'coverage', 'node_modules', 'build', 'public/**/*.ts'],
},
{
files: ['**/*.{ts,tsx,js,jsx}'],
extends: [
js.configs.recommended,
...tseslint.configs.strictTypeChecked,
...tseslint.configs.stylisticTypeChecked,
],
languageOptions: {
ecmaVersion: 2022,
globals: {
...globals.browser,
},
parserOptions: {
project: './tsconfig.app.json',
tsconfigRootDir,
},
},
plugins: {
'react-hooks': reactHooks,
'react-refresh': reactRefresh,
'simple-import-sort': simpleImportSort,
tailwindcss,
},
settings: {
tailwindcss: {
callees: ['cn'],
config: 'tailwind.config.ts',
},
},
rules: {
...reactHooks.configs.recommended.rules,
'react-refresh/only-export-components': 'off',
'simple-import-sort/imports': 'error',
'simple-import-sort/exports': 'error',
'@typescript-eslint/consistent-type-imports': ['error', { prefer: 'type-imports' }],
'@typescript-eslint/no-unused-vars': ['warn', { argsIgnorePattern: '^_', ignoreRestSiblings: true }],
'@typescript-eslint/no-misused-promises': ['error', { checksVoidReturn: { attributes: false } }],
'tailwindcss/classnames-order': 'warn',
'tailwindcss/no-arbitrary-value': 'off',
'tailwindcss/no-custom-classname': 'off',
},
},
])

33
frontend/index.html Normal file
View File

@ -0,0 +1,33 @@
<!doctype html>
<html lang="en" class="light" data-theme="system">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="Modern multi-tenant mini CRM dashboard" />
<meta name="application-name" content="Kitchen CRM" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="theme-color" content="#0f172a" media="(prefers-color-scheme: light)" />
<meta name="theme-color" content="#020617" media="(prefers-color-scheme: dark)" />
<meta name="color-scheme" content="dark light" />
<meta property="og:title" content="Kitchen CRM" />
<meta property="og:description" content="Unified sales, contacts, tasks, and analytics workspace" />
<meta property="og:type" content="website" />
<meta property="og:url" content="https://kitchen-crm.k1nq.tech" />
<link rel="icon" type="image/svg+xml" href="/pwa-icon.svg" />
<link rel="apple-touch-icon" sizes="180x180" href="/pwa-192x192.png" />
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="preconnect" href="https://fonts.googleapis.com" />
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin />
<link
href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap"
rel="stylesheet"
/>
<title>Kitchen CRM</title>
</head>
<body class="antialiased bg-background text-foreground">
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>

12276
frontend/package-lock.json generated Normal file

File diff suppressed because it is too large Load Diff

84
frontend/package.json Normal file
View File

@ -0,0 +1,84 @@
{
"name": "frontend",
"private": true,
"version": "0.1.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"preview": "vite preview",
"lint": "eslint . --max-warnings=0",
"lint:fix": "eslint . --fix",
"typecheck": "tsc -b",
"format": "prettier --write \"./**/*.{ts,tsx,js,jsx,json,md,css,scss}\"",
"check": "npm run lint && npm run typecheck",
"prepare": "husky"
},
"dependencies": {
"@hookform/resolvers": "^5.2.2",
"@radix-ui/react-avatar": "^1.1.11",
"@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
"@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-popover": "^1.1.15",
"@radix-ui/react-scroll-area": "^1.2.10",
"@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-separator": "^1.1.8",
"@radix-ui/react-slot": "^1.2.4",
"@radix-ui/react-tabs": "^1.1.13",
"@radix-ui/react-toast": "^1.2.15",
"@radix-ui/react-tooltip": "^1.2.8",
"@tanstack/react-query": "^5.90.11",
"@tanstack/react-query-devtools": "^5.91.1",
"@tanstack/react-table": "^8.21.3",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"date-fns": "^4.1.0",
"jwt-decode": "^4.0.0",
"lucide-react": "^0.555.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"react-hook-form": "^7.67.0",
"react-router-dom": "^7.9.6",
"recharts": "^3.5.1",
"tailwind-merge": "^3.4.0",
"zod": "^4.1.13",
"zustand": "^5.0.9"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@tailwindcss/postcss": "^4.1.17",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react-swc": "^4.2.2",
"autoprefixer": "^10.4.22",
"eslint": "^9.39.1",
"eslint-config-prettier": "^10.1.8",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"eslint-plugin-simple-import-sort": "^12.1.1",
"eslint-plugin-tailwindcss": "^4.0.0-beta.0",
"globals": "^16.5.0",
"husky": "^9.1.7",
"lint-staged": "^16.2.7",
"postcss": "^8.5.6",
"prettier": "^3.7.3",
"prettier-plugin-tailwindcss": "^0.7.1",
"tailwindcss": "^4.0.0",
"tailwindcss-animate": "^1.0.7",
"typescript": "^5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.2.4",
"vite-plugin-pwa": "^1.2.0"
},
"lint-staged": {
"*.{ts,tsx,js,jsx,mjs,cjs}": [
"eslint --fix"
],
"*.{ts,tsx,js,jsx,mjs,cjs,json,md,css,scss}": [
"prettier --write"
]
}
}

View File

@ -0,0 +1,6 @@
import tailwindcss from '@tailwindcss/postcss'
import autoprefixer from 'autoprefixer'
export default {
plugins: [tailwindcss(), autoprefixer()],
}

View File

@ -0,0 +1,10 @@
/** @type {import('prettier').Config} */
const config = {
semi: false,
singleQuote: true,
trailingComma: 'all',
printWidth: 100,
plugins: ['prettier-plugin-tailwindcss'],
}
export default config

View File

@ -0,0 +1,28 @@
{
"name": "Kitchen CRM",
"short_name": "KitchenCRM",
"start_url": "/",
"display": "standalone",
"background_color": "#020617",
"theme_color": "#0f172a",
"description": "Multi-tenant mini CRM dashboard for organizations, deals, contacts, and analytics.",
"icons": [
{
"src": "/pwa-icon.svg",
"sizes": "any",
"type": "image/svg+xml",
"purpose": "any"
},
{
"src": "/pwa-192x192.png",
"sizes": "192x192",
"type": "image/png"
},
{
"src": "/pwa-512x512.png",
"sizes": "512x512",
"type": "image/png",
"purpose": "any maskable"
}
]
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 329 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 355 B

View File

@ -0,0 +1,15 @@
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 64 64" fill="none">
<defs>
<linearGradient id="grad" x1="0" y1="0" x2="1" y2="1">
<stop offset="0%" stop-color="#38bdf8" />
<stop offset="100%" stop-color="#6366f1" />
</linearGradient>
</defs>
<rect width="64" height="64" rx="14" fill="#020617" />
<path
d="M16 40c0-8 6.5-14.5 14.5-14.5H36v-1.5c0-3.6-2.9-6.5-6.5-6.5S23 20.4 23 24h-7c0-7.5 6.1-13.5 13.5-13.5S43 16.5 43 24v6h2.5C50.4 30 55 34.6 55 40s-4.6 10-10.5 10H22.5C16.5 50 12 45.4 12 40Z"
fill="url(#grad)"
/>
<circle cx="25" cy="39" r="4" fill="#f8fafc" />
<circle cx="41" cy="39" r="4" fill="#f8fafc" />
</svg>

After

Width:  |  Height:  |  Size: 666 B

1
frontend/public/vite.svg Normal file
View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="31.88" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 257"><defs><linearGradient id="IconifyId1813088fe1fbc01fb466" x1="-.828%" x2="57.636%" y1="7.652%" y2="78.411%"><stop offset="0%" stop-color="#41D1FF"></stop><stop offset="100%" stop-color="#BD34FE"></stop></linearGradient><linearGradient id="IconifyId1813088fe1fbc01fb467" x1="43.376%" x2="50.316%" y1="2.242%" y2="89.03%"><stop offset="0%" stop-color="#FFEA83"></stop><stop offset="8.333%" stop-color="#FFDD35"></stop><stop offset="100%" stop-color="#FFA800"></stop></linearGradient></defs><path fill="url(#IconifyId1813088fe1fbc01fb466)" d="M255.153 37.938L134.897 252.976c-2.483 4.44-8.862 4.466-11.382.048L.875 37.958c-2.746-4.814 1.371-10.646 6.827-9.67l120.385 21.517a6.537 6.537 0 0 0 2.322-.004l117.867-21.483c5.438-.991 9.574 4.796 6.877 9.62Z"></path><path fill="url(#IconifyId1813088fe1fbc01fb467)" d="M185.432.063L96.44 17.501a3.268 3.268 0 0 0-2.634 3.014l-5.474 92.456a3.268 3.268 0 0 0 3.997 3.378l24.777-5.718c2.318-.535 4.413 1.507 3.936 3.838l-7.361 36.047c-.495 2.426 1.782 4.5 4.151 3.78l15.304-4.649c2.372-.72 4.652 1.36 4.15 3.788l-11.698 56.621c-.732 3.542 3.979 5.473 5.943 2.437l1.313-2.028l72.516-144.72c1.215-2.423-.88-5.186-3.54-4.672l-25.505 4.922c-2.396.462-4.435-1.77-3.759-4.114l16.646-57.705c.677-2.35-1.37-4.583-3.769-4.113Z"></path></svg>

After

Width:  |  Height:  |  Size: 1.5 KiB

42
frontend/src/App.css Normal file
View File

@ -0,0 +1,42 @@
#root {
max-width: 1280px;
margin: 0 auto;
padding: 2rem;
text-align: center;
}
.logo {
height: 6em;
padding: 1.5em;
will-change: filter;
transition: filter 300ms;
}
.logo:hover {
filter: drop-shadow(0 0 2em #646cffaa);
}
.logo.react:hover {
filter: drop-shadow(0 0 2em #61dafbaa);
}
@keyframes logo-spin {
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
}
@media (prefers-reduced-motion: no-preference) {
a:nth-of-type(2) .logo {
animation: logo-spin infinite 20s linear;
}
}
.card {
padding: 2em;
}
.read-the-docs {
color: #888;
}

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

@ -0,0 +1,16 @@
import { Suspense } from 'react'
import { RouterProvider } from 'react-router-dom'
import { AppProvider } from '@/app/providers/app-provider'
import { AppLoading } from '@/components/system/app-loading'
import { router } from '@/routes/router'
const App = () => (
<AppProvider>
<Suspense fallback={<AppLoading />}>
<RouterProvider router={router} />
</Suspense>
</AppProvider>
)
export default App

View File

@ -0,0 +1,22 @@
import { QueryClientProvider } from '@tanstack/react-query'
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'
import { useState } from 'react'
import { type PropsWithChildren } from 'react'
import { ThemeProvider } from '@/components/theme/theme-provider'
import { Toaster } from '@/components/ui/toaster'
import { createQueryClient } from '@/lib/query-client'
export const AppProvider = ({ children }: PropsWithChildren) => {
const [queryClient] = useState(() => createQueryClient())
return (
<QueryClientProvider client={queryClient}>
<ThemeProvider>
{children}
<Toaster />
</ThemeProvider>
{import.meta.env.DEV ? <ReactQueryDevtools initialIsOpen={false} buttonPosition="bottom-left" /> : null}
</QueryClientProvider>
)
}

View File

@ -0,0 +1 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img" class="iconify iconify--logos" width="35.93" height="32" preserveAspectRatio="xMidYMid meet" viewBox="0 0 256 228"><path fill="#00D8FF" d="M210.483 73.824a171.49 171.49 0 0 0-8.24-2.597c.465-1.9.893-3.777 1.273-5.621c6.238-30.281 2.16-54.676-11.769-62.708c-13.355-7.7-35.196.329-57.254 19.526a171.23 171.23 0 0 0-6.375 5.848a155.866 155.866 0 0 0-4.241-3.917C100.759 3.829 77.587-4.822 63.673 3.233C50.33 10.957 46.379 33.89 51.995 62.588a170.974 170.974 0 0 0 1.892 8.48c-3.28.932-6.445 1.924-9.474 2.98C17.309 83.498 0 98.307 0 113.668c0 15.865 18.582 31.778 46.812 41.427a145.52 145.52 0 0 0 6.921 2.165a167.467 167.467 0 0 0-2.01 9.138c-5.354 28.2-1.173 50.591 12.134 58.266c13.744 7.926 36.812-.22 59.273-19.855a145.567 145.567 0 0 0 5.342-4.923a168.064 168.064 0 0 0 6.92 6.314c21.758 18.722 43.246 26.282 56.54 18.586c13.731-7.949 18.194-32.003 12.4-61.268a145.016 145.016 0 0 0-1.535-6.842c1.62-.48 3.21-.974 4.76-1.488c29.348-9.723 48.443-25.443 48.443-41.52c0-15.417-17.868-30.326-45.517-39.844Zm-6.365 70.984c-1.4.463-2.836.91-4.3 1.345c-3.24-10.257-7.612-21.163-12.963-32.432c5.106-11 9.31-21.767 12.459-31.957c2.619.758 5.16 1.557 7.61 2.4c23.69 8.156 38.14 20.213 38.14 29.504c0 9.896-15.606 22.743-40.946 31.14Zm-10.514 20.834c2.562 12.94 2.927 24.64 1.23 33.787c-1.524 8.219-4.59 13.698-8.382 15.893c-8.067 4.67-25.32-1.4-43.927-17.412a156.726 156.726 0 0 1-6.437-5.87c7.214-7.889 14.423-17.06 21.459-27.246c12.376-1.098 24.068-2.894 34.671-5.345a134.17 134.17 0 0 1 1.386 6.193ZM87.276 214.515c-7.882 2.783-14.16 2.863-17.955.675c-8.075-4.657-11.432-22.636-6.853-46.752a156.923 156.923 0 0 1 1.869-8.499c10.486 2.32 22.093 3.988 34.498 4.994c7.084 9.967 14.501 19.128 21.976 27.15a134.668 134.668 0 0 1-4.877 4.492c-9.933 8.682-19.886 14.842-28.658 17.94ZM50.35 144.747c-12.483-4.267-22.792-9.812-29.858-15.863c-6.35-5.437-9.555-10.836-9.555-15.216c0-9.322 13.897-21.212 37.076-29.293c2.813-.98 5.757-1.905 8.812-2.773c3.204 10.42 7.406 21.315 12.477 32.332c-5.137 11.18-9.399 22.249-12.634 32.792a134.718 134.718 0 0 1-6.318-1.979Zm12.378-84.26c-4.811-24.587-1.616-43.134 6.425-47.789c8.564-4.958 27.502 2.111 47.463 19.835a144.318 144.318 0 0 1 3.841 3.545c-7.438 7.987-14.787 17.08-21.808 26.988c-12.04 1.116-23.565 2.908-34.161 5.309a160.342 160.342 0 0 1-1.76-7.887Zm110.427 27.268a347.8 347.8 0 0 0-7.785-12.803c8.168 1.033 15.994 2.404 23.343 4.08c-2.206 7.072-4.956 14.465-8.193 22.045a381.151 381.151 0 0 0-7.365-13.322Zm-45.032-43.861c5.044 5.465 10.096 11.566 15.065 18.186a322.04 322.04 0 0 0-30.257-.006c4.974-6.559 10.069-12.652 15.192-18.18ZM82.802 87.83a323.167 323.167 0 0 0-7.227 13.238c-3.184-7.553-5.909-14.98-8.134-22.152c7.304-1.634 15.093-2.97 23.209-3.984a321.524 321.524 0 0 0-7.848 12.897Zm8.081 65.352c-8.385-.936-16.291-2.203-23.593-3.793c2.26-7.3 5.045-14.885 8.298-22.6a321.187 321.187 0 0 0 7.257 13.246c2.594 4.48 5.28 8.868 8.038 13.147Zm37.542 31.03c-5.184-5.592-10.354-11.779-15.403-18.433c4.902.192 9.899.29 14.978.29c5.218 0 10.376-.117 15.453-.343c-4.985 6.774-10.018 12.97-15.028 18.486Zm52.198-57.817c3.422 7.8 6.306 15.345 8.596 22.52c-7.422 1.694-15.436 3.058-23.88 4.071a382.417 382.417 0 0 0 7.859-13.026a347.403 347.403 0 0 0 7.425-13.565Zm-16.898 8.101a358.557 358.557 0 0 1-12.281 19.815a329.4 329.4 0 0 1-23.444.823c-7.967 0-15.716-.248-23.178-.732a310.202 310.202 0 0 1-12.513-19.846h.001a307.41 307.41 0 0 1-10.923-20.627a310.278 310.278 0 0 1 10.89-20.637l-.001.001a307.318 307.318 0 0 1 12.413-19.761c7.613-.576 15.42-.876 23.31-.876H128c7.926 0 15.743.303 23.354.883a329.357 329.357 0 0 1 12.335 19.695a358.489 358.489 0 0 1 11.036 20.54a329.472 329.472 0 0 1-11 20.722Zm22.56-122.124c8.572 4.944 11.906 24.881 6.52 51.026c-.344 1.668-.73 3.367-1.15 5.09c-10.622-2.452-22.155-4.275-34.23-5.408c-7.034-10.017-14.323-19.124-21.64-27.008a160.789 160.789 0 0 1 5.888-5.4c18.9-16.447 36.564-22.941 44.612-18.3ZM128 90.808c12.625 0 22.86 10.235 22.86 22.86s-10.235 22.86-22.86 22.86s-22.86-10.235-22.86-22.86s10.235-22.86 22.86-22.86Z"></path></svg>

After

Width:  |  Height:  |  Size: 4.0 KiB

View File

@ -0,0 +1,18 @@
import { Link } from 'react-router-dom'
import { Sparkles } from 'lucide-react'
import { env } from '@/config/env'
import { cn } from '@/lib/utils'
interface AppLogoProps {
className?: string
}
export const AppLogo = ({ className }: AppLogoProps) => (
<Link to="/dashboard" className={cn('flex items-center gap-2 text-lg font-semibold text-foreground', className)}>
<span className="flex h-9 w-9 items-center justify-center rounded-lg bg-primary/10 text-primary">
<Sparkles className="h-5 w-5" />
</span>
{env.APP_NAME}
</Link>
)

View File

@ -0,0 +1,26 @@
import { NavLink } from 'react-router-dom'
import { appNavItems } from '@/config/navigation'
import { cn } from '@/lib/utils'
export const SidebarNav = () => {
return (
<nav className="flex flex-col gap-1">
{appNavItems.map(({ path, label, icon: Icon }) => (
<NavLink
key={path}
to={path}
className={({ isActive }) =>
cn(
'flex items-center gap-3 rounded-lg px-3 py-2 text-sm font-medium text-muted-foreground transition-colors hover:bg-muted hover:text-foreground',
isActive && 'bg-primary/10 text-primary',
)
}
>
<Icon className="h-4 w-4" />
{label}
</NavLink>
))}
</nav>
)
}

View File

@ -0,0 +1,56 @@
import { useNavigate } from 'react-router-dom'
import { LogOut } from 'lucide-react'
import { Avatar, AvatarFallback } from '@/components/ui/avatar'
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu'
import { useToast } from '@/components/ui/use-toast'
import { useAuthStore } from '@/stores/auth-store'
export const UserMenu = () => {
const navigate = useNavigate()
const logout = useAuthStore((state) => state.logout)
const user = useAuthStore((state) => state.user)
const { toast } = useToast()
const initials = user?.name
?.split(' ')
.map((part) => part[0])
.join('')
.slice(0, 2)
.toUpperCase()
const handleLogout = () => {
logout()
toast({ title: 'Вы вышли из системы' })
navigate('/login', { replace: true })
}
return (
<DropdownMenu>
<DropdownMenuTrigger className="rounded-full focus:outline-none focus:ring-2 focus:ring-ring">
<Avatar className="h-9 w-9">
<AvatarFallback>{initials || (user?.email ?? '?')[0]?.toUpperCase() || 'U'}</AvatarFallback>
</Avatar>
</DropdownMenuTrigger>
<DropdownMenuContent align="end" className="w-56">
<DropdownMenuLabel>
<div className="flex flex-col">
<span className="text-sm font-semibold">{user?.name ?? 'Сотрудник'}</span>
<span className="text-xs text-muted-foreground">{user?.email}</span>
</div>
</DropdownMenuLabel>
<DropdownMenuSeparator />
<DropdownMenuItem className="gap-2 text-destructive" onSelect={handleLogout}>
<LogOut className="h-4 w-4" /> Выйти
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
)
}

View File

@ -0,0 +1,75 @@
import { useMemo, useTransition } from 'react'
import { Building2, Loader2 } from 'lucide-react'
import { useQueryClient } from '@tanstack/react-query'
import { Button } from '@/components/ui/button'
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from '@/components/ui/select'
import { useToast } from '@/components/ui/use-toast'
import { useOrganizationsQuery } from '@/features/organizations/hooks'
import { useAuthStore } from '@/stores/auth-store'
export const OrganizationSwitcher = () => {
const { data, isLoading, isFetching } = useOrganizationsQuery()
const activeOrganizationId = useAuthStore((state) => state.activeOrganizationId)
const setActiveOrganization = useAuthStore((state) => state.setActiveOrganization)
const organizations = data ?? []
const { toast } = useToast()
const queryClient = useQueryClient()
const [isPending, startTransition] = useTransition()
const activeOrganization = useMemo(
() => organizations.find((org) => org.id === activeOrganizationId) ?? organizations[0],
[activeOrganizationId, organizations],
)
const handleChange = (value: string) => {
const nextId = Number(value)
if (!Number.isFinite(nextId)) return
startTransition(() => {
setActiveOrganization(nextId)
queryClient.invalidateQueries({ predicate: () => true })
toast({
title: 'Организация переключена',
description: activeOrganization?.id === nextId ? 'Контекст обновлён' : 'Интерфейс обновится под выбранную организацию',
})
})
}
if (isLoading && !data) {
return (
<Button variant="ghost" size="sm" disabled className="gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Загружаем организации
</Button>
)
}
if (!organizations.length) {
return (
<Button variant="ghost" size="sm" className="gap-2" disabled>
<Building2 className="h-4 w-4" />
Нет организаций
</Button>
)
}
return (
<Select value={String(activeOrganization?.id ?? '')} onValueChange={handleChange} disabled={isPending || isFetching}>
<SelectTrigger className="w-[220px] bg-muted/40">
<SelectValue>
<span className="flex items-center gap-2 text-sm font-medium">
{isPending || isFetching ? <Loader2 className="h-4 w-4 animate-spin" /> : <Building2 className="h-4 w-4" />}
{activeOrganization?.name ?? 'Выбрать организацию'}
</span>
</SelectValue>
</SelectTrigger>
<SelectContent>
{organizations.map((org) => (
<SelectItem key={org.id} value={String(org.id)}>
{org.name}
</SelectItem>
))}
</SelectContent>
</Select>
)
}

View File

@ -0,0 +1,8 @@
export const AppLoading = () => (
<div className="flex min-h-screen items-center justify-center bg-background text-foreground">
<div className="space-y-3 text-center">
<div className="mx-auto h-10 w-10 animate-spin rounded-full border-2 border-primary border-t-transparent" />
<p className="text-sm text-muted-foreground">Загружаем Kitchen CRM</p>
</div>
</div>
)

View File

@ -0,0 +1,17 @@
import { useEffect } from 'react'
import { useThemeStore } from '@/stores/theme-store'
interface ThemeProviderProps {
children: React.ReactNode
}
export const ThemeProvider = ({ children }: ThemeProviderProps) => {
const hydrate = useThemeStore((state) => state.hydrate)
useEffect(() => {
hydrate()
}, [hydrate])
return <>{children}</>
}

View File

@ -0,0 +1,14 @@
import { Moon, Sun } from 'lucide-react'
import { Button } from '@/components/ui/button'
import { useTheme } from '@/hooks/useTheme'
export const ThemeToggle = () => {
const { resolvedTheme, toggleTheme } = useTheme()
return (
<Button variant="ghost" size="icon" aria-label="Переключить тему" onClick={toggleTheme}>
{resolvedTheme === 'dark' ? <Sun className="h-4 w-4" /> : <Moon className="h-4 w-4" />}
</Button>
)
}

View File

@ -0,0 +1,31 @@
import * as React from 'react'
import * as AvatarPrimitive from '@radix-ui/react-avatar'
import { cn } from '@/lib/utils'
const Avatar = React.forwardRef<React.ElementRef<typeof AvatarPrimitive.Root>, React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Root>>(
({ className, ...props }, ref) => (
<AvatarPrimitive.Root ref={ref} className={cn('relative flex h-9 w-9 shrink-0 overflow-hidden rounded-full', className)} {...props} />
),
)
Avatar.displayName = AvatarPrimitive.Root.displayName
const AvatarImage = React.forwardRef<React.ElementRef<typeof AvatarPrimitive.Image>, React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Image>>(
({ className, ...props }, ref) => (
<AvatarPrimitive.Image ref={ref} className={cn('aspect-square h-full w-full', className)} {...props} />
),
)
AvatarImage.displayName = AvatarPrimitive.Image.displayName
const AvatarFallback = React.forwardRef<React.ElementRef<typeof AvatarPrimitive.Fallback>, React.ComponentPropsWithoutRef<typeof AvatarPrimitive.Fallback>>(
({ className, ...props }, ref) => (
<AvatarPrimitive.Fallback
ref={ref}
className={cn('flex h-full w-full items-center justify-center rounded-full bg-muted text-sm font-medium text-muted-foreground', className)}
{...props}
/>
),
)
AvatarFallback.displayName = AvatarPrimitive.Fallback.displayName
export { Avatar, AvatarFallback, AvatarImage }

View File

@ -0,0 +1,32 @@
import { cva, type VariantProps } from 'class-variance-authority'
import * as React from 'react'
import { cn } from '@/lib/utils'
const badgeVariants = cva(
'inline-flex items-center rounded-full border px-2.5 py-0.5 text-xs font-semibold transition-colors focus:outline-none focus:ring-1 focus:ring-ring',
{
variants: {
variant: {
default: 'border-transparent bg-primary text-primary-foreground shadow',
secondary: 'border-transparent bg-secondary text-secondary-foreground',
outline: 'text-foreground',
success: 'border-transparent bg-emerald-500/15 text-emerald-600 dark:text-emerald-400',
warning: 'border-transparent bg-amber-500/15 text-amber-600 dark:text-amber-300',
destructive: 'border-transparent bg-destructive text-destructive-foreground',
},
},
defaultVariants: {
variant: 'default',
},
},
)
export interface BadgeProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {}
const Badge = React.forwardRef<HTMLDivElement, BadgeProps>(({ className, variant, ...props }, ref) => (
<div ref={ref} className={cn(badgeVariants({ variant }), className)} {...props} />
))
Badge.displayName = 'Badge'
export { Badge, badgeVariants }

View File

@ -0,0 +1,48 @@
import * as React from 'react'
import { Slot } from '@radix-ui/react-slot'
import { cva, type VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
const buttonVariants = cva(
'inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50',
{
variants: {
variant: {
default: 'bg-primary text-primary-foreground shadow hover:bg-primary/90',
secondary: 'bg-secondary text-secondary-foreground hover:bg-secondary/80',
destructive: 'bg-destructive text-destructive-foreground shadow-sm hover:bg-destructive/90',
outline:
'border border-input bg-transparent text-foreground shadow-sm hover:bg-background/80 hover:text-foreground',
ghost: 'text-foreground hover:bg-muted hover:text-foreground',
link: 'text-primary underline-offset-4 hover:underline',
},
size: {
default: 'h-10 px-4 py-2',
sm: 'h-9 rounded-md px-3',
lg: 'h-11 rounded-md px-8',
icon: 'h-10 w-10',
},
},
defaultVariants: {
variant: 'default',
size: 'default',
},
},
)
export interface ButtonProps
extends React.ButtonHTMLAttributes<HTMLButtonElement>,
VariantProps<typeof buttonVariants> {
asChild?: boolean
}
const Button = React.forwardRef<HTMLButtonElement, ButtonProps>(
({ className, variant, size, asChild = false, ...props }, ref) => {
const Comp = asChild ? Slot : 'button'
return <Comp className={cn(buttonVariants({ variant, size, className }))} ref={ref} {...props} />
},
)
Button.displayName = 'Button'
export { Button, buttonVariants }

View File

@ -0,0 +1,47 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
const Card = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('rounded-xl border bg-card text-card-foreground shadow-sm', className)} {...props} />
),
)
Card.displayName = 'Card'
const CardHeader = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('flex flex-col space-y-1.5 p-6', className)} {...props} />
),
)
CardHeader.displayName = 'CardHeader'
const CardTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(
({ className, ...props }, ref) => (
<h3 ref={ref} className={cn('text-lg font-semibold leading-none tracking-tight', className)} {...props} />
),
)
CardTitle.displayName = 'CardTitle'
const CardDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
({ className, ...props }, ref) => (
<p ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
),
)
CardDescription.displayName = 'CardDescription'
const CardContent = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('p-6 pt-0', className)} {...props} />
),
)
CardContent.displayName = 'CardContent'
const CardFooter = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(
({ className, ...props }, ref) => (
<div ref={ref} className={cn('flex items-center p-6 pt-0', className)} {...props} />
),
)
CardFooter.displayName = 'CardFooter'
export { Card, CardContent, CardDescription, CardFooter, CardHeader, CardTitle }

View File

@ -0,0 +1,178 @@
import * as React from 'react'
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu'
import { Check, ChevronRight, Circle } from 'lucide-react'
import { cn } from '@/lib/utils'
const DropdownMenu = DropdownMenuPrimitive.Root
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
const DropdownMenuGroup = DropdownMenuPrimitive.Group
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
const DropdownMenuSub = DropdownMenuPrimitive.Sub
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
const DropdownMenuSubTrigger = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & { inset?: boolean }
>(({ className, inset, children, ...props }, ref) => (
<DropdownMenuPrimitive.SubTrigger
ref={ref}
className={cn(
'flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm font-medium outline-none focus:bg-muted data-[state=open]:bg-muted',
inset && 'pl-8',
className,
)}
{...props}
>
{children}
<ChevronRight className="ml-auto h-4 w-4" />
</DropdownMenuPrimitive.SubTrigger>
))
DropdownMenuSubTrigger.displayName = DropdownMenuPrimitive.SubTrigger.displayName
const DropdownMenuSubContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.SubContent
ref={ref}
className={cn(
'z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out',
className,
)}
{...props}
/>
))
DropdownMenuSubContent.displayName = DropdownMenuPrimitive.SubContent.displayName
const DropdownMenuContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
>(({ className, align = 'end', sideOffset = 4, ...props }, ref) => (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content
ref={ref}
align={align}
sideOffset={sideOffset}
className={cn(
'z-50 min-w-[10rem] overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[side=bottom]:slide-in-from-top-1 data-[side=top]:slide-in-from-bottom-1',
className,
)}
{...props}
/>
</DropdownMenuPrimitive.Portal>
))
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
const DropdownMenuItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & { inset?: boolean }
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
inset && 'pl-8',
className,
)}
{...props}
/>
))
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
const DropdownMenuCheckboxItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
>(({ className, children, checked, ...props }, ref) => (
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
checked={checked}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.CheckboxItem>
))
DropdownMenuCheckboxItem.displayName = DropdownMenuPrimitive.CheckboxItem.displayName
const DropdownMenuRadioItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
>(({ className, children, ...props }, ref) => (
<DropdownMenuPrimitive.RadioItem
ref={ref}
className={cn(
'relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-muted data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<Circle className="h-2 w-2 fill-current" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.RadioItem>
))
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
const DropdownMenuLabel = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & { inset?: boolean }
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Label
ref={ref}
className={cn('px-2 py-1.5 text-sm font-semibold text-foreground', inset && 'pl-8', className)}
{...props}
/>
))
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
const DropdownMenuSeparator = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator
ref={ref}
className={cn('-mx-1 my-1 h-px bg-border', className)}
{...props}
/>
))
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
const DropdownMenuShortcut = ({ className, ...props }: React.HTMLAttributes<HTMLSpanElement>) => {
return <span className={cn('ml-auto text-xs tracking-widest text-muted-foreground', className)} {...props} />
}
DropdownMenuShortcut.displayName = 'DropdownMenuShortcut'
export {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuGroup,
DropdownMenuPortal,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuRadioGroup,
}

View File

@ -0,0 +1,108 @@
import * as LabelPrimitive from '@radix-ui/react-label'
import { Slot } from '@radix-ui/react-slot'
import * as React from 'react'
import { Controller, type ControllerProps, FormProvider, type FieldPath, type FieldValues, useFormContext } from 'react-hook-form'
import { cn } from '@/lib/utils'
const Form = FormProvider
const FormFieldContext = React.createContext<{ name: string }>({ name: '' })
const FormItemContext = React.createContext<{ id: string }>({ id: '' })
const FormField = <TFieldValues extends FieldValues = FieldValues, TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>(
props: ControllerProps<TFieldValues, TName>,
) => (
<FormFieldContext.Provider value={{ name: props.name }}>
<Controller {...props} />
</FormFieldContext.Provider>
)
const FormItem = React.forwardRef<HTMLDivElement, React.HTMLAttributes<HTMLDivElement>>(({ className, ...props }, ref) => {
const id = React.useId()
return (
<FormItemContext.Provider value={{ id }}>
<div ref={ref} className={cn('space-y-2', className)} {...props} />
</FormItemContext.Provider>
)
})
FormItem.displayName = 'FormItem'
const useFormField = () => {
const fieldContext = React.useContext(FormFieldContext)
const itemContext = React.useContext(FormItemContext)
const { getFieldState, formState } = useFormContext()
if (!fieldContext) throw new Error('useFormField should be used within <FormField>')
if (!itemContext) throw new Error('useFormField should be used within <FormItem>')
const fieldState = getFieldState(fieldContext.name, formState)
return {
name: fieldContext.name,
id: itemContext.id,
...fieldState,
}
}
const FormLabel = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root> & { optional?: boolean }
>(({ className, optional, ...props }, ref) => {
const { error, id } = useFormField()
return (
<LabelPrimitive.Root
ref={ref}
className={cn('text-sm font-medium text-foreground', error && 'text-destructive', className)}
htmlFor={id}
{...props}
>
{props.children}
{optional ? <span className="pl-1 text-xs font-normal text-muted-foreground">(необязательно)</span> : null}
</LabelPrimitive.Root>
)
})
FormLabel.displayName = 'FormLabel'
const FormControl = React.forwardRef<React.ElementRef<typeof Slot>, React.ComponentPropsWithoutRef<typeof Slot>>(
({ className, ...props }, ref) => {
const { error, id } = useFormField()
return (
<Slot
ref={ref}
id={id}
aria-describedby={error ? `${id}-description ${id}-message` : `${id}-description`}
aria-invalid={!!error}
className={className}
{...props}
/>
)
},
)
FormControl.displayName = 'FormControl'
const FormDescription = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
({ className, ...props }, ref) => {
const { id } = useFormField()
return <p ref={ref} id={`${id}-description`} className={cn('text-xs text-muted-foreground', className)} {...props} />
},
)
FormDescription.displayName = 'FormDescription'
const FormMessage = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLParagraphElement>>(
({ className, children, ...props }, ref) => {
const { error, id } = useFormField()
const body = error ? String(error.message) : children
if (!body) return null
return (
<p ref={ref} id={`${id}-message`} className={cn('text-xs font-medium text-destructive', className)} {...props}>
{body}
</p>
)
},
)
FormMessage.displayName = 'FormMessage'
export { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage }

View File

@ -0,0 +1,22 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
export interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}
const Input = React.forwardRef<HTMLInputElement, InputProps>(({ className, type, ...props }, ref) => {
return (
<input
type={type}
className={cn(
'flex h-10 w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm transition-colors file:border-0 file:bg-transparent file:text-sm file:font-medium placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
{...props}
/>
)
})
Input.displayName = 'Input'
export { Input }

View File

@ -0,0 +1,18 @@
import * as React from 'react'
import * as LabelPrimitive from '@radix-ui/react-label'
import { cn } from '@/lib/utils'
const Label = React.forwardRef<
React.ElementRef<typeof LabelPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof LabelPrimitive.Root>
>(({ className, ...props }, ref) => (
<LabelPrimitive.Root
ref={ref}
className={cn('text-sm font-medium leading-none peer-disabled:cursor-not-allowed peer-disabled:opacity-70', className)}
{...props}
/>
))
Label.displayName = LabelPrimitive.Root.displayName
export { Label }

View File

@ -0,0 +1,100 @@
import * as React from 'react'
import * as SelectPrimitive from '@radix-ui/react-select'
import { Check, ChevronDown, ChevronUp } from 'lucide-react'
import { cn } from '@/lib/utils'
const Select = SelectPrimitive.Root
const SelectGroup = SelectPrimitive.Group
const SelectValue = SelectPrimitive.Value
const SelectTrigger = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Trigger>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Trigger
ref={ref}
className={cn(
'flex h-10 w-full items-center justify-between rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
{...props}
>
{children}
<SelectPrimitive.Icon asChild>
<ChevronDown className="h-4 w-4 opacity-50" />
</SelectPrimitive.Icon>
</SelectPrimitive.Trigger>
))
SelectTrigger.displayName = SelectPrimitive.Trigger.displayName
const SelectContent = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Content>
>(({ className, children, position = 'popper', ...props }, ref) => (
<SelectPrimitive.Portal>
<SelectPrimitive.Content
ref={ref}
className={cn(
'relative z-50 min-w-[8rem] overflow-hidden rounded-md border bg-popover text-popover-foreground shadow-md animate-in fade-in-80',
position === 'popper' && 'data-[side=bottom]:slide-in-from-top-1 data-[side=top]:slide-in-from-bottom-1',
className,
)}
position={position}
{...props}
>
<SelectPrimitive.ScrollUpButton className="flex cursor-default items-center justify-center py-1">
<ChevronUp className="h-4 w-4" />
</SelectPrimitive.ScrollUpButton>
<SelectPrimitive.Viewport className={cn('p-1', position === 'popper' && 'h-[var(--radix-select-trigger-height)] w-full min-w-[var(--radix-select-trigger-width)]')}>
{children}
</SelectPrimitive.Viewport>
<SelectPrimitive.ScrollDownButton className="flex cursor-default items-center justify-center py-1">
<ChevronDown className="h-4 w-4" />
</SelectPrimitive.ScrollDownButton>
</SelectPrimitive.Content>
</SelectPrimitive.Portal>
))
SelectContent.displayName = SelectPrimitive.Content.displayName
const SelectLabel = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Label>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Label ref={ref} className={cn('px-2 py-1.5 text-sm font-semibold', className)} {...props} />
))
SelectLabel.displayName = SelectPrimitive.Label.displayName
const SelectItem = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Item>
>(({ className, children, ...props }, ref) => (
<SelectPrimitive.Item
ref={ref}
className={cn(
'relative flex w-full cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-muted focus:text-foreground data-[disabled]:pointer-events-none data-[disabled]:opacity-50',
className,
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<SelectPrimitive.ItemIndicator>
<Check className="h-4 w-4" />
</SelectPrimitive.ItemIndicator>
</span>
<SelectPrimitive.ItemText>{children}</SelectPrimitive.ItemText>
</SelectPrimitive.Item>
))
SelectItem.displayName = SelectPrimitive.Item.displayName
const SelectSeparator = React.forwardRef<
React.ElementRef<typeof SelectPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof SelectPrimitive.Separator>
>(({ className, ...props }, ref) => (
<SelectPrimitive.Separator ref={ref} className={cn('-mx-1 my-1 h-px bg-muted', className)} {...props} />
))
SelectSeparator.displayName = SelectPrimitive.Separator.displayName
export { Select, SelectContent, SelectGroup, SelectItem, SelectLabel, SelectSeparator, SelectTrigger, SelectValue }

View File

@ -0,0 +1,20 @@
import * as React from 'react'
import * as SeparatorPrimitive from '@radix-ui/react-separator'
import { cn } from '@/lib/utils'
const Separator = React.forwardRef<
React.ElementRef<typeof SeparatorPrimitive.Root>,
React.ComponentPropsWithoutRef<typeof SeparatorPrimitive.Root>
>(({ className, orientation = 'horizontal', decorative = true, ...props }, ref) => (
<SeparatorPrimitive.Root
ref={ref}
decorative={decorative}
orientation={orientation}
className={cn('bg-border', orientation === 'horizontal' ? 'h-px w-full' : 'h-full w-px', className)}
{...props}
/>
))
Separator.displayName = SeparatorPrimitive.Root.displayName
export { Separator }

View File

@ -0,0 +1,78 @@
import * as React from 'react'
import * as SheetPrimitive from '@radix-ui/react-dialog'
import { X } from 'lucide-react'
import { cn } from '@/lib/utils'
const Sheet = SheetPrimitive.Root
const SheetTrigger = SheetPrimitive.Trigger
const SheetClose = SheetPrimitive.Close
const SheetPortal = SheetPrimitive.Portal
const SheetOverlay = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Overlay>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Overlay>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Overlay
ref={ref}
className={cn('fixed inset-0 z-50 bg-black/40 backdrop-blur-sm data-[state=open]:animate-in data-[state=closed]:animate-out', className)}
{...props}
/>
))
SheetOverlay.displayName = SheetPrimitive.Overlay.displayName
interface SheetContentProps extends React.ComponentPropsWithoutRef<typeof SheetPrimitive.Content> {
side?: 'left' | 'right' | 'top' | 'bottom'
}
const SheetContent = React.forwardRef<React.ElementRef<typeof SheetPrimitive.Content>, SheetContentProps>(
({ className, side = 'right', children, ...props }, ref) => (
<SheetPortal>
<SheetOverlay />
<SheetPrimitive.Content
ref={ref}
className={cn(
'fixed z-50 gap-4 bg-background p-6 shadow-lg transition ease-in-out data-[state=open]:animate-in data-[state=closed]:animate-out',
side === 'right' && 'inset-y-0 right-0 h-full w-80 border-l',
side === 'left' && 'inset-y-0 left-0 h-full w-80 border-r',
side === 'top' && 'inset-x-0 top-0 w-full border-b',
side === 'bottom' && 'inset-x-0 bottom-0 w-full border-t',
className,
)}
{...props}
>
{children}
<SheetPrimitive.Close className="absolute right-4 top-4 rounded-sm opacity-70 transition-opacity hover:opacity-100 focus:outline-none focus:ring-2 focus:ring-ring">
<X className="h-4 w-4" />
<span className="sr-only">Закрыть</span>
</SheetPrimitive.Close>
</SheetPrimitive.Content>
</SheetPortal>
),
)
SheetContent.displayName = SheetPrimitive.Content.displayName
const SheetHeader = ({ className, ...props }: React.HTMLAttributes<HTMLDivElement>) => (
<div className={cn('flex flex-col space-y-2 text-center sm:text-left', className)} {...props} />
)
const SheetTitle = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Title>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Title>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Title ref={ref} className={cn('text-lg font-semibold text-foreground', className)} {...props} />
))
SheetTitle.displayName = SheetPrimitive.Title.displayName
const SheetDescription = React.forwardRef<
React.ElementRef<typeof SheetPrimitive.Description>,
React.ComponentPropsWithoutRef<typeof SheetPrimitive.Description>
>(({ className, ...props }, ref) => (
<SheetPrimitive.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
))
SheetDescription.displayName = SheetPrimitive.Description.displayName
export { Sheet, SheetClose, SheetContent, SheetDescription, SheetHeader, SheetPortal, SheetTitle, SheetTrigger }

View File

@ -0,0 +1,9 @@
import { cn } from '@/lib/utils'
interface SkeletonProps extends React.HTMLAttributes<HTMLDivElement> {}
const Skeleton = ({ className, ...props }: SkeletonProps) => {
return <div className={cn('animate-pulse rounded-md bg-muted/60', className)} {...props} />
}
export { Skeleton }

View File

@ -0,0 +1,27 @@
import * as React from 'react'
import * as SwitchPrimitives from '@radix-ui/react-checkbox'
import { cn } from '@/lib/utils'
const Switch = React.forwardRef<
React.ElementRef<typeof SwitchPrimitives.Root>,
React.ComponentPropsWithoutRef<typeof SwitchPrimitives.Root>
>(({ className, ...props }, ref) => (
<SwitchPrimitives.Root
ref={ref}
className={cn(
'peer inline-flex h-6 w-11 shrink-0 cursor-pointer items-center rounded-full border-2 border-transparent bg-input transition-colors focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring data-[state=checked]:bg-primary',
className,
)}
{...props}
>
<SwitchPrimitives.Indicator
className={cn(
'pointer-events-none block h-5 w-5 rounded-full bg-background shadow-lg ring-0 transition-transform data-[state=checked]:translate-x-5 data-[state=unchecked]:translate-x-0',
)}
/>
</SwitchPrimitives.Root>
))
Switch.displayName = SwitchPrimitives.Root.displayName
export { Switch }

View File

@ -0,0 +1,51 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
const Table = React.forwardRef<HTMLTableElement, React.HTMLAttributes<HTMLTableElement>>(({ className, ...props }, ref) => (
<div className="w-full overflow-auto">
<table ref={ref} className={cn('w-full caption-bottom text-sm', className)} {...props} />
</div>
))
Table.displayName = 'Table'
const TableHeader = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => (
<thead ref={ref} className={cn('[&_tr]:border-b', className)} {...props} />
))
TableHeader.displayName = 'TableHeader'
const TableBody = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => (
<tbody ref={ref} className={cn('[&_tr:last-child]:border-0', className)} {...props} />
))
TableBody.displayName = 'TableBody'
const TableFooter = React.forwardRef<HTMLTableSectionElement, React.HTMLAttributes<HTMLTableSectionElement>>(({ className, ...props }, ref) => (
<tfoot ref={ref} className={cn('bg-muted/50 font-medium text-foreground', className)} {...props} />
))
TableFooter.displayName = 'TableFooter'
const TableRow = React.forwardRef<HTMLTableRowElement, React.HTMLAttributes<HTMLTableRowElement>>(({ className, ...props }, ref) => (
<tr ref={ref} className={cn('border-b transition-colors hover:bg-muted/40 data-[state=selected]:bg-muted', className)} {...props} />
))
TableRow.displayName = 'TableRow'
const TableHead = React.forwardRef<HTMLTableCellElement, React.ThHTMLAttributes<HTMLTableCellElement>>(({ className, ...props }, ref) => (
<th
ref={ref}
className={cn('h-10 px-2 text-left align-middle text-xs font-semibold text-muted-foreground [&:has([role=checkbox])]:pr-0', className)}
{...props}
/>
))
TableHead.displayName = 'TableHead'
const TableCell = React.forwardRef<HTMLTableCellElement, React.TdHTMLAttributes<HTMLTableCellElement>>(({ className, ...props }, ref) => (
<td ref={ref} className={cn('p-2 align-middle [&:has([role=checkbox])]:pr-0', className)} {...props} />
))
TableCell.displayName = 'TableCell'
const TableCaption = React.forwardRef<HTMLTableCaptionElement, React.HTMLAttributes<HTMLTableCaptionElement>>(({ className, ...props }, ref) => (
<caption ref={ref} className={cn('mt-4 text-sm text-muted-foreground', className)} {...props} />
))
TableCaption.displayName = 'TableCaption'
export { Table, TableBody, TableCaption, TableCell, TableFooter, TableHead, TableHeader, TableRow }

View File

@ -0,0 +1,43 @@
import * as React from 'react'
import * as TabsPrimitive from '@radix-ui/react-tabs'
import { cn } from '@/lib/utils'
const Tabs = TabsPrimitive.Root
const TabsList = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.List>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.List>
>(({ className, ...props }, ref) => (
<TabsPrimitive.List ref={ref} className={cn('inline-flex h-9 items-center justify-center rounded-lg bg-muted p-1 text-muted-foreground', className)} {...props} />
))
TabsList.displayName = TabsPrimitive.List.displayName
const TabsTrigger = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Trigger>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Trigger>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Trigger
ref={ref}
className={cn(
'inline-flex min-w-[120px] items-center justify-center whitespace-nowrap rounded-md px-3 py-1 text-sm font-medium transition-all focus-visible:outline-none data-[state=active]:bg-background data-[state=active]:text-foreground data-[state=inactive]:opacity-60',
className,
)}
{...props}
/>
))
TabsTrigger.displayName = TabsPrimitive.Trigger.displayName
const TabsContent = React.forwardRef<
React.ElementRef<typeof TabsPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TabsPrimitive.Content>
>(({ className, ...props }, ref) => (
<TabsPrimitive.Content
ref={ref}
className={cn('mt-4 focus-visible:outline-none', className)}
{...props}
/>
))
TabsContent.displayName = TabsPrimitive.Content.displayName
export { Tabs, TabsContent, TabsList, TabsTrigger }

View File

@ -0,0 +1,23 @@
import * as React from 'react'
import { cn } from '@/lib/utils'
export interface TextareaProps extends React.TextareaHTMLAttributes<HTMLTextAreaElement> {}
const Textarea = React.forwardRef<HTMLTextAreaElement, TextareaProps>(
({ className, ...props }, ref) => {
return (
<textarea
className={cn(
'flex min-h-[80px] w-full rounded-md border border-input bg-transparent px-3 py-2 text-sm shadow-sm placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-1 focus-visible:ring-ring disabled:cursor-not-allowed disabled:opacity-50',
className,
)}
ref={ref}
{...props}
/>
)
},
)
Textarea.displayName = 'Textarea'
export { Textarea }

View File

@ -0,0 +1,97 @@
import * as React from 'react'
import * as ToastPrimitives from '@radix-ui/react-toast'
import { cva, type VariantProps } from 'class-variance-authority'
import { X } from 'lucide-react'
import { cn } from '@/lib/utils'
const ToastProvider = ToastPrimitives.Provider
const ToastViewport = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Viewport>, React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport>>(
({ className, ...props }, ref) => (
<ToastPrimitives.Viewport
ref={ref}
className={cn(
'fixed top-0 right-0 z-[100] flex max-h-screen w-full flex-col-reverse gap-3 p-4 md:max-w-sm',
className,
)}
{...props}
/>
),
)
ToastViewport.displayName = ToastPrimitives.Viewport.displayName
const toastVariants = cva(
'pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-xl border p-4 pr-6 shadow-lg transition-all data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=cancel]:translate-x-0 data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out',
{
variants: {
variant: {
default: 'border bg-background text-foreground',
success: 'border border-emerald-500/50 bg-emerald-500/10 text-emerald-100 dark:text-emerald-200',
destructive: 'border-destructive bg-destructive text-destructive-foreground',
},
},
defaultVariants: {
variant: 'default',
},
},
)
const Toast = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Root>, React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & VariantProps<typeof toastVariants>>(
({ className, variant, ...props }, ref) => {
return <ToastPrimitives.Root ref={ref} className={cn(toastVariants({ variant }), className)} {...props} />
},
)
Toast.displayName = ToastPrimitives.Root.displayName
const ToastAction = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Action>, React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action>>(
({ className, ...props }, ref) => (
<ToastPrimitives.Action
ref={ref}
className={cn('rounded-md border border-input px-3 py-1 text-sm font-medium transition-colors hover:bg-muted', className)}
{...props}
/>
),
)
ToastAction.displayName = ToastPrimitives.Action.displayName
const ToastClose = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Close>, React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close>>(
({ className, ...props }, ref) => (
<ToastPrimitives.Close
ref={ref}
className={cn('absolute right-2 top-2 rounded-md p-1 text-foreground/60 transition-colors hover:text-foreground focus:outline-none focus:ring-2 focus:ring-ring', className)}
{...props}
>
<X className="h-4 w-4" />
</ToastPrimitives.Close>
),
)
ToastClose.displayName = ToastPrimitives.Close.displayName
const ToastTitle = React.forwardRef<React.ElementRef<typeof ToastPrimitives.Title>, React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title>>(
({ className, ...props }, ref) => (
<ToastPrimitives.Title ref={ref} className={cn('text-sm font-semibold', className)} {...props} />
),
)
ToastTitle.displayName = ToastPrimitives.Title.displayName
const ToastDescription = React.forwardRef<
React.ElementRef<typeof ToastPrimitives.Description>,
React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description>
>(({ className, ...props }, ref) => (
<ToastPrimitives.Description ref={ref} className={cn('text-sm text-muted-foreground', className)} {...props} />
))
ToastDescription.displayName = ToastPrimitives.Description.displayName
export type ToastProps = React.ComponentPropsWithoutRef<typeof Toast>
export type ToastActionElement = React.ReactElement<typeof ToastAction>
export {
Toast,
ToastAction,
ToastClose,
ToastDescription,
ToastProvider,
ToastTitle,
ToastViewport,
}

View File

@ -0,0 +1,24 @@
import { Fragment } from 'react'
import { Toast, ToastClose, ToastDescription, ToastProvider, ToastTitle, ToastViewport } from '@/components/ui/toast'
import { useToast } from '@/components/ui/use-toast'
export const Toaster = () => {
const { toasts, dismiss } = useToast()
return (
<ToastProvider swipeDirection="right">
<ToastViewport />
{toasts.map(({ id, title, description, action, ...toast }) => (
<Toast key={id} onOpenChange={(open) => !open && dismiss(id)} {...toast}>
<div className="grid gap-1">
{title ? <ToastTitle>{title}</ToastTitle> : null}
{description ? <ToastDescription>{description}</ToastDescription> : null}
</div>
{action ? <Fragment>{action}</Fragment> : null}
<ToastClose />
</Toast>
))}
</ToastProvider>
)
}

View File

@ -0,0 +1,25 @@
import * as React from 'react'
import * as TooltipPrimitive from '@radix-ui/react-tooltip'
import { cn } from '@/lib/utils'
const TooltipProvider = TooltipPrimitive.Provider
const Tooltip = TooltipPrimitive.Root
const TooltipTrigger = TooltipPrimitive.Trigger
const TooltipContent = React.forwardRef<
React.ElementRef<typeof TooltipPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof TooltipPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<TooltipPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn('z-50 overflow-hidden rounded-md border bg-popover px-3 py-1.5 text-xs text-popover-foreground shadow-md', className)}
{...props}
/>
))
TooltipContent.displayName = TooltipPrimitive.Content.displayName
export { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger }

View File

@ -0,0 +1,84 @@
import * as React from 'react'
import type { ToastActionElement, ToastProps } from '@/components/ui/toast'
const TOAST_LIMIT = 10
const TOAST_REMOVE_DELAY = 1000
type ToasterToast = ToastProps & {
id: string
title?: React.ReactNode
description?: React.ReactNode
action?: ToastActionElement
}
const toastTimeouts = new Map<string, ReturnType<typeof setTimeout>>()
const addToRemoveQueue = (toastId: string) => {
if (toastTimeouts.has(toastId)) return
const timeout = setTimeout(() => {
toastTimeouts.delete(toastId)
toastState.remove(toastId)
}, TOAST_REMOVE_DELAY)
toastTimeouts.set(toastId, timeout)
}
const createToastState = () => {
const listeners = new Set<(toasts: ToasterToast[]) => void>()
let toasts: ToasterToast[] = []
const notify = () => {
listeners.forEach((listener) => listener(toasts))
}
return {
subscribe: (listener: (toasts: ToasterToast[]) => void) => {
listeners.add(listener)
return () => {
listeners.delete(listener)
}
},
add: (toast: ToasterToast) => {
toasts = [toast, ...toasts].slice(0, TOAST_LIMIT)
notify()
},
update: (toastId: string, toast: Partial<ToasterToast>) => {
toasts = toasts.map((item) => (item.id === toastId ? { ...item, ...toast } : item))
notify()
},
dismiss: (toastId: string) => {
addToRemoveQueue(toastId)
},
remove: (toastId: string) => {
toasts = toasts.filter((item) => item.id !== toastId)
notify()
},
getSnapshot: () => toasts,
}
}
const toastState = createToastState()
export const useToast = () => {
const [toasts, setToasts] = React.useState<ToasterToast[]>(toastState.getSnapshot())
React.useEffect(() => toastState.subscribe(setToasts), [])
const toast = React.useCallback((props: Omit<ToasterToast, 'id'>) => {
const id = crypto.randomUUID()
toastState.add({ id, ...props })
return id
}, [])
const dismiss = React.useCallback((toastId: string) => {
toastState.dismiss(toastId)
}, [])
return {
toast,
dismiss,
toasts,
}
}
export type { ToastProps, ToasterToast }

View File

@ -0,0 +1,24 @@
const API_URL = import.meta.env.VITE_API_URL?.replace(/\/$/, '') || 'http://localhost:8000'
const API_PREFIX = '/api/v1'
const APP_NAME = 'Kitchen CRM'
const ORG_HEADER = 'X-Organization-Id'
export const env = {
APP_NAME,
API_URL,
API_PREFIX,
ORG_HEADER,
DASHBOARD_URL: import.meta.env.VITE_APP_URL || (typeof window !== 'undefined' ? window.location.origin : ''),
}
export const storageKeys = {
theme: 'kcrm-theme',
tokens: 'kcrm-auth-tokens',
user: 'kcrm-user',
activeOrg: 'kcrm-active-org',
}
export const pagination = {
defaultPageSize: 20,
maxPageSize: 100,
}

View File

@ -0,0 +1,10 @@
import { LayoutDashboard, Users, Briefcase, ListTodo, Activity, Building2 } from 'lucide-react'
export const appNavItems = [
{ label: 'Дашборд', path: '/dashboard', icon: LayoutDashboard },
{ label: 'Контакты', path: '/contacts', icon: Users },
{ label: 'Сделки', path: '/deals', icon: Briefcase },
{ label: 'Задачи', path: '/tasks', icon: ListTodo },
{ label: 'Аналитика', path: '/analytics', icon: Activity },
{ label: 'Организации', path: '/organizations', icon: Building2 },
]

View File

@ -0,0 +1,8 @@
import { apiClient } from '@/lib/api-client'
import type { LoginPayload, RegisterPayload, TokenResponse } from '@/types/crm'
export const login = (payload: LoginPayload) =>
apiClient.post<TokenResponse, LoginPayload>('/auth/login', payload, { auth: false })
export const register = (payload: RegisterPayload) =>
apiClient.post<TokenResponse, RegisterPayload>('/auth/register', payload, { auth: false })

View File

@ -0,0 +1,4 @@
import { apiClient } from '@/lib/api-client'
import type { Organization } from '@/types/crm'
export const listOrganizations = () => apiClient.get<Organization[]>('/organizations/me')

View File

@ -0,0 +1,26 @@
import { useQuery, useQueryClient } from '@tanstack/react-query'
import { listOrganizations } from '@/features/organizations/api'
import { useAuthStore } from '@/stores/auth-store'
export const organizationsQueryKey = ['organizations', 'me'] as const
export const useOrganizationsQuery = () => {
const setOrganizations = useAuthStore((state) => state.setOrganizations)
const enabled = useAuthStore((state) => state.tokens !== null)
return useQuery({
queryKey: organizationsQueryKey,
queryFn: async () => {
const data = await listOrganizations()
setOrganizations(data)
return data
},
enabled,
})
}
export const useInvalidateOrganizations = () => {
const queryClient = useQueryClient()
return () => queryClient.invalidateQueries({ queryKey: organizationsQueryKey })
}

View File

@ -0,0 +1,20 @@
import { useCallback } from 'react'
import { useThemeStore } from '@/stores/theme-store'
export const useTheme = () => {
const theme = useThemeStore((state) => state.theme)
const resolvedTheme = useThemeStore((state) => state.resolvedTheme)
const setTheme = useThemeStore((state) => state.setTheme)
const toggleTheme = useCallback(() => {
setTheme(resolvedTheme === 'dark' ? 'light' : 'dark')
}, [resolvedTheme, setTheme])
return {
theme,
resolvedTheme,
setTheme,
toggleTheme,
}
}

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

@ -0,0 +1,68 @@
:root {
font-family: system-ui, Avenir, Helvetica, Arial, sans-serif;
line-height: 1.5;
font-weight: 400;
color-scheme: light dark;
color: rgba(255, 255, 255, 0.87);
background-color: #242424;
font-synthesis: none;
text-rendering: optimizeLegibility;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
a {
font-weight: 500;
color: #646cff;
text-decoration: inherit;
}
a:hover {
color: #535bf2;
}
body {
margin: 0;
display: flex;
place-items: center;
min-width: 320px;
min-height: 100vh;
}
h1 {
font-size: 3.2em;
line-height: 1.1;
}
button {
border-radius: 8px;
border: 1px solid transparent;
padding: 0.6em 1.2em;
font-size: 1em;
font-weight: 500;
font-family: inherit;
background-color: #1a1a1a;
cursor: pointer;
transition: border-color 0.25s;
}
button:hover {
border-color: #646cff;
}
button:focus,
button:focus-visible {
outline: 4px auto -webkit-focus-ring-color;
}
@media (prefers-color-scheme: light) {
:root {
color: #213547;
background-color: #ffffff;
}
a:hover {
color: #747bff;
}
button {
background-color: #f9f9f9;
}
}

View File

@ -0,0 +1,57 @@
import { Menu } from 'lucide-react'
import { Outlet } from 'react-router-dom'
import { OrganizationSwitcher } from '@/components/organization/organization-switcher'
import { AppLogo } from '@/components/navigation/app-logo'
import { SidebarNav } from '@/components/navigation/sidebar'
import { UserMenu } from '@/components/navigation/user-menu'
import { ThemeToggle } from '@/components/theme/theme-toggle'
import { Button } from '@/components/ui/button'
import { Sheet, SheetContent, SheetTrigger } from '@/components/ui/sheet'
export const AppShell = () => {
return (
<div className="flex min-h-screen bg-background text-foreground">
<aside className="hidden w-64 flex-col border-r bg-card/30 p-4 shadow-sm md:flex">
<AppLogo className="mb-6" />
<OrganizationSwitcher />
<div className="mt-6 flex-1">
<SidebarNav />
</div>
</aside>
<div className="flex flex-1 flex-col">
<header className="flex items-center justify-between border-b bg-card/30 px-4 py-3">
<div className="flex items-center gap-3">
<Sheet>
<SheetTrigger asChild>
<Button variant="ghost" size="icon" className="md:hidden">
<Menu className="h-5 w-5" />
</Button>
</SheetTrigger>
<SheetContent side="left" className="w-64">
<AppLogo className="mb-6" />
<OrganizationSwitcher />
<div className="mt-6">
<SidebarNav />
</div>
</SheetContent>
</Sheet>
<div className="md:hidden">
<AppLogo />
</div>
</div>
<div className="flex items-center gap-2">
<div className="hidden sm:block">
<OrganizationSwitcher />
</div>
<ThemeToggle />
<UserMenu />
</div>
</header>
<main className="flex-1 bg-muted/20 p-4 md:p-6">
<Outlet />
</main>
</div>
</div>
)
}

View File

@ -0,0 +1,22 @@
import { Outlet } from 'react-router-dom'
import { AppLogo } from '@/components/navigation/app-logo'
import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card'
export const AuthLayout = () => (
<div className="flex min-h-screen flex-col items-center justify-center bg-gradient-to-br from-slate-950 via-slate-900 to-slate-950 p-6 text-white">
<div className="mb-8 text-center">
<AppLogo className="text-white" />
<p className="text-sm text-slate-300">Войдите, чтобы управлять воронкой продаж</p>
</div>
<Card className="w-full max-w-md border-white/10 bg-white/5 text-white">
<CardHeader>
<CardTitle>Kitchen CRM</CardTitle>
<CardDescription className="text-slate-200">Мини-CRM с мультитенантной архитектурой</CardDescription>
</CardHeader>
<CardContent>
<Outlet />
</CardContent>
</Card>
</div>
)

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

@ -0,0 +1,11 @@
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import App from '@/App'
import '@/styles/global.css'
createRoot(document.getElementById('root')!).render(
<StrictMode>
<App />
</StrictMode>,
)

View File

@ -0,0 +1,110 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { useMutation } from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { Link, useNavigate } from 'react-router-dom'
import { z } from 'zod'
import { Button } from '@/components/ui/button'
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { useToast } from '@/components/ui/use-toast'
import { login } from '@/features/auth/api'
import { HttpError } from '@/lib/api-client'
import { authSelectors, useAuthStore } from '@/stores/auth-store'
const loginSchema = z.object({
email: z.string().email('Введите корректный email'),
password: z.string().min(8, 'Минимальная длина пароля — 8 символов'),
})
type LoginValues = z.infer<typeof loginSchema>
const LoginPage = () => {
const form = useForm<LoginValues>({
resolver: zodResolver(loginSchema),
defaultValues: { email: '', password: '' },
})
const navigate = useNavigate()
const { toast } = useToast()
const setSession = useAuthStore((state) => state.setSession)
const { mutateAsync, isPending } = useMutation({
mutationFn: login,
})
const handleSubmit = async (values: LoginValues) => {
form.clearErrors('root')
try {
const tokenResponse = await mutateAsync(values)
const tokens = authSelectors.mapTokens(tokenResponse)
setSession({ tokens, organizations: [], activeOrganizationId: null })
toast({ title: 'Добро пожаловать 👋', description: 'Контакты и сделки синхронизируются с сервером.' })
navigate('/dashboard')
} catch (error) {
const message = error instanceof HttpError ? error.message : 'Не удалось выполнить вход'
form.setError('root', { message })
}
}
const rootError = form.formState.errors.root?.message
return (
<div className="space-y-6">
<div>
<h2 className="text-2xl font-semibold">С возвращением</h2>
<p className="text-sm text-muted-foreground">Введите корпоративный email и пароль.</p>
</div>
<Form {...form}>
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-5">
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>E-mail</FormLabel>
<FormControl>
<Input type="email" placeholder="you@company.com" autoComplete="email" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Пароль</FormLabel>
<FormControl>
<Input type="password" placeholder="Введите пароль" autoComplete="current-password" {...field} />
</FormControl>
<FormDescription>Минимум 8 символов, буквы и цифры.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
{rootError ? <p className="text-sm font-medium text-destructive">{rootError}</p> : null}
<Button type="submit" className="w-full" disabled={isPending}>
{isPending ? (
<span className="flex items-center justify-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Входим
</span>
) : (
'Войти'
)}
</Button>
</form>
</Form>
<p className="text-center text-sm text-muted-foreground">
Нет аккаунта?{' '}
<Link to="/auth/register" className="font-medium text-primary hover:underline">
Зарегистрироваться
</Link>
</p>
</div>
)
}
export default LoginPage

View File

@ -0,0 +1,155 @@
import { zodResolver } from '@hookform/resolvers/zod'
import { useMutation } from '@tanstack/react-query'
import { Loader2 } from 'lucide-react'
import { useForm } from 'react-hook-form'
import { Link, useNavigate } from 'react-router-dom'
import { z } from 'zod'
import { Button } from '@/components/ui/button'
import { Form, FormControl, FormDescription, FormField, FormItem, FormLabel, FormMessage } from '@/components/ui/form'
import { Input } from '@/components/ui/input'
import { useToast } from '@/components/ui/use-toast'
import { register } from '@/features/auth/api'
import { HttpError } from '@/lib/api-client'
import { authSelectors, useAuthStore } from '@/stores/auth-store'
const registerSchema = z.object({
name: z.string().min(2, 'Введите имя владельца'),
email: z.string().email('Введите корректный email'),
password: z
.string()
.min(8, 'Минимальная длина пароля — 8 символов')
.regex(/[A-Za-z]/, 'Добавьте буквы')
.regex(/\d/, 'Добавьте цифры'),
organization_name: z
.string()
.transform((value) => value.trim())
.refine((value) => value.length <= 120, 'Название слишком длинное'),
})
type RegisterValues = z.infer<typeof registerSchema>
const RegisterPage = () => {
const form = useForm<RegisterValues>({
resolver: zodResolver(registerSchema),
defaultValues: { name: '', email: '', password: '', organization_name: '' },
})
const setSession = useAuthStore((state) => state.setSession)
const navigate = useNavigate()
const { toast } = useToast()
const { mutateAsync, isPending } = useMutation({
mutationFn: register,
})
const handleSubmit = async (values: RegisterValues) => {
form.clearErrors('root')
try {
const payload = {
...values,
organization_name: values.organization_name?.trim() ? values.organization_name.trim() : null,
}
const tokenResponse = await mutateAsync(payload)
const tokens = authSelectors.mapTokens(tokenResponse)
setSession({ tokens, organizations: [], activeOrganizationId: null })
toast({
title: 'Организация создана',
description: 'Вы владелец первой организации. Добавьте коллег на вкладке «Организации».',
})
navigate('/dashboard')
} catch (error) {
const message = error instanceof HttpError ? error.message : 'Не удалось завершить регистрацию'
form.setError('root', { message })
}
}
const rootError = form.formState.errors.root?.message
return (
<div className="space-y-6">
<div className="space-y-1">
<h2 className="text-2xl font-semibold">Создайте организацию</h2>
<p className="text-sm text-muted-foreground">Владелец получит полный доступ и сможет пригласить команду.</p>
</div>
<Form {...form}>
<form onSubmit={form.handleSubmit(handleSubmit)} className="space-y-5">
<FormField
control={form.control}
name="name"
render={({ field }) => (
<FormItem>
<FormLabel>Имя и фамилия</FormLabel>
<FormControl>
<Input placeholder="Алиса Менеджер" autoComplete="name" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="email"
render={({ field }) => (
<FormItem>
<FormLabel>Корпоративный email</FormLabel>
<FormControl>
<Input type="email" placeholder="owner@acme.io" autoComplete="email" {...field} />
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="password"
render={({ field }) => (
<FormItem>
<FormLabel>Пароль</FormLabel>
<FormControl>
<Input type="password" placeholder="Сложный пароль" autoComplete="new-password" {...field} />
</FormControl>
<FormDescription>Используйте минимум 8 символов, буквы и цифры.</FormDescription>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={form.control}
name="organization_name"
render={({ field }) => (
<FormItem>
<FormLabel optional>Организация</FormLabel>
<FormControl>
<Input placeholder="Acme Inc" {...field} />
</FormControl>
<FormDescription>
Укажите, чтобы сразу создать компанию и стать владельцем. Можно пропустить и присоединиться позже.
</FormDescription>
<FormMessage />
</FormItem>
)}
/>
{rootError ? <p className="text-sm font-medium text-destructive">{rootError}</p> : null}
<Button type="submit" className="w-full" disabled={isPending}>
{isPending ? (
<span className="flex items-center justify-center gap-2">
<Loader2 className="h-4 w-4 animate-spin" />
Создаём
</span>
) : (
'Зарегистрироваться'
)}
</Button>
</form>
</Form>
<p className="text-center text-sm text-muted-foreground">
Уже есть аккаунт?{' '}
<Link to="/auth/login" className="font-medium text-primary hover:underline">
Войти
</Link>
</p>
</div>
)
}
export default RegisterPage

View File

@ -0,0 +1,13 @@
const DashboardPage = () => (
<div className="space-y-4">
<div>
<h1 className="text-2xl font-semibold text-foreground">Дашборд</h1>
<p className="text-sm text-muted-foreground">Скоро здесь появится аналитика сделок и активностей.</p>
</div>
<div className="rounded-lg border border-dashed border-border p-6 text-muted-foreground">
Контент дашборда в разработке.
</div>
</div>
)
export default DashboardPage

View File

@ -0,0 +1,14 @@
import { Link } from 'react-router-dom'
export const NotFoundPage = () => (
<div className="flex min-h-[60vh] flex-col items-center justify-center space-y-4 text-center">
<div className="space-y-2">
<p className="text-sm font-semibold text-primary">404</p>
<h1 className="text-3xl font-bold tracking-tight text-foreground">Страница не найдена</h1>
<p className="text-sm text-muted-foreground">Мы не смогли найти запрошенную страницу. Проверьте URL или вернитесь на дашборд.</p>
</div>
<Link className="text-sm font-semibold text-primary hover:underline" to="/dashboard">
Вернуться в приложение
</Link>
</div>
)

View File

@ -0,0 +1,13 @@
import { Navigate, Outlet } from 'react-router-dom'
import { useAuthStore } from '@/stores/auth-store'
export const GuestOnly = () => {
const hasSession = useAuthStore((state) => Boolean(state.tokens))
if (hasSession) {
return <Navigate to="/dashboard" replace />
}
return <Outlet />
}

View File

@ -0,0 +1,26 @@
import { Navigate, Outlet, useLocation } from 'react-router-dom'
import { AppLoading } from '@/components/system/app-loading'
import { useOrganizationsQuery } from '@/features/organizations/hooks'
import { useAuthStore } from '@/stores/auth-store'
export const RequireAuth = () => {
const status = useAuthStore((state) => state.status)
const tokens = useAuthStore((state) => state.tokens)
const location = useLocation()
const { isLoading: orgsLoading, data: orgs } = useOrganizationsQuery()
if (status === 'loading') {
return <AppLoading />
}
if (!tokens) {
return <Navigate to="/auth/login" state={{ from: location }} replace />
}
if (orgsLoading && !orgs) {
return <AppLoading />
}
return <Outlet />
}

View File

@ -0,0 +1,43 @@
import { lazy } from 'react'
import { Navigate, createBrowserRouter } from 'react-router-dom'
import { AuthLayout } from '@/layouts/auth-layout'
import { AppShell } from '@/layouts/app-shell'
import { NotFoundPage } from '@/pages/not-found-page'
import { GuestOnly } from '@/routes/guards/guest-only'
import { RequireAuth } from '@/routes/guards/require-auth'
const LoginPage = lazy(() => import('@/pages/auth/login-page'))
const RegisterPage = lazy(() => import('@/pages/auth/register-page'))
const DashboardPage = lazy(() => import('@/pages/dashboard/dashboard-page'))
export const router = createBrowserRouter([
{
path: '/auth',
element: <GuestOnly />,
children: [
{
element: <AuthLayout />,
children: [
{ index: true, element: <Navigate to="/auth/login" replace /> },
{ path: 'login', element: <LoginPage /> },
{ path: 'register', element: <RegisterPage /> },
],
},
],
},
{
element: <RequireAuth />,
children: [
{
path: '/',
element: <AppShell />,
children: [
{ index: true, element: <Navigate to="/dashboard" replace /> },
{ path: 'dashboard', element: <DashboardPage /> },
],
},
],
},
{ path: '*', element: <NotFoundPage /> },
])

View File

@ -0,0 +1,133 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import { env, storageKeys } from '@/config/env'
import type { Organization, User } from '@/types/crm'
import { parseToken } from '@/lib/token'
type TokenBundle = {
accessToken: string
refreshToken: string
expiresAt: number
refreshExpiresAt: number
}
type AuthStatus = 'idle' | 'authenticated' | 'loading'
interface AuthState {
status: AuthStatus
user: User | null
organizations: Organization[]
activeOrganizationId: number | null
tokens: TokenBundle | null
setSession: (payload: {
user?: User | null
organizations: Organization[]
activeOrganizationId?: number | null
tokens: TokenBundle
}) => void
setOrganizations: (organizations: Organization[]) => void
setActiveOrganization: (organizationId: number | null) => void
setTokens: (tokens: TokenBundle | null) => void
logout: () => void
refreshSession: () => Promise<void>
}
const mapTokens = (input: {
access_token: string
refresh_token: string
expires_in: number
refresh_expires_in: number
}): TokenBundle => ({
accessToken: input.access_token,
refreshToken: input.refresh_token,
expiresAt: Date.now() + input.expires_in * 1000,
refreshExpiresAt: Date.now() + input.refresh_expires_in * 1000,
})
const deriveUser = (tokens: TokenBundle, fallback?: User | null): User | null => {
if (fallback) return fallback
const payload = parseToken(tokens.accessToken)
if (!payload?.sub) return null
const derived: User = {
id: Number(payload.sub),
email: payload.email ?? 'anonymous@unknown',
name: payload.name ?? payload.email?.split('@')[0] ?? 'Сотрудник',
created_at: new Date().toISOString(),
}
return derived
}
export const useAuthStore = create<AuthState>()(
persist(
(set, get) => ({
status: 'idle',
user: null,
organizations: [],
activeOrganizationId: null,
tokens: null,
setSession: ({ user, organizations, activeOrganizationId, tokens }) => {
const nextUser = deriveUser(tokens, user ?? get().user)
set({
status: 'authenticated',
user: nextUser,
organizations,
activeOrganizationId: activeOrganizationId ?? organizations[0]?.id ?? null,
tokens,
})
},
setOrganizations: (organizations) => {
const current = get().activeOrganizationId
const fallback = organizations[0]?.id ?? null
set({
organizations,
activeOrganizationId: current && organizations.some((org) => org.id === current) ? current : fallback,
})
},
setActiveOrganization: (organizationId) => {
set({ activeOrganizationId: organizationId })
},
setTokens: (tokens) => set({ tokens }),
logout: () => {
set({ status: 'idle', user: null, tokens: null, organizations: [], activeOrganizationId: null })
},
refreshSession: async () => {
const { tokens, logout } = get()
if (!tokens?.refreshToken) {
logout()
return
}
const response = await fetch(`${env.API_URL}${env.API_PREFIX}/auth/refresh`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ refresh_token: tokens.refreshToken }),
})
if (!response.ok) {
logout()
throw new Error('Unable to refresh session')
}
const nextTokens = mapTokens(await response.json())
set({ tokens: nextTokens, status: 'authenticated' })
},
}),
{
name: storageKeys.tokens,
partialize: ({ tokens, user, organizations, activeOrganizationId, status }) => ({
tokens,
user,
organizations,
activeOrganizationId,
status,
}),
},
),
)
export const authSelectors = {
accessToken: () => useAuthStore.getState().tokens?.accessToken ?? null,
refreshToken: () => useAuthStore.getState().tokens?.refreshToken ?? null,
expiresAt: () => useAuthStore.getState().tokens?.expiresAt ?? null,
organizationId: () => useAuthStore.getState().activeOrganizationId,
isAuthenticated: () => useAuthStore.getState().status === 'authenticated',
mapTokens,
}

View File

@ -0,0 +1,59 @@
import { create } from 'zustand'
import { persist } from 'zustand/middleware'
import { storageKeys } from '@/config/env'
type Theme = 'light' | 'dark' | 'system'
interface ThemeState {
theme: Theme
resolvedTheme: 'light' | 'dark'
setTheme: (theme: Theme) => void
hydrate: () => void
}
const getPreferred = (): 'light' | 'dark' => {
if (typeof window === 'undefined') return 'light'
return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'
}
const applyThemeClass = (theme: 'light' | 'dark') => {
if (typeof document === 'undefined') return
const root = document.documentElement
root.classList.remove('light', 'dark')
root.classList.add(theme)
}
export const useThemeStore = create<ThemeState>()(
persist(
(set, get) => ({
theme: 'system',
resolvedTheme: 'light',
setTheme: (next) => {
const resolved = next === 'system' ? getPreferred() : next
set({ theme: next, resolvedTheme: resolved })
applyThemeClass(resolved)
if (typeof window !== 'undefined') {
window.localStorage.setItem(storageKeys.theme, next)
}
},
hydrate: () => {
const { theme } = get()
const resolved = theme === 'system' ? getPreferred() : theme
set({ resolvedTheme: resolved })
applyThemeClass(resolved)
},
}),
{
name: storageKeys.theme,
partialize: ({ theme }) => ({ theme }),
onRehydrateStorage: () => (state) => {
if (state) {
const resolved = state.theme === 'system' ? getPreferred() : state.theme
state.resolvedTheme = resolved
requestAnimationFrame(() => applyThemeClass(resolved))
}
},
},
),
)

View File

@ -0,0 +1,73 @@
@import 'tailwindcss';
:root {
color-scheme: light;
--background: 210 40% 98%;
--foreground: 222 47% 11%;
--muted: 214 32% 91%;
--muted-foreground: 215 16% 46%;
--popover: 0 0% 100%;
--popover-foreground: 222 47% 11%;
--card: 0 0% 100%;
--card-foreground: 222 47% 11%;
--border: 214 32% 91%;
--input: 214 32% 91%;
--primary: 217 91% 60%;
--primary-foreground: 210 40% 98%;
--secondary: 214 32% 91%;
--secondary-foreground: 222 47% 11%;
--accent: 221 83% 53%;
--accent-foreground: 210 40% 98%;
--destructive: 0 72% 51%;
--destructive-foreground: 210 40% 98%;
--ring: 221 83% 53%;
--radius: 0.75rem;
}
.dark {
color-scheme: dark;
--background: 222 47% 11%;
--foreground: 213 31% 91%;
--muted: 217 32% 25%;
--muted-foreground: 215 20% 65%;
--popover: 224 47% 7%;
--popover-foreground: 213 31% 91%;
--card: 224 47% 7%;
--card-foreground: 213 31% 91%;
--border: 217 32% 25%;
--input: 217 32% 25%;
--primary: 217 91% 60%;
--primary-foreground: 222 47% 11%;
--secondary: 217 32% 25%;
--secondary-foreground: 213 31% 91%;
--accent: 199 89% 48%;
--accent-foreground: 210 40% 98%;
--destructive: 0 84% 60%;
--destructive-foreground: 210 40% 98%;
--ring: 199 89% 48%;
}
@layer base {
* {
border-color: hsl(var(--border));
}
body {
min-height: 100vh;
background-color: hsl(var(--background));
color: hsl(var(--foreground));
font-family: 'Inter', 'Inter var', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
-webkit-font-smoothing: antialiased;
}
::selection {
background-color: hsla(var(--primary), 0.2);
color: hsl(var(--primary));
}
}
@layer utilities {
.text-balance {
text-wrap: balance;
}
}

135
frontend/src/types/crm.ts Normal file
View File

@ -0,0 +1,135 @@
export type OrganizationRole = 'owner' | 'admin' | 'manager' | 'member'
export interface Organization {
id: number
name: string
created_at: string
}
export interface OrganizationMembership {
id: number
organization_id: number
user_id: number
role: OrganizationRole
}
export interface User {
id: number
name: string
email: string
created_at: string
}
export interface Contact {
id: number
organization_id: number
owner_id: number
name: string
email?: string | null
phone?: string | null
created_at: string
}
export type DealStatus = 'new' | 'in_progress' | 'won' | 'lost'
export type DealStage = 'qualification' | 'proposal' | 'negotiation' | 'closed'
export interface Deal {
id: number
organization_id: number
contact_id: number
owner_id: number
title: string
amount?: string | null
currency?: string | null
status: DealStatus
stage: DealStage
created_at: string
updated_at: string
}
export interface Task {
id: number
deal_id: number
title: string
description?: string | null
due_date?: string | null
is_done: boolean
created_at: string
}
export type ActivityType = 'comment' | 'status_changed' | 'stage_changed' | 'task_created' | 'system'
export interface ActivityPayload {
text?: string
previous_status?: DealStatus
new_status?: DealStatus
previous_stage?: DealStage
new_stage?: DealStage
[key: string]: unknown
}
export interface Activity {
id: number
deal_id: number
author_id?: number | null
type: ActivityType
payload: ActivityPayload
created_at: string
}
export interface TokenResponse {
access_token: string
refresh_token: string
token_type: string
expires_in: number
refresh_expires_in: number
}
export interface LoginPayload {
email: string
password: string
}
export interface RegisterPayload extends LoginPayload {
name: string
organization_name?: string | null
}
export interface DealSummaryByStatus {
status: DealStatus
count: number
amount_sum: string
}
export interface WonStatisticsSummary {
count: number
amount_sum: string
average_amount: string
}
export interface NewDealsWindowSummary {
days: number
count: number
}
export interface DealSummaryResponse {
by_status: DealSummaryByStatus[]
won: WonStatisticsSummary
new_deals: NewDealsWindowSummary
total_deals: number
}
export interface StageBreakdownItem {
stage: DealStage
total: number
by_status: Record<DealStatus, number>
conversion_to_next: number | null
}
export interface DealFunnelResponse {
stages: StageBreakdownItem[]
}
export type ApiError = {
detail: string | { msg: string } | { [key: string]: unknown }
}

1
frontend/src/vite-env.d.ts vendored Normal file
View File

@ -0,0 +1 @@
/// <reference types="vite/client" />

View File

@ -0,0 +1,84 @@
import type { Config } from 'tailwindcss'
import animatePlugin from 'tailwindcss-animate'
import defaultTheme from 'tailwindcss/defaultTheme'
const config: Config = {
darkMode: ['class', '.dark'],
content: ['./index.html', './src/**/*.{ts,tsx}'],
theme: {
container: {
center: true,
padding: '1.5rem',
screens: {
'2xl': '1400px',
},
},
extend: {
fontFamily: {
sans: ['Inter', ...defaultTheme.fontFamily.sans],
},
colors: {
border: 'hsl(var(--border))',
input: 'hsl(var(--input))',
ring: 'hsl(var(--ring))',
background: 'hsl(var(--background))',
foreground: 'hsl(var(--foreground))',
primary: {
DEFAULT: 'hsl(var(--primary))',
foreground: 'hsl(var(--primary-foreground))',
},
secondary: {
DEFAULT: 'hsl(var(--secondary))',
foreground: 'hsl(var(--secondary-foreground))',
},
destructive: {
DEFAULT: 'hsl(var(--destructive))',
foreground: 'hsl(var(--destructive-foreground))',
},
muted: {
DEFAULT: 'hsl(var(--muted))',
foreground: 'hsl(var(--muted-foreground))',
},
accent: {
DEFAULT: 'hsl(var(--accent))',
foreground: 'hsl(var(--accent-foreground))',
},
popover: {
DEFAULT: 'hsl(var(--popover))',
foreground: 'hsl(var(--popover-foreground))',
},
card: {
DEFAULT: 'hsl(var(--card))',
foreground: 'hsl(var(--card-foreground))',
},
},
borderRadius: {
lg: 'var(--radius)',
md: 'calc(var(--radius) - 2px)',
sm: 'calc(var(--radius) - 4px)',
},
keyframes: {
'accordion-down': {
from: { height: '0' },
to: { height: 'var(--radix-accordion-content-height)' },
},
'accordion-up': {
from: { height: 'var(--radix-accordion-content-height)' },
to: { height: '0' },
},
shimmer: {
'0%': { backgroundPosition: '-468px 0' },
'100%': { backgroundPosition: '468px 0' },
},
},
animation: {
'accordion-down': 'accordion-down 0.2s ease-out',
'accordion-up': 'accordion-up 0.2s ease-out',
shimmer: 'shimmer 1.2s ease-in-out infinite',
},
},
},
plugins: [animatePlugin],
}
export default config

View File

@ -0,0 +1,32 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
"target": "ES2022",
"useDefineForClassFields": true,
"lib": ["ES2022", "DOM", "DOM.Iterable"],
"module": "ESNext",
"types": ["vite/client"],
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
/* 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
frontend/tsconfig.json Normal file
View File

@ -0,0 +1,7 @@
{
"files": [],
"references": [
{ "path": "./tsconfig.app.json" },
{ "path": "./tsconfig.node.json" }
]
}

View File

@ -0,0 +1,30 @@
{
"compilerOptions": {
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
"target": "ES2023",
"lib": ["ES2023"],
"module": "ESNext",
"types": ["node"],
"skipLibCheck": true,
"baseUrl": ".",
"paths": {
"@/*": ["./src/*"]
},
/* 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", "tailwind.config.ts", "postcss.config.js"]
}

86
frontend/vite.config.ts Normal file
View File

@ -0,0 +1,86 @@
import { fileURLToPath } from 'node:url'
import path from 'node:path'
import react from '@vitejs/plugin-react-swc'
import { defineConfig } from 'vite'
import { VitePWA } from 'vite-plugin-pwa'
const __dirname = path.dirname(fileURLToPath(import.meta.url))
const pwaPlugin = VitePWA({
registerType: 'autoUpdate',
includeAssets: ['pwa-icon.svg', 'pwa-192x192.png', 'pwa-512x512.png'],
manifest: {
name: 'Kitchen CRM',
short_name: 'KitchenCRM',
display: 'standalone',
start_url: '/',
lang: 'en',
description: 'Multi-tenant CRM dashboard for organizations, contacts, deals, and analytics.',
background_color: '#020617',
theme_color: '#0f172a',
icons: [
{
src: '/pwa-icon.svg',
sizes: 'any',
type: 'image/svg+xml',
},
{
src: '/pwa-192x192.png',
sizes: '192x192',
type: 'image/png',
},
{
src: '/pwa-512x512.png',
sizes: '512x512',
type: 'image/png',
purpose: 'any maskable',
},
],
},
devOptions: {
enabled: true,
suppressWarnings: true,
},
workbox: {
globPatterns: ['**/*.{js,css,html,png,svg,ico,webmanifest,json}'],
runtimeCaching: [
{
urlPattern: ({ url }) => url.pathname.startsWith('/api'),
handler: 'NetworkFirst',
options: {
cacheName: 'api-cache',
networkTimeoutSeconds: 5,
expiration: {
maxEntries: 50,
maxAgeSeconds: 60 * 15,
},
},
},
{
urlPattern: ({ request }) => request.destination === 'document',
handler: 'NetworkFirst',
},
],
},
})
export default defineConfig({
plugins: [react(), pwaPlugin],
resolve: {
alias: {
'@': path.resolve(__dirname, 'src'),
},
},
envPrefix: 'VITE_',
server: {
host: '0.0.0.0',
port: 5173,
},
preview: {
port: 4173,
},
build: {
target: 'es2022',
},
})