initial commit
This commit is contained in:
parent
e1b43921fa
commit
69b5b0376a
37 changed files with 6239 additions and 0 deletions
3
task_management_app/.eslintrc.json
Normal file
3
task_management_app/.eslintrc.json
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
{
|
||||||
|
"extends": "next/core-web-vitals"
|
||||||
|
}
|
37
task_management_app/.gitignore
vendored
Normal file
37
task_management_app/.gitignore
vendored
Normal file
|
@ -0,0 +1,37 @@
|
||||||
|
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||||
|
|
||||||
|
# dependencies
|
||||||
|
/node_modules
|
||||||
|
/.pnp
|
||||||
|
.pnp.js
|
||||||
|
.yarn/install-state.gz
|
||||||
|
|
||||||
|
# testing
|
||||||
|
/coverage
|
||||||
|
|
||||||
|
# next.js
|
||||||
|
/.next/
|
||||||
|
/out/
|
||||||
|
|
||||||
|
# production
|
||||||
|
/build
|
||||||
|
|
||||||
|
# misc
|
||||||
|
.DS_Store
|
||||||
|
*.pem
|
||||||
|
|
||||||
|
# debug
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# local env files
|
||||||
|
.env*.local
|
||||||
|
.env
|
||||||
|
|
||||||
|
# vercel
|
||||||
|
.vercel
|
||||||
|
|
||||||
|
# typescript
|
||||||
|
*.tsbuildinfo
|
||||||
|
next-env.d.ts
|
36
task_management_app/README.md
Normal file
36
task_management_app/README.md
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
This is a [Next.js](https://nextjs.org/) project bootstrapped with [`create-next-app`](https://github.com/vercel/next.js/tree/canary/packages/create-next-app).
|
||||||
|
|
||||||
|
## Getting Started
|
||||||
|
|
||||||
|
First, run the development server:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
npm run dev
|
||||||
|
# or
|
||||||
|
yarn dev
|
||||||
|
# or
|
||||||
|
pnpm dev
|
||||||
|
# or
|
||||||
|
bun dev
|
||||||
|
```
|
||||||
|
|
||||||
|
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||||
|
|
||||||
|
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
|
||||||
|
|
||||||
|
This project uses [`next/font`](https://nextjs.org/docs/basic-features/font-optimization) to automatically optimize and load Inter, a custom Google Font.
|
||||||
|
|
||||||
|
## Learn More
|
||||||
|
|
||||||
|
To learn more about Next.js, take a look at the following resources:
|
||||||
|
|
||||||
|
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||||
|
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||||
|
|
||||||
|
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js/) - your feedback and contributions are welcome!
|
||||||
|
|
||||||
|
## Deploy on Vercel
|
||||||
|
|
||||||
|
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||||
|
|
||||||
|
Check out our [Next.js deployment documentation](https://nextjs.org/docs/deployment) for more details.
|
4
task_management_app/next.config.mjs
Normal file
4
task_management_app/next.config.mjs
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
/** @type {import('next').NextConfig} */
|
||||||
|
const nextConfig = {};
|
||||||
|
|
||||||
|
export default nextConfig;
|
5379
task_management_app/package-lock.json
generated
Normal file
5379
task_management_app/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
39
task_management_app/package.json
Normal file
39
task_management_app/package.json
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
{
|
||||||
|
"name": "task_management_app",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"private": true,
|
||||||
|
"scripts": {
|
||||||
|
"dev": "next dev",
|
||||||
|
"build": "next build",
|
||||||
|
"start": "next start",
|
||||||
|
"lint": "next lint"
|
||||||
|
},
|
||||||
|
"dependencies": {
|
||||||
|
"@auth/mongodb-adapter": "^2.5.1",
|
||||||
|
"@liveblocks/client": "^1.11.0",
|
||||||
|
"@liveblocks/node": "^1.11.0",
|
||||||
|
"@liveblocks/react": "^1.11.0",
|
||||||
|
"@tailwindcss/forms": "^0.5.7",
|
||||||
|
"mongodb": "^6.5.0",
|
||||||
|
"next": "14.1.4",
|
||||||
|
"next-auth": "^4.24.7",
|
||||||
|
"react": "^18",
|
||||||
|
"react-dom": "^18",
|
||||||
|
"react-icons": "^5.0.1",
|
||||||
|
"react-sortablejs": "^6.1.4",
|
||||||
|
"sortablejs": "^1.15.2",
|
||||||
|
"uniqid": "^5.4.0"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@types/node": "^20",
|
||||||
|
"@types/react": "^18",
|
||||||
|
"@types/react-dom": "^18",
|
||||||
|
"@types/uniqid": "^5.3.4",
|
||||||
|
"autoprefixer": "^10.0.1",
|
||||||
|
"eslint": "^8",
|
||||||
|
"eslint-config-next": "14.1.4",
|
||||||
|
"postcss": "^8",
|
||||||
|
"tailwindcss": "^3.3.0",
|
||||||
|
"typescript": "^5"
|
||||||
|
}
|
||||||
|
}
|
6
task_management_app/postcss.config.js
Normal file
6
task_management_app/postcss.config.js
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
module.exports = {
|
||||||
|
plugins: {
|
||||||
|
tailwindcss: {},
|
||||||
|
autoprefixer: {},
|
||||||
|
},
|
||||||
|
};
|
1
task_management_app/public/next.svg
Normal file
1
task_management_app/public/next.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
1
task_management_app/public/vercel.svg
Normal file
1
task_management_app/public/vercel.svg
Normal file
|
@ -0,0 +1 @@
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 283 64"><path fill="black" d="M141 16c-11 0-19 7-19 18s9 18 20 18c7 0 13-3 16-7l-7-5c-2 3-6 4-9 4-5 0-9-3-10-7h28v-3c0-11-8-18-19-18zm-9 15c1-4 4-7 9-7s8 3 9 7h-18zm117-15c-11 0-19 7-19 18s9 18 20 18c6 0 12-3 16-7l-8-5c-2 3-5 4-8 4-5 0-9-3-11-7h28l1-3c0-11-8-18-19-18zm-10 15c2-4 5-7 10-7s8 3 9 7h-19zm-39 3c0 6 4 10 10 10 4 0 7-2 9-5l8 5c-3 5-9 8-17 8-11 0-19-7-19-18s8-18 19-18c8 0 14 3 17 8l-8 5c-2-3-5-5-9-5-6 0-10 4-10 10zm83-29v46h-9V5h9zM37 0l37 64H0L37 0zm92 5-27 48L74 5h10l18 30 17-30h10zm59 12v10l-3-1c-6 0-10 4-10 10v15h-9V17h9v9c0-5 6-9 13-9z"/></svg>
|
After Width: | Height: | Size: 629 B |
38
task_management_app/src/app/actions/boardActions.ts
Normal file
38
task_management_app/src/app/actions/boardActions.ts
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
"use server"
|
||||||
|
import { authOptions } from "@/lib/authOptions";
|
||||||
|
import { liveblocksClient } from "@/lib/liveblocksClient";
|
||||||
|
import { Liveblocks, RoomInfo } from "@liveblocks/node";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import uniqid from 'uniqid'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
export async function craeteBoard(name: string) : Promise<boolean | RoomInfo> {
|
||||||
|
const liveblocksClient = new Liveblocks({
|
||||||
|
secret: process.env.LIVEBLOCKS_SECRET_KEY || '',
|
||||||
|
});
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
const email = session?.user?.email || '';
|
||||||
|
if(email){
|
||||||
|
const roomId = uniqid.time();
|
||||||
|
return await liveblocksClient.createRoom(roomId, {
|
||||||
|
defaultAccesses: [],
|
||||||
|
usersAccesses: {
|
||||||
|
[email]: ['room:write']
|
||||||
|
},
|
||||||
|
metadata: {
|
||||||
|
boardName: name,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function addEmailtoBoard(boardId: string, email: string){
|
||||||
|
const room = await liveblocksClient.getRoom(boardId);
|
||||||
|
const usersAccesses = room.usersAccesses;
|
||||||
|
usersAccesses[email] = ['room:write'];
|
||||||
|
await liveblocksClient.updateRoom(boardId, {usersAccesses});
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -0,0 +1,6 @@
|
||||||
|
import NextAuth from "next-auth"
|
||||||
|
import { authOptions } from "@/lib/authOptions";
|
||||||
|
|
||||||
|
const handler = NextAuth(authOptions)
|
||||||
|
|
||||||
|
export { handler as GET, handler as POST }
|
33
task_management_app/src/app/api/liveblocks-auth/route.ts
Normal file
33
task_management_app/src/app/api/liveblocks-auth/route.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { authOptions } from "@/lib/authOptions";
|
||||||
|
import { liveblocksClient } from "@/lib/liveblocksClient";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
|
||||||
|
|
||||||
|
export async function POST(request: Request) {
|
||||||
|
// Get the current user from your database
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
|
||||||
|
if(!session || !session.user){
|
||||||
|
return new Response('Unauthorized', {status: 401})
|
||||||
|
}
|
||||||
|
|
||||||
|
const user = session.user;
|
||||||
|
const email = user.email || '';
|
||||||
|
const { status, body } = await liveblocksClient.identifyUser(
|
||||||
|
{
|
||||||
|
userId: email,
|
||||||
|
groupIds: [],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
userInfo: {
|
||||||
|
name: user.name || '',
|
||||||
|
email: email,
|
||||||
|
image: user.image,
|
||||||
|
}
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
|
return new Response(body, { status });
|
||||||
|
|
||||||
|
}
|
||||||
|
|
36
task_management_app/src/app/boards/[boardId]/page.tsx
Normal file
36
task_management_app/src/app/boards/[boardId]/page.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"use server"
|
||||||
|
|
||||||
|
import Board from "@/components/Board";
|
||||||
|
import { liveblocksClient } from "@/lib/liveblocksClient";
|
||||||
|
import { getUserEmail } from "@/lib/userClient";
|
||||||
|
|
||||||
|
|
||||||
|
type PageProps ={
|
||||||
|
params: {
|
||||||
|
boardId: string;
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const BoardPage = async (props: PageProps) => {
|
||||||
|
const boardId = props.params.boardId
|
||||||
|
const userEmail = await getUserEmail();
|
||||||
|
const boardInfo = await liveblocksClient.getRoom(boardId)
|
||||||
|
const userAcess = boardInfo.usersAccesses?.[userEmail];
|
||||||
|
const hasAccess = userAcess && [...userAcess].includes('room:write');
|
||||||
|
|
||||||
|
if(!hasAccess){
|
||||||
|
return(
|
||||||
|
<div>Access denied</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Board name={boardInfo.metadata.boardName} id={boardId}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default BoardPage
|
|
@ -0,0 +1,40 @@
|
||||||
|
"use server"
|
||||||
|
import NewUserAccess from "@/components/forms/NewUserAccess";
|
||||||
|
import { liveblocksClient } from "@/lib/liveblocksClient";
|
||||||
|
import { getUserEmail } from "@/lib/userClient";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { ImBackward2 } from "react-icons/im";
|
||||||
|
|
||||||
|
|
||||||
|
type PageProps ={
|
||||||
|
params: {
|
||||||
|
boardId: string;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const page = async ({params}: PageProps) => {
|
||||||
|
const {boardId} = params;
|
||||||
|
const boardInfo = await liveblocksClient.getRoom(boardId);
|
||||||
|
const userEmail = await getUserEmail()
|
||||||
|
if(!boardInfo.usersAccesses[userEmail]){
|
||||||
|
return 'Access denied';
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<Link href={`/boards/${boardId}`} className="flex items-center gap-1 text-[#164863] font-semibold hover:text-[#427D9D] hover:duration-300"><ImBackward2/>Go back</Link>
|
||||||
|
<h1 className="text-2xl">Access to {boardInfo.metadata.boardName}:</h1>
|
||||||
|
<div className="mb-6">
|
||||||
|
{Object.keys(boardInfo.usersAccesses).map(email => (
|
||||||
|
<div>
|
||||||
|
{email}
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
<NewUserAccess boardId = {boardId}/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default page
|
BIN
task_management_app/src/app/favicon.ico
Normal file
BIN
task_management_app/src/app/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
12
task_management_app/src/app/globals.css
Normal file
12
task_management_app/src/app/globals.css
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
@tailwind base;
|
||||||
|
@tailwind components;
|
||||||
|
@tailwind utilities;
|
||||||
|
|
||||||
|
|
||||||
|
body{}
|
||||||
|
button[type="button"], button[type="submit"], button.primary{
|
||||||
|
@apply bg-[#164863] text-white p-2 text-sm font-semibold rounded-md
|
||||||
|
}
|
||||||
|
button[type="submit"], button.primary{
|
||||||
|
@apply bg-[#427D9D] rounded-md
|
||||||
|
}
|
28
task_management_app/src/app/layout.tsx
Normal file
28
task_management_app/src/app/layout.tsx
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
import type { Metadata } from "next";
|
||||||
|
import { Inter } from "next/font/google";
|
||||||
|
import "./globals.css";
|
||||||
|
import Header from "@/components/Header";
|
||||||
|
|
||||||
|
const inter = Inter({ subsets: ["latin"] });
|
||||||
|
|
||||||
|
export const metadata: Metadata = {
|
||||||
|
title: "Task Management App",
|
||||||
|
description: "Generated by create next app",
|
||||||
|
};
|
||||||
|
|
||||||
|
export default function RootLayout({
|
||||||
|
children,
|
||||||
|
}: Readonly<{
|
||||||
|
children: React.ReactNode;
|
||||||
|
}>) {
|
||||||
|
return (
|
||||||
|
<html lang="en">
|
||||||
|
<body className={inter.className}>
|
||||||
|
<Header/>
|
||||||
|
<main className="p-10">
|
||||||
|
{children}
|
||||||
|
</main>
|
||||||
|
</body>
|
||||||
|
</html>
|
||||||
|
);
|
||||||
|
}
|
43
task_management_app/src/app/liveblocks.config.ts
Normal file
43
task_management_app/src/app/liveblocks.config.ts
Normal file
|
@ -0,0 +1,43 @@
|
||||||
|
import { LiveList, LiveObject, createClient } from "@liveblocks/client";
|
||||||
|
import { createRoomContext } from "@liveblocks/react";
|
||||||
|
|
||||||
|
const client = createClient({
|
||||||
|
authEndpoint: "/api/liveblocks-auth",
|
||||||
|
throttle: 100,
|
||||||
|
});
|
||||||
|
|
||||||
|
type Presence = {
|
||||||
|
// cursor: { x: number, y: number } | null,
|
||||||
|
// ...
|
||||||
|
};
|
||||||
|
export type Column ={
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
index: number;
|
||||||
|
};
|
||||||
|
|
||||||
|
export type Card ={
|
||||||
|
name: string;
|
||||||
|
id: string;
|
||||||
|
index: number;
|
||||||
|
columnId: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
type Storage = {
|
||||||
|
columns: LiveList<LiveObject<Column>>;
|
||||||
|
cards: LiveList<LiveObject<Card>>;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
export const {
|
||||||
|
RoomProvider,
|
||||||
|
useMyPresence,
|
||||||
|
useStorage,
|
||||||
|
useMutation,
|
||||||
|
useRoom,
|
||||||
|
/* ...all the other hooks you’re using... */
|
||||||
|
} = createRoomContext<
|
||||||
|
Presence,
|
||||||
|
Storage
|
||||||
|
/* UserMeta, RoomEvent, ThreadMetadata */
|
||||||
|
>(client);
|
25
task_management_app/src/app/new-board/page.tsx
Normal file
25
task_management_app/src/app/new-board/page.tsx
Normal file
|
@ -0,0 +1,25 @@
|
||||||
|
"use client"
|
||||||
|
import React from 'react'
|
||||||
|
import { craeteBoard } from '@/app/actions/boardActions';
|
||||||
|
import { redirect } from 'next/navigation';
|
||||||
|
|
||||||
|
const NewBoardPage = () => {
|
||||||
|
async function handleNewBoardSubmit(formData: FormData){
|
||||||
|
const boardName = formData.get('name')?.toString() || '';
|
||||||
|
const {id} = await craeteBoard(boardName);
|
||||||
|
redirect(`/boards/${id}`)
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<form action={handleNewBoardSubmit} className='max-w-xs block'>
|
||||||
|
<h1 className='text-2xl mb-4'>Create new board</h1>
|
||||||
|
<input type="text" name='name' placeholder='board name' className='w-full outline-none p-2 border border-[#164863] rounded-md'/>
|
||||||
|
<button type="submit" className='w-full mt-2'>Create board</button>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewBoardPage
|
27
task_management_app/src/app/page.tsx
Normal file
27
task_management_app/src/app/page.tsx
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
import Boards from "@/components/Boards";
|
||||||
|
import LoginView from "@/components/views/LoginView";
|
||||||
|
import { authOptions } from "@/lib/authOptions";
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import Link from "next/link";
|
||||||
|
import { FiPlusCircle } from "react-icons/fi";
|
||||||
|
|
||||||
|
|
||||||
|
export default async function Home() {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
if(!session){
|
||||||
|
return(
|
||||||
|
<LoginView/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return (
|
||||||
|
<div>
|
||||||
|
<h1 className="text-2xl mb-4">Your boards</h1>
|
||||||
|
<Boards/>
|
||||||
|
<div className="mt-4">
|
||||||
|
<Link href={'/new-board'} className="p-2 bg-[#427D9D] text-sm text-white font-semibold rounded-md inline-flex">
|
||||||
|
<p className="flex gap-2 items-center">Create new board <FiPlusCircle className="text-[18px] font-semibold"/></p>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
);
|
||||||
|
}
|
36
task_management_app/src/components/Board.tsx
Normal file
36
task_management_app/src/components/Board.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"use client"
|
||||||
|
import { RoomProvider } from '@/app/liveblocks.config';
|
||||||
|
import { LiveList } from '@liveblocks/client';
|
||||||
|
import { ClientSideSuspense } from '@liveblocks/react';
|
||||||
|
import Columns from './Columns';
|
||||||
|
import Link from 'next/link';
|
||||||
|
import { IoMdSettings } from "react-icons/io";
|
||||||
|
|
||||||
|
|
||||||
|
const Board = ({id, name}: {id: string, name: string}) => {
|
||||||
|
|
||||||
|
return (
|
||||||
|
<RoomProvider id={id} initialPresence={{}} initialStorage={
|
||||||
|
{
|
||||||
|
columns: new LiveList(),
|
||||||
|
cards: new LiveList(),
|
||||||
|
}}>
|
||||||
|
<ClientSideSuspense fallback={(<div>Loading...</div>)}>{() => (
|
||||||
|
<>
|
||||||
|
<div className='flex justify-between gap-2 items-center mb-4'>
|
||||||
|
<div>
|
||||||
|
<h1 className='text-2xl'>Board: {name}</h1>
|
||||||
|
</div>
|
||||||
|
<Link href={`/boards/${id}/settings`} className='flex items-center gap-1 bg-[#427D9D] p-2 rounded-full'>
|
||||||
|
<IoMdSettings className='text-white text-[18px]'/>
|
||||||
|
</Link>
|
||||||
|
</div>
|
||||||
|
<Columns/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</ClientSideSuspense>
|
||||||
|
</RoomProvider>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Board
|
23
task_management_app/src/components/Boards.tsx
Normal file
23
task_management_app/src/components/Boards.tsx
Normal file
|
@ -0,0 +1,23 @@
|
||||||
|
"use server"
|
||||||
|
import { liveblocksClient } from "@/lib/liveblocksClient"
|
||||||
|
import { getUserEmail } from "@/lib/userClient"
|
||||||
|
import Link from "next/link";
|
||||||
|
|
||||||
|
const Boards = async () => {
|
||||||
|
const email = await getUserEmail();
|
||||||
|
const {data: rooms} = await liveblocksClient.getRooms({userId: email});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className="my-4 grid md:grid-cols-5 gap-2">
|
||||||
|
{rooms?.length > 0 && rooms.map(room => (
|
||||||
|
<Link key={room.id} href={`/boards/${room.id}`} className="p-4 bg-gray-200 rounded-md block">
|
||||||
|
{room.metadata.boardName}
|
||||||
|
</Link>
|
||||||
|
))}
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Boards
|
61
task_management_app/src/components/Column.tsx
Normal file
61
task_management_app/src/components/Column.tsx
Normal file
|
@ -0,0 +1,61 @@
|
||||||
|
import { Card, useMutation, useStorage } from '@/app/liveblocks.config';
|
||||||
|
import { shallow } from '@liveblocks/client';
|
||||||
|
import { ReactSortable } from 'react-sortablejs';
|
||||||
|
import NewCardForm from './forms/NewCardForm';
|
||||||
|
|
||||||
|
|
||||||
|
type ColumnProps = {
|
||||||
|
id: string;
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const Column = ({id, name}: ColumnProps) => {
|
||||||
|
const columnCards = useStorage<Card[]>(root => {
|
||||||
|
return root.cards.filter(card => card.columnId === id).map(c => ({...c})).sort((a, b) => a.index - b.index);
|
||||||
|
}, shallow)
|
||||||
|
|
||||||
|
const updateCard = useMutation(({storage}, index, updateData) => {
|
||||||
|
const card = storage.get('cards').get(index);
|
||||||
|
if(card){
|
||||||
|
for(let key in updateData){
|
||||||
|
card?.set(key as keyof Card, updateData[key]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, []);
|
||||||
|
|
||||||
|
const setTasksOrderForColumn = useMutation(({storage}, sortedCards: Card[], newColumnId) => {
|
||||||
|
const idsOfSortedCards = sortedCards.map(c => c.id.toString());
|
||||||
|
const allCards: Card[] = [...storage.get('cards').map(c => c.toObject())]
|
||||||
|
idsOfSortedCards.forEach((sortedCardId, colIndex) => {
|
||||||
|
const cardStorageIndex = allCards.findIndex(c => c.id.toString() === sortedCardId);
|
||||||
|
updateCard(cardStorageIndex, {
|
||||||
|
columnId: newColumnId,
|
||||||
|
index: colIndex,
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
},[])
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='w-50 shadow-md rounded-md p-2 bg-gray-100'>
|
||||||
|
<h3>{name}</h3>
|
||||||
|
{columnCards && (
|
||||||
|
<>
|
||||||
|
<ReactSortable list={columnCards} setList={items => setTasksOrderForColumn(items, id)} group="cards" ghostClass='opacity-40' className='min-h-12'>
|
||||||
|
{columnCards.map(card => (
|
||||||
|
<div key={card.id} className='border my-2 p-2 rounded-sm bg-white'>
|
||||||
|
<span>{card.name}</span>
|
||||||
|
</div>
|
||||||
|
))}
|
||||||
|
</ReactSortable>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
<NewCardForm columnId={id}/>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Column
|
42
task_management_app/src/components/Columns.tsx
Normal file
42
task_management_app/src/components/Columns.tsx
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
"use client"
|
||||||
|
import { Column, useMutation, useStorage } from "@/app/liveblocks.config"
|
||||||
|
import {default as BoardColumn} from "./Column"
|
||||||
|
import NewForm from "./forms/NewForm"
|
||||||
|
import { ReactSortable } from "react-sortablejs"
|
||||||
|
import { LiveList, LiveObject, shallow } from "@liveblocks/client"
|
||||||
|
|
||||||
|
|
||||||
|
const Columns = () => {
|
||||||
|
const columns = useStorage(root => root.columns.map(c => ({...c})), shallow);
|
||||||
|
const updateColumns = useMutation(({storage}, columns:LiveObject<Column>[]) => {
|
||||||
|
storage.set('columns', new LiveList(columns))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function setColumnsOrder(sortedColumns: Column[]){
|
||||||
|
const newColumns:LiveObject<Column>[] = [];
|
||||||
|
sortedColumns.forEach((sortedColumn, newIndex) => {
|
||||||
|
const newSortedColumn = {...sortedColumn};
|
||||||
|
newSortedColumn.index = newIndex;
|
||||||
|
newColumns.push(new LiveObject(newSortedColumn))
|
||||||
|
});
|
||||||
|
updateColumns(newColumns)
|
||||||
|
}
|
||||||
|
|
||||||
|
if(!columns){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (
|
||||||
|
<div className='flex gap-4'>
|
||||||
|
<ReactSortable group={'board-column'} list={columns} setList={setColumnsOrder} className="flex gap-4" ghostClass="opacity-40">
|
||||||
|
{columns?.length >0 && columns.map(column => (
|
||||||
|
<BoardColumn key={column.id} {...column} />
|
||||||
|
)
|
||||||
|
)}
|
||||||
|
</ReactSortable>
|
||||||
|
<NewForm/>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Columns
|
32
task_management_app/src/components/Header.tsx
Normal file
32
task_management_app/src/components/Header.tsx
Normal file
|
@ -0,0 +1,32 @@
|
||||||
|
import { authOptions } from '@/lib/authOptions'
|
||||||
|
import { getServerSession } from 'next-auth'
|
||||||
|
import LogoutButton from './LogoutButton';
|
||||||
|
import LoginButton from './LoginButton';
|
||||||
|
import Link from 'next/link';
|
||||||
|
|
||||||
|
const Header = async () => {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
return (
|
||||||
|
<header className="p-4 border border-b-[#9BBEC8] px-10">
|
||||||
|
<div className='flex justify-between items-center'>
|
||||||
|
<Link href="/" className="logo">Task Management</Link>
|
||||||
|
<div>
|
||||||
|
{session && (
|
||||||
|
<>
|
||||||
|
Hello, {session?.user?.name}
|
||||||
|
<LogoutButton/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
{!session && (
|
||||||
|
<>
|
||||||
|
Not logged in
|
||||||
|
<LoginButton/>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default Header
|
12
task_management_app/src/components/LoginButton.tsx
Normal file
12
task_management_app/src/components/LoginButton.tsx
Normal file
|
@ -0,0 +1,12 @@
|
||||||
|
"use client"
|
||||||
|
import { signIn } from "next-auth/react"
|
||||||
|
|
||||||
|
const LoginButton = () => {
|
||||||
|
return (
|
||||||
|
<button onClick={() => signIn('google')} className='p-2 bg-[#DDF2FD] font-semibold ml-2 rounded-md'>
|
||||||
|
Login
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginButton
|
13
task_management_app/src/components/LogoutButton.tsx
Normal file
13
task_management_app/src/components/LogoutButton.tsx
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
"use client"
|
||||||
|
import { signOut } from "next-auth/react"
|
||||||
|
import { IoLogOutOutline } from "react-icons/io5";
|
||||||
|
|
||||||
|
const LogoutButton = () => {
|
||||||
|
return (
|
||||||
|
<button onClick={() => signOut()} className='p-2 bg-[#DDF2FD] font-semibold ml-2 rounded-md inline-flex items-center gap-2'>
|
||||||
|
Logout <IoLogOutOutline className="text-[18px] font-semibold"/>
|
||||||
|
</button>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LogoutButton
|
36
task_management_app/src/components/forms/NewCardForm.tsx
Normal file
36
task_management_app/src/components/forms/NewCardForm.tsx
Normal file
|
@ -0,0 +1,36 @@
|
||||||
|
"use client"
|
||||||
|
import uniqid from 'uniqid'
|
||||||
|
import { Card, useMutation } from "@/app/liveblocks.config";
|
||||||
|
import { LiveObject } from "@liveblocks/client";
|
||||||
|
import { FormEvent } from "react";
|
||||||
|
|
||||||
|
const NewCardForm = ({columnId}: {columnId: string}) => {
|
||||||
|
const addCard = useMutation(({storage}, cardName) => {
|
||||||
|
return storage.get('cards').push(new LiveObject<Card>({
|
||||||
|
name: cardName,
|
||||||
|
id: uniqid.time(),
|
||||||
|
columnId: columnId,
|
||||||
|
index: 999,
|
||||||
|
}))
|
||||||
|
}, [columnId])
|
||||||
|
|
||||||
|
function handleNewCardFormSubmit(ev: FormEvent){
|
||||||
|
ev.preventDefault();
|
||||||
|
const input = (ev.target as HTMLFormElement).querySelector("input");
|
||||||
|
if(input){
|
||||||
|
const cardName = input?.value;
|
||||||
|
addCard(cardName)
|
||||||
|
input.value='';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleNewCardFormSubmit}>
|
||||||
|
<input type="text" placeholder="card name" className='border my-2 p-2 rounded-sm bg-white'/>
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewCardForm
|
39
task_management_app/src/components/forms/NewForm.tsx
Normal file
39
task_management_app/src/components/forms/NewForm.tsx
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
"use client"
|
||||||
|
import { useMutation} from '@/app/liveblocks.config';
|
||||||
|
import { LiveObject } from '@liveblocks/client';
|
||||||
|
import React, { FormEvent } from 'react'
|
||||||
|
import uniqid from 'uniqid'
|
||||||
|
|
||||||
|
const NewForm = () => {
|
||||||
|
const addColumn = useMutation(({storage}, columnName) => {
|
||||||
|
return storage.get('columns').push(new LiveObject({
|
||||||
|
name: columnName,
|
||||||
|
id: uniqid.time(),
|
||||||
|
index: 9999,
|
||||||
|
}))
|
||||||
|
}, [])
|
||||||
|
|
||||||
|
function handleNewColumn(ev: FormEvent) {
|
||||||
|
ev.preventDefault();
|
||||||
|
const input = (ev.target as HTMLFormElement).querySelector("input");
|
||||||
|
if(input){
|
||||||
|
const columnName = input?.value;
|
||||||
|
addColumn(columnName);
|
||||||
|
input.value='';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form onSubmit={handleNewColumn} className='max-w-xs'>
|
||||||
|
<label className='block'>
|
||||||
|
<span className='block'>Column name:</span>
|
||||||
|
<input type="text" placeholder='New column' className='w-full outline-none p-2 border border-[#164863] rounded-md'/>
|
||||||
|
</label>
|
||||||
|
<button type="submit" className='mt-2 block w-full'>Create column</button>
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewForm
|
31
task_management_app/src/components/forms/NewUserAccess.tsx
Normal file
31
task_management_app/src/components/forms/NewUserAccess.tsx
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { addEmailtoBoard } from "@/app/actions/boardActions";
|
||||||
|
import { useRouter } from "next/navigation";
|
||||||
|
import { useRef } from "react";
|
||||||
|
|
||||||
|
const NewUserAccess = ({boardId}: {boardId:string}) => {
|
||||||
|
const router = useRouter();
|
||||||
|
const inputRef = useRef<HTMLInputElement>(null);
|
||||||
|
async function addEmail(formData: FormData){
|
||||||
|
const email = formData.get('email')?.toString() || '';
|
||||||
|
await addEmailtoBoard(boardId, email);
|
||||||
|
if(inputRef.current){
|
||||||
|
inputRef.current.value = '';
|
||||||
|
}
|
||||||
|
router.refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
return (
|
||||||
|
<form action={addEmail} className="max-w-xs">
|
||||||
|
<h2 className="mb-1 text-sm">Add email</h2>
|
||||||
|
<input ref={inputRef} type="text" placeholder="email@example.com" name="email" className="border p-2 w-full rounded-md"/>
|
||||||
|
<button type="submit" className="w-full mt-2">Save</button>
|
||||||
|
</form>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default NewUserAccess
|
13
task_management_app/src/components/views/LoginView.tsx
Normal file
13
task_management_app/src/components/views/LoginView.tsx
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
"use client"
|
||||||
|
|
||||||
|
import { signIn } from "next-auth/react"
|
||||||
|
|
||||||
|
const LoginView = () => {
|
||||||
|
return (
|
||||||
|
<div className="w-full pt-11 text-center">
|
||||||
|
<button onClick={() => signIn('google')} className="primary">Login</button>
|
||||||
|
</div>
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
export default LoginView
|
14
task_management_app/src/lib/authOptions.ts
Normal file
14
task_management_app/src/lib/authOptions.ts
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
import { MongoDBAdapter } from "@auth/mongodb-adapter"
|
||||||
|
import clientPromise from "@/lib/mongoClient"
|
||||||
|
import GoogleProvider from "next-auth/providers/google";
|
||||||
|
import { AuthOptions } from "next-auth";
|
||||||
|
|
||||||
|
export const authOptions: AuthOptions = {
|
||||||
|
providers: [
|
||||||
|
GoogleProvider({
|
||||||
|
clientId: process.env.GOOGLE_CLIENT_ID as string,
|
||||||
|
clientSecret: process.env.GOOGLE_CLIENT_SECRET as string,
|
||||||
|
})
|
||||||
|
],
|
||||||
|
adapter: MongoDBAdapter(clientPromise),
|
||||||
|
}
|
5
task_management_app/src/lib/liveblocksClient.ts
Normal file
5
task_management_app/src/lib/liveblocksClient.ts
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
import { Liveblocks } from "@liveblocks/node";
|
||||||
|
|
||||||
|
export const liveblocksClient = new Liveblocks({
|
||||||
|
secret: process.env.LIVEBLOCKS_SECRET_KEY || '',
|
||||||
|
});
|
33
task_management_app/src/lib/mongoClient.ts
Normal file
33
task_management_app/src/lib/mongoClient.ts
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
import { MongoClient } from "mongodb";
|
||||||
|
|
||||||
|
if (!process.env.MONGODB_URI) {
|
||||||
|
throw new Error("Please add your Mongo URI to .env.local");
|
||||||
|
}
|
||||||
|
|
||||||
|
const uri: string = process.env.MONGODB_URI;
|
||||||
|
let client: MongoClient;
|
||||||
|
let clientPromise: Promise<MongoClient>;
|
||||||
|
|
||||||
|
if (process.env.NODE_ENV === "development") {
|
||||||
|
// In development mode, use a global variable so that the value
|
||||||
|
// is preserved across module reloads caused by HMR (Hot Module Replacement).
|
||||||
|
|
||||||
|
let globalWithMongoClientPromise = global as typeof globalThis & {
|
||||||
|
_mongoClientPromise: Promise<MongoClient>;
|
||||||
|
};
|
||||||
|
|
||||||
|
if (!globalWithMongoClientPromise._mongoClientPromise) {
|
||||||
|
client = new MongoClient(uri);
|
||||||
|
globalWithMongoClientPromise._mongoClientPromise = client.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
clientPromise = globalWithMongoClientPromise._mongoClientPromise;
|
||||||
|
} else {
|
||||||
|
// In production mode, it's best to not use a global variable.
|
||||||
|
client = new MongoClient(uri);
|
||||||
|
clientPromise = client.connect();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export a module-scoped MongoClient promise. By doing this in a
|
||||||
|
// separate module, the client can be shared across functions.
|
||||||
|
export default clientPromise;
|
7
task_management_app/src/lib/userClient.ts
Normal file
7
task_management_app/src/lib/userClient.ts
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
import { getServerSession } from "next-auth";
|
||||||
|
import { authOptions } from "./authOptions";
|
||||||
|
|
||||||
|
export async function getUserEmail(): Promise<string> {
|
||||||
|
const session = await getServerSession(authOptions);
|
||||||
|
return session?.user?.email || '';
|
||||||
|
}
|
22
task_management_app/tailwind.config.ts
Normal file
22
task_management_app/tailwind.config.ts
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
import type { Config } from "tailwindcss";
|
||||||
|
|
||||||
|
const config: Config = {
|
||||||
|
content: [
|
||||||
|
"./src/pages/**/*.{js,ts,jsx,tsx,mdx}",
|
||||||
|
"./src/components/**/*.{js,ts,jsx,tsx,mdx}",
|
||||||
|
"./src/app/**/*.{js,ts,jsx,tsx,mdx}",
|
||||||
|
],
|
||||||
|
theme: {
|
||||||
|
extend: {
|
||||||
|
backgroundImage: {
|
||||||
|
"gradient-radial": "radial-gradient(var(--tw-gradient-stops))",
|
||||||
|
"gradient-conic":
|
||||||
|
"conic-gradient(from 180deg at 50% 50%, var(--tw-gradient-stops))",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
plugins: [
|
||||||
|
//require('@tailwindcss/forms'),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
export default config;
|
26
task_management_app/tsconfig.json
Normal file
26
task_management_app/tsconfig.json
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
{
|
||||||
|
"compilerOptions": {
|
||||||
|
"lib": ["dom", "dom.iterable", "esnext"],
|
||||||
|
"allowJs": true,
|
||||||
|
"skipLibCheck": true,
|
||||||
|
"strict": true,
|
||||||
|
"noEmit": true,
|
||||||
|
"esModuleInterop": true,
|
||||||
|
"module": "esnext",
|
||||||
|
"moduleResolution": "bundler",
|
||||||
|
"resolveJsonModule": true,
|
||||||
|
"isolatedModules": true,
|
||||||
|
"jsx": "preserve",
|
||||||
|
"incremental": true,
|
||||||
|
"plugins": [
|
||||||
|
{
|
||||||
|
"name": "next"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"paths": {
|
||||||
|
"@/*": ["./src/*"]
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"],
|
||||||
|
"exclude": ["node_modules"]
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue