first commit

This commit is contained in:
2023-10-12 18:29:47 +05:00
commit 826ac1f621
64 changed files with 5159 additions and 0 deletions
+1
View File
@@ -0,0 +1 @@
VITE_SERVER_URL=http://192.168.1.170:3000
+18
View File
@@ -0,0 +1,18 @@
module.exports = {
root: true,
env: { browser: true, es2020: true },
extends: [
'eslint:recommended',
'plugin:@typescript-eslint/recommended',
'plugin:react-hooks/recommended',
],
ignorePatterns: ['dist', '.eslintrc.cjs'],
parser: '@typescript-eslint/parser',
plugins: ['react-refresh'],
rules: {
'react-refresh/only-export-components': [
'warn',
{ allowConstantExport: true },
],
},
}
+24
View File
@@ -0,0 +1,24 @@
# 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?
+27
View File
@@ -0,0 +1,27 @@
# 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/README.md) uses [Babel](https://babeljs.io/) for Fast Refresh
- [@vitejs/plugin-react-swc](https://github.com/vitejs/vite-plugin-react-swc) uses [SWC](https://swc.rs/) for Fast Refresh
## Expanding the ESLint configuration
If you are developing a production application, we recommend updating the configuration to enable type aware lint rules:
- Configure the top-level `parserOptions` property like this:
```js
parserOptions: {
ecmaVersion: 'latest',
sourceType: 'module',
project: ['./tsconfig.json', './tsconfig.node.json'],
tsconfigRootDir: __dirname,
},
```
- Replace `plugin:@typescript-eslint/recommended` to `plugin:@typescript-eslint/recommended-type-checked` or `plugin:@typescript-eslint/strict-type-checked`
- Optionally add `plugin:@typescript-eslint/stylistic-type-checked`
- Install [eslint-plugin-react](https://github.com/jsx-eslint/eslint-plugin-react) and add `plugin:react/recommended` & `plugin:react/jsx-runtime` to the `extends` list
+13
View File
@@ -0,0 +1,13 @@
<!doctype html>
<html lang="">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Stream CRM</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
</body>
</html>
+39
View File
@@ -0,0 +1,39 @@
{
"name": "client",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc && vite build",
"lint": "eslint . --ext ts,tsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview"
},
"dependencies": {
"date-fns": "^2.30.0",
"ky": "^1.0.1",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-google-recaptcha": "^3.1.0",
"react-router-dom": "^6.15.0",
"react-transition-group": "^4.4.5",
"zustand": "^4.4.1"
},
"devDependencies": {
"@types/react": "^18.2.15",
"@types/react-dom": "^18.2.7",
"@types/react-google-recaptcha": "^2.1.6",
"@types/react-transition-group": "^4.4.7",
"@typescript-eslint/eslint-plugin": "^6.0.0",
"@typescript-eslint/parser": "^6.0.0",
"@vitejs/plugin-react-swc": "^3.3.2",
"autoprefixer": "^10.4.15",
"eslint": "^8.45.0",
"eslint-plugin-react-hooks": "^4.6.0",
"eslint-plugin-react-refresh": "^0.4.3",
"postcss": "^8.4.29",
"tailwindcss": "^3.3.3",
"typescript": "^5.0.2",
"vite": "^4.4.5"
}
}
+6
View File
@@ -0,0 +1,6 @@
export default {
plugins: {
tailwindcss: {},
autoprefixer: {},
},
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.6 KiB

+1
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

View File
+10
View File
@@ -0,0 +1,10 @@
import { useEffect } from "react";
import "./App.css";
function App() {
useEffect(() => {}, []);
return <h1 className="text-3xl font-bold underline">Hello world!</h1>;
}
export default App;
+1
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

+45
View File
@@ -0,0 +1,45 @@
import SpinnerIcon from "./icons/SpinnerIcon";
interface ButtonProps {
type?: "button" | "reset" | "submit";
color?: "primary" | "secondary";
size?: "small" | "medium";
disabled?: boolean;
loading?: boolean;
icon?: React.ReactNode;
children?: React.ReactNode;
className?: string;
handleClick?: () => void;
}
function Button({
type = "button",
color = "primary",
size = "small",
disabled,
loading = false,
icon,
children,
className,
handleClick,
}: ButtonProps) {
return (
<button
disabled={disabled || loading}
type={type}
onClick={handleClick}
className={`relative outline-none rounded-lg transition-colors font-semibold flex justify-center items-center gap-1 active:bg-[#49A1F5] disabled:bg-[#F2F2F2] disabled:text-[#CCCCCC] ${
(color === "primary" && "bg-[#49A1F5] text-white hover:bg-[#4190DB]") ||
(color === "secondary" &&
"bg-[#F0F1F2] text-[#77828C] active:text-white")
} ${
(size === "small" && `h-[32px] px-3 py-2.5 text-xs`) ||
(size === "medium" && "h-[40px] px-6 py-3 text-sm")
} ${className}`}
>
{loading ? <SpinnerIcon /> : icon} {children}
</button>
);
}
export default Button;
+71
View File
@@ -0,0 +1,71 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import MoreIcon from "./icons/MoreIcon";
interface CardProps {
client: {
name: string;
phone: string;
email: string;
};
manager?: {
id: string;
name: string;
avatar: string;
};
}
function Card({ client, manager }: CardProps) {
return (
<div className="w-[264px] h-[128px] px-3 py-2 bg-white border-r border-b border-[#DAE0E5] flex flex-col gap-2">
<div className="flex justify-between">
<p className="text-sm font-semibold">{client.name}</p>
{manager ? (
<div className="bg-[#DAF2E4] rounded-full px-2 h-[20px] flex items-center gap-1">
<div className="w-1 h-1 rounded-full bg-[#27AE60]"></div>
<p className="text-[10px] font-semibold text-[#27AE60] pt-0.5">
Сеанс начат
</p>
</div>
) : (
<div className="bg-[#F2DADA] rounded-full px-2 h-[20px] flex items-center gap-1">
<div className="w-1 h-1 rounded-full bg-[#EB5757]"></div>
<p className="text-[10px] font-semibold text-[#EB5757] pt-0.5">
Нет менеджена
</p>
</div>
)}
</div>
<div className="border-b border-[#DAE0E5] pb-2">
<p className="text-xs text-[#77828C] leading-tight">{client.phone}</p>
<p className="text-xs text-[#77828C] leading-tight">{client.email}</p>
</div>
<div className="flex justify-between items-center py-1">
<div className="flex items-center gap-2">
{manager ? (
<div className="relative">
<img
src={manager.avatar}
alt=""
className="w-6 h-6 rounded-full"
/>
<div className="absolute right-0 bottom-0 bg-[#27AE60] border border-white rounded-full w-2 h-2"></div>
</div>
) : (
<div className="w-6 h-6 bg-[#ccc] rounded-full"></div>
)}
<p className="text-xs font-semibold">
{manager ? manager.name : "Не назначен"}
</p>
</div>
<button
onClick={() => alert("Чё тыкаешь? В разработке еще!!")}
className="p-1 text-[#77828C] hover:bg-neutral-100 rounded-lg"
>
<MoreIcon />
</button>
</div>
</div>
);
}
export default Card;
+7
View File
@@ -0,0 +1,7 @@
function EmptyCard() {
return (
<div className="w-[264px] h-[128px] text-sm font-semibold bg-[#F0F1F2] border-r border-b border-[#DAE0E5]"></div>
);
}
export default EmptyCard;
+26
View File
@@ -0,0 +1,26 @@
import { FormEvent } from "react";
interface FormProps {
children: React.ReactNode;
className?: string;
handleSubmit: () => void;
}
function Form({ children, className, handleSubmit }: FormProps) {
function preHandleSubmit(e: FormEvent) {
e.preventDefault();
handleSubmit();
}
return (
<form
onSubmit={preHandleSubmit}
className={`flex flex-col gap-4 w-[302px] ${className}`}
>
{children}
</form>
);
}
export default Form;
+51
View File
@@ -0,0 +1,51 @@
import { Link } from "react-router-dom";
import useAuthStore from "../stores/useAuthStore";
import Button from "./Button";
function Header() {
const [accessToken, setAccessToken] = useAuthStore((state) => [
state.accessToken,
state.setAccessToken,
]);
function logout() {
setAccessToken(null);
}
return (
<div className="border-b border-neutral-300">
<div className="container mx-auto px-4 xl:max-w-screen-xl">
<div className="flex justify-between">
<div className="">
<a
href="/"
className="p-2 inline-block transition-colors hover:bg-neutral-200"
>
<span className="text-2xl">Logo</span>
</a>
</div>
<div className="">
{accessToken ? (
<Button
type="button"
handleClick={logout}
className="bg-transparent text-black hover:bg-neutral-200"
>
Logout
</Button>
) : (
<Link
to="/login"
className="p-3 inline-block transition-colors hover:bg-neutral-200"
>
Login
</Link>
)}
</div>
</div>
</div>
</div>
);
}
export default Header;
+40
View File
@@ -0,0 +1,40 @@
import { useEffect, useState } from "react";
interface InputProps {
type?: "text" | "email" | "password";
placeholder?: string;
autoFocus?: boolean;
required?: boolean;
handleChange?: (value: string) => void;
}
function Input({
type = "text",
placeholder,
autoFocus,
required,
handleChange,
}: InputProps) {
const [value, setValue] = useState<string>("");
useEffect(() => {
if (handleChange) {
handleChange(value);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [value]);
return (
<input
type={type}
placeholder={placeholder}
autoFocus={autoFocus}
required={required}
value={value}
onChange={(e) => setValue(e.target.value)}
className="px-3 py-2.5 outline-none rounded-lg border border-[#DAE0E5]"
/>
);
}
export default Input;
+11
View File
@@ -0,0 +1,11 @@
interface LabelProps {
value: string;
}
function Label({ value }: LabelProps) {
return (
<label className="text-xs text-[#697C8C]">{value}</label>
);
}
export default Label;
+26
View File
@@ -0,0 +1,26 @@
interface TabButtonProps {
children: React.ReactNode;
active?: boolean;
className?: string;
handleClick?: () => void;
}
function TabButton({
children,
active = false,
className,
handleClick,
}: TabButtonProps) {
return (
<button
className={`px-6 py-4 text-sm font-semibold leading-none transition-colors ${
active ? "bg-white" : "hover:bg-neutral-200"
} ${className}`}
onClick={handleClick}
>
{children}
</button>
);
}
export default TabButton;
@@ -0,0 +1,20 @@
function BurgerIcon() {
return (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
fillRule="evenodd"
clipRule="evenodd"
d="M19 8H5C4.44772 8 4 7.55228 4 7C4 6.44772 4.44772 6 5 6L19 6C19.5523 6 20 6.44772 20 7C20 7.55228 19.5523 8 19 8ZM4 12C4 11.4477 4.44772 11 5 11H19C19.5523 11 20 11.4477 20 12C20 12.5523 19.5523 13 19 13H5C4.44772 13 4 12.5523 4 12ZM4 17C4 16.4477 4.44772 16 5 16H19C19.5523 16 20 16.4477 20 17C20 17.5523 19.5523 18 19 18H5C4.44772 18 4 17.5523 4 17Z"
fill="#111C26"
/>
</svg>
);
}
export default BurgerIcon;
@@ -0,0 +1,21 @@
function ChevronLeftIcon() {
return (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M13 7L8 12L13 17"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
export default ChevronLeftIcon;
@@ -0,0 +1,21 @@
function ChevronLeftIcon() {
return (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<path
d="M11 7L16 12L11 17"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
/>
</svg>
);
}
export default ChevronLeftIcon;
+17
View File
@@ -0,0 +1,17 @@
function MoreIcon() {
return (
<svg
width="24"
height="24"
viewBox="0 0 24 24"
fill="none"
xmlns="http://www.w3.org/2000/svg"
>
<circle cx="5" cy="12" r="1.5" fill="currentColor" />
<circle cx="12" cy="12" r="1.5" fill="currentColor" />
<circle cx="19" cy="12" r="1.5" fill="currentColor" />
</svg>
);
}
export default MoreIcon;
@@ -0,0 +1,26 @@
function SpinnerIcon() {
return (
<svg
className="animate-spin h-4 w-4 mr-1"
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
>
<circle
className="opacity-25"
cx="12"
cy="12"
r="10"
stroke="currentColor"
strokeWidth="4"
></circle>
<path
className="opacity-75"
fill="currentColor"
d="M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"
></path>
</svg>
);
}
export default SpinnerIcon;
+42
View File
@@ -0,0 +1,42 @@
/* @import url("https://fonts.googleapis.com/css2?family=Manrope:wght@400;600&display=swap"); */
@import url("https://fonts.googleapis.com/css2?family=Inter:wght@400;600&display=swap");
@tailwind base;
@tailwind components;
@tailwind utilities;
body {
/* font-family: "Manrope", sans-serif; */
font-family: "Inter", sans-serif;
color: #111c26;
}
*::-webkit-scrollbar {
width: 8px;
}
*::-webkit-scrollbar-thumb {
background-color: #858585;
border: 3.5px solid #f2f2f2;
border-radius: 4px;
}
*::-webkit-scrollbar-thumb:hover {
border-width: 2px;
}
.entering {
opacity: 1;
}
.entered {
opacity: 1;
}
.exiting {
opacity: 0;
}
.exited {
opacity: 0;
}
+13
View File
@@ -0,0 +1,13 @@
import { Outlet } from "react-router-dom";
import Header from "../components/Header";
function DefaultLayout() {
return (
<div className="min-h-screen flex flex-col bg-[#F2F2F2]">
<Header />
<Outlet />
</div>
);
}
export default DefaultLayout;
+59
View File
@@ -0,0 +1,59 @@
import ReactDOM from "react-dom/client";
import { createBrowserRouter, RouterProvider } from "react-router-dom";
import "./index.css";
import HomePage from "./pages/HomePage.tsx";
import DashboardPage from "./pages/DashboardPage.tsx";
import ProtectedRoute from "./utils/ProtectedRoute.tsx";
import LoginPage from "./pages/LoginPage.tsx";
import RegistrationPage from "./pages/RegistrationPage.tsx";
import RegistrationCompanyPage from "./pages/RegistrationCompanyPage.tsx";
import RegistrationManagerPage from "./pages/RegistrationManagerPage.tsx";
const router = createBrowserRouter([
{
path: "/",
children: [
{
index: true,
element: <HomePage />,
},
{
path: "login",
element: <LoginPage />,
},
{
path: "registration",
children: [
{
index: true,
element: <RegistrationPage />,
},
{
path: "company",
element: <RegistrationCompanyPage />,
},
{
path: "manager",
element: <RegistrationManagerPage />,
},
],
},
{
path: "dashboard",
element: <ProtectedRoute />,
children: [
{
index: true,
element: <DashboardPage />,
},
],
},
],
},
]);
ReactDOM.createRoot(document.getElementById("root")!).render(
// <React.StrictMode>
<RouterProvider router={router} />
// </React.StrictMode>,
);
+370
View File
@@ -0,0 +1,370 @@
/* eslint-disable react-hooks/exhaustive-deps */
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useEffect, useState } from "react";
import Card from "../components/Card";
import EmptyCard from "../components/EmptyCard";
import TabButton from "../components/TabButton";
import BurgerIcon from "../components/icons/BurgerIcon";
import ChevronLeftIcon from "../components/icons/ChevronLeftIcon";
import ChevronRightIcon from "../components/icons/ChevronRightIcon";
import api from "../utils/api";
import useAuthStore from "../stores/useAuthStore";
import {
eachMinuteOfInterval,
format,
parse,
addDays,
subDays,
} from "date-fns";
import Button from "../components/Button";
import { ru } from "date-fns/locale";
import { Transition } from "react-transition-group";
import SpinnerIcon from "../components/icons/SpinnerIcon";
function DashboardPage() {
const [user, setAccessToken] = useAuthStore((state) => [
state.user,
state.setAccessToken,
]);
const [company, setCompany] = useState<{ [key: string]: any }>();
const [managers, setManagers] = useState<any[]>();
const [builds, setBuilds] = useState<any[]>();
const [selectedBuild, setSelectedBuild] = useState<{ [key: string]: any }>();
const [scheduledSessions, setScheduledSessions] = useState<any[]>();
const [generatedScheduledSessions, setGeneratedScheduledSessions] =
useState<any[][]>();
const [selectedDate, setSelectedDate] = useState(new Date());
const startDateTime = parse("10:00", "HH:mm", selectedDate);
const endDateTime = parse("20:00", "HH:mm", selectedDate);
const dateTimes: Date[] = eachMinuteOfInterval(
{
start: startDateTime,
end: endDateTime,
},
{ step: 60 }
);
const [currentTime, setCurrentTime] = useState<string>(
format(new Date(), "HH:mm")
);
const [isLoadingScheduledSessions, setIsLoadingScheduledSessions] =
useState(true);
// const [selectedDate, setSelectedDate] = useState(
// format(new Date(), "d MMMM, yyyy", { locale: ru })
// );
function selectNextDay() {
setSelectedDate((prev) => addDays(prev, 1));
}
function selectPrevDay() {
setSelectedDate((prev) => subDays(prev, 1));
}
function selectCurrentDate() {
setSelectedDate(new Date());
}
async function getCompany() {
if (!user) {
console.log("No User", user);
return;
}
try {
const result: any = await api.get(`companies/${user.companyId}`).json();
console.log("getCompany result: ", result);
setCompany(result);
} catch (error) {
if (error instanceof Error) {
console.log("Error: ", error.message);
}
}
}
async function getBuilds() {
if (!user) {
console.log("No User", user);
return;
}
try {
const result: any = await api
.get(`companies/${user.companyId}/builds`)
.json();
console.log("getBuilds result: ", result);
setBuilds(result);
} catch (error) {
if (error instanceof Error) {
console.log("Error: ", error.message);
}
}
}
async function getManagers() {
if (!company) {
console.log("No Managers", managers);
return;
}
try {
const result: any = await api.get(`companies/${company.id}/users`).json();
console.log("getManagers result: ", result);
setManagers(result);
} catch (error) {
if (error instanceof Error) {
console.log("Error: ", error.message);
}
}
}
async function getScheduledSessions() {
if (!company) {
console.log("No ScheduledSessions");
return;
}
console.log("selectedBuild", selectedBuild);
if (!selectedBuild || !selectedBuild.id) {
console.log("No selectedBuild");
return;
}
setIsLoadingScheduledSessions(true);
try {
const result: any = await api
.get(
`companies/${company.id}/builds/${
selectedBuild.id
}/scheduled_sessions?date=${selectedDate.toISOString()}`
)
.json();
console.log("getScheduledSessions result: ", result);
setScheduledSessions(result);
setIsLoadingScheduledSessions(false);
} catch (error) {
setIsLoadingScheduledSessions(false);
if (error instanceof Error) {
console.log("Error: ", error.message);
}
}
}
function logout() {
setAccessToken(null);
}
function generateScheduledSessions() {
if (!scheduledSessions || !selectedBuild) return;
const arr: any[][] = [];
dateTimes.forEach((dateTime) => {
const arr2 = [];
const findedSessionsCount = scheduledSessions.filter(
(session) => session.startAt === dateTime.toISOString()
);
arr2.push(dateTime);
for (let i = 0; i < selectedBuild.sessionLimit; i++) {
if (findedSessionsCount[i]) {
arr2.push(findedSessionsCount[i]);
} else {
arr2.push({});
}
}
arr.push(arr2);
});
setGeneratedScheduledSessions(arr);
}
useEffect(() => {
getCompany();
const interval = setInterval(() => {
setCurrentTime(format(new Date(), "HH:mm"));
}, 1000);
return () => {
clearInterval(interval);
};
}, []);
useEffect(() => {
if (!company) return;
getBuilds();
}, [company]);
useEffect(() => {
if (!builds) return;
setSelectedBuild(builds[0]);
getManagers();
}, [builds]);
useEffect(() => {
if (!managers || !selectedDate || !selectedBuild) return;
getScheduledSessions();
console.log(selectedBuild);
}, [managers, selectedDate, selectedBuild]);
useEffect(() => {
if (!scheduledSessions) return;
generateScheduledSessions();
console.log(scheduledSessions);
}, [scheduledSessions]);
return (
<div className="main h-screen flex">
<div className="left flex flex-col w-full">
<div className="flex bg-[#F0F1F2] ">
<button
onClick={() => alert("Чё тыкаешь? В разработке еще!!")}
className="p-3 transition-colors hover:bg-neutral-200"
>
<BurgerIcon />
</button>
{builds?.map((build) => (
<TabButton
key={build.id}
handleClick={() => setSelectedBuild(build)}
active={selectedBuild && build.id === selectedBuild.id}
>
{build.name}
</TabButton>
))}
</div>
<div className="flex justify-between items-center px-4 py-2 h-12 border-r border-b border-[#DAE0E5]">
<p className="text-sm font-semibold">Расписание</p>
<div className="flex items-center gap-4">
<p className="text-sm font-semibold">
{format(selectedDate, "PPPP", { locale: ru })}
</p>
<div className="flex gap-1">
<Button
handleClick={selectPrevDay}
icon={<ChevronLeftIcon />}
color="secondary"
/>
<Button
handleClick={selectNextDay}
icon={<ChevronRightIcon />}
color="secondary"
/>
</div>
<Button handleClick={selectCurrentDate}>Сегодня</Button>
</div>
</div>
<div className="flex bg-[#F2F2F2]">
<div className="w-[84px] h-[40px] flex justify-center items-center text-sm font-semibold bg-white border-r border-b border-[#DAE0E5]">
{currentTime}
</div>
{selectedBuild &&
[...Array(selectedBuild.sessionLimit)].map((_, index) => (
<div key={index}>
<div className="w-[264px] h-[40px] px-3 flex items-center text-sm font-semibold bg-[#F0F1F2] border-r border-b border-[#DAE0E5]">
Слот {index + 1}
</div>
</div>
))}
</div>
<div
className={`overflow-y-auto overflow-x-hidden flex-1 bg-[#F2F2F2] border-r border-[#DAE0E5]`}
>
<Transition
in={isLoadingScheduledSessions}
timeout={150}
mountOnEnter
unmountOnExit
>
{(state) => (
<div
className={`fixed z-10 top-0 left-0 w-full h-full bg-black bg-opacity-80 transition-opacity flex justify-center items-center text-white ${state}`}
>
<SpinnerIcon />
</div>
)}
</Transition>
{!isLoadingScheduledSessions &&
generatedScheduledSessions?.map(
(generatedScheduledSession, index) => (
<div key={index} className="flex">
{generatedScheduledSession.map((scheduledSession, index2) => {
if (index2 === 0) {
return (
<div
key={index2}
className="w-[84px] h-[128px] flex justify-center items-center text-sm font-semibold bg-[#F0F1F2] border-r border-b border-[#DAE0E5]"
>
{format(scheduledSession, "HH:mm")}
</div>
);
} else {
if (Object.keys(scheduledSession).length) {
return (
<Card
key={index2}
client={{
name: scheduledSession.clientName,
phone: scheduledSession.clientPhone,
email: scheduledSession.clientEmail,
}}
manager={managers?.find(
(manager) =>
manager.id === scheduledSession.userId
)}
/>
);
} else {
return <EmptyCard key={index2} />;
}
}
})}
</div>
)
)}
</div>
</div>
<div className="right w-[320px] flex flex-col">
<div className="min-h-[48px] bg-[#F0F1F2] flex justify-between items-center">
<p className="text-xs font-semibold px-3 text-green-600">
{company?.name}
</p>
<p className="text-xs font-semibold px-3">{user?.username}</p>
<TabButton handleClick={logout} className="text-red-600">
Выйти
</TabButton>
</div>
<div className="flex gap-2 h-[48px] border-b border-[#DAE0E5]">
<button className="p-4 text-sm font-semibold">Параметры</button>
<button
disabled
className="p-4 text-sm font-semibold disabled:text-[#77828C]"
>
Статистика
</button>
</div>
<div className="overflow-y-auto overflow-x-hidden">
<p className="p-4">...</p>
</div>
</div>
</div>
);
}
export default DashboardPage;
+15
View File
@@ -0,0 +1,15 @@
import { Link } from "react-router-dom";
import Button from "../components/Button";
function HomePage() {
return (
<div className="p-8 flex flex-col gap-4 w-fit">
<p>HomePage</p>
<Link to="/login">
<Button type="button">Login</Button>
</Link>
</div>
);
}
export default HomePage;
+102
View File
@@ -0,0 +1,102 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { useRef, useState } from "react";
import ky from "ky";
import ReCAPTCHA from "react-google-recaptcha";
import Form from "../components/Form";
import Label from "../components/Label";
import Input from "../components/Input";
import Button from "../components/Button";
import { Link, useNavigate } from "react-router-dom";
import useAuthStore from "../stores/useAuthStore";
function LoginPage() {
const [username, setUsername] = useState<string>();
const [password, setPassword] = useState<string>();
const recaptchaRef = useRef(null);
const [setAccessToken, setUser] = useAuthStore((state) => [
state.setAccessToken,
state.setUser,
]);
const [isLoading, setisLoading] = useState<boolean>(false);
const navigate = useNavigate();
async function login() {
setisLoading(true);
const result: any = await ky
.post(import.meta.env.VITE_SERVER_URL + "/login", {
json: {
username,
password,
},
})
.json();
if (result.error) {
alert(result.error);
return;
}
setAccessToken(result.accessToken);
setUser(result.user);
navigate("/dashboard");
setTimeout(() => {
setisLoading(false);
}, 3000);
}
return (
<div className="min-h-screen flex flex-col justify-center items-center p-8 flex-1 ">
<div className=" bg-white rounded-lg shadow-md overflow-hidden">
<div className="flex flex-col gap-6 p-12">
<p className="text-2xl font-semibold">Вход</p>
<Form handleSubmit={login}>
<div className="flex flex-col gap-1">
<Label value="Email" />
<Input
type="email"
placeholder="example@gmail.com"
autoFocus
required
handleChange={(value) => setUsername(value)}
/>
</div>
<div className="flex flex-col gap-1">
<Label value="Пароль" />
<Input
type="password"
placeholder="********"
required
handleChange={(value) => setPassword(value)}
/>
</div>
<ReCAPTCHA
ref={recaptchaRef}
sitekey="6LdKPH4oAAAAAM8cyMoCkmNvbnBbe2UIrwRwQ425"
className="mt-3"
/>
<Button
type="submit"
size="medium"
className="mt-10"
loading={isLoading}
>
Войти
</Button>
</Form>
<div className="self-center flex gap-6">
<Link to="/registration" className="text-xs text-[#49A1F5]">
Нет аккаунта?
</Link>
{/* <Link to="" className="text-xs text-[#49A1F5]">
Забыли пароль?
</Link> */}
</div>
</div>
</div>
</div>
);
}
export default LoginPage;
@@ -0,0 +1,35 @@
/* eslint-disable no-irregular-whitespace */
import { Link } from "react-router-dom";
import Button from "../components/Button";
function RegistrationCompanyPage() {
return (
<div className="min-h-screen flex flex-col justify-center items-center p-8 flex-1">
<div className=" bg-white rounded-lg shadow-md overflow-hidden">
<div className="flex flex-col gap-6 p-12 w-[528px]">
<p className="text-2xl font-semibold">Вы представитель компании</p>
<p>
Для получения данных для входа обратитесь в компанию GRAFF
interactive любым удобным для вас способом
</p>
<div className="flex gap-6">
<a href="tel:88007700067" className="text-blue-500">
8 800 770 00 67
</a>
<a href="mailto:support@graff.tech" className="text-blue-500">
support@graff.tech
</a>
</div>
<Link to="/login" className="mt-4">
<Button size="medium">На главную</Button>
</Link>
</div>
</div>
</div>
);
}
export default RegistrationCompanyPage;
@@ -0,0 +1,26 @@
/* eslint-disable no-irregular-whitespace */
import { Link } from "react-router-dom";
import Button from "../components/Button";
function RegistrationManagerPage() {
return (
<div className="min-h-screen flex flex-col justify-center items-center p-8 flex-1">
<div className=" bg-white rounded-lg shadow-md overflow-hidden">
<div className="flex flex-col gap-6 p-12 w-[528px]">
<p className="text-2xl font-semibold">Получение данных для входа</p>
<p>
Чтобы получить данные для входа обратитесь к представителю вашей
организации, для подключения вас к системе.
</p>
<Link to="/login" className="mt-4">
<Button size="medium">На главную</Button>
</Link>
</div>
</div>
</div>
);
}
export default RegistrationManagerPage;
+35
View File
@@ -0,0 +1,35 @@
import { Link } from "react-router-dom";
import Button from "../components/Button";
function RegistrationPage() {
return (
<div className="min-h-screen flex flex-col justify-center items-center p-8 flex-1">
<div className=" bg-white rounded-lg shadow-md overflow-hidden">
<div className="flex flex-col gap-6 p-12 w-[528px]">
<p className="text-2xl font-semibold">Получение данных для входа</p>
<div className="flex flex-col gap-4">
<Link to="company">
<button className="h-[56px] px-6 py-4 rounded-lg border border-[#DAE0E5] text-[#77828C] text-left w-full">
Я представитель компании
</button>
</Link>
<Link to="manager">
<button className="h-[56px] px-6 py-4 rounded-lg border border-[#DAE0E5] text-[#77828C] text-left w-full">
Я менеджер отдела продаж
</button>
</Link>
</div>
<Link to="/login">
<Button size="medium" color="secondary">
Назад
</Button>
</Link>
</div>
</div>
</div>
);
}
export default RegistrationPage;
+25
View File
@@ -0,0 +1,25 @@
import { create } from "zustand";
import { persist } from "zustand/middleware";
interface AuthState {
accessToken: string | null;
user: Record<string, never> | null;
setAccessToken: (accessToken: string | null) => void;
setUser: (user: Record<string, never> | null) => void;
}
const useAuthStore = create<AuthState>()(
persist(
(set) => ({
accessToken: null,
user: null,
setAccessToken: (accessToken) => set({ accessToken }),
setUser: (user) => set({ user }),
}),
{
name: "auth",
}
)
);
export default useAuthStore;
+10
View File
@@ -0,0 +1,10 @@
import { Navigate, Outlet } from "react-router-dom";
import useAuthStore from "../stores/useAuthStore";
function ProtectedRoute() {
const accessToken = useAuthStore((state) => state.accessToken);
return accessToken ? <Outlet /> : <Navigate to="/login" />;
}
export default ProtectedRoute;
+17
View File
@@ -0,0 +1,17 @@
import ky from "ky";
import useAuthStore from "../stores/useAuthStore";
const api = ky.extend({
prefixUrl: `${import.meta.env.VITE_SERVER_URL}`,
hooks: {
beforeRequest: [
(request) => {
const accessToken = useAuthStore.getState().accessToken;
request.headers.set("Authorization", `Bearer ${accessToken}`);
},
],
},
});
export default api;
+1
View File
@@ -0,0 +1 @@
/// <reference types="vite/client" />
+12
View File
@@ -0,0 +1,12 @@
/** @type {import('tailwindcss').Config} */
export default {
content: [
"./index.html",
"./src/**/*.{js,ts,jsx,tsx}",
],
theme: {
extend: {},
},
plugins: [],
}
+25
View File
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"module": "ESNext",
"skipLibCheck": true,
/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx",
/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src"],
"references": [{ "path": "./tsconfig.node.json" }]
}
+10
View File
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
+7
View File
@@ -0,0 +1,7 @@
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react-swc'
// https://vitejs.dev/config/
export default defineConfig({
plugins: [react()],
})
+1738
View File
File diff suppressed because it is too large Load Diff