Compare commits
No commits in common. "feature/webpack-shit" and "develop" have entirely different histories.
feature/we
...
develop
@ -3,7 +3,6 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
||||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@latest/dist/tailwind.min.css" rel="stylesheet">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||||
<title>Vite + React + TS</title>
|
<title>Vite + React + TS</title>
|
||||||
</head>
|
</head>
|
||||||
@ -1,2 +0,0 @@
|
|||||||
import('./src/main')
|
|
||||||
export { }
|
|
||||||
@ -1,63 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "host",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"scripts": {
|
|
||||||
"start": "webpack serve --env mode=development",
|
|
||||||
"build:dev": "webpack --env mode=development",
|
|
||||||
"build:prod": "webpack --env mode=production",
|
|
||||||
"build:mobile": "webpack --env mode=production --env platform=mobile",
|
|
||||||
"build:desktop": "webpack --env mode=production --env platform=desktop",
|
|
||||||
"typecheck": "tsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@packages/build-config": "*",
|
|
||||||
"react": "^19.1.0",
|
|
||||||
"react-dom": "^19.1.0",
|
|
||||||
"react-router-dom": "^6.26.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@eslint/js": "^9.19.0",
|
|
||||||
"@hello-pangea/dnd": "^18.0.1",
|
|
||||||
"@radix-ui/react-form": "^0.1.2",
|
|
||||||
"@radix-ui/react-icons": "^1.3.2",
|
|
||||||
"@radix-ui/themes": "^3.2.0",
|
|
||||||
"@reduxjs/toolkit": "^2.6.1",
|
|
||||||
"@tailwindcss/postcss": "^4.1.3",
|
|
||||||
"@tailwindcss/vite": "^4.0.6",
|
|
||||||
"@tanstack/react-query": "^5.66.0",
|
|
||||||
"@tanstack/react-query-devtools": "^5.66.0",
|
|
||||||
"@types/js-cookie": "^3.0.6",
|
|
||||||
"@types/node": "^22.14.0",
|
|
||||||
"@types/react": "^19.0.8",
|
|
||||||
"@types/react-dom": "^19.0.3",
|
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
|
||||||
"autoprefixer": "^10.4.21",
|
|
||||||
"axios": "^1.7.9",
|
|
||||||
"css-loader": "^7.1.2",
|
|
||||||
"eslint": "^9.19.0",
|
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
|
||||||
"eslint-plugin-react-refresh": "^0.4.18",
|
|
||||||
"globals": "^15.14.0",
|
|
||||||
"jotai": "^2.12.0",
|
|
||||||
"js-cookie": "^3.0.5",
|
|
||||||
"mini-css-extract-plugin": "^2.9.2",
|
|
||||||
"postcss": "^8.5.3",
|
|
||||||
"postcss-loader": "^8.1.1",
|
|
||||||
"react-redux": "^9.2.0",
|
|
||||||
"style-loader": "^4.0.0",
|
|
||||||
"tailwindcss": "^4.1.3",
|
|
||||||
"typescript": "~5.7.2",
|
|
||||||
"typescript-eslint": "^8.22.0",
|
|
||||||
"vite": "^6.1.0",
|
|
||||||
"webpack": "^5.88.2",
|
|
||||||
"webpack-bundle-analyzer": "^4.9.1",
|
|
||||||
"webpack-cli": "^5.1.4",
|
|
||||||
"webpack-dev-server": "^4.15.1",
|
|
||||||
"mobx": "^6.13.7",
|
|
||||||
"mobx-react-lite": "^4.1.0",
|
|
||||||
"react": "^19.0.0",
|
|
||||||
"react-dom": "^19.0.0",
|
|
||||||
"react-router-dom": "^6.26.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: [
|
|
||||||
require('@tailwindcss/postcss'),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
import { Theme } from '@radix-ui/themes';
|
|
||||||
import '@radix-ui/themes/styles.css';
|
|
||||||
import './App.css';
|
|
||||||
//@ts-ignore
|
|
||||||
import MainApp from 'main/AppMain';
|
|
||||||
|
|
||||||
function App() {
|
|
||||||
return (
|
|
||||||
<Theme className="size-full" accentColor="amber" grayColor="gray">
|
|
||||||
I will fuck youuuuuuu!!!!!!
|
|
||||||
<div className="w-[40rem]">
|
|
||||||
<MainApp />
|
|
||||||
</div>
|
|
||||||
</Theme>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default App;
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { appStore } from "./stores/AppStore";
|
|
||||||
|
|
||||||
export const Ctx = React.createContext(appStore);
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
export const content = [
|
|
||||||
'./src/**/*.{html,js,tsx}',
|
|
||||||
];
|
|
||||||
export const theme = {
|
|
||||||
extend: {},
|
|
||||||
};
|
|
||||||
export const plugins = [];
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.base.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "./dist/",
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
import { BuildMode, BuildPaths, BuildPlatform, buildWebpack } from '@packages/build-config';
|
|
||||||
import fs from 'fs';
|
|
||||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
||||||
import path from 'path';
|
|
||||||
import webpack from 'webpack';
|
|
||||||
import packageJson from './package.json';
|
|
||||||
|
|
||||||
interface EnvVariables {
|
|
||||||
mode?: BuildMode;
|
|
||||||
analyzer?: boolean;
|
|
||||||
port?: number;
|
|
||||||
platform?: BuildPlatform;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (env: EnvVariables) => {
|
|
||||||
const paths: BuildPaths = {
|
|
||||||
output: path.resolve(__dirname, 'build'),
|
|
||||||
entry: path.resolve(__dirname, 'index.tsx'),
|
|
||||||
html: path.resolve(__dirname, 'index.html'),
|
|
||||||
public: path.resolve(__dirname, 'public'),
|
|
||||||
src: path.resolve(__dirname, 'src'),
|
|
||||||
}
|
|
||||||
|
|
||||||
const config: webpack.Configuration = buildWebpack({
|
|
||||||
port: env.port ?? 3000,
|
|
||||||
mode: env.mode ?? 'development',
|
|
||||||
paths,
|
|
||||||
analyzer: env.analyzer,
|
|
||||||
platform: env.platform ?? 'desktop'
|
|
||||||
})
|
|
||||||
|
|
||||||
const tailwindConfigPath = path.resolve(__dirname, 'tailwind.config.js');
|
|
||||||
if (!fs.existsSync(tailwindConfigPath)) {
|
|
||||||
console.error('tailwind.config.js does not exist. Please create it or check the path.');
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.log(` tailwind.config.js found at: ${tailwindConfigPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const postcssConfigPath = path.resolve(__dirname, 'postcss.config.js');
|
|
||||||
if (!fs.existsSync(postcssConfigPath)) {
|
|
||||||
console.error('postcss.config.js does not exist. Please create it or check the path.');
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.log(`postcss.config.js found at: ${postcssConfigPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!config.plugins) {
|
|
||||||
console.error('No plugins found in webpack configuration');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.module && config.module.rules) {
|
|
||||||
config.module.rules.push({
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
env.mode === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
||||||
'css-loader',
|
|
||||||
'postcss-loader'
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
config.plugins.push(
|
|
||||||
new MiniCssExtractPlugin({
|
|
||||||
filename: '[name].[contenthash].css',
|
|
||||||
}),
|
|
||||||
new webpack.container.ModuleFederationPlugin({
|
|
||||||
name: 'todo_thingy',
|
|
||||||
filename: 'remoteEntry.js',
|
|
||||||
remotes: {
|
|
||||||
main: 'todo_thingy@http://localhost:3001/remoteEntry.js',
|
|
||||||
},
|
|
||||||
shared: {
|
|
||||||
...packageJson.dependencies,
|
|
||||||
'react': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react'],
|
|
||||||
},
|
|
||||||
'react-router-dom': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react-router-dom'],
|
|
||||||
},
|
|
||||||
'react-dom': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react-dom'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
}))
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
<!doctype html>
|
|
||||||
<html lang="en">
|
|
||||||
<head>
|
|
||||||
<meta charset="UTF-8" />
|
|
||||||
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
|
|
||||||
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@latest/dist/tailwind.min.css" rel="stylesheet">
|
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
||||||
<title>Vite + React + TS</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
|
||||||
<div id="root"></div>
|
|
||||||
<script type="module" src="/src/main.tsx"></script>
|
|
||||||
</body>
|
|
||||||
</html>
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
import('./src/main')
|
|
||||||
export { }
|
|
||||||
@ -1,67 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "main",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "index.js",
|
|
||||||
"keywords": [],
|
|
||||||
"author": "",
|
|
||||||
"license": "ISC",
|
|
||||||
"description": "",
|
|
||||||
"scripts": {
|
|
||||||
"start": "webpack serve --env mode=development",
|
|
||||||
"build:dev": "webpack --env mode=development",
|
|
||||||
"build:prod": "webpack --env mode=production",
|
|
||||||
"build:mobile": "webpack --env mode=production --env platform=mobile",
|
|
||||||
"build:desktop": "webpack --env mode=production --env platform=desktop",
|
|
||||||
"typecheck": "tsc"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@packages/build-config": "*",
|
|
||||||
"react": "^19.1.0",
|
|
||||||
"react-dom": "^19.1.0",
|
|
||||||
"react-router-dom": "^6.26.2"
|
|
||||||
},
|
|
||||||
"devDependencies": {
|
|
||||||
"@eslint/js": "^9.19.0",
|
|
||||||
"@hello-pangea/dnd": "^18.0.1",
|
|
||||||
"@radix-ui/react-form": "^0.1.2",
|
|
||||||
"@radix-ui/react-icons": "^1.3.2",
|
|
||||||
"@radix-ui/themes": "^3.2.0",
|
|
||||||
"@reduxjs/toolkit": "^2.6.1",
|
|
||||||
"@tailwindcss/postcss": "^4.1.3",
|
|
||||||
"@tailwindcss/vite": "^4.0.6",
|
|
||||||
"@tanstack/react-query": "^5.66.0",
|
|
||||||
"@tanstack/react-query-devtools": "^5.66.0",
|
|
||||||
"@types/js-cookie": "^3.0.6",
|
|
||||||
"@types/node": "^22.14.0",
|
|
||||||
"@types/react": "^19.0.8",
|
|
||||||
"@types/react-dom": "^19.0.3",
|
|
||||||
"@vitejs/plugin-react": "^4.3.4",
|
|
||||||
"autoprefixer": "^10.4.21",
|
|
||||||
"axios": "^1.7.9",
|
|
||||||
"css-loader": "^7.1.2",
|
|
||||||
"eslint": "^9.19.0",
|
|
||||||
"eslint-plugin-react-hooks": "^5.0.0",
|
|
||||||
"eslint-plugin-react-refresh": "^0.4.18",
|
|
||||||
"globals": "^15.14.0",
|
|
||||||
"jotai": "^2.12.0",
|
|
||||||
"js-cookie": "^3.0.5",
|
|
||||||
"mini-css-extract-plugin": "^2.9.2",
|
|
||||||
"postcss": "^8.5.3",
|
|
||||||
"postcss-loader": "^8.1.1",
|
|
||||||
"react-redux": "^9.2.0",
|
|
||||||
"style-loader": "^4.0.0",
|
|
||||||
"tailwindcss": "^4.1.3",
|
|
||||||
"typescript": "~5.7.2",
|
|
||||||
"typescript-eslint": "^8.22.0",
|
|
||||||
"vite": "^6.1.0",
|
|
||||||
"webpack": "^5.88.2",
|
|
||||||
"webpack-bundle-analyzer": "^4.9.1",
|
|
||||||
"webpack-cli": "^5.1.4",
|
|
||||||
"webpack-dev-server": "^4.15.1",
|
|
||||||
"mobx": "^6.13.7",
|
|
||||||
"mobx-react-lite": "^4.1.0",
|
|
||||||
"react": "^19.0.0",
|
|
||||||
"react-dom": "^19.0.0",
|
|
||||||
"react-router-dom": "^6.26.2"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
module.exports = {
|
|
||||||
plugins: [
|
|
||||||
require('@tailwindcss/postcss'),
|
|
||||||
],
|
|
||||||
}
|
|
||||||
@ -1 +0,0 @@
|
|||||||
<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>
|
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB |
@ -1,54 +0,0 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
|
||||||
import { DragDropContext } from '@hello-pangea/dnd';
|
|
||||||
import { Button, Flex, ScrollArea } from '@radix-ui/themes';
|
|
||||||
|
|
||||||
import CardGroup from '../CardGroup/CardGroup';
|
|
||||||
import CreateProjectDialog from '../dialogs/CreateProjectDialog/CreateProjectDialog';
|
|
||||||
import { useStore } from '../../hooks/useStore';
|
|
||||||
|
|
||||||
function MainBoard() {
|
|
||||||
const store = useStore();
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
store.mainStore.fetchProjects().catch(console.error);
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const dragEndHandle = (result: TDragResult) => {
|
|
||||||
console.log(result);
|
|
||||||
};
|
|
||||||
|
|
||||||
const createProject = (newProjectData: any) => {
|
|
||||||
store.mainStore.createProject(newProjectData);
|
|
||||||
};
|
|
||||||
|
|
||||||
const cringe = store.mainStore.projects;
|
|
||||||
const isLoading = store.mainStore.isLoading;
|
|
||||||
|
|
||||||
return (
|
|
||||||
<>
|
|
||||||
<DragDropContext onDragEnd={dragEndHandle}>
|
|
||||||
<ScrollArea scrollbars="horizontal" className="pb-3">
|
|
||||||
<Flex gap={'2'} className="min-w-fit">
|
|
||||||
{isLoading && <div>Loading Projects...</div>}
|
|
||||||
|
|
||||||
{!isLoading &&
|
|
||||||
cringe.map((item: any) => (
|
|
||||||
<CardGroup
|
|
||||||
key={item.id}
|
|
||||||
id={item.id}
|
|
||||||
title={item.title}
|
|
||||||
/>
|
|
||||||
))}
|
|
||||||
</Flex>
|
|
||||||
</ScrollArea>
|
|
||||||
</DragDropContext>
|
|
||||||
|
|
||||||
<CreateProjectDialog onCreate={createProject}>
|
|
||||||
<Button>Create project</Button>
|
|
||||||
</CreateProjectDialog>
|
|
||||||
</>
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
export default observer(MainBoard);
|
|
||||||
@ -1,4 +0,0 @@
|
|||||||
import React from "react";
|
|
||||||
import { appStore } from "./stores/AppStore";
|
|
||||||
|
|
||||||
export const Ctx = React.createContext(appStore);
|
|
||||||
@ -1,8 +0,0 @@
|
|||||||
import { useContext } from "react";
|
|
||||||
import { Ctx } from "../context";
|
|
||||||
|
|
||||||
export function useStore() {
|
|
||||||
const store = useContext(Ctx)
|
|
||||||
|
|
||||||
return store;
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
@import 'tailwindcss';
|
|
||||||
|
|
||||||
#root {
|
|
||||||
height: 100vh;
|
|
||||||
}
|
|
||||||
@ -1,5 +0,0 @@
|
|||||||
import { createRoot } from 'react-dom/client';
|
|
||||||
import App from './App.tsx';
|
|
||||||
import './index.css';
|
|
||||||
|
|
||||||
createRoot(document.getElementById('root')!).render(<App />);
|
|
||||||
@ -1,15 +0,0 @@
|
|||||||
import { makeAutoObservable } from 'mobx';
|
|
||||||
import { MainStore } from './MainStore';
|
|
||||||
import { AuthStore } from './AuthStore';
|
|
||||||
|
|
||||||
export class AppStore {
|
|
||||||
mainStore: MainStore
|
|
||||||
authStore: AuthStore
|
|
||||||
|
|
||||||
constructor() {
|
|
||||||
this.mainStore = new MainStore(this)
|
|
||||||
this.authStore = new AuthStore(this)
|
|
||||||
makeAutoObservable(this);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export const appStore = new AppStore()
|
|
||||||
@ -1,95 +0,0 @@
|
|||||||
import { makeAutoObservable, runInAction } from 'mobx';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { AppStore } from './AppStore';
|
|
||||||
|
|
||||||
|
|
||||||
export class AuthStore {
|
|
||||||
appStore: AppStore
|
|
||||||
|
|
||||||
isLoading = false;
|
|
||||||
error: string | null = null;
|
|
||||||
|
|
||||||
allUsers: any[] = [];
|
|
||||||
|
|
||||||
constructor(appStore:any) {
|
|
||||||
this.appStore = appStore
|
|
||||||
makeAutoObservable(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
get token() {
|
|
||||||
return localStorage.getItem('token') || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
async login(credentials: { username: string; password: string }) {
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
'http://109.107.166.17:4000/api/auth/login',
|
|
||||||
credentials,
|
|
||||||
);
|
|
||||||
|
|
||||||
runInAction(() => {
|
|
||||||
if (response.data.access_token) {
|
|
||||||
localStorage.setItem('token', response.data.access_token);
|
|
||||||
window.location.href = '/';
|
|
||||||
}
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при логине';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async register(credentials: { username: string; password: string }) {
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
'http://109.107.166.17:4000/api/auth/register',
|
|
||||||
credentials,
|
|
||||||
);
|
|
||||||
|
|
||||||
runInAction(() => {
|
|
||||||
if (response.status === 201) {
|
|
||||||
window.location.href = '/login';
|
|
||||||
}
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при регистрации';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchAllUsers(force = false) {
|
|
||||||
if (this.allUsers.length && !force) {
|
|
||||||
return this.allUsers;
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.get('http://109.107.166.17:4000/api/users');
|
|
||||||
runInAction(() => {
|
|
||||||
this.allUsers = response.data;
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
return this.allUsers;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при получении пользователей';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,323 +0,0 @@
|
|||||||
import { makeAutoObservable, runInAction } from 'mobx';
|
|
||||||
import axios from 'axios';
|
|
||||||
import { AppStore } from './AppStore';
|
|
||||||
|
|
||||||
export class MainStore {
|
|
||||||
appStore: AppStore
|
|
||||||
|
|
||||||
isLoading = false;
|
|
||||||
error: string | null = null;
|
|
||||||
|
|
||||||
|
|
||||||
tasks: any[] = [];
|
|
||||||
tasksByProject = new Map<string, any[]>();
|
|
||||||
|
|
||||||
projects: any[] = [];
|
|
||||||
projectById = new Map<string, any>();
|
|
||||||
projectMembersById = new Map<string, any[]>();
|
|
||||||
|
|
||||||
constructor(appStore:any) {
|
|
||||||
this.appStore = appStore
|
|
||||||
makeAutoObservable(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
get token() {
|
|
||||||
return localStorage.getItem('token') || '';
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
get headers() {
|
|
||||||
return {
|
|
||||||
Authorization: `Bearer ${this.token}`,
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchTasksForGroup(projectId: string, force = false) {
|
|
||||||
if (this.tasksByProject.has(projectId) && !force) {
|
|
||||||
return this.tasksByProject.get(projectId);
|
|
||||||
}
|
|
||||||
console.log(`This is tasks for ${projectId}`);
|
|
||||||
|
|
||||||
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.get(
|
|
||||||
`http://109.107.166.17:5000/api/tasks/project/${projectId}`,
|
|
||||||
{
|
|
||||||
headers: this.headers,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
runInAction(() => {
|
|
||||||
this.tasksByProject.set(projectId, response.data);
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при загрузке задач группы';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchTask(taskId: string) {
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.get(
|
|
||||||
`http://109.107.166.17:5000/api/tasks/${taskId}`,
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при загрузке задачи';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
} finally {
|
|
||||||
runInAction(() => {
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createTask(newTask: any) {
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
'http://109.107.166.17:5000/api/tasks/create',
|
|
||||||
newTask,
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
const createdTask = response.data;
|
|
||||||
this.tasks.push(createdTask);
|
|
||||||
const oldTasks = this.tasksByProject.get(newTask.projectId) ?? [];
|
|
||||||
this.tasksByProject.set(newTask.projectId, [...oldTasks, createdTask]);
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при создании задачи';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateTask(task: { id: string; status: string }) {
|
|
||||||
try {
|
|
||||||
const response = await axios.patch(
|
|
||||||
`http://109.107.166.17:5000/api/tasks/${task.id}`,
|
|
||||||
{ status: task.status },
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
runInAction(() => {
|
|
||||||
const index = this.tasks.findIndex((t) => t.id === task.id);
|
|
||||||
if (index !== -1) {
|
|
||||||
this.tasks[index].status = task.status;
|
|
||||||
}
|
|
||||||
const projectId = response.data.project.id;
|
|
||||||
const oldArray = this.tasksByProject.get(projectId) || [];
|
|
||||||
const indexInMap = oldArray.findIndex((t) => t.id === +task.id);
|
|
||||||
if (indexInMap !== -1) {
|
|
||||||
oldArray[indexInMap].status = task.status;
|
|
||||||
this.tasksByProject.set(projectId, [...oldArray]);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при обновлении задачи';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async deleteTask(taskId: string) {
|
|
||||||
try {
|
|
||||||
await axios.delete(`http://109.107.166.17:5000/api/tasks/${taskId}`, {
|
|
||||||
headers: this.headers,
|
|
||||||
});
|
|
||||||
// Удаляем локально
|
|
||||||
runInAction(() => {
|
|
||||||
this.tasks = this.tasks.filter((t) => t.id !== taskId);
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при удалении задачи';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
async fetchProjects(force = false) {
|
|
||||||
if (this.projects.length && !force) {
|
|
||||||
return this.projects;
|
|
||||||
}
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
|
|
||||||
try {
|
|
||||||
const response = await axios.get(
|
|
||||||
'http://109.107.166.17:5000/api/projects/my',
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
runInAction(() => {
|
|
||||||
this.projects = response.data;
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
return this.projects;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при получении проектов';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async fetchProject(projectId: string) {
|
|
||||||
if (this.projectById.has(projectId)) {
|
|
||||||
return this.projectById.get(projectId);
|
|
||||||
}
|
|
||||||
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.get(
|
|
||||||
`http://109.107.166.17:5000/api/projects/${projectId}`,
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
runInAction(() => {
|
|
||||||
this.projectById.set(projectId, response.data);
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при получении проекта';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async createProject(newProject: any) {
|
|
||||||
try {
|
|
||||||
const response = await axios.post(
|
|
||||||
'http://109.107.166.17:5000/api/projects/create',
|
|
||||||
newProject,
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
const created = response.data;
|
|
||||||
runInAction(() => {
|
|
||||||
this.projects.push(created);
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при создании проекта';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async updateProject(id: string, projectData: any) {
|
|
||||||
try {
|
|
||||||
await axios.patch(
|
|
||||||
`http://109.107.166.17:5000/api/projects/${id}`,
|
|
||||||
projectData,
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
this.fetchProjects(true);
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при обновлении проекта';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async deleteProject(id: string) {
|
|
||||||
try {
|
|
||||||
await axios.delete(`http://109.107.166.17:5000/api/projects/${id}`, {
|
|
||||||
headers: this.headers,
|
|
||||||
});
|
|
||||||
// Удаляем локально
|
|
||||||
runInAction(() => {
|
|
||||||
this.projects = this.projects.filter((p) => p.id !== id);
|
|
||||||
});
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при удалении проекта';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async addProjectMember(projectId: string, memberId: string) {
|
|
||||||
try {
|
|
||||||
await axios.post(
|
|
||||||
`http://109.107.166.17:5000/api/projects/${projectId}/members/add`,
|
|
||||||
{
|
|
||||||
userId: memberId,
|
|
||||||
role: '',
|
|
||||||
},
|
|
||||||
{ headers: this.headers },
|
|
||||||
);
|
|
||||||
this.projectMembersById.delete(projectId);
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при добавлении участника';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
async fetchProjectMembers(projectId: string, force = false) {
|
|
||||||
if (this.projectMembersById.has(projectId) && !force) {
|
|
||||||
return this.projectMembersById.get(projectId);
|
|
||||||
}
|
|
||||||
this.isLoading = true;
|
|
||||||
this.error = null;
|
|
||||||
try {
|
|
||||||
const response = await axios.get(
|
|
||||||
`http://109.107.166.17:5000/api/projects/${projectId}/members`,
|
|
||||||
{
|
|
||||||
headers: this.headers,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
runInAction(() => {
|
|
||||||
this.projectMembersById.set(projectId, response.data);
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
return response.data;
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при получении участников проекта';
|
|
||||||
this.isLoading = false;
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
async removeProjectMember(projectId: string, memberId: string) {
|
|
||||||
try {
|
|
||||||
await axios.delete(
|
|
||||||
`http://109.107.166.17:5000/api/projects/${projectId}/members/remove`,
|
|
||||||
{
|
|
||||||
data: { userId: memberId },
|
|
||||||
headers: this.headers,
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
this.projectMembersById.delete(projectId);
|
|
||||||
} catch (error: any) {
|
|
||||||
runInAction(() => {
|
|
||||||
this.error = error?.response?.data?.message || 'Ошибка при удалении участника';
|
|
||||||
});
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
@ -1 +0,0 @@
|
|||||||
/// <reference types="vite/client" />
|
|
||||||
@ -1,7 +0,0 @@
|
|||||||
export const content = [
|
|
||||||
'./src/**/*.{html,js,tsx}',
|
|
||||||
];
|
|
||||||
export const theme = {
|
|
||||||
extend: {},
|
|
||||||
};
|
|
||||||
export const plugins = [];
|
|
||||||
@ -1,10 +0,0 @@
|
|||||||
{
|
|
||||||
"extends": "../tsconfig.base.json",
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "./dist/",
|
|
||||||
"baseUrl": ".",
|
|
||||||
"paths": {
|
|
||||||
"@/*": ["./src/*"]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,94 +0,0 @@
|
|||||||
import { BuildMode, BuildPaths, BuildPlatform, buildWebpack } from '@packages/build-config';
|
|
||||||
import fs from 'fs';
|
|
||||||
import MiniCssExtractPlugin from 'mini-css-extract-plugin';
|
|
||||||
import path from 'path';
|
|
||||||
import webpack from 'webpack';
|
|
||||||
import packageJson from './package.json';
|
|
||||||
|
|
||||||
interface EnvVariables {
|
|
||||||
mode?: BuildMode;
|
|
||||||
analyzer?: boolean;
|
|
||||||
port?: number;
|
|
||||||
platform?: BuildPlatform;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default (env: EnvVariables) => {
|
|
||||||
const paths: BuildPaths = {
|
|
||||||
output: path.resolve(__dirname, 'build'),
|
|
||||||
entry: path.resolve(__dirname, 'index.tsx'),
|
|
||||||
html: path.resolve(__dirname, 'index.html'),
|
|
||||||
public: path.resolve(__dirname, 'public'),
|
|
||||||
src: path.resolve(__dirname, 'src'),
|
|
||||||
}
|
|
||||||
|
|
||||||
const config: webpack.Configuration = buildWebpack({
|
|
||||||
port: env.port ?? 3001,
|
|
||||||
mode: env.mode ?? 'development',
|
|
||||||
paths,
|
|
||||||
analyzer: env.analyzer,
|
|
||||||
platform: env.platform ?? 'desktop'
|
|
||||||
})
|
|
||||||
|
|
||||||
const tailwindConfigPath = path.resolve(__dirname, 'tailwind.config.js');
|
|
||||||
if (!fs.existsSync(tailwindConfigPath)) {
|
|
||||||
console.error('tailwind.config.js does not exist. Please create it or check the path.');
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.log(` tailwind.config.js found at: ${tailwindConfigPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
const postcssConfigPath = path.resolve(__dirname, 'postcss.config.js');
|
|
||||||
if (!fs.existsSync(postcssConfigPath)) {
|
|
||||||
console.error('postcss.config.js does not exist. Please create it or check the path.');
|
|
||||||
process.exit(1);
|
|
||||||
} else {
|
|
||||||
console.log(`postcss.config.js found at: ${postcssConfigPath}`);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(!config.plugins) {
|
|
||||||
console.error('No plugins found in webpack configuration');
|
|
||||||
process.exit(1);
|
|
||||||
}
|
|
||||||
|
|
||||||
if(config.module && config.module.rules) {
|
|
||||||
config.module.rules.push({
|
|
||||||
test: /\.css$/,
|
|
||||||
use: [
|
|
||||||
env.mode === 'development' ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
||||||
'css-loader',
|
|
||||||
'postcss-loader'
|
|
||||||
]
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
config.plugins.push(
|
|
||||||
new MiniCssExtractPlugin({
|
|
||||||
filename: '[name].[contenthash].css',
|
|
||||||
}),
|
|
||||||
new webpack.container.ModuleFederationPlugin({
|
|
||||||
name: 'todo_thingy',
|
|
||||||
filename: 'remoteEntry.js',
|
|
||||||
exposes: {
|
|
||||||
'./AppMain': './src/App.tsx',
|
|
||||||
},
|
|
||||||
shared: {
|
|
||||||
...packageJson.dependencies,
|
|
||||||
'react': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react'],
|
|
||||||
},
|
|
||||||
'react-router-dom': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react-router-dom'],
|
|
||||||
},
|
|
||||||
'react-dom': {
|
|
||||||
eager: true,
|
|
||||||
requiredVersion: packageJson.dependencies['react-dom'],
|
|
||||||
},
|
|
||||||
},
|
|
||||||
|
|
||||||
}))
|
|
||||||
|
|
||||||
return config;
|
|
||||||
}
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"module": "ESNext",
|
|
||||||
"target": "es5",
|
|
||||||
"jsx": "react-jsx",
|
|
||||||
"allowJs": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"resolveJsonModule": true
|
|
||||||
},
|
|
||||||
"ts-node": {
|
|
||||||
"compilerOptions": {
|
|
||||||
"module": "CommonJS"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
9048
cool_todo_manager/package-lock.json
generated
9048
cool_todo_manager/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -2,8 +2,43 @@
|
|||||||
"name": "cool_todo_manager",
|
"name": "cool_todo_manager",
|
||||||
"private": true,
|
"private": true,
|
||||||
"version": "0.0.0",
|
"version": "0.0.0",
|
||||||
"workspaces": [
|
"type": "module",
|
||||||
"mainApp/*",
|
"scripts": {
|
||||||
"packages/*"
|
"dev": "vite",
|
||||||
]
|
"build": "tsc -b && vite build",
|
||||||
|
"lint": "eslint .",
|
||||||
|
"preview": "vite preview"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@hello-pangea/dnd": "^18.0.1",
|
||||||
|
"@radix-ui/react-form": "^0.1.2",
|
||||||
|
"@radix-ui/react-icons": "^1.3.2",
|
||||||
|
"@radix-ui/themes": "^3.2.0",
|
||||||
|
"@reduxjs/toolkit": "^2.6.0",
|
||||||
|
"@tailwindcss/vite": "^4.0.6",
|
||||||
|
"@tanstack/react-query": "^5.66.0",
|
||||||
|
"@tanstack/react-query-devtools": "^5.66.0",
|
||||||
|
"axios": "^1.7.9",
|
||||||
|
"jotai": "^2.12.0",
|
||||||
|
"js-cookie": "^3.0.5",
|
||||||
|
"react": "^19.0.0",
|
||||||
|
"react-dom": "^19.0.0",
|
||||||
|
"react-redux": "^9.2.0",
|
||||||
|
"react-router-dom": "^6.26.2",
|
||||||
|
"tailwindcss": "^4.0.6"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@eslint/js": "^9.19.0",
|
||||||
|
"@types/js-cookie": "^3.0.6",
|
||||||
|
"@types/react": "^19.0.8",
|
||||||
|
"@types/react-dom": "^19.0.3",
|
||||||
|
"@vitejs/plugin-react": "^4.3.4",
|
||||||
|
"eslint": "^9.19.0",
|
||||||
|
"eslint-plugin-react-hooks": "^5.0.0",
|
||||||
|
"eslint-plugin-react-refresh": "^0.4.18",
|
||||||
|
"globals": "^15.14.0",
|
||||||
|
"typescript": "~5.7.2",
|
||||||
|
"typescript-eslint": "^8.22.0",
|
||||||
|
"vite": "^6.1.0"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,38 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "@packages/build-config",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"main": "./src/index.ts",
|
|
||||||
"devDependencies": {
|
|
||||||
"@babel/core": "^7.23.2",
|
|
||||||
"@babel/preset-react": "^7.22.15",
|
|
||||||
"@babel/preset-typescript": "^7.23.2",
|
|
||||||
"@pmmmwh/react-refresh-webpack-plugin": "^0.5.11",
|
|
||||||
"@svgr/webpack": "^8.1.0",
|
|
||||||
"@types/babel__core": "^7.20.3",
|
|
||||||
"@types/node": "^20.8.3",
|
|
||||||
"@types/webpack": "^5.28.3",
|
|
||||||
"@types/webpack-bundle-analyzer": "^4.6.1",
|
|
||||||
"@types/webpack-dev-server": "^4.7.2",
|
|
||||||
"babel-loader": "^9.1.3",
|
|
||||||
"copy-webpack-plugin": "^11.0.0",
|
|
||||||
"css-loader": "^6.8.1",
|
|
||||||
"fork-ts-checker-webpack-plugin": "^9.0.0",
|
|
||||||
"html-webpack-plugin": "^5.5.3",
|
|
||||||
"mini-css-extract-plugin": "^2.7.6",
|
|
||||||
"react-refresh": "^0.14.0",
|
|
||||||
"react-refresh-typescript": "^2.0.9",
|
|
||||||
"sass": "^1.69.0",
|
|
||||||
"sass-loader": "^13.3.2",
|
|
||||||
"style-loader": "^3.3.3",
|
|
||||||
"ts-loader": "^9.5.0",
|
|
||||||
"ts-node": "^10.9.1",
|
|
||||||
"typescript": "^5.2.2",
|
|
||||||
"webpack": "^5.88.2",
|
|
||||||
"webpack-bundle-analyzer": "^4.9.1",
|
|
||||||
"webpack-cli": "^5.1.4",
|
|
||||||
"webpack-dev-server": "^4.15.1"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"react": "^19.1.0"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
import type { Configuration as DevServerConfiguration } from "webpack-dev-server";
|
|
||||||
import { BuildOptions } from "./types/types";
|
|
||||||
|
|
||||||
export function buildDevServer(options: BuildOptions): DevServerConfiguration {
|
|
||||||
return {
|
|
||||||
port: options.port ?? 3000,
|
|
||||||
open: true,
|
|
||||||
// если раздавать статику через nginx То надо делать проксирование на Index.html
|
|
||||||
historyApiFallback: true,
|
|
||||||
hot: true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,87 +0,0 @@
|
|||||||
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
||||||
import ReactRefreshTypeScript from "react-refresh-typescript";
|
|
||||||
import { ModuleOptions } from "webpack";
|
|
||||||
import { BuildOptions } from "./types/types";
|
|
||||||
|
|
||||||
export function buildLoaders(options: BuildOptions): ModuleOptions['rules'] {
|
|
||||||
const isDev = options.mode === 'development';
|
|
||||||
|
|
||||||
const assetLoader = {
|
|
||||||
test: /\.(png|jpg|jpeg|gif)$/i,
|
|
||||||
type: 'asset/resource',
|
|
||||||
}
|
|
||||||
|
|
||||||
const svgrLoader = {
|
|
||||||
test: /\.svg$/i,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: '@svgr/webpack',
|
|
||||||
options: {
|
|
||||||
icon: true,
|
|
||||||
svgoConfig: {
|
|
||||||
plugins: [
|
|
||||||
{
|
|
||||||
name: 'convertColors',
|
|
||||||
params: {
|
|
||||||
currentColor: true,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
const cssLoaderWithModules = {
|
|
||||||
loader: "css-loader",
|
|
||||||
options: {
|
|
||||||
modules: {
|
|
||||||
localIdentName: isDev ? '[path][name]__[local]' : '[hash:base64:8]'
|
|
||||||
},
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
const scssLoader = {
|
|
||||||
test: /\.s[ac]ss$/i,
|
|
||||||
use: [
|
|
||||||
// Creates `style` nodes from JS strings
|
|
||||||
isDev ? 'style-loader' : MiniCssExtractPlugin.loader,
|
|
||||||
// Translates CSS into CommonJS
|
|
||||||
cssLoaderWithModules,
|
|
||||||
// Compiles Sass to CSS
|
|
||||||
"sass-loader",
|
|
||||||
],
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
const tsLoader = {
|
|
||||||
// ts-loader умеет работать с JSX
|
|
||||||
// Если б мы не использовали тайпскрипт: нужен был бы babel-loader
|
|
||||||
exclude: /node_modules/,
|
|
||||||
test: /\.tsx?$/,
|
|
||||||
use: [
|
|
||||||
{
|
|
||||||
loader: 'ts-loader',
|
|
||||||
options: {
|
|
||||||
transpileOnly: true,
|
|
||||||
getCustomTransformers: () => ({
|
|
||||||
before: [isDev && ReactRefreshTypeScript()].filter(Boolean),
|
|
||||||
}),
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
|
|
||||||
// const babelLoader = buildBabelLoader(options);
|
|
||||||
|
|
||||||
|
|
||||||
return [
|
|
||||||
assetLoader,
|
|
||||||
scssLoader,
|
|
||||||
tsLoader,
|
|
||||||
// babelLoader,
|
|
||||||
svgrLoader
|
|
||||||
]
|
|
||||||
}
|
|
||||||
@ -1,52 +0,0 @@
|
|||||||
import HtmlWebpackPlugin from "html-webpack-plugin";
|
|
||||||
import MiniCssExtractPlugin from "mini-css-extract-plugin";
|
|
||||||
import webpack, { Configuration, DefinePlugin } from "webpack";
|
|
||||||
import { BundleAnalyzerPlugin } from "webpack-bundle-analyzer";
|
|
||||||
import { BuildOptions } from "./types/types";
|
|
||||||
// import ForkTsCheckerWebpackPlugin from "fork-ts-checker-webpack-plugin";
|
|
||||||
import ReactRefreshWebpackPlugin from "@pmmmwh/react-refresh-webpack-plugin";
|
|
||||||
import CopyPlugin from "copy-webpack-plugin";
|
|
||||||
import path from "path";
|
|
||||||
|
|
||||||
export function buildPlugins({mode, paths, analyzer, platform}: BuildOptions): Configuration['plugins'] {
|
|
||||||
const isDev = mode === 'development';
|
|
||||||
const isProd = mode === 'production';
|
|
||||||
|
|
||||||
const plugins: Configuration['plugins'] = [
|
|
||||||
new HtmlWebpackPlugin({
|
|
||||||
template: paths.html,
|
|
||||||
favicon: path.resolve(paths.public, 'favicon.ico'),
|
|
||||||
publicPath: '/'
|
|
||||||
}),
|
|
||||||
new DefinePlugin({
|
|
||||||
__PLATFORM__: JSON.stringify(platform),
|
|
||||||
__ENV__: JSON.stringify(mode),
|
|
||||||
}),
|
|
||||||
|
|
||||||
]
|
|
||||||
|
|
||||||
if(isDev) {
|
|
||||||
plugins.push(new webpack.ProgressPlugin())
|
|
||||||
/** Выносит проверку типов в отдельный процесс: не нагружая сборку */
|
|
||||||
// plugins.push(new ForkTsCheckerWebpackPlugin())
|
|
||||||
plugins.push(new ReactRefreshWebpackPlugin())
|
|
||||||
}
|
|
||||||
|
|
||||||
if(isProd) {
|
|
||||||
plugins.push(new MiniCssExtractPlugin({
|
|
||||||
filename: 'css/[name].[contenthash:8].css',
|
|
||||||
chunkFilename: 'css/[name].[contenthash:8].css',
|
|
||||||
}))
|
|
||||||
plugins.push(new CopyPlugin({
|
|
||||||
patterns: [
|
|
||||||
{ from: path.resolve(paths.public, 'locales'), to: path.resolve(paths.output, 'locales') },
|
|
||||||
],
|
|
||||||
}),)
|
|
||||||
}
|
|
||||||
|
|
||||||
if(analyzer) {
|
|
||||||
plugins.push(new BundleAnalyzerPlugin())
|
|
||||||
}
|
|
||||||
|
|
||||||
return plugins;
|
|
||||||
}
|
|
||||||
@ -1,11 +0,0 @@
|
|||||||
import { Configuration } from "webpack";
|
|
||||||
import { BuildOptions } from "./types/types";
|
|
||||||
|
|
||||||
export function buildResolvers(options: BuildOptions): Configuration['resolve'] {
|
|
||||||
return {
|
|
||||||
extensions: ['.tsx', '.ts', '.js'],
|
|
||||||
alias: {
|
|
||||||
'@': options.paths.src,
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
import webpack from "webpack";
|
|
||||||
import { buildDevServer } from "./buildDevServer";
|
|
||||||
import { buildLoaders } from "./buildLoaders";
|
|
||||||
import { buildPlugins } from "./buildPlugins";
|
|
||||||
import { buildResolvers } from "./buildResolvers";
|
|
||||||
import { BuildOptions } from "./types/types";
|
|
||||||
|
|
||||||
export function buildWebpack(options: BuildOptions): webpack.Configuration {
|
|
||||||
const {mode, paths} = options
|
|
||||||
const isDev = mode === 'development';
|
|
||||||
|
|
||||||
return {
|
|
||||||
mode: mode ?? 'development',
|
|
||||||
entry: paths.entry,
|
|
||||||
output: {
|
|
||||||
path: paths.output,
|
|
||||||
filename: '[name].[contenthash].js',
|
|
||||||
clean: true
|
|
||||||
},
|
|
||||||
plugins: buildPlugins(options),
|
|
||||||
module: {
|
|
||||||
rules: buildLoaders(options),
|
|
||||||
},
|
|
||||||
resolve: buildResolvers(options),
|
|
||||||
devtool: isDev ? 'eval-cheap-module-source-map' : 'source-map',
|
|
||||||
devServer: isDev ? buildDevServer(options) : undefined,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,2 +0,0 @@
|
|||||||
export { buildWebpack } from './buildWebpack'
|
|
||||||
export type { BuildMode, BuildOptions, BuildPaths, BuildPlatform } from './types/types'
|
|
||||||
@ -1,18 +0,0 @@
|
|||||||
export interface BuildPaths {
|
|
||||||
entry: string;
|
|
||||||
html: string;
|
|
||||||
public: string;
|
|
||||||
output: string;
|
|
||||||
src: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export type BuildMode = 'production' | 'development';
|
|
||||||
export type BuildPlatform = 'mobile' | 'desktop';
|
|
||||||
|
|
||||||
export interface BuildOptions {
|
|
||||||
port: number;
|
|
||||||
paths: BuildPaths;
|
|
||||||
mode: BuildMode;
|
|
||||||
platform: BuildPlatform;
|
|
||||||
analyzer?: boolean;
|
|
||||||
}
|
|
||||||
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"outDir": "./dist/",
|
|
||||||
"noImplicitAny": true,
|
|
||||||
"module": "ESNext",
|
|
||||||
"target": "es5",
|
|
||||||
"jsx": "react-jsx",
|
|
||||||
"allowJs": true,
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"allowSyntheticDefaultImports": true,
|
|
||||||
"composite": true
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 1.5 KiB |
@ -1,19 +1,24 @@
|
|||||||
import { Theme } from '@radix-ui/themes';
|
import { Theme } from '@radix-ui/themes';
|
||||||
import '@radix-ui/themes/styles.css';
|
import '@radix-ui/themes/styles.css';
|
||||||
|
import { QueryClientProvider } from '@tanstack/react-query';
|
||||||
|
import { Provider } from 'react-redux';
|
||||||
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
import { createBrowserRouter, RouterProvider } from 'react-router-dom';
|
||||||
|
import queryClient from './api/queryClient';
|
||||||
|
import { store } from './api/RTKQuery';
|
||||||
import './App.css';
|
import './App.css';
|
||||||
import MyRoutes from './routes/routes';
|
import MyRoutes from './routes/routes';
|
||||||
import { appStore } from './stores/AppStore';
|
|
||||||
import { Ctx } from './context';
|
|
||||||
|
|
||||||
const router = createBrowserRouter(MyRoutes);
|
const router = createBrowserRouter(MyRoutes);
|
||||||
|
|
||||||
function App() {
|
function App() {
|
||||||
return (
|
return (
|
||||||
<Theme className="size-full" accentColor="amber" grayColor="gray">
|
<Theme className="size-full" accentColor="amber" grayColor="gray">
|
||||||
<Ctx.Provider value={appStore}>
|
<QueryClientProvider client={queryClient}>
|
||||||
<RouterProvider router={router} />
|
<Provider store={store}>
|
||||||
</Ctx.Provider>
|
{/* <ThemePanel /> */}
|
||||||
|
<RouterProvider router={router} />
|
||||||
|
</Provider>
|
||||||
|
</QueryClientProvider>
|
||||||
</Theme>
|
</Theme>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
33
cool_todo_manager/src/api/RTKQuery.ts
Normal file
33
cool_todo_manager/src/api/RTKQuery.ts
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
import { configureStore, isRejectedWithValue, Middleware } from '@reduxjs/toolkit';
|
||||||
|
import { setupListeners } from '@reduxjs/toolkit/query';
|
||||||
|
import { authApi, mainApi } from '../services/mainApi';
|
||||||
|
|
||||||
|
const loggerMiddleware: Middleware = (_store) => (next) => (action) => {
|
||||||
|
console.log('dispatching', action);
|
||||||
|
if(isRejectedWithValue(action)) {
|
||||||
|
// @ts-ignore
|
||||||
|
const statusCode = action.payload.status;
|
||||||
|
if(statusCode === 401) {
|
||||||
|
console.log('Unauthorized, redirecting to login page');
|
||||||
|
localStorage.removeItem('token');
|
||||||
|
window.location.href = '/login';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
let result = next(action);
|
||||||
|
return result;
|
||||||
|
};
|
||||||
|
|
||||||
|
export const store = configureStore({
|
||||||
|
reducer: {
|
||||||
|
[mainApi.reducerPath]: mainApi.reducer,
|
||||||
|
[authApi.reducerPath]: authApi.reducer,
|
||||||
|
},
|
||||||
|
middleware: (getDefaultMiddleware) =>
|
||||||
|
getDefaultMiddleware()
|
||||||
|
.prepend(loggerMiddleware)
|
||||||
|
.concat(mainApi.middleware)
|
||||||
|
.concat(authApi.middleware),
|
||||||
|
});
|
||||||
|
|
||||||
|
setupListeners(store.dispatch);
|
||||||
|
|
||||||
@ -9,6 +9,6 @@ export const axiosBase = axios.create({
|
|||||||
export const axiosAuth = axios.create({
|
export const axiosAuth = axios.create({
|
||||||
baseURL: BASE_URL,
|
baseURL: BASE_URL,
|
||||||
headers: {
|
headers: {
|
||||||
Authorization: `Bearer ${localStorage.getItem('token')}`
|
Authorization: `Bearer ${localStorage.getItem('token')}` // Maybe we will use cookies
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
11
cool_todo_manager/src/api/queryClient.ts
Normal file
11
cool_todo_manager/src/api/queryClient.ts
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
import { QueryClient } from "@tanstack/react-query";
|
||||||
|
|
||||||
|
const queryClient = new QueryClient({
|
||||||
|
defaultOptions: {
|
||||||
|
queries: {
|
||||||
|
retry: 2,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
export default queryClient;
|
||||||
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.0 KiB |
@ -1,8 +1,7 @@
|
|||||||
import { observer } from 'mobx-react-lite';
|
|
||||||
import { PropsWithChildren } from 'react';
|
import { PropsWithChildren } from 'react';
|
||||||
import { Navigate } from 'react-router-dom';
|
import { Navigate } from 'react-router-dom';
|
||||||
|
|
||||||
const AuthWrapper = observer((props: PropsWithChildren) => {
|
export default function AuthWrapper(props: PropsWithChildren) {
|
||||||
|
|
||||||
if (!localStorage.getItem('token')) {
|
if (!localStorage.getItem('token')) {
|
||||||
console.log('No token found, redirecting to login');
|
console.log('No token found, redirecting to login');
|
||||||
@ -10,6 +9,4 @@ const AuthWrapper = observer((props: PropsWithChildren) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return <div>{props.children}</div>;
|
return <div>{props.children}</div>;
|
||||||
})
|
}
|
||||||
|
|
||||||
export default AuthWrapper;
|
|
||||||
@ -1,34 +1,30 @@
|
|||||||
import { useEffect } from 'react';
|
|
||||||
import { Droppable } from '@hello-pangea/dnd';
|
import { Droppable } from '@hello-pangea/dnd';
|
||||||
import { Box, Button, Flex, Text } from '@radix-ui/themes';
|
import { Box, Button, Flex, Text } from '@radix-ui/themes';
|
||||||
import { PlusIcon } from '@radix-ui/react-icons';
|
import {
|
||||||
import { observer } from 'mobx-react-lite';
|
useCreateTaskMutation,
|
||||||
|
useDeleteProjectMutation,
|
||||||
|
useGetTasksForGroupQuery,
|
||||||
|
} from '../../services/mainApi';
|
||||||
import TaskCard from '../TaskCard/TaskCard';
|
import TaskCard from '../TaskCard/TaskCard';
|
||||||
import AddUserToProjectDialog from '../dialogs/AddUserToProjectDialog/AddUserToProjectDialog';
|
import AddUserToProjectDialog from '../dialogs/AddUserToProjectDialog/AddUserToProjectDialog';
|
||||||
import CreateTaskDialog from '../dialogs/CreateTaskDialog/CreateTaskDialog';
|
import CreateTaskDialog from '../dialogs/CreateTaskDialog/CreateTaskDialog';
|
||||||
import DeleteProjectDialog from '../dialogs/DeleteProjectDialog/CreateTaskDialog';
|
import DeleteProjectDialog from '../dialogs/DeleteProjectDialog/CreateTaskDialog';
|
||||||
|
|
||||||
import { useStore } from '../../hooks/useStore';
|
import { PlusIcon } from '@radix-ui/react-icons';
|
||||||
|
|
||||||
type TCardGroup = {
|
type TCardGroup = {
|
||||||
id: string;
|
id: string;
|
||||||
title: string;
|
title: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export default function CardGroup(props: TCardGroup) {
|
||||||
|
const { data, isLoading } = useGetTasksForGroupQuery(props.id);
|
||||||
|
|
||||||
|
const [createTaskForGroup] = useCreateTaskMutation();
|
||||||
|
const [deleteProject] = useDeleteProjectMutation();
|
||||||
|
|
||||||
function CardGroup(props: TCardGroup) {
|
|
||||||
const store = useStore();
|
|
||||||
useEffect(() => {
|
|
||||||
store.mainStore.fetchTasksForGroup(props.id).catch(console.error);
|
|
||||||
}, [props.id, store.mainStore]);
|
|
||||||
|
|
||||||
|
|
||||||
const tasks = store.mainStore.tasksByProject.get(props.id) ?? [];
|
|
||||||
const isLoading = store.mainStore.isLoading;
|
|
||||||
|
|
||||||
const createTask = (taskText: string, date: string) => {
|
const createTask = (taskText: string, date: string) => {
|
||||||
store.mainStore.createTask({
|
createTaskForGroup({
|
||||||
title: taskText,
|
title: taskText,
|
||||||
projectId: props.id,
|
projectId: props.id,
|
||||||
assignedUserId: 1,
|
assignedUserId: 1,
|
||||||
@ -37,7 +33,7 @@ function CardGroup(props: TCardGroup) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const deleteGroup = () => {
|
const deleteGroup = () => {
|
||||||
store.mainStore.deleteProject(props.id);
|
deleteProject(props.id);
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -45,32 +41,26 @@ function CardGroup(props: TCardGroup) {
|
|||||||
{(provided) => (
|
{(provided) => (
|
||||||
<Box className="flex flex-col text-center rounded-lg p-4 bg-gray-200 min-w-fit">
|
<Box className="flex flex-col text-center rounded-lg p-4 bg-gray-200 min-w-fit">
|
||||||
<Text className="mb-2">{props.title}</Text>
|
<Text className="mb-2">{props.title}</Text>
|
||||||
|
|
||||||
<Box
|
<Box
|
||||||
ref={provided.innerRef}
|
ref={provided.innerRef}
|
||||||
className="bg-gray-200 min-w-full rounded-lg !flex flex-col gap-2"
|
className="bg-gray-200 min-w-full rounded-lg !flex flex-col gap-2"
|
||||||
>
|
>
|
||||||
{isLoading && <Text>Loading...</Text>}
|
{data &&
|
||||||
|
data.map((task, i) => (
|
||||||
{!isLoading && tasks.map((task: any, i: number) => (
|
<TaskCard
|
||||||
<TaskCard
|
key={task.id}
|
||||||
projectId={props.id}
|
id={task.id.toString()}
|
||||||
key={task.id}
|
title={task.title}
|
||||||
id={task.id.toString()}
|
description={task.status}
|
||||||
title={task.title}
|
index={i}
|
||||||
description={task.status}
|
status={task.status}
|
||||||
index={i}
|
/>
|
||||||
status={task.status}
|
))}
|
||||||
/>
|
|
||||||
))}
|
|
||||||
{provided.placeholder}
|
|
||||||
</Box>
|
</Box>
|
||||||
|
|
||||||
<Flex gap={'2'} className="mx-auto w-full mt-2">
|
<Flex gap={'2'} className="mx-auto w-full mt-2">
|
||||||
<CreateTaskDialog onClose={createTask}>
|
<CreateTaskDialog onClose={createTask}>
|
||||||
<Button className='!grow-1'>Add Task</Button>
|
<Button className='!grow-1'>Add Task</Button>
|
||||||
</CreateTaskDialog>
|
</CreateTaskDialog>
|
||||||
|
|
||||||
<DeleteProjectDialog onClose={deleteGroup}>
|
<DeleteProjectDialog onClose={deleteGroup}>
|
||||||
<Button className='!grow-1' color="red">Delete Project</Button>
|
<Button className='!grow-1' color="red">Delete Project</Button>
|
||||||
</DeleteProjectDialog>
|
</DeleteProjectDialog>
|
||||||
@ -79,7 +69,7 @@ function CardGroup(props: TCardGroup) {
|
|||||||
<AddUserToProjectDialog projectId={+props.id}>
|
<AddUserToProjectDialog projectId={+props.id}>
|
||||||
<Button className='!mt-2'>
|
<Button className='!mt-2'>
|
||||||
<PlusIcon />
|
<PlusIcon />
|
||||||
Add user
|
Add user
|
||||||
</Button>
|
</Button>
|
||||||
</AddUserToProjectDialog>
|
</AddUserToProjectDialog>
|
||||||
</Box>
|
</Box>
|
||||||
@ -87,5 +77,3 @@ function CardGroup(props: TCardGroup) {
|
|||||||
</Droppable>
|
</Droppable>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(CardGroup);
|
|
||||||
36
cool_todo_manager/src/components/MainBoard/MainBoard.tsx
Normal file
36
cool_todo_manager/src/components/MainBoard/MainBoard.tsx
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
import { DragDropContext } from '@hello-pangea/dnd';
|
||||||
|
import { Button, Flex, ScrollArea } from '@radix-ui/themes';
|
||||||
|
import {
|
||||||
|
useCreateProjectMutation,
|
||||||
|
useGetProjectsQuery
|
||||||
|
} from '../../services/mainApi';
|
||||||
|
import CardGroup from '../CardGroup/CardGroup';
|
||||||
|
import CreateProjectDialog from '../dialogs/CreateProjectDialog/CreateProjectDialog';
|
||||||
|
|
||||||
|
export default function MainBoard() {
|
||||||
|
const dragEndHandle = (result: TDragResult) => {
|
||||||
|
result;
|
||||||
|
};
|
||||||
|
|
||||||
|
const [createProject] = useCreateProjectMutation();
|
||||||
|
const { data: cringe, isLoading } = useGetProjectsQuery({});
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<DragDropContext onDragEnd={dragEndHandle}>
|
||||||
|
<ScrollArea scrollbars="horizontal" className="pb-3">
|
||||||
|
<Flex gap={'2'} className="min-w-fit">
|
||||||
|
{!isLoading &&
|
||||||
|
(cringe as any[]).map((item: any) => (
|
||||||
|
<CardGroup id={item.id} title={item.title} />
|
||||||
|
))}
|
||||||
|
</Flex>
|
||||||
|
</ScrollArea>
|
||||||
|
</DragDropContext>
|
||||||
|
|
||||||
|
<CreateProjectDialog onCreate={createProject}>
|
||||||
|
<Button>Create project</Button>
|
||||||
|
</CreateProjectDialog>
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
@ -1,7 +1,6 @@
|
|||||||
import { Draggable } from '@hello-pangea/dnd';
|
import { Draggable } from '@hello-pangea/dnd';
|
||||||
import { Badge, Button, Card, Flex, Text } from '@radix-ui/themes';
|
import { Badge, Button, Card, Flex, Text } from '@radix-ui/themes';
|
||||||
import { observer } from 'mobx-react-lite';
|
import { useUpdateTaskMutation } from '../../services/mainApi';
|
||||||
import { useStore } from '../../hooks/useStore';
|
|
||||||
|
|
||||||
type TTaskCard = {
|
type TTaskCard = {
|
||||||
title?: string;
|
title?: string;
|
||||||
@ -9,32 +8,26 @@ type TTaskCard = {
|
|||||||
id?: string;
|
id?: string;
|
||||||
index?: number;
|
index?: number;
|
||||||
status: 'todo' | 'in-progress' | 'completed';
|
status: 'todo' | 'in-progress' | 'completed';
|
||||||
projectId: string;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const badgeNames = {
|
const badgeNames = {
|
||||||
todo: 'To do',
|
todo: 'To do',
|
||||||
'in-progress': 'In progress',
|
'in-progress': 'In progress',
|
||||||
completed: 'Completed',
|
completed: 'Completed',
|
||||||
} as const;
|
} as const
|
||||||
|
|
||||||
const badgeColors = {
|
const badgeColors = {
|
||||||
todo: 'blue',
|
todo: 'blue',
|
||||||
'in-progress': 'orange',
|
'in-progress': 'orange',
|
||||||
completed: 'green',
|
completed: 'green',
|
||||||
} as const;
|
} as const
|
||||||
|
|
||||||
const TaskCard = observer((props: TTaskCard) => {
|
export default function TaskCard(props: TTaskCard) {
|
||||||
|
const [updateTask] = useUpdateTaskMutation();
|
||||||
|
|
||||||
const store = useStore()
|
|
||||||
|
|
||||||
const updateStatus = (newStatus: 'todo' | 'in-progress' | 'completed') => {
|
const updateStatus = (newStatus: 'todo' | 'in-progress' | 'completed') => {
|
||||||
if (!props.id) return;
|
updateTask({ id: props.id, status: newStatus });
|
||||||
store.mainStore.updateTask({ id: props.id, status: newStatus });
|
|
||||||
};
|
};
|
||||||
// @ts-ignore
|
|
||||||
console.log(`rerendered with`, store.mainStore.tasksByProject.get(2) );
|
|
||||||
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Draggable draggableId={props.id || '123'} index={props.index || 0}>
|
<Draggable draggableId={props.id || '123'} index={props.index || 0}>
|
||||||
@ -43,7 +36,6 @@ const TaskCard = observer((props: TTaskCard) => {
|
|||||||
className="!w-62 !flex flex-col gap-2"
|
className="!w-62 !flex flex-col gap-2"
|
||||||
ref={provided.innerRef}
|
ref={provided.innerRef}
|
||||||
{...provided.draggableProps}
|
{...provided.draggableProps}
|
||||||
{...provided.dragHandleProps}
|
|
||||||
>
|
>
|
||||||
<Flex direction="column" gap="2">
|
<Flex direction="column" gap="2">
|
||||||
<Flex justify={'between'}>
|
<Flex justify={'between'}>
|
||||||
@ -54,26 +46,17 @@ const TaskCard = observer((props: TTaskCard) => {
|
|||||||
|
|
||||||
<Flex justify={'between'}>
|
<Flex justify={'between'}>
|
||||||
{props.status !== 'todo' && (
|
{props.status !== 'todo' && (
|
||||||
<Button
|
<Button color={badgeColors['todo']} onClick={() => updateStatus('todo')}>
|
||||||
color={badgeColors['todo']}
|
|
||||||
onClick={() => updateStatus('todo')}
|
|
||||||
>
|
|
||||||
Todo
|
Todo
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{props.status !== 'in-progress' && (
|
{props.status !== 'in-progress' && (
|
||||||
<Button
|
<Button color={badgeColors['in-progress']} onClick={() => updateStatus('in-progress')}>
|
||||||
color={badgeColors['in-progress']}
|
|
||||||
onClick={() => updateStatus('in-progress')}
|
|
||||||
>
|
|
||||||
In Progress
|
In Progress
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
{props.status !== 'completed' && (
|
{props.status !== 'completed' && (
|
||||||
<Button
|
<Button color={badgeColors['completed']} onClick={() => updateStatus('completed')}>
|
||||||
color={badgeColors['completed']}
|
|
||||||
onClick={() => updateStatus('completed')}
|
|
||||||
>
|
|
||||||
Completed
|
Completed
|
||||||
</Button>
|
</Button>
|
||||||
)}
|
)}
|
||||||
@ -82,6 +65,4 @@ const TaskCard = observer((props: TTaskCard) => {
|
|||||||
)}
|
)}
|
||||||
</Draggable>
|
</Draggable>
|
||||||
);
|
);
|
||||||
})
|
}
|
||||||
|
|
||||||
export default TaskCard;
|
|
||||||
@ -1,28 +1,28 @@
|
|||||||
import { PropsWithChildren, useEffect, useState } from 'react';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
|
||||||
import { Button, Dialog, Flex, Select } from '@radix-ui/themes';
|
import { Button, Dialog, Flex, Select } from '@radix-ui/themes';
|
||||||
|
import { PropsWithChildren, useState } from 'react';
|
||||||
import { useStore } from '../../../hooks/useStore';
|
import {
|
||||||
|
useAddProjectMemberMutation,
|
||||||
|
useGetAllUsersQuery,
|
||||||
|
} from '../../../services/mainApi';
|
||||||
|
|
||||||
type TAddUserToProjectDialog = {
|
type TAddUserToProjectDialog = {
|
||||||
projectId: number;
|
projectId: number;
|
||||||
} & PropsWithChildren;
|
} & PropsWithChildren;
|
||||||
|
|
||||||
function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
export default function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
||||||
const { projectId, children } = props;
|
const { projectId, children } = props;
|
||||||
|
const { data: users, isLoading, error, refetch } = useGetAllUsersQuery({});
|
||||||
|
const [addProjectMember, { isLoading: isAdding }] =
|
||||||
|
useAddProjectMemberMutation();
|
||||||
const [selectedUserId, setSelectedUserId] = useState<number | null>(null);
|
const [selectedUserId, setSelectedUserId] = useState<number | null>(null);
|
||||||
|
|
||||||
const store = useStore();
|
|
||||||
|
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
store.authStore.fetchAllUsers();
|
|
||||||
}, []);
|
|
||||||
|
|
||||||
const handleAddUser = async () => {
|
const handleAddUser = async () => {
|
||||||
if (selectedUserId) {
|
if (selectedUserId) {
|
||||||
try {
|
try {
|
||||||
await store.mainStore.addProjectMember(projectId.toString(), selectedUserId.toString());
|
await addProjectMember({
|
||||||
|
projectId,
|
||||||
|
memberId: selectedUserId,
|
||||||
|
}).unwrap();
|
||||||
setSelectedUserId(null);
|
setSelectedUserId(null);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to add user:', err);
|
console.error('Failed to add user:', err);
|
||||||
@ -30,12 +30,9 @@ function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
const isLoading = store.authStore.isLoading;
|
|
||||||
const error = store.authStore.error;
|
|
||||||
const users = store.authStore.allUsers;
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Dialog.Root>
|
<Dialog.Root onOpenChange={() => refetch()}>
|
||||||
<Dialog.Trigger>{children}</Dialog.Trigger>
|
<Dialog.Trigger>{children}</Dialog.Trigger>
|
||||||
|
|
||||||
<Dialog.Content maxWidth="450px">
|
<Dialog.Content maxWidth="450px">
|
||||||
@ -45,21 +42,26 @@ function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
|||||||
{isLoading ? (
|
{isLoading ? (
|
||||||
<span>Loading users...</span>
|
<span>Loading users...</span>
|
||||||
) : error ? (
|
) : error ? (
|
||||||
<span>Error loading users: {error}</span>
|
<span>Error loading users.</span>
|
||||||
) : (
|
) : (
|
||||||
<Select.Root
|
<Select.Root
|
||||||
value={selectedUserId?.toString() || ''}
|
value={selectedUserId?.toString() || ''}
|
||||||
onValueChange={(value) => setSelectedUserId(Number(value))}
|
onValueChange={(value) =>
|
||||||
|
setSelectedUserId(Number(value))
|
||||||
|
}
|
||||||
required
|
required
|
||||||
>
|
>
|
||||||
<Select.Trigger aria-label="User">
|
<Select.Trigger aria-label="User">
|
||||||
{selectedUserId
|
{selectedUserId
|
||||||
? users?.find((user: any) => user.id === selectedUserId)?.username
|
? users?.find(
|
||||||
|
(user: any) =>
|
||||||
|
user.id === selectedUserId,
|
||||||
|
)?.username
|
||||||
: 'Select a user'}
|
: 'Select a user'}
|
||||||
</Select.Trigger>
|
</Select.Trigger>
|
||||||
<Select.Content>
|
<Select.Content>
|
||||||
{users?.map((user: any) => (
|
{users?.map((user: any) => (
|
||||||
<Select.Item key={user.id} value={user.id.toString()}>
|
<Select.Item key={user.id} value={user.id}>
|
||||||
{user.username}
|
{user.username}
|
||||||
</Select.Item>
|
</Select.Item>
|
||||||
))}
|
))}
|
||||||
@ -74,10 +76,13 @@ function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
|||||||
Cancel
|
Cancel
|
||||||
</Button>
|
</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
|
|
||||||
<Dialog.Close>
|
<Dialog.Close>
|
||||||
<Button color="green" onClick={handleAddUser} disabled={!selectedUserId || isLoading}>
|
<Button
|
||||||
{isLoading ? 'Adding...' : 'Add'}
|
color="green"
|
||||||
|
onClick={handleAddUser}
|
||||||
|
disabled={!selectedUserId || isAdding}
|
||||||
|
>
|
||||||
|
{isAdding ? 'Adding...' : 'Add'}
|
||||||
</Button>
|
</Button>
|
||||||
</Dialog.Close>
|
</Dialog.Close>
|
||||||
</Flex>
|
</Flex>
|
||||||
@ -85,5 +90,3 @@ function AddUserToProjectDialog(props: TAddUserToProjectDialog) {
|
|||||||
</Dialog.Root>
|
</Dialog.Root>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(AddUserToProjectDialog);
|
|
||||||
@ -1,5 +1,3 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@ -10,24 +8,18 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { Form } from 'radix-ui';
|
import { Form } from 'radix-ui';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useLoginMutation } from '../../../services/mainApi';
|
||||||
|
|
||||||
// Импортируем store.authStore
|
export default function LoginPage() {
|
||||||
import { useStore } from '../../../hooks/useStore';
|
const [login, { isError }] = useLoginMutation();
|
||||||
|
|
||||||
|
|
||||||
function LoginPage() {
|
|
||||||
const [username, setUsername] = useState('');
|
const [username, setUsername] = useState('');
|
||||||
const [password, setPassword] = useState('');
|
const [password, setPassword] = useState('');
|
||||||
|
|
||||||
const store = useStore();
|
|
||||||
// В RTK Query было: [login, { isError } ] = useLoginMutation();
|
|
||||||
// Теперь берем store.authStore.error, store.authStore.isLoading
|
|
||||||
const isError = !!store.authStore.error;
|
|
||||||
const isLoading = store.authStore.isLoading;
|
|
||||||
|
|
||||||
const submitHandler = async (e: React.FormEvent<HTMLFormElement>) => {
|
const submitHandler = (e: React.FormEvent<HTMLFormElement>) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
await store.authStore.login({ username, password }).catch(() => {});
|
login({ username, password });
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
@ -37,11 +29,15 @@ function LoginPage() {
|
|||||||
Login
|
Login
|
||||||
</Heading>
|
</Heading>
|
||||||
|
|
||||||
<Form.Root className="flex flex-col gap-4" onSubmit={submitHandler}>
|
<Form.Root
|
||||||
|
className="flex flex-col gap-4"
|
||||||
|
onSubmit={submitHandler}
|
||||||
|
>
|
||||||
<Form.Field name="email">
|
<Form.Field name="email">
|
||||||
<Form.Message match={'valueMissing'}>
|
<Form.Message match={'valueMissing'}>
|
||||||
<Text>Username is required</Text>
|
<Text>Username is required</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
type="text"
|
type="text"
|
||||||
@ -58,6 +54,7 @@ function LoginPage() {
|
|||||||
<Form.Message match="valueMissing">
|
<Form.Message match="valueMissing">
|
||||||
<Text>Password is required</Text>
|
<Text>Password is required</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
type="password"
|
type="password"
|
||||||
@ -71,13 +68,16 @@ function LoginPage() {
|
|||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
|
||||||
{isError && (
|
{isError && (
|
||||||
<Text>{store.authStore.error || 'Unable to login. Please try again.'}</Text>
|
<Text>{'Unable to login. Please try again.'}</Text>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
<Button type="submit" className="mt-4" disabled={isLoading}>
|
<Button
|
||||||
{isLoading ? 'Loading...' : 'Sign In'}
|
// onClick={(e) => e.preventDefault()}
|
||||||
|
className="mt-4"
|
||||||
|
>
|
||||||
|
Sign In
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
<Box className='w-full !flex justify-center'>
|
<Box className='w-full !flex justify-center'>
|
||||||
<Link href="/register">
|
<Link href="/register">
|
||||||
<Text>Register</Text>
|
<Text>Register</Text>
|
||||||
@ -88,5 +88,3 @@ function LoginPage() {
|
|||||||
</>
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(LoginPage);
|
|
||||||
@ -1,5 +1,3 @@
|
|||||||
import { useState } from 'react';
|
|
||||||
import { observer } from 'mobx-react-lite';
|
|
||||||
import {
|
import {
|
||||||
Box,
|
Box,
|
||||||
Button,
|
Button,
|
||||||
@ -10,23 +8,17 @@ import {
|
|||||||
TextField,
|
TextField,
|
||||||
} from '@radix-ui/themes';
|
} from '@radix-ui/themes';
|
||||||
import { Form } from 'radix-ui';
|
import { Form } from 'radix-ui';
|
||||||
|
import { useState } from 'react';
|
||||||
|
import { useRegisterMutation } from '../../../services/mainApi';
|
||||||
|
|
||||||
// Импортируем store.authStore
|
export default function RegisterPage() {
|
||||||
import { useStore } from '../../../hooks/useStore';
|
const [register, { isLoading, error }] = useRegisterMutation();
|
||||||
|
|
||||||
|
|
||||||
function RegisterPage() {
|
|
||||||
const [formData, setFormData] = useState({
|
const [formData, setFormData] = useState({
|
||||||
username: '',
|
username: '',
|
||||||
email: '',
|
email: '',
|
||||||
password: '',
|
password: '',
|
||||||
});
|
});
|
||||||
|
|
||||||
const store = useStore();
|
|
||||||
|
|
||||||
const isLoading = store.authStore.isLoading;
|
|
||||||
const error = store.authStore.error;
|
|
||||||
|
|
||||||
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
|
||||||
setFormData({
|
setFormData({
|
||||||
...formData,
|
...formData,
|
||||||
@ -37,7 +29,7 @@ function RegisterPage() {
|
|||||||
const handleSubmit = async (e: React.FormEvent) => {
|
const handleSubmit = async (e: React.FormEvent) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
try {
|
try {
|
||||||
await store.authStore.register(formData);
|
await register(formData).unwrap();
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Failed to register:', err);
|
console.error('Failed to register:', err);
|
||||||
}
|
}
|
||||||
@ -48,11 +40,15 @@ function RegisterPage() {
|
|||||||
<Heading size="4" className="text-center !mb-2">
|
<Heading size="4" className="text-center !mb-2">
|
||||||
Register
|
Register
|
||||||
</Heading>
|
</Heading>
|
||||||
<Form.Root className="flex flex-col gap-4" onSubmit={handleSubmit}>
|
<Form.Root
|
||||||
|
className="flex flex-col gap-4"
|
||||||
|
onSubmit={handleSubmit}
|
||||||
|
>
|
||||||
<Form.Field name="username">
|
<Form.Field name="username">
|
||||||
<Form.Message match="valueMissing">
|
<Form.Message match="valueMissing">
|
||||||
<Text>Username is required</Text>
|
<Text>Username is required</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
type="text"
|
type="text"
|
||||||
@ -71,9 +67,11 @@ function RegisterPage() {
|
|||||||
<Form.Message match="valueMissing">
|
<Form.Message match="valueMissing">
|
||||||
<Text>Email is required</Text>
|
<Text>Email is required</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Message match="typeMismatch">
|
<Form.Message match="typeMismatch">
|
||||||
<Text>Email is not valid</Text>
|
<Text>Email is not valid</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
type="email"
|
type="email"
|
||||||
@ -92,10 +90,10 @@ function RegisterPage() {
|
|||||||
<Form.Message match="valueMissing">
|
<Form.Message match="valueMissing">
|
||||||
<Text>Password is required</Text>
|
<Text>Password is required</Text>
|
||||||
</Form.Message>
|
</Form.Message>
|
||||||
|
|
||||||
<Form.Control asChild>
|
<Form.Control asChild>
|
||||||
<TextField.Root
|
<TextField.Root
|
||||||
type="password"
|
type="password"
|
||||||
name="password"
|
|
||||||
placeholder="Password"
|
placeholder="Password"
|
||||||
required
|
required
|
||||||
value={formData.password}
|
value={formData.password}
|
||||||
@ -107,12 +105,12 @@ function RegisterPage() {
|
|||||||
</Form.Field>
|
</Form.Field>
|
||||||
|
|
||||||
<Button type="submit" disabled={isLoading} className="mt-4">
|
<Button type="submit" disabled={isLoading} className="mt-4">
|
||||||
{isLoading ? 'Loading...' : 'Register'}
|
Register
|
||||||
</Button>
|
</Button>
|
||||||
|
|
||||||
{error && (
|
{error && (
|
||||||
<Box className="text-red-500">
|
<Box className="text-red-500">
|
||||||
<Text>Error registering user: {error}</Text>
|
<Text>Error registering user.</Text>
|
||||||
</Box>
|
</Box>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
@ -124,6 +122,4 @@ function RegisterPage() {
|
|||||||
</Form.Root>
|
</Form.Root>
|
||||||
</Card>
|
</Card>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
export default observer(RegisterPage);
|
|
||||||
@ -1,14 +1,10 @@
|
|||||||
import { Box } from '@radix-ui/themes'
|
import { Box } from '@radix-ui/themes'
|
||||||
import { observer } from 'mobx-react-lite'
|
|
||||||
import { Outlet } from 'react-router-dom'
|
import { Outlet } from 'react-router-dom'
|
||||||
|
|
||||||
const MainPage = observer(() => {
|
export default function MainPage() {
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box className='size-full'>
|
<Box className='size-full'>
|
||||||
<Outlet />
|
<Outlet />
|
||||||
</Box>
|
</Box>
|
||||||
)
|
)
|
||||||
})
|
}
|
||||||
|
|
||||||
export default MainPage
|
|
||||||
231
cool_todo_manager/src/services/mainApi.ts
Normal file
231
cool_todo_manager/src/services/mainApi.ts
Normal file
@ -0,0 +1,231 @@
|
|||||||
|
import { createApi, fetchBaseQuery } from '@reduxjs/toolkit/query/react';
|
||||||
|
|
||||||
|
export const mainApi = createApi({
|
||||||
|
reducerPath: 'api',
|
||||||
|
baseQuery: fetchBaseQuery({
|
||||||
|
baseUrl: 'http://109.107.166.17:5000/api/',
|
||||||
|
prepareHeaders: (headers) => {
|
||||||
|
headers.set(
|
||||||
|
'Authorization',
|
||||||
|
`Bearer ${localStorage.getItem('token')}`,
|
||||||
|
);
|
||||||
|
return headers;
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
tagTypes: ['Task', 'Project', 'ProjectMembers'],
|
||||||
|
endpoints: (builder) => ({
|
||||||
|
getTasks: builder.query<string[], void>({
|
||||||
|
query: () => ({
|
||||||
|
url: 'tasks',
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result) =>
|
||||||
|
result
|
||||||
|
? [
|
||||||
|
...result.map((task) => ({
|
||||||
|
type: 'Task' as const,
|
||||||
|
id: task,
|
||||||
|
})),
|
||||||
|
{ type: 'Task', id: 'LIST' },
|
||||||
|
]
|
||||||
|
: [{ type: 'Task', id: 'LIST' }],
|
||||||
|
}),
|
||||||
|
getTasksForGroup: builder.query<any[], string>({
|
||||||
|
query: (id: string) => ({
|
||||||
|
url: `tasks/project/${id}`,
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result) =>
|
||||||
|
result
|
||||||
|
? [
|
||||||
|
...result.map((task) => ({
|
||||||
|
type: 'Task' as const,
|
||||||
|
id: task,
|
||||||
|
})),
|
||||||
|
{ type: 'Task', id: 'LIST' },
|
||||||
|
]
|
||||||
|
: [{ type: 'Task', id: 'LIST' }],
|
||||||
|
}),
|
||||||
|
getTask: builder.query<string, string>({
|
||||||
|
query: (id) => ({
|
||||||
|
url: `tasks/${id}`,
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result, error, id) => [{ type: 'Task', id }],
|
||||||
|
}),
|
||||||
|
updateTask: builder.mutation({
|
||||||
|
query: (task) => ({
|
||||||
|
url: `tasks/${task.id}`,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: { status: task.status },
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, id) => [{ type: 'Task', id }],
|
||||||
|
}),
|
||||||
|
deleteTask: builder.mutation({
|
||||||
|
query: (id) => ({
|
||||||
|
url: `tasks/${id}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, id) => [{ type: 'Task', id }],
|
||||||
|
}),
|
||||||
|
createTask: builder.mutation({
|
||||||
|
query: (newTask) => ({
|
||||||
|
url: 'tasks/create',
|
||||||
|
method: 'POST',
|
||||||
|
body: newTask,
|
||||||
|
}),
|
||||||
|
invalidatesTags: [{ type: 'Task', id: 'LIST' }],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// PROJECTS
|
||||||
|
createProject: builder.mutation({
|
||||||
|
query: (newProject) => ({
|
||||||
|
url: 'projects/create',
|
||||||
|
method: 'POST',
|
||||||
|
body: newProject,
|
||||||
|
}),
|
||||||
|
invalidatesTags: [{ type: 'Project', id: 'LIST' }],
|
||||||
|
}),
|
||||||
|
getProjects: builder.query({
|
||||||
|
query: () => ({
|
||||||
|
url: 'projects/my',
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result, error, id) => [
|
||||||
|
{ type: 'Project', id: 'LIST' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
getProject: builder.query({
|
||||||
|
query: (id) => ({
|
||||||
|
url: `projects/${id}`,
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result, error, id) => [{ type: 'Project', id }],
|
||||||
|
}),
|
||||||
|
updateProject: builder.mutation({
|
||||||
|
query: ({ id, project }) => ({
|
||||||
|
url: `projects/${id}`,
|
||||||
|
method: 'PATCH',
|
||||||
|
body: project,
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, id) => [{ type: 'Project', id }],
|
||||||
|
}),
|
||||||
|
deleteProject: builder.mutation({
|
||||||
|
query: (id) => ({
|
||||||
|
url: `projects/${id}`,
|
||||||
|
method: 'DELETE',
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, id) => [
|
||||||
|
{ type: 'Project', id: 'LIST' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
|
||||||
|
// PROJECT MEMBERS
|
||||||
|
addProjectMember: builder.mutation({
|
||||||
|
query: ({ projectId, memberId }) => ({
|
||||||
|
url: `projects/${projectId}/members/add`,
|
||||||
|
method: 'POST',
|
||||||
|
body: { userId: memberId, role: '' },
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, args) => [
|
||||||
|
{ type: 'ProjectMembers', id: 'LIST' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
getProjectMembers: builder.query({
|
||||||
|
query: (id) => ({
|
||||||
|
url: `projects/${id}/members`,
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
providesTags: (result, error, args) => [
|
||||||
|
{ type: 'ProjectMembers', id: 'LIST' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
removeProjectMember: builder.mutation({
|
||||||
|
query: ({ projectId, memberId }) => ({
|
||||||
|
url: `projects/${projectId}/members/remove`,
|
||||||
|
method: 'DELETE',
|
||||||
|
body: { userId: memberId },
|
||||||
|
}),
|
||||||
|
invalidatesTags: (result, error, id) => [
|
||||||
|
{ type: 'ProjectMembers', id: 'LIST' },
|
||||||
|
],
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const authApi = createApi({
|
||||||
|
reducerPath: 'authApi',
|
||||||
|
baseQuery: fetchBaseQuery({
|
||||||
|
baseUrl: 'http://109.107.166.17:4000/api/',
|
||||||
|
}),
|
||||||
|
endpoints: (builder) => ({
|
||||||
|
login: builder.mutation({
|
||||||
|
query: (credentials) => ({
|
||||||
|
url: '/auth/login',
|
||||||
|
method: 'POST',
|
||||||
|
body: credentials,
|
||||||
|
}),
|
||||||
|
async onQueryStarted(arg, { queryFulfilled }) {
|
||||||
|
try {
|
||||||
|
const response = await queryFulfilled;
|
||||||
|
if (response.data.access_token) {
|
||||||
|
localStorage.setItem(
|
||||||
|
'token',
|
||||||
|
response.data.access_token,
|
||||||
|
);
|
||||||
|
if (response.meta?.response?.status === 201)
|
||||||
|
window.location.href = '/';
|
||||||
|
}
|
||||||
|
} catch (error) {}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
register: builder.mutation({
|
||||||
|
query: (credentials) => ({
|
||||||
|
url: '/auth/register',
|
||||||
|
method: 'POST',
|
||||||
|
body: credentials,
|
||||||
|
}),
|
||||||
|
onQueryStarted: async (arg, { queryFulfilled }) => {
|
||||||
|
try {
|
||||||
|
const response = await queryFulfilled;
|
||||||
|
if (response.meta?.response?.status === 201)
|
||||||
|
window.location.href = '/login';
|
||||||
|
} catch (error) {}
|
||||||
|
},
|
||||||
|
}),
|
||||||
|
|
||||||
|
// USERS
|
||||||
|
getAllUsers: builder.query({
|
||||||
|
query: () => ({
|
||||||
|
url: '/users',
|
||||||
|
method: 'GET',
|
||||||
|
}),
|
||||||
|
keepUnusedDataFor: 0,
|
||||||
|
|
||||||
|
}),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
|
||||||
|
export const { useLoginMutation, useRegisterMutation, useGetAllUsersQuery } =
|
||||||
|
authApi;
|
||||||
|
|
||||||
|
export const {
|
||||||
|
useGetTasksQuery,
|
||||||
|
useCreateTaskMutation,
|
||||||
|
useUpdateTaskMutation,
|
||||||
|
useDeleteTaskMutation,
|
||||||
|
useGetTasksForGroupQuery,
|
||||||
|
} = mainApi;
|
||||||
|
|
||||||
|
export const {
|
||||||
|
useGetProjectsQuery,
|
||||||
|
useCreateProjectMutation,
|
||||||
|
useUpdateProjectMutation,
|
||||||
|
useDeleteProjectMutation,
|
||||||
|
} = mainApi;
|
||||||
|
|
||||||
|
export const {
|
||||||
|
useRemoveProjectMemberMutation,
|
||||||
|
useAddProjectMemberMutation,
|
||||||
|
useGetProjectMembersQuery,
|
||||||
|
} = mainApi;
|
||||||
26
cool_todo_manager/tsconfig.app.json
Normal file
26
cool_todo_manager/tsconfig.app.json
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.app.tsbuildinfo",
|
||||||
|
"target": "ES2020",
|
||||||
|
"useDefineForClassFields": true,
|
||||||
|
"lib": ["ES2020", "DOM", "DOM.Iterable"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
"jsx": "react-jsx",
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["src", "../@types/**/*"]
|
||||||
|
}
|
||||||
7
cool_todo_manager/tsconfig.json
Normal file
7
cool_todo_manager/tsconfig.json
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
{
|
||||||
|
"files": [],
|
||||||
|
"references": [
|
||||||
|
{ "path": "./tsconfig.app.json" },
|
||||||
|
{ "path": "./tsconfig.node.json" }
|
||||||
|
]
|
||||||
|
}
|
||||||
24
cool_todo_manager/tsconfig.node.json
Normal file
24
cool_todo_manager/tsconfig.node.json
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"tsBuildInfoFile": "./node_modules/.tmp/tsconfig.node.tsbuildinfo",
|
||||||
|
"target": "ES2022",
|
||||||
|
"lib": ["ES2023"],
|
||||||
|
"module": "ESNext",
|
||||||
|
"skipLibCheck": true,
|
||||||
|
|
||||||
|
/* Bundler mode */
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"allowImportingTsExtensions": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"moduleDetection": "force",
|
||||||
|
"noEmit": true,
|
||||||
|
|
||||||
|
/* Linting */
|
||||||
|
"strict": true,
|
||||||
|
"noUnusedLocals": true,
|
||||||
|
"noUnusedParameters": true,
|
||||||
|
"noFallthroughCasesInSwitch": true,
|
||||||
|
"noUncheckedSideEffectImports": true
|
||||||
|
},
|
||||||
|
"include": ["vite.config.ts"]
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user