diff --git a/prisma/migrations/20231003063648_profile_and_img/migration.sql b/prisma/migrations/20231003063648_profile_and_img/migration.sql new file mode 100644 index 00000000..d4aa8505 --- /dev/null +++ b/prisma/migrations/20231003063648_profile_and_img/migration.sql @@ -0,0 +1,41 @@ +-- CreateTable +CREATE TABLE "Profile" ( + "id" TEXT NOT NULL, + "name" TEXT NOT NULL, + "email" TEXT NOT NULL, + "alamat" TEXT NOT NULL, + "jenisKelamin" TEXT NOT NULL, + "active" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "userId" TEXT, + "imagesId" TEXT, + + CONSTRAINT "Profile_pkey" PRIMARY KEY ("id") +); + +-- CreateTable +CREATE TABLE "Images" ( + "id" TEXT NOT NULL, + "url" TEXT NOT NULL, + "active" BOOLEAN NOT NULL DEFAULT true, + "createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + "updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP, + + CONSTRAINT "Images_pkey" PRIMARY KEY ("id") +); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile_email_key" ON "Profile"("email"); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile_userId_key" ON "Profile"("userId"); + +-- CreateIndex +CREATE UNIQUE INDEX "Profile_imagesId_key" ON "Profile"("imagesId"); + +-- AddForeignKey +ALTER TABLE "Profile" ADD CONSTRAINT "Profile_userId_fkey" FOREIGN KEY ("userId") REFERENCES "User"("id") ON DELETE SET NULL ON UPDATE CASCADE; + +-- AddForeignKey +ALTER TABLE "Profile" ADD CONSTRAINT "Profile_imagesId_fkey" FOREIGN KEY ("imagesId") REFERENCES "Images"("id") ON DELETE SET NULL ON UPDATE CASCADE; diff --git a/prisma/schema.prisma b/prisma/schema.prisma index 9fd28852..e4edf771 100644 --- a/prisma/schema.prisma +++ b/prisma/schema.prisma @@ -9,7 +9,7 @@ datasource db { provider = "postgresql" url = env("DATABASE_URL") } - + model User { id String @id @default(cuid()) username String @unique @@ -20,6 +20,7 @@ model User { MasterUserRole MasterUserRole @relation(fields: [masterUserRoleId], references: [id]) masterUserRoleId String @default("1") UserSession UserSession? + Profile Profile? } model MasterUserRole { @@ -41,3 +42,27 @@ model UserSession { User User @relation(fields: [userId], references: [id]) userId String @unique } + +model Profile { + id String @id @default(cuid()) + name String + email String @unique + alamat String + jenisKelamin String + active Boolean @default(true) + createdAt DateTime @default(now()) + updatedAt DateTime @default(now()) @updatedAt + User User? @relation(fields: [userId], references: [id]) + userId String? @unique + ImageProfile Images? @relation(fields: [imagesId], references: [id]) + imagesId String? @unique +} + +model Images { + id String @id @default(cuid()) + url String + active Boolean @default(true) + createdAt DateTime @default(now()) + updatedAt DateTime @default(now()) @updatedAt + Profile Profile? +} diff --git a/public/aset/avatar.png b/public/aset/avatar.png new file mode 100644 index 00000000..20e377a6 Binary files /dev/null and b/public/aset/avatar.png differ diff --git a/public/img/logo.png b/public/aset/logo.png similarity index 100% rename from public/img/logo.png rename to public/aset/logo.png diff --git a/src/app/api/profile/create/route.ts b/src/app/api/profile/create/route.ts new file mode 100644 index 00000000..6f984be7 --- /dev/null +++ b/src/app/api/profile/create/route.ts @@ -0,0 +1,25 @@ +import { myConsole } from "@/app/fun/my_console"; +import prisma from "@/app/lib/prisma"; +import { NextResponse } from "next/server"; + +export async function POST(req: Request) { + if (req.method === "POST") { + const body = await req.json(); + myConsole(body); + + const data = await prisma.profile.create({ + data: { + userId: body.userId, + name: body.name, + email: body.email, + alamat: body.alamat, + jenisKelamin: body.jenisKelamin, + }, + }); + + if (data) return NextResponse.json({ status: 201 }); + + return NextResponse.json({ success: true }); + } + return NextResponse.json({ success: false }); +} diff --git a/src/app/dev/home/layout.tsx b/src/app/dev/home/layout.tsx new file mode 100644 index 00000000..6d14346a --- /dev/null +++ b/src/app/dev/home/layout.tsx @@ -0,0 +1,9 @@ +import { HomeLayout } from "@/app_modules/home"; + +export default async function Layout({children}: {children: any}) { + return <> + {children} + + + +} \ No newline at end of file diff --git a/src/app/dev/home/page.tsx b/src/app/dev/home/page.tsx index ab5679e5..ce7a8440 100644 --- a/src/app/dev/home/page.tsx +++ b/src/app/dev/home/page.tsx @@ -14,7 +14,7 @@ export default async function Page() { // }) // ); - if (!c?.value) return redirect("/dev/auth/login"); + // if (!c?.value) return redirect("/dev/auth/login"); return ( <> diff --git a/src/app/dev/katalog/profile/create/layout.tsx b/src/app/dev/katalog/profile/create/layout.tsx new file mode 100644 index 00000000..30c363ec --- /dev/null +++ b/src/app/dev/katalog/profile/create/layout.tsx @@ -0,0 +1,9 @@ +import { ProfileLayout } from "@/app_modules/katalog/profile"; + +export default function Layout({ children }: { children: any }) { + return ( + <> + {children} + + ); +} diff --git a/src/app/dev/katalog/profile/create/page.tsx b/src/app/dev/katalog/profile/create/page.tsx new file mode 100644 index 00000000..97c50e37 --- /dev/null +++ b/src/app/dev/katalog/profile/create/page.tsx @@ -0,0 +1,7 @@ +import { CreateProfile } from "@/app_modules/katalog/profile"; + +export default async function Page() { + return <> + + +} \ No newline at end of file diff --git a/src/app/dev/katalog/view/layout.tsx b/src/app/dev/katalog/view/layout.tsx new file mode 100644 index 00000000..034b9257 --- /dev/null +++ b/src/app/dev/katalog/view/layout.tsx @@ -0,0 +1,9 @@ +import { KatalogLayout } from "@/app_modules/katalog/view"; + +export default async function Layout({ children }: { children: any }) { + return ( + <> + {children} + + ); +} diff --git a/src/app/dev/katalog/view/page.tsx b/src/app/dev/katalog/view/page.tsx new file mode 100644 index 00000000..5463ee42 --- /dev/null +++ b/src/app/dev/katalog/view/page.tsx @@ -0,0 +1,7 @@ +import { KatalogView } from "@/app_modules/katalog/view"; + +export default async function Page() { + return <> + + +} \ No newline at end of file diff --git a/src/app/lib/api.ts b/src/app/lib/api.ts index 72d6b4a8..30855752 100644 --- a/src/app/lib/api.ts +++ b/src/app/lib/api.ts @@ -6,4 +6,7 @@ export const ApiHipmi = { validasi: "/api/auth/validasi", register: "/api/auth/register", logout: "/api/auth/logout", + + //Profile + create_profile: "/api/profile/create" }; diff --git a/src/app_modules/auth/login/view.tsx b/src/app_modules/auth/login/view.tsx index fe2c12ba..1d85d77c 100644 --- a/src/app_modules/auth/login/view.tsx +++ b/src/app_modules/auth/login/view.tsx @@ -64,34 +64,35 @@ export default function Login() { align={"center"} gap={"lg"} > - <> - - Login + + Login - { - setNomor(val.target.value); - }} - /> + { + setNomor(val.target.value); + }} + /> - - + ); diff --git a/src/app_modules/auth/logout/view.tsx b/src/app_modules/auth/logout/view.tsx index 1c6e3630..9da7b017 100644 --- a/src/app_modules/auth/logout/view.tsx +++ b/src/app_modules/auth/logout/view.tsx @@ -1,15 +1,20 @@ "use client"; import { myConsole } from "@/app/fun/my_console"; import { ApiHipmi } from "@/app/lib/api"; -import { Button } from "@mantine/core"; +import { ActionIcon, Button } from "@mantine/core"; import { useRouter } from "next/navigation"; import { useAtom } from "jotai"; import { gs_nomor, gs_otp } from "../state/state"; +import { IconLogout } from "@tabler/icons-react"; +import { Warna } from "@/app/lib/warna"; +import { gs_token } from "@/app_modules/home/state/global_state"; export default function Logout() { const router = useRouter(); const [nomor, setnomor] = useAtom(gs_nomor); const [code, setCode] = useAtom(gs_otp); + const [token, setToken] = useAtom(gs_token); + const onLogout = async () => { // MyConsole("keluar"); @@ -20,6 +25,7 @@ export default function Logout() { if (val.status == 200) { setnomor(null); setCode(null); + setToken(null) return router.push("/dev/auth/login"); } @@ -28,9 +34,9 @@ export default function Logout() { return ( <> - + + onLogout()}/> + ); } diff --git a/src/app_modules/auth/register/view.tsx b/src/app_modules/auth/register/view.tsx index 77138810..7a416909 100644 --- a/src/app_modules/auth/register/view.tsx +++ b/src/app_modules/auth/register/view.tsx @@ -60,6 +60,7 @@ export default function Register() { { @@ -70,6 +71,8 @@ export default function Register() { Nomor : {nomor}