-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
111 additions
and
197 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
export async function GET(req: Request) { | ||
const endPoint: (string | undefined) = `${process.env.NEXT_PUBLIC_API_BASE_URL}/api/user/get-all` | ||
|
||
console.log('endPoint', endPoint); | ||
console.log('process.env.X_API_KEY', process.env.X_API_KEY); | ||
|
||
|
||
if (endPoint) { | ||
try { | ||
console.log('Fetching Users'); | ||
|
||
const res = await fetch(endPoint, { | ||
headers: { | ||
'Content-Type': 'application/json', // Set the appropriate content type for your request | ||
'x-api-key': process.env.X_API_KEY!, | ||
}, | ||
}); | ||
const data = await res.json(); | ||
return Response.json({ data }) | ||
} catch (error) { | ||
console.error('Error during request:', error); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,89 @@ | ||
"use client"; | ||
import React from 'react'; | ||
|
||
export default function Page(): JSX.Element { | ||
return ( | ||
<div className="w-screen flex justify-center items-center h-screen"> | ||
<h1 className='text-primary'>FlexAuth Dashboard</h1> | ||
</div> | ||
); | ||
import { Loader } from '@/components/custom/Loader'; | ||
import { IUser } from '@/interfaces/IUser'; | ||
import React, { useEffect, useState } from 'react' | ||
import { ColumnDef } from "@tanstack/react-table"; | ||
import { DataTable } from '@/components/ui/data-table'; | ||
|
||
const DashboardPage = () => { | ||
const [users, setUsers] = useState([] as IUser[]) | ||
const [loading, setLoading] = useState(true) | ||
|
||
const getAllUsers = async () => { | ||
try{ | ||
setLoading(true) | ||
const res = await fetch(`${process.env.NEXT_PUBLIC_ENDPOINT}/api/user/get-all`, { | ||
method: 'GET', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
}); | ||
const { data } = await res.json(); | ||
setUsers(data); | ||
} catch (error) { | ||
console.error('Error during POST request:', error); | ||
} | ||
setLoading(false) | ||
} | ||
|
||
const columns: ColumnDef<IUser>[] = [ | ||
{ | ||
accessorKey: "name", | ||
header: "Name", | ||
}, | ||
{ | ||
accessorKey: "email", | ||
header: "Email", | ||
}, | ||
{ | ||
accessorKey: "role", | ||
header: "Role", | ||
}, | ||
{ | ||
accessorKey: "email_verified", | ||
header: "Email Verified", | ||
}, | ||
{ | ||
accessorKey: "is_active", | ||
header: "Active", | ||
}, | ||
{ | ||
accessorKey: "created_at", | ||
header: "Created At", | ||
cell: ({ row }) => { | ||
return ( | ||
<div> | ||
{new Date(parseInt(row.original.created_at.$date.$numberLong)).toLocaleString()} | ||
</div> | ||
) | ||
}, | ||
}, | ||
]; | ||
|
||
useEffect(() => { | ||
getAllUsers() | ||
}, []) | ||
|
||
return ( | ||
<div className='p-6'> | ||
<div> | ||
{ | ||
loading ? | ||
<div className='h-[100vh] flex justify-center items-center'> | ||
<Loader /> | ||
</div> | ||
: <div> | ||
<h1 className='text-3xl text-primary mb-4'>Dashboard</h1> | ||
<DataTable | ||
data={users ? users : []} | ||
columns={columns} | ||
/> | ||
</div> | ||
} | ||
</div> | ||
|
||
</div> | ||
) | ||
} | ||
|
||
export default DashboardPage |