From 5ba5d9f5bbd89555624d31020a5b9261730727ac Mon Sep 17 00:00:00 2001 From: herz Date: Sun, 2 Apr 2023 17:44:54 +0200 Subject: [PATCH] added components --- .../migration.sql | 85 +++++++++++++ prisma/migrations/migration_lock.toml | 3 + prisma/schema.prisma | 16 +++ src/components/Navbar.tsx | 27 ++++ src/components/nim/device/Devices.tsx | 65 ++++++++++ src/pages/dev.tsx | 117 +++--------------- src/pages/nim/manufacturer/index.tsx | 35 ++++++ 7 files changed, 247 insertions(+), 101 deletions(-) create mode 100644 prisma/migrations/20230402154437_added_manuacturer_and_devicetype/migration.sql create mode 100644 prisma/migrations/migration_lock.toml create mode 100644 src/components/Navbar.tsx create mode 100644 src/components/nim/device/Devices.tsx create mode 100644 src/pages/nim/manufacturer/index.tsx diff --git a/prisma/migrations/20230402154437_added_manuacturer_and_devicetype/migration.sql b/prisma/migrations/20230402154437_added_manuacturer_and_devicetype/migration.sql new file mode 100644 index 0000000..36fd6f1 --- /dev/null +++ b/prisma/migrations/20230402154437_added_manuacturer_and_devicetype/migration.sql @@ -0,0 +1,85 @@ +-- CreateTable +CREATE TABLE "Example" ( + "id" TEXT NOT NULL PRIMARY KEY, + "createdAt" DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Account" ( + "id" TEXT NOT NULL PRIMARY KEY, + "userId" TEXT NOT NULL, + "type" TEXT NOT NULL, + "provider" TEXT NOT NULL, + "providerAccountId" TEXT NOT NULL, + "refresh_token" TEXT, + "access_token" TEXT, + "expires_at" INTEGER, + "token_type" TEXT, + "scope" TEXT, + "id_token" TEXT, + "session_state" TEXT, + CONSTRAINT "Account_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Session" ( + "id" TEXT NOT NULL PRIMARY KEY, + "sessionToken" TEXT NOT NULL, + "userId" TEXT NOT NULL, + "expires" DATETIME NOT NULL, + CONSTRAINT "Session_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User" ("id") ON DELETE CASCADE ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "User" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT, + "email" TEXT, + "emailVerified" DATETIME, + "image" TEXT +); + +-- CreateTable +CREATE TABLE "VerificationToken" ( + "identifier" TEXT NOT NULL, + "token" TEXT NOT NULL, + "expires" DATETIME NOT NULL +); + +-- CreateTable +CREATE TABLE "Manufacturer" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL +); + +-- CreateTable +CREATE TABLE "DeviceTypes" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "manufacturerId" TEXT NOT NULL, + CONSTRAINT "DeviceTypes_manufacturerId_fkey" FOREIGN KEY ("manufacturerId") REFERENCES "Manufacturer" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateTable +CREATE TABLE "Device" ( + "id" TEXT NOT NULL PRIMARY KEY, + "name" TEXT NOT NULL, + "deviceTypeId" TEXT NOT NULL, + CONSTRAINT "Device_deviceTypeId_fkey" FOREIGN KEY ("deviceTypeId") REFERENCES "DeviceTypes" ("id") ON DELETE RESTRICT ON UPDATE CASCADE +); + +-- CreateIndex +CREATE UNIQUE INDEX "Account_provider_providerAccountId_key" ON "Account"("provider", "providerAccountId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Session_sessionToken_key" ON "Session"("sessionToken"); + +-- CreateIndex +CREATE UNIQUE INDEX "User_email_key" ON "User"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_token_key" ON "VerificationToken"("token"); + +-- CreateIndex +CREATE UNIQUE INDEX "VerificationToken_identifier_token_key" ON "VerificationToken"("identifier", "token"); diff --git a/prisma/migrations/migration_lock.toml b/prisma/migrations/migration_lock.toml new file mode 100644 index 0000000..e5e5c47 --- /dev/null +++ b/prisma/migrations/migration_lock.toml @@ -0,0 +1,3 @@ +# Please do not edit this file manually +# It should be added in your version-control system (i.e. Git) +provider = "sqlite" \ No newline at end of file diff --git a/prisma/schema.prisma b/prisma/schema.prisma index d06d0da..53b1470 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -65,7 +65,23 @@ model VerificationToken { @@unique([identifier, token]) } +model Manufacturer { + id String @id @default(cuid()) + name String + deviceTypes DeviceTypes[] +} + +model DeviceTypes { + id String @id @default(cuid()) + name String + manufacturerId String + manufacturer Manufacturer @relation(fields: [manufacturerId], references: [id]) + devices Device[] +} + model Device { id String @id @default(cuid()) name String + deviceTypeId String + deviceType DeviceTypes @relation(fields: [deviceTypeId], references: [id]) } diff --git a/src/components/Navbar.tsx b/src/components/Navbar.tsx new file mode 100644 index 0000000..1854a34 --- /dev/null +++ b/src/components/Navbar.tsx @@ -0,0 +1,27 @@ +import { signIn, signOut } from "next-auth/react"; + +const Navbar: React.FC = (props) => { + const sessionData = props.sessionData + return ( +
+
+ +

HerZ NSOT

+
+
+ +
+
+ + +
+
+ ); +}; + +export default Navbar \ No newline at end of file diff --git a/src/components/nim/device/Devices.tsx b/src/components/nim/device/Devices.tsx new file mode 100644 index 0000000..d3094e1 --- /dev/null +++ b/src/components/nim/device/Devices.tsx @@ -0,0 +1,65 @@ +import { api } from "~/utils/api"; +import { useState } from "react"; + + +const Devices: React.FC = (props) => { + const sessionData = props.sessionData + const [newDevice, setNewDevice] = useState(""); + const addDevice = api.device.addDevice.useMutation(); + const device = api.device.getAll.useQuery(); + + + + + return ( +
+

+

+

+ Devices +

+
+ { + !device.data ? "Loading tRPC query..." + : + device.data.map((device) => ( +
+

{device.name}

+
+ )) + } +
+
+

Create Device

+
{ + event.preventDefault(); + addDevice.mutate({ + name: newDevice + }); + setNewDevice(""); + }} + > + setNewDevice(event.target.value)} + /> + +
+
+
+ ); + }; + +export default Devices; \ No newline at end of file diff --git a/src/pages/dev.tsx b/src/pages/dev.tsx index 315a569..016e633 100644 --- a/src/pages/dev.tsx +++ b/src/pages/dev.tsx @@ -1,120 +1,35 @@ import { type NextPage } from "next"; import Head from "next/head"; import Link from "next/link"; -import { signIn, signOut, useSession } from "next-auth/react"; -import { useState } from "react"; -import { api } from "~/utils/api"; +import { useSession } from "next-auth/react"; + + +import Navbar from "~/components/Navbar"; +import Devices from "~/components/nim/device/Devices"; const Home: NextPage = () => { - const hello = api.example.hello.useQuery({ text: "from tRPC" }); - + const { data: sessionData } = useSession(); return ( <> - - Create T3 App + + Dev Page
+ {!sessionData + ? + : + } + {sessionData ? : <>}
- - + +
); }; -export default Home; - -const AuthShowcase: React.FC = () => { - const [newDevice, setNewDevice] = useState(""); - const addDevice = api.device.addDevice.useMutation(); - const device = api.device.getAll.useQuery(); - - const { data: sessionData } = useSession(); - - const { data: secretMessage } = api.example.getSecretMessage.useQuery( - undefined, // no input - { enabled: sessionData?.user !== undefined }, - ); - - - - return ( -
-

- {sessionData && Logged in as {sessionData.user?.name}} - {secretMessage && - {secretMessage}} -

-

- Devices -

-
- { - !device.data ? "Loading tRPC query..." - : - device.data.map((device) => ( -
-

{device.name}

-
- )) - } -
-
-

Create Device

-
{ - event.preventDefault(); - addDevice.mutate({ - name: newDevice - }); - setNewDevice(""); - }} - > - setNewDevice(event.target.value)} - /> - -
-
-
- ); -}; - - -const Navbar: React.FC = () => { - const { data: sessionData } = useSession(); - return ( -
-
- -

HerZ NSOT

-
-
- -
-
- -
-
- ); -} \ No newline at end of file +export default Home; \ No newline at end of file diff --git a/src/pages/nim/manufacturer/index.tsx b/src/pages/nim/manufacturer/index.tsx new file mode 100644 index 0000000..b2bab4a --- /dev/null +++ b/src/pages/nim/manufacturer/index.tsx @@ -0,0 +1,35 @@ +import { type NextPage } from "next"; +import Head from "next/head"; +import Link from "next/link"; +import { useSession } from "next-auth/react"; + + +import Navbar from "~/components/Navbar"; +import Devices from "~/components/nim/device/Devices"; + +const Home: NextPage = () => { + const { data: sessionData } = useSession(); + + return ( + <> + + Manufacturer + + + +
+ {!sessionData + ? + : + } + {sessionData ? : <>} +
+ + +
+
+ + ); +}; + +export default Home; \ No newline at end of file