Skip to content

Commit

Permalink
#93 Adding the basic dashboard and authentication mechanism
Browse files Browse the repository at this point in the history
  • Loading branch information
santthosh committed Jun 30, 2024
1 parent d5a2d1f commit f89ce66
Show file tree
Hide file tree
Showing 5 changed files with 165 additions and 70 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
Warnings:
- You are about to drop the `Account` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Authenticator` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `Session` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `User` table. If the table is not empty, all the data it contains will be lost.
- You are about to drop the `VerificationToken` table. If the table is not empty, all the data it contains will be lost.
*/
-- DropForeignKey
ALTER TABLE "Account" DROP CONSTRAINT "Account_userId_fkey";

-- DropForeignKey
ALTER TABLE "Authenticator" DROP CONSTRAINT "Authenticator_userId_fkey";

-- DropForeignKey
ALTER TABLE "Session" DROP CONSTRAINT "Session_userId_fkey";

-- DropTable
DROP TABLE "Account";

-- DropTable
DROP TABLE "Authenticator";

-- DropTable
DROP TABLE "Session";

-- DropTable
DROP TABLE "User";

-- DropTable
DROP TABLE "VerificationToken";
70 changes: 0 additions & 70 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -139,73 +139,3 @@ model File {
Assistant Assistant? @relation(fields: [assistantId], references: [id])
assistantId String?
}

// NextAuth.js schema
model User {
id String @id @default(cuid())
name String?
email String @unique
emailVerified DateTime?
image String?
accounts Account[]
sessions Session[]
// Optional for WebAuthn support
Authenticator Authenticator[]
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model Account {
userId String
type String
provider String
providerAccountId String
refresh_token String?
access_token String?
expires_at Int?
token_type String?
scope String?
id_token String?
session_state String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
@@id([provider, providerAccountId])
}

model Session {
sessionToken String @unique
userId String
expires DateTime
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
}

model VerificationToken {
identifier String
token String
expires DateTime
@@id([identifier, token])
}

// Optional for WebAuthn support
model Authenticator {
id String @id @default(cuid())
credentialID String @unique
userId String
providerAccountId String
credentialPublicKey String
counter Int
credentialDeviceType String
credentialBackedUp Boolean
transports String?
user User @relation(fields: [userId], references: [id], onDelete: Cascade)
}
63 changes: 63 additions & 0 deletions src/app/admin/dashboard/AssistantMetrics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import prisma from '@/app/api/utils/prisma';
import { Card } from 'flowbite-react';

export default function AssistantMetrics() {
const getAssistantCount = async function() {
let total = await prisma.assistant.aggregate({
_count: {
id: true
}
})

return total._count.id
}

const getThreadCount = async function() {
let total = await prisma.thread.aggregate({
_count: {
id: true
}
})

return total._count.id
}

const getMessageCount = async function() {
let total = await prisma.message.aggregate({
_count: {
id: true
}
})

return total._count.id
}

return (
<div className={'grid xs:grid-flow-row sm:grid-flow-col gap-4'}>
<Card className="flex flex-auto">
<h5 className="text-lg tracking-tight text-gray-400 dark:text-white">
Assistants
</h5>
<p className="text-7xl text-gray-700 dark:text-gray-400">
{getAssistantCount()}
</p>
</Card>
<Card className="flex flex-auto">
<h5 className="text-lg tracking-tight text-gray-400 dark:text-white">
Threads
</h5>
<p className="text-7xl text-gray-700 dark:text-gray-400">
{getThreadCount()}
</p>
</Card>
<Card className="flex flex-auto">
<h5 className="text-lg tracking-tight text-gray-400 dark:text-white">
Messages
</h5>
<p className="text-7xl text-gray-700 dark:text-gray-400">
{getMessageCount()}
</p>
</Card>
</div>
)
}
55 changes: 55 additions & 0 deletions src/app/admin/dashboard/UserMetrics.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
import prisma from '@/app/api/utils/prisma';
import { Card } from 'flowbite-react';

export default function UserMetrics() {
const getUserCount = async function() {
let total = await prisma.organization.aggregate({
where: {
ownerType: {
in: ['personal'],
},
},
_count: {
owner: true
}
})

return total._count.owner
}

const getOrganizationCount = async function() {
let total = await prisma.organization.aggregate({
where: {
ownerType: {
notIn: ['personal'],
},
},
_count: {
owner: true
}
})

return total._count.owner
}

return (
<div className={'grid xs:grid-flow-row sm:grid-flow-col gap-4'}>
<Card className="flex flex-auto">
<h5 className="text-lg tracking-tight text-gray-400 dark:text-white">
Users
</h5>
<p className="text-7xl text-gray-700 dark:text-gray-400">
{getUserCount()}
</p>
</Card>
<Card className="flex flex-auto">
<h5 className="text-lg tracking-tight text-gray-400 dark:text-white">
Organizations
</h5>
<p className="text-7xl text-gray-700 dark:text-gray-400">
{getOrganizationCount()}
</p>
</Card>
</div>
)
}
14 changes: 14 additions & 0 deletions src/app/admin/dashboard/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import React from 'react';
import AssistantMetrics from '@/app/admin/dashboard/AssistantMetrics';
import UserMetrics from '@/app/admin/dashboard/UserMetrics';

export default function Dashboard() {
return (
Expand All @@ -7,6 +9,18 @@ export default function Dashboard() {
<p className={'pb-4 text-sm text-gray-400'}>
Analytics on your Assistants Hub instance
</p>
<div className={'pt-4'}>
<div className={'pb-4 text-xl text-gray-400'}>
Assistant Metrics
</div>
<AssistantMetrics />
</div>
<div className={'pt-4'}>
<div className={'pb-4 text-xl text-gray-400'}>
User Metrics
</div>
<UserMetrics />
</div>
</div>
);
}

0 comments on commit f89ce66

Please sign in to comment.