Skip to content

Commit

Permalink
Feat/newproject (#11)
Browse files Browse the repository at this point in the history
* added basic authsch login

* new project page added

---------

Co-authored-by: Bujdosó Gergő <bujgergo@gmail.com>
  • Loading branch information
IvnDmnks and FearsomeRover authored Oct 11, 2024
1 parent a6a790b commit 6818e96
Show file tree
Hide file tree
Showing 11 changed files with 398 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@
# Prisma supports the native connection string format for PostgreSQL, MySQL, SQLite, SQL Server, MongoDB and CockroachDB.
# See the documentation for all the connection string options: https://pris.ly/d/connection-strings

DATABASE_URL="postgresql://johndoe:randompassword@localhost:5432/mydb?schema=public"
DATABASE_URL="postgresql://postgres:postgres@localhost:5432/mydb?schema=public"
50 changes: 50 additions & 0 deletions apps/backend/prisma/migrations/20241011172547_/migration.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
-- CreateEnum
CREATE TYPE "Role" AS ENUM ('ADMIN', 'USER');

-- AlterTable
ALTER TABLE "User" ADD COLUMN "role" "Role" NOT NULL DEFAULT 'USER';

-- CreateTable
CREATE TABLE "Projekt" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT NOT NULL,
"userId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Projekt_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Sprint" (
"id" SERIAL NOT NULL,
"name" TEXT NOT NULL,
"startDate" TIMESTAMP(3) NOT NULL,
"endDate" TIMESTAMP(3) NOT NULL,

CONSTRAINT "Sprint_pkey" PRIMARY KEY ("id")
);

-- CreateTable
CREATE TABLE "Tasks" (
"id" SERIAL NOT NULL,
"description" TEXT NOT NULL,
"sprintId" INTEGER NOT NULL,
"userId" INTEGER NOT NULL,
"projektId" INTEGER NOT NULL,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,

CONSTRAINT "Tasks_pkey" PRIMARY KEY ("id")
);

-- AddForeignKey
ALTER TABLE "Projekt" ADD CONSTRAINT "Projekt_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_sprintId_fkey" FOREIGN KEY ("sprintId") REFERENCES "Sprint"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE RESTRICT ON UPDATE CASCADE;

-- AddForeignKey
ALTER TABLE "Tasks" ADD CONSTRAINT "Tasks_projektId_fkey" FOREIGN KEY ("projektId") REFERENCES "Projekt"("id") ON DELETE RESTRICT ON UPDATE CASCADE;
1 change: 1 addition & 0 deletions apps/frontend/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
BACKEND_URL= https://localhost:3001
1 change: 1 addition & 0 deletions apps/frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
"lint": "next lint"
},
"dependencies": {
"axios": "^1.7.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"frontend": "file:",
Expand Down
9 changes: 9 additions & 0 deletions apps/frontend/src/app/newproject/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import SprintLogin from '../../components/NewProject';

export default function Home() {
return (
<main className='flex items-center justify-center bg-page-bg-color'>
<SprintLogin />
</main>
);
}
84 changes: 84 additions & 0 deletions apps/frontend/src/components/NewProject.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
'use client';
import { FormEvent, useState } from 'react';

import api from '../lib/axiosConfig';
import { Footer } from './Footer';
import Navbar from './Navbar';

export default function NewProject() {
const [formData, setFormData] = useState({
name: '',
description: '',
});

const [errorMessage, setErrorMessage] = useState<string | null>(null);

const handleChange = (event: { target: { name: any; value: any } }) => {
setFormData({ ...formData, [event.target.name]: event.target.value });
console.log('asda');
};

const projectFormState = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault();
console.log(formData);
if (!formData.name || !formData.description) {
setErrorMessage('Incomplete Row(s)');
return;
}

try {
await api('/project', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
data: JSON.stringify(formData),
});
} catch (error) {
console.log((error as any).message);
}
};

return (
<div className='w-3/5 flex flex-col justify-center px-8 py-8 mx-auto md:h-screen lg:py-0'>
<Navbar />
<div className='p-6 space-y-4 md:space-y-6 sm:p-8 w-full'>
<h1 className='text-xl font-bold leading-tight tracking-tight text-text-color-h1 md:text-4xl dark:text-bg-color2 w-full text-center'>
Új Projekt Létrehozása
</h1>
{errorMessage && <p className='text-red-500'>{errorMessage}</p>}
<form onSubmit={projectFormState}>
<div className='mb-6'>
<label className='block mb-2 text-m font-medium text-text-color dark:text-bg-color2'>Projekt név</label>
<input
onChange={handleChange}
type='text'
id='name'
name='name'
className='bg-bg-color2 border border-gray-300 text-white sm:text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-bg-color2 dark:focus:ring-blue-500 dark:focus:border-blue-500'
/>
</div>
<div className='mb-10'>
<label className='block mb-2 text-m font-medium text-text-color dark:text-bg-color2'>Leírás</label>
<textarea
onChange={handleChange}
name='description'
id='description'
className='w-full h-60 bg-bg-color2 border border-gray-300 text-white sm:text-sm rounded-lg block p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-bg-color2 dark:focus:ring-blue-500 dark:focus:border-blue-500'
/>
</div>

<div className='justify-center flex'>
<button
type='submit'
className='w-1/2 border font-semibold text-text-color rounded-lg text-sm px-5 py-2.5 text-center border-[#8b97a4] hover:border-text-color hover:bg-[#2c3540] focus:ring-4 '
>
Létrehozás
</button>
</div>
</form>
</div>
<a href='https://github.com/kir-dev/sprint-review-app' target='_blank' rel='noreferrer'>
<Footer />
</a>
</div>
);
}
7 changes: 4 additions & 3 deletions apps/frontend/src/components/SprintRegistration.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
'use client';
import { useState } from 'react';

import api from '../lib/axiosConfig';
import { Footer } from './Footer';

export default function RegistrationForm() {
Expand Down Expand Up @@ -38,13 +39,13 @@ export default function RegistrationForm() {
}

try {
const response = await fetch('http://localhost:3001/user', {
const response = await api('/user', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(formData),
data: JSON.stringify(formData),
});

if (!response.ok) {
if (!response.status) {
throw new Error(`A regisztráció nem sikerült. hibakód: ${response.status}`);
}

Expand Down
6 changes: 6 additions & 0 deletions apps/frontend/src/lib/axiosConfig.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import axios from 'axios';

const api = axios.create({
baseURL: process.env.BACKEND_URL,
});
export default api;
Loading

0 comments on commit 6818e96

Please sign in to comment.