first commit
This commit is contained in:
@@ -0,0 +1 @@
|
||||
VITE_SERVER_URL=http://192.168.1.170:3000
|
||||
@@ -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 },
|
||||
],
|
||||
},
|
||||
}
|
||||
@@ -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?
|
||||
@@ -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
|
||||
@@ -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>
|
||||
@@ -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"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
export default {
|
||||
plugins: {
|
||||
tailwindcss: {},
|
||||
autoprefixer: {},
|
||||
},
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 2.6 KiB |
@@ -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 |
@@ -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;
|
||||
@@ -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 |
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -0,0 +1,11 @@
|
||||
interface LabelProps {
|
||||
value: string;
|
||||
}
|
||||
|
||||
function Label({ value }: LabelProps) {
|
||||
return (
|
||||
<label className="text-xs text-[#697C8C]">{value}</label>
|
||||
);
|
||||
}
|
||||
|
||||
export default Label;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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;
|
||||
@@ -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>,
|
||||
);
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
@@ -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;
|
||||
Vendored
+1
@@ -0,0 +1 @@
|
||||
/// <reference types="vite/client" />
|
||||
@@ -0,0 +1,12 @@
|
||||
/** @type {import('tailwindcss').Config} */
|
||||
export default {
|
||||
content: [
|
||||
"./index.html",
|
||||
"./src/**/*.{js,ts,jsx,tsx}",
|
||||
],
|
||||
theme: {
|
||||
extend: {},
|
||||
},
|
||||
plugins: [],
|
||||
}
|
||||
|
||||
@@ -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" }]
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"composite": true,
|
||||
"skipLibCheck": true,
|
||||
"module": "ESNext",
|
||||
"moduleResolution": "bundler",
|
||||
"allowSyntheticDefaultImports": true
|
||||
},
|
||||
"include": ["vite.config.ts"]
|
||||
}
|
||||
@@ -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
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
PORT=3000
|
||||
MONGO_URI=mongodb://root:p62Z!ZatgY25@194.26.138.94:27017/
|
||||
JWT_SECRET=yDcdWJgvlj2bJAuovYfQHTvtc3U9xQPw
|
||||
@@ -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?
|
||||
@@ -0,0 +1,30 @@
|
||||
{
|
||||
"name": "server",
|
||||
"private": true,
|
||||
"version": "0.0.0",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"dev": "nodemon ./src/index.ts",
|
||||
"build": "tsc",
|
||||
"start": "node ./dist/index.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"bcrypt": "^5.1.1",
|
||||
"cors": "^2.8.5",
|
||||
"date-fns": "^2.30.0",
|
||||
"dotenv": "^16.3.1",
|
||||
"express": "^4.18.2",
|
||||
"jsonwebtoken": "^9.0.2",
|
||||
"mongoose": "^7.5.1"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@types/bcrypt": "^5.0.0",
|
||||
"@types/cors": "^2.8.14",
|
||||
"@types/express": "^4.17.17",
|
||||
"@types/jsonwebtoken": "^9.0.2",
|
||||
"@types/node": "^20.5.9",
|
||||
"nodemon": "^3.0.1",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^5.2.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
import { connect } from "mongoose";
|
||||
|
||||
async function connectDB() {
|
||||
try {
|
||||
await connect(process.env.MONGO_URI!, { dbName: "test2" });
|
||||
console.log("MongoDB connected...");
|
||||
} catch (error) {
|
||||
if (error instanceof Error) {
|
||||
console.error(error.message);
|
||||
}
|
||||
|
||||
process.exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
export default connectDB;
|
||||
@@ -0,0 +1,32 @@
|
||||
import "dotenv/config";
|
||||
import express, { json } from "express";
|
||||
import connectDB from "./config/db.js";
|
||||
import cors from "cors";
|
||||
import loginRouter from "./routes/login.js";
|
||||
import registrationRouter from "./routes/registration.js";
|
||||
import authMiddleware from "./middlewares/auth.js";
|
||||
import appRouter from "./routes/app.js";
|
||||
import companiesRouter from "./routes/companies.js";
|
||||
import scheduledSessionsRouter from "./routes/scheduledSessions.js";
|
||||
import usersRouter from "./routes/users.js";
|
||||
import buildsRouter from "./routes/builds.js";
|
||||
|
||||
const app = express();
|
||||
const port = process.env.PORT || 3000;
|
||||
|
||||
connectDB();
|
||||
|
||||
app.use(json());
|
||||
app.use(cors());
|
||||
|
||||
app.use("/login", loginRouter);
|
||||
app.use("/registration", registrationRouter);
|
||||
app.use("/app", authMiddleware, appRouter);
|
||||
app.use("/companies", authMiddleware, companiesRouter);
|
||||
app.use("/users", authMiddleware, usersRouter);
|
||||
app.use("/builds", authMiddleware, buildsRouter);
|
||||
app.use("/scheduled_sessions", authMiddleware, scheduledSessionsRouter);
|
||||
|
||||
app.listen(port, () => {
|
||||
console.log(`Server listening on port ${port}`);
|
||||
});
|
||||
@@ -0,0 +1,32 @@
|
||||
import { Request, Response, NextFunction } from "express";
|
||||
import jwt, { Secret } from "jsonwebtoken";
|
||||
import Token from "../models/Token.js";
|
||||
import User from "../models/User.js";
|
||||
|
||||
async function authMiddleware(req: Request, res: Response, next: NextFunction) {
|
||||
if (!req.headers.authorization || !req.headers.authorization.split(" ")[1]) {
|
||||
return res.status(401).json({ error: 10 });
|
||||
}
|
||||
|
||||
const accessToken = req.headers.authorization.split(" ")[1];
|
||||
|
||||
try {
|
||||
jwt.verify(accessToken, process.env.JWT_SECRET as Secret);
|
||||
} catch (error) {
|
||||
return res.status(401).json({ erorr: 20 });
|
||||
}
|
||||
|
||||
const foundAccessToken = await Token.findOne({ accessToken });
|
||||
|
||||
if (!foundAccessToken) {
|
||||
return res.status(401).json({ error: 30 });
|
||||
}
|
||||
|
||||
const user = await User.findById(foundAccessToken.userId);
|
||||
|
||||
res.locals = { accessToken, user };
|
||||
|
||||
next();
|
||||
}
|
||||
|
||||
export default authMiddleware;
|
||||
@@ -0,0 +1,34 @@
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const buildSchema = new Schema(
|
||||
{
|
||||
companyId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
sessionLimit: {
|
||||
type: Number,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
}
|
||||
);
|
||||
|
||||
buildSchema.virtual("scheduledSessions", {
|
||||
ref: "Scheduled_Session",
|
||||
localField: "_id",
|
||||
foreignField: "buildId",
|
||||
});
|
||||
|
||||
const Build = model("Build", buildSchema);
|
||||
|
||||
export default Build;
|
||||
@@ -0,0 +1,38 @@
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const companySchema = new Schema(
|
||||
{
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
}
|
||||
);
|
||||
|
||||
companySchema.virtual("users", {
|
||||
ref: "User",
|
||||
localField: "_id",
|
||||
foreignField: "companyId",
|
||||
});
|
||||
|
||||
companySchema.virtual("scheduledSessions", {
|
||||
ref: "Scheduled_Session",
|
||||
localField: "_id",
|
||||
foreignField: "companyId",
|
||||
});
|
||||
|
||||
companySchema.virtual("builds", {
|
||||
ref: "Build",
|
||||
localField: "_id",
|
||||
foreignField: "companyId",
|
||||
});
|
||||
|
||||
const Company = model("Company", companySchema);
|
||||
|
||||
export default Company;
|
||||
@@ -0,0 +1,45 @@
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const scheduledSessionSchema = new Schema(
|
||||
{
|
||||
companyId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "Company",
|
||||
required: true,
|
||||
},
|
||||
buildId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "Build",
|
||||
required: true,
|
||||
},
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
},
|
||||
startAt: {
|
||||
type: Date,
|
||||
required: true,
|
||||
},
|
||||
clientName: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
clientPhone: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
clientEmail: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
}
|
||||
);
|
||||
|
||||
const ScheduledSession = model("Scheduled_Session", scheduledSessionSchema);
|
||||
|
||||
export default ScheduledSession;
|
||||
@@ -0,0 +1,24 @@
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const tokenSchema = new Schema(
|
||||
{
|
||||
userId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "User",
|
||||
required: true,
|
||||
},
|
||||
accessToken: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
}
|
||||
);
|
||||
|
||||
const Token = model("Token", tokenSchema);
|
||||
|
||||
export default Token;
|
||||
@@ -0,0 +1,40 @@
|
||||
import { model, Schema } from "mongoose";
|
||||
|
||||
const userSchema = new Schema(
|
||||
{
|
||||
username: {
|
||||
type: String,
|
||||
required: true,
|
||||
unique: true,
|
||||
},
|
||||
password: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
companyId: {
|
||||
type: Schema.Types.ObjectId,
|
||||
ref: "Company",
|
||||
required: true,
|
||||
},
|
||||
name: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
role: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
avatar: {
|
||||
type: String,
|
||||
},
|
||||
},
|
||||
{
|
||||
timestamps: true,
|
||||
toJSON: { virtuals: true },
|
||||
toObject: { virtuals: true },
|
||||
}
|
||||
);
|
||||
|
||||
const User = model("User", userSchema);
|
||||
|
||||
export default User;
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Router } from "express";
|
||||
import Company from "../models/Company.js";
|
||||
|
||||
const appRouter = Router();
|
||||
|
||||
appRouter.post("/", async (_req, res) => {
|
||||
const companies = await Company.find();
|
||||
console.log(companies);
|
||||
|
||||
res.json({ route: "app" });
|
||||
});
|
||||
|
||||
export default appRouter;
|
||||
@@ -0,0 +1,18 @@
|
||||
import { Router } from "express";
|
||||
import Build from "../models/Build.js";
|
||||
|
||||
const buildsRouter = Router();
|
||||
|
||||
buildsRouter.get("/", async (_req, res) => {
|
||||
await Build.find();
|
||||
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
|
||||
buildsRouter.post("/", async (req, res) => {
|
||||
const build = await Build.create(req.body);
|
||||
|
||||
res.json(build);
|
||||
});
|
||||
|
||||
export default buildsRouter;
|
||||
@@ -0,0 +1,85 @@
|
||||
import { Router } from "express";
|
||||
import Company from "../models/Company.js";
|
||||
import { parseISO, startOfDay, endOfDay } from "date-fns";
|
||||
|
||||
const companiesRouter = Router();
|
||||
|
||||
// companiesRouter.get("/", async (_req, res) => {
|
||||
// const companies = await Company.find();
|
||||
|
||||
// res.json(companies);
|
||||
// });
|
||||
|
||||
companiesRouter.get("/:id", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied!" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company = await Company.findById(req.params.id);
|
||||
|
||||
res.json(company);
|
||||
});
|
||||
|
||||
companiesRouter.get("/:id/builds", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied!" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate("builds");
|
||||
const { builds } = company;
|
||||
|
||||
res.json(builds);
|
||||
});
|
||||
|
||||
companiesRouter.get("/:id/users", async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied!" });
|
||||
return;
|
||||
}
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate("users");
|
||||
const { users } = company;
|
||||
|
||||
res.json(users);
|
||||
});
|
||||
|
||||
companiesRouter.get(
|
||||
"/:id/builds/:buildId/scheduled_sessions",
|
||||
async (req, res) => {
|
||||
if (req.params.id != res.locals.user.companyId) {
|
||||
res.json({ error: "Access denied!" });
|
||||
return;
|
||||
}
|
||||
|
||||
if (!req.query.date) {
|
||||
res.json({ error: "req.query.date" });
|
||||
return;
|
||||
}
|
||||
|
||||
const date = parseISO(req.query.date as string);
|
||||
|
||||
const company: any = await Company.findById(req.params.id).populate({
|
||||
path: "builds",
|
||||
match: {
|
||||
_id: req.params.buildId,
|
||||
},
|
||||
populate: {
|
||||
path: "scheduledSessions",
|
||||
match: {
|
||||
startAt: {
|
||||
$gte: startOfDay(date),
|
||||
$lte: endOfDay(date),
|
||||
},
|
||||
},
|
||||
},
|
||||
});
|
||||
|
||||
const { scheduledSessions } = company.builds[0];
|
||||
|
||||
res.json(scheduledSessions);
|
||||
}
|
||||
);
|
||||
|
||||
export default companiesRouter;
|
||||
@@ -0,0 +1,39 @@
|
||||
import { Router } from "express";
|
||||
import jwt, { Secret } from "jsonwebtoken";
|
||||
import bcrypt from "bcrypt";
|
||||
import User from "../models/User.js";
|
||||
import Token from "../models/Token.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
|
||||
if (!username || !password) {
|
||||
return res.json({
|
||||
error: "You must pass the 'username' and 'password' parameters",
|
||||
});
|
||||
}
|
||||
|
||||
const user = await User.findOne({ username });
|
||||
|
||||
if (!user) {
|
||||
return res.json({ error: "A user with this name was not found" });
|
||||
}
|
||||
|
||||
if (!bcrypt.compareSync(password, user.password)) {
|
||||
return res.json({ error: "Invalid username or password" });
|
||||
}
|
||||
|
||||
const accessToken = jwt.sign({ username }, process.env.JWT_SECRET as Secret, {
|
||||
expiresIn: "365d",
|
||||
});
|
||||
|
||||
await Token.create({ userId: user.id, accessToken });
|
||||
|
||||
res.json({ accessToken, user });
|
||||
});
|
||||
|
||||
const loginRouter = router;
|
||||
|
||||
export default loginRouter;
|
||||
@@ -0,0 +1,40 @@
|
||||
import { Router } from "express";
|
||||
import jwt, { Secret } from "jsonwebtoken";
|
||||
import bcrypt from "bcrypt";
|
||||
import User from "../models/User.js";
|
||||
import Token from "../models/Token.js";
|
||||
|
||||
const router = Router();
|
||||
|
||||
router.post("/", async (req, res) => {
|
||||
const { username, password } = req.body;
|
||||
|
||||
if (!username || !password) {
|
||||
return res.json({ error: 1 });
|
||||
}
|
||||
|
||||
if (await User.exists({ username })) {
|
||||
return res.json({ error: 2 });
|
||||
}
|
||||
|
||||
const passwordHash = bcrypt.hashSync(password, 12);
|
||||
|
||||
if (!passwordHash) {
|
||||
return res.json({ error: 3 });
|
||||
}
|
||||
|
||||
const accessToken = jwt.sign({ username }, process.env.JWT_SECRET as Secret, {
|
||||
expiresIn: "365d",
|
||||
});
|
||||
|
||||
const user = await User.create({ username, password: passwordHash });
|
||||
const userId = user.id;
|
||||
|
||||
await Token.create({ userId, accessToken });
|
||||
|
||||
res.json({ accessToken });
|
||||
});
|
||||
|
||||
const registerRouter = router;
|
||||
|
||||
export default registerRouter;
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Router } from "express";
|
||||
import ScheduledSession from "../models/ScheduledSession.js";
|
||||
|
||||
const scheduledSessionsRouter = Router();
|
||||
|
||||
scheduledSessionsRouter.get("/", async (_req, res) => {
|
||||
await ScheduledSession.find();
|
||||
|
||||
res.json({ ok: 1 });
|
||||
});
|
||||
|
||||
export default scheduledSessionsRouter;
|
||||
@@ -0,0 +1,20 @@
|
||||
import { Router } from "express";
|
||||
// import User from "../models/User.js";
|
||||
|
||||
const usersRouter = Router();
|
||||
|
||||
// usersRouter.get("/", async (_req, res) => {
|
||||
// const users = await User.find();
|
||||
// console.log(users);
|
||||
|
||||
// res.json(users);
|
||||
// });
|
||||
|
||||
// usersRouter.get("/:id", async (req, res) => {
|
||||
// const user = await User.findById(req.params.id);
|
||||
// console.log(user);
|
||||
|
||||
// res.json(user);
|
||||
// });
|
||||
|
||||
export default usersRouter;
|
||||
Vendored
+12
@@ -0,0 +1,12 @@
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface ProcessEnv {
|
||||
PORT?: string;
|
||||
NODE_ENV: "development" | "production";
|
||||
MONGO_URI: string;
|
||||
JWT_SECRET: string;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export {};
|
||||
@@ -0,0 +1,113 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
/* Visit https://aka.ms/tsconfig to read more about this file */
|
||||
|
||||
/* Projects */
|
||||
// "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */
|
||||
// "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */
|
||||
// "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */
|
||||
// "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */
|
||||
// "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */
|
||||
// "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */
|
||||
|
||||
/* Language and Environment */
|
||||
"target": "ES6" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */,
|
||||
// "lib": [] /* Specify a set of bundled library declaration files that describe the target runtime environment. */,
|
||||
// "jsx": "preserve", /* Specify what JSX code is generated. */
|
||||
// "experimentalDecorators": true, /* Enable experimental support for legacy experimental decorators. */
|
||||
// "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */
|
||||
// "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */
|
||||
// "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */
|
||||
// "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */
|
||||
// "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */
|
||||
// "noLib": true, /* Disable including any library files, including the default lib.d.ts. */
|
||||
// "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */
|
||||
// "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */
|
||||
|
||||
/* Modules */
|
||||
"module": "ESNext" /* Specify what module code is generated. */,
|
||||
// "rootDir": "./", /* Specify the root folder within your source files. */
|
||||
"moduleResolution": "Node" /* Specify how TypeScript looks up a file from a given module specifier. */,
|
||||
// "baseUrl": "." /* Specify the base directory to resolve non-relative module names. */,
|
||||
// "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */
|
||||
// "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */
|
||||
// "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */
|
||||
// "types": [], /* Specify type package names to be included without being referenced in a source file. */
|
||||
// "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */
|
||||
// "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */
|
||||
// "allowImportingTsExtensions": true /* Allow imports to include TypeScript file extensions. Requires '--moduleResolution bundler' and either '--noEmit' or '--emitDeclarationOnly' to be set. */,
|
||||
// "resolvePackageJsonExports": true, /* Use the package.json 'exports' field when resolving package imports. */
|
||||
// "resolvePackageJsonImports": true, /* Use the package.json 'imports' field when resolving imports. */
|
||||
// "customConditions": [], /* Conditions to set in addition to the resolver-specific defaults when resolving imports. */
|
||||
"resolveJsonModule": true /* Enable importing .json files. */,
|
||||
// "allowArbitraryExtensions": true, /* Enable importing files with any extension, provided a declaration file is present. */
|
||||
// "noResolve": true, /* Disallow 'import's, 'require's or '<reference>'s from expanding the number of files TypeScript should add to a project. */
|
||||
|
||||
/* JavaScript Support */
|
||||
// "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */
|
||||
// "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */
|
||||
// "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */
|
||||
|
||||
/* Emit */
|
||||
// "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */
|
||||
// "declarationMap": true, /* Create sourcemaps for d.ts files. */
|
||||
// "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */
|
||||
// "sourceMap": true, /* Create source map files for emitted JavaScript files. */
|
||||
// "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */
|
||||
// "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */
|
||||
"outDir": "dist" /* Specify an output folder for all emitted files. */,
|
||||
// "removeComments": true, /* Disable emitting comments. */
|
||||
// "noEmit": true /* Disable emitting files from a compilation. */,
|
||||
// "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */
|
||||
// "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */
|
||||
// "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */
|
||||
// "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */
|
||||
// "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */
|
||||
// "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */
|
||||
// "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */
|
||||
// "newLine": "crlf", /* Set the newline character for emitting files. */
|
||||
// "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */
|
||||
// "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */
|
||||
// "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */
|
||||
// "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */
|
||||
// "declarationDir": "./", /* Specify the output directory for generated declaration files. */
|
||||
// "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */
|
||||
|
||||
/* Interop Constraints */
|
||||
"isolatedModules": true /* Ensure that each file can be safely transpiled without relying on other imports. */,
|
||||
// "verbatimModuleSyntax": true, /* Do not transform or elide any imports or exports not marked as type-only, ensuring they are written in the output file's format based on the 'module' setting. */
|
||||
// "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */
|
||||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */,
|
||||
// "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */
|
||||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */,
|
||||
|
||||
/* Type Checking */
|
||||
"strict": true /* Enable all strict type-checking options. */,
|
||||
// "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */
|
||||
// "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */
|
||||
// "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */
|
||||
// "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */
|
||||
// "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */
|
||||
// "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */
|
||||
// "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */
|
||||
// "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */
|
||||
"noUnusedLocals": true /* Enable error reporting when local variables aren't read. */,
|
||||
"noUnusedParameters": true /* Raise an error when a function parameter isn't read. */,
|
||||
// "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */
|
||||
// "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */
|
||||
"noFallthroughCasesInSwitch": true /* Enable error reporting for fallthrough cases in switch statements. */,
|
||||
// "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */
|
||||
// "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */
|
||||
// "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */
|
||||
// "allowUnusedLabels": true, /* Disable error reporting for unused labels. */
|
||||
// "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */
|
||||
|
||||
/* Completeness */
|
||||
// "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */
|
||||
"skipLibCheck": true /* Skip type checking all .d.ts files. */
|
||||
},
|
||||
"include": ["./src/**/*"],
|
||||
"ts-node": {
|
||||
"esm": true
|
||||
}
|
||||
}
|
||||
+1425
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user