first commit
This commit is contained in:
commit
cf13141cb2
41
.gitignore
vendored
Normal file
41
.gitignore
vendored
Normal file
@ -0,0 +1,41 @@
|
||||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/.pnp
|
||||
.pnp.*
|
||||
.yarn/*
|
||||
!.yarn/patches
|
||||
!.yarn/plugins
|
||||
!.yarn/releases
|
||||
!.yarn/versions
|
||||
|
||||
# testing
|
||||
/coverage
|
||||
|
||||
# next.js
|
||||
/.next/
|
||||
/out/
|
||||
|
||||
# production
|
||||
/build
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
*.pem
|
||||
|
||||
# debug
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
.pnpm-debug.log*
|
||||
|
||||
# env files (can opt-in for committing if needed)
|
||||
.env*
|
||||
|
||||
# vercel
|
||||
.vercel
|
||||
|
||||
# typescript
|
||||
*.tsbuildinfo
|
||||
next-env.d.ts
|
36
README.md
Normal file
36
README.md
Normal file
@ -0,0 +1,36 @@
|
||||
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
|
||||
|
||||
## Getting Started
|
||||
|
||||
First, run the development server:
|
||||
|
||||
```bash
|
||||
npm run dev
|
||||
# or
|
||||
yarn dev
|
||||
# or
|
||||
pnpm dev
|
||||
# or
|
||||
bun dev
|
||||
```
|
||||
|
||||
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
|
||||
|
||||
You can start editing the page by modifying `app/page.js`. The page auto-updates as you edit the file.
|
||||
|
||||
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
|
||||
|
||||
## Learn More
|
||||
|
||||
To learn more about Next.js, take a look at the following resources:
|
||||
|
||||
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
|
||||
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
|
||||
|
||||
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
|
||||
|
||||
## Deploy on Vercel
|
||||
|
||||
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
|
||||
|
||||
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.
|
14
eslint.config.mjs
Normal file
14
eslint.config.mjs
Normal file
@ -0,0 +1,14 @@
|
||||
import { dirname } from "path";
|
||||
import { fileURLToPath } from "url";
|
||||
import { FlatCompat } from "@eslint/eslintrc";
|
||||
|
||||
const __filename = fileURLToPath(import.meta.url);
|
||||
const __dirname = dirname(__filename);
|
||||
|
||||
const compat = new FlatCompat({
|
||||
baseDirectory: __dirname,
|
||||
});
|
||||
|
||||
const eslintConfig = [...compat.extends("next/core-web-vitals")];
|
||||
|
||||
export default eslintConfig;
|
7
jsconfig.json
Normal file
7
jsconfig.json
Normal file
@ -0,0 +1,7 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"paths": {
|
||||
"@/*": ["./src/*"]
|
||||
}
|
||||
}
|
||||
}
|
4
next.config.mjs
Normal file
4
next.config.mjs
Normal file
@ -0,0 +1,4 @@
|
||||
/** @type {import('next').NextConfig} */
|
||||
const nextConfig = {};
|
||||
|
||||
export default nextConfig;
|
5698
package-lock.json
generated
Normal file
5698
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
25
package.json
Normal file
25
package.json
Normal file
@ -0,0 +1,25 @@
|
||||
{
|
||||
"name": "fspl-hr--employees-platform",
|
||||
"version": "0.1.0",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"dev": "next dev --turbopack",
|
||||
"build": "next build",
|
||||
"start": "next start",
|
||||
"lint": "next lint"
|
||||
},
|
||||
"dependencies": {
|
||||
"@tailwindcss/postcss": "^4.1.3",
|
||||
"appwrite": "^17.0.1",
|
||||
"next": "15.2.4",
|
||||
"postcss": "^8.5.3",
|
||||
"react": "^19.0.0",
|
||||
"react-dom": "^19.0.0",
|
||||
"tailwindcss": "^4.1.3"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/eslintrc": "^3",
|
||||
"eslint": "^9",
|
||||
"eslint-config-next": "15.2.4"
|
||||
}
|
||||
}
|
6
postcss.config.mjs
Normal file
6
postcss.config.mjs
Normal file
@ -0,0 +1,6 @@
|
||||
const config = {
|
||||
plugins: {
|
||||
"@tailwindcss/postcss": {},
|
||||
},
|
||||
};
|
||||
export default config;
|
1
public/file.svg
Normal file
1
public/file.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg"><path d="M14.5 13.5V5.41a1 1 0 0 0-.3-.7L9.8.29A1 1 0 0 0 9.08 0H1.5v13.5A2.5 2.5 0 0 0 4 16h8a2.5 2.5 0 0 0 2.5-2.5m-1.5 0v-7H8v-5H3v12a1 1 0 0 0 1 1h8a1 1 0 0 0 1-1M9.5 5V2.12L12.38 5zM5.13 5h-.62v1.25h2.12V5zm-.62 3h7.12v1.25H4.5zm.62 3h-.62v1.25h7.12V11z" clip-rule="evenodd" fill="#666" fill-rule="evenodd"/></svg>
|
After Width: | Height: | Size: 391 B |
1
public/globe.svg
Normal file
1
public/globe.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><g clip-path="url(#a)"><path fill-rule="evenodd" clip-rule="evenodd" d="M10.27 14.1a6.5 6.5 0 0 0 3.67-3.45q-1.24.21-2.7.34-.31 1.83-.97 3.1M8 16A8 8 0 1 0 8 0a8 8 0 0 0 0 16m.48-1.52a7 7 0 0 1-.96 0H7.5a4 4 0 0 1-.84-1.32q-.38-.89-.63-2.08a40 40 0 0 0 3.92 0q-.25 1.2-.63 2.08a4 4 0 0 1-.84 1.31zm2.94-4.76q1.66-.15 2.95-.43a7 7 0 0 0 0-2.58q-1.3-.27-2.95-.43a18 18 0 0 1 0 3.44m-1.27-3.54a17 17 0 0 1 0 3.64 39 39 0 0 1-4.3 0 17 17 0 0 1 0-3.64 39 39 0 0 1 4.3 0m1.1-1.17q1.45.13 2.69.34a6.5 6.5 0 0 0-3.67-3.44q.65 1.26.98 3.1M8.48 1.5l.01.02q.41.37.84 1.31.38.89.63 2.08a40 40 0 0 0-3.92 0q.25-1.2.63-2.08a4 4 0 0 1 .85-1.32 7 7 0 0 1 .96 0m-2.75.4a6.5 6.5 0 0 0-3.67 3.44 29 29 0 0 1 2.7-.34q.31-1.83.97-3.1M4.58 6.28q-1.66.16-2.95.43a7 7 0 0 0 0 2.58q1.3.27 2.95.43a18 18 0 0 1 0-3.44m.17 4.71q-1.45-.12-2.69-.34a6.5 6.5 0 0 0 3.67 3.44q-.65-1.27-.98-3.1" fill="#666"/></g><defs><clipPath id="a"><path fill="#fff" d="M0 0h16v16H0z"/></clipPath></defs></svg>
|
After Width: | Height: | Size: 1.0 KiB |
1
public/next.svg
Normal file
1
public/next.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 394 80"><path fill="#000" d="M262 0h68.5v12.7h-27.2v66.6h-13.6V12.7H262V0ZM149 0v12.7H94v20.4h44.3v12.6H94v21h55v12.6H80.5V0h68.7zm34.3 0h-17.8l63.8 79.4h17.9l-32-39.7 32-39.6h-17.9l-23 28.6-23-28.6zm18.3 56.7-9-11-27.1 33.7h17.8l18.3-22.7z"/><path fill="#000" d="M81 79.3 17 0H0v79.3h13.6V17l50.2 62.3H81Zm252.6-.4c-1 0-1.8-.4-2.5-1s-1.1-1.6-1.1-2.6.3-1.8 1-2.5 1.6-1 2.6-1 1.8.3 2.5 1a3.4 3.4 0 0 1 .6 4.3 3.7 3.7 0 0 1-3 1.8zm23.2-33.5h6v23.3c0 2.1-.4 4-1.3 5.5a9.1 9.1 0 0 1-3.8 3.5c-1.6.8-3.5 1.3-5.7 1.3-2 0-3.7-.4-5.3-1s-2.8-1.8-3.7-3.2c-.9-1.3-1.4-3-1.4-5h6c.1.8.3 1.6.7 2.2s1 1.2 1.6 1.5c.7.4 1.5.5 2.4.5 1 0 1.8-.2 2.4-.6a4 4 0 0 0 1.6-1.8c.3-.8.5-1.8.5-3V45.5zm30.9 9.1a4.4 4.4 0 0 0-2-3.3 7.5 7.5 0 0 0-4.3-1.1c-1.3 0-2.4.2-3.3.5-.9.4-1.6 1-2 1.6a3.5 3.5 0 0 0-.3 4c.3.5.7.9 1.3 1.2l1.8 1 2 .5 3.2.8c1.3.3 2.5.7 3.7 1.2a13 13 0 0 1 3.2 1.8 8.1 8.1 0 0 1 3 6.5c0 2-.5 3.7-1.5 5.1a10 10 0 0 1-4.4 3.5c-1.8.8-4.1 1.2-6.8 1.2-2.6 0-4.9-.4-6.8-1.2-2-.8-3.4-2-4.5-3.5a10 10 0 0 1-1.7-5.6h6a5 5 0 0 0 3.5 4.6c1 .4 2.2.6 3.4.6 1.3 0 2.5-.2 3.5-.6 1-.4 1.8-1 2.4-1.7a4 4 0 0 0 .8-2.4c0-.9-.2-1.6-.7-2.2a11 11 0 0 0-2.1-1.4l-3.2-1-3.8-1c-2.8-.7-5-1.7-6.6-3.2a7.2 7.2 0 0 1-2.4-5.7 8 8 0 0 1 1.7-5 10 10 0 0 1 4.3-3.5c2-.8 4-1.2 6.4-1.2 2.3 0 4.4.4 6.2 1.2 1.8.8 3.2 2 4.3 3.4 1 1.4 1.5 3 1.5 5h-5.8z"/></svg>
|
After Width: | Height: | Size: 1.3 KiB |
1
public/vercel.svg
Normal file
1
public/vercel.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1155 1000"><path d="m577.3 0 577.4 1000H0z" fill="#fff"/></svg>
|
After Width: | Height: | Size: 128 B |
1
public/window.svg
Normal file
1
public/window.svg
Normal file
@ -0,0 +1 @@
|
||||
<svg fill="none" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 16 16"><path fill-rule="evenodd" clip-rule="evenodd" d="M1.5 2.5h13v10a1 1 0 0 1-1 1h-11a1 1 0 0 1-1-1zM0 1h16v11.5a2.5 2.5 0 0 1-2.5 2.5h-11A2.5 2.5 0 0 1 0 12.5zm3.75 4.5a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5M7 4.75a.75.75 0 1 1-1.5 0 .75.75 0 0 1 1.5 0m1.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5" fill="#666"/></svg>
|
After Width: | Height: | Size: 385 B |
16
src/app/ClientLayout.js
Normal file
16
src/app/ClientLayout.js
Normal file
@ -0,0 +1,16 @@
|
||||
'use client';
|
||||
import Sidebar from "./components/Sidebar";
|
||||
import Navbar from "./components/Navbar";
|
||||
|
||||
export default function ClientLayout({ children }) {
|
||||
return (
|
||||
<div className="flex h-screen">
|
||||
<Sidebar />
|
||||
<div className="flex-1 flex flex-col">
|
||||
<Navbar />
|
||||
<main className="p-4 overflow-y-auto">{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
18
src/app/admin/layout.js
Normal file
18
src/app/admin/layout.js
Normal file
@ -0,0 +1,18 @@
|
||||
// app/admin/members/layout.js
|
||||
|
||||
export const metadata = {
|
||||
title: "Manage Members | Admin",
|
||||
description: "Add or view team members in the portal",
|
||||
};
|
||||
|
||||
export default function AdminLayout({ children }) {
|
||||
return (
|
||||
<section className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-4">Team Members</h1>
|
||||
<div className="bg-white shadow-md rounded-lg p-4">
|
||||
{children}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
18
src/app/admin/members/layout.js
Normal file
18
src/app/admin/members/layout.js
Normal file
@ -0,0 +1,18 @@
|
||||
// app/admin/members/layout.js
|
||||
|
||||
export const metadata = {
|
||||
title: "Manage Members | Admin",
|
||||
description: "Add or view team members in the portal",
|
||||
};
|
||||
|
||||
export default function MembersLayout({ children }) {
|
||||
return (
|
||||
<section className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-4">Team Members</h1>
|
||||
<div className="bg-white shadow-md rounded-lg p-4">
|
||||
{children}
|
||||
</div>
|
||||
</section>
|
||||
);
|
||||
}
|
||||
|
14
src/app/admin/members/page.js
Normal file
14
src/app/admin/members/page.js
Normal file
@ -0,0 +1,14 @@
|
||||
'use client';
|
||||
|
||||
import MemberForm from "../../components/MemberForm";
|
||||
import MemberList from "../../components/MemberList";
|
||||
|
||||
export default function AdminMembersPage() {
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-6">Manage Members</h1>
|
||||
<MemberForm />
|
||||
<MemberList />
|
||||
</div>
|
||||
);
|
||||
}
|
74
src/app/admin/page.js
Normal file
74
src/app/admin/page.js
Normal file
@ -0,0 +1,74 @@
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import Link from "next/link";
|
||||
import { databases } from "../lib/appwrite";
|
||||
|
||||
const DB_ID = process.env.NEXT_PUBLIC_APPWRITE_DB_ID;
|
||||
const MEMBERS_COLLECTION_ID = "members";
|
||||
const ASSIGNMENTS_COLLECTION_ID = "assignments";
|
||||
|
||||
export default function AdminDashboard() {
|
||||
const [stats, setStats] = useState({
|
||||
totalMembers: 0,
|
||||
pendingAssignments: 0,
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
const fetchStats = async () => {
|
||||
try {
|
||||
const members = await databases.listDocuments(DB_ID, MEMBERS_COLLECTION_ID);
|
||||
const assignments = await databases.listDocuments(DB_ID, ASSIGNMENTS_COLLECTION_ID);
|
||||
|
||||
const pending = assignments.documents.filter(
|
||||
(a) => !a.submitted || a.submittedLate
|
||||
).length;
|
||||
|
||||
setStats({
|
||||
totalMembers: members.total,
|
||||
pendingAssignments: pending,
|
||||
});
|
||||
} catch (error) {
|
||||
console.error("Failed to fetch stats", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchStats();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-3xl font-bold mb-6">Welcome, Admin 👋</h1>
|
||||
|
||||
{/* Stats Section */}
|
||||
<div className="grid grid-cols-1 sm:grid-cols-2 gap-6 mb-8">
|
||||
<div className="bg-white p-4 shadow rounded-lg">
|
||||
<p className="text-gray-500">Total Members</p>
|
||||
<h2 className="text-2xl font-bold">{stats.totalMembers}</h2>
|
||||
</div>
|
||||
|
||||
<div className="bg-white p-4 shadow rounded-lg">
|
||||
<p className="text-gray-500">Pending Assignments</p>
|
||||
<h2 className="text-2xl font-bold">{stats.pendingAssignments}</h2>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Navigation Buttons */}
|
||||
<div className="space-y-4">
|
||||
<Link
|
||||
href="/admin/members"
|
||||
className="block bg-blue-600 hover:bg-blue-700 text-white font-semibold px-4 py-2 rounded"
|
||||
>
|
||||
➕ Add or View Members
|
||||
</Link>
|
||||
|
||||
<Link
|
||||
href="/assignments"
|
||||
className="block bg-green-600 hover:bg-green-700 text-white font-semibold px-4 py-2 rounded"
|
||||
>
|
||||
📋 Manage Assignments
|
||||
</Link>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
92
src/app/assignments/page.js
Normal file
92
src/app/assignments/page.js
Normal file
@ -0,0 +1,92 @@
|
||||
// app/assignments/page.js
|
||||
"use client";
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { databases } from "../lib/appwrite"; // Appwrite SDK
|
||||
import { ID } from "appwrite";
|
||||
|
||||
export default function AssignmentsPage() {
|
||||
const [assignments, setAssignments] = useState([]);
|
||||
const [submissionLinks, setSubmissionLinks] = useState({});
|
||||
const [userId, setUserId] = useState(""); // You might fetch this from your auth context/session
|
||||
|
||||
useEffect(() => {
|
||||
// Fetch assignments from Appwrite
|
||||
const fetchAssignments = async () => {
|
||||
try {
|
||||
const response = await databases.listDocuments(
|
||||
"your_database_id",
|
||||
"assignments_collection_id"
|
||||
);
|
||||
setAssignments(response.documents);
|
||||
} catch (error) {
|
||||
console.error("Error fetching assignments:", error);
|
||||
}
|
||||
};
|
||||
|
||||
fetchAssignments();
|
||||
}, []);
|
||||
|
||||
const handleSubmit = async (assignmentId) => {
|
||||
try {
|
||||
await databases.createDocument(
|
||||
"67e1452b00016444b37f",
|
||||
"67f0f285001a1614b4e8",
|
||||
ID.unique(),
|
||||
{
|
||||
assignmentId,
|
||||
userId,
|
||||
submissionLink: submissionLinks[assignmentId],
|
||||
}
|
||||
);
|
||||
|
||||
alert("Submitted!");
|
||||
} catch (error) {
|
||||
console.error("Submission failed:", error);
|
||||
}
|
||||
};
|
||||
|
||||
const handleInputChange = (assignmentId, value) => {
|
||||
setSubmissionLinks({
|
||||
...submissionLinks,
|
||||
[assignmentId]: value,
|
||||
});
|
||||
};
|
||||
|
||||
return (
|
||||
<div>
|
||||
<h1 className="text-2xl font-bold mb-4">Assignments</h1>
|
||||
|
||||
{assignments.length === 0 ? (
|
||||
<p>No assignments available.</p>
|
||||
) : (
|
||||
assignments.map((assignment) => (
|
||||
<div key={assignment.$id} className="mb-6 border p-4 rounded-lg">
|
||||
<h2 className="text-xl font-semibold">{assignment.title}</h2>
|
||||
<p className="text-gray-600">{assignment.description}</p>
|
||||
<p className="text-sm text-gray-400">
|
||||
Deadline: {assignment.deadline}
|
||||
</p>
|
||||
|
||||
<input
|
||||
type="text"
|
||||
className="mt-2 border px-2 py-1 w-full"
|
||||
placeholder="Paste your GitHub/Firebase/Netlify link"
|
||||
value={submissionLinks[assignment.$id] || ""}
|
||||
onChange={(e) =>
|
||||
handleInputChange(assignment.$id, e.target.value)
|
||||
}
|
||||
/>
|
||||
|
||||
<button
|
||||
onClick={() => handleSubmit(assignment.$id)}
|
||||
className="mt-2 bg-blue-600 text-white px-4 py-1 rounded"
|
||||
>
|
||||
Submit
|
||||
</button>
|
||||
</div>
|
||||
))
|
||||
)}
|
||||
</div>
|
||||
);
|
||||
}
|
0
src/app/components/AssignmentCard.js
Normal file
0
src/app/components/AssignmentCard.js
Normal file
42
src/app/components/MemberForm.js
Normal file
42
src/app/components/MemberForm.js
Normal file
@ -0,0 +1,42 @@
|
||||
import { useState } from "react";
|
||||
import { databases, ID, databaseId, membersCollectionId } from "../lib/appwrite";
|
||||
|
||||
export default function MemberForm() {
|
||||
const [form, setForm] = useState({
|
||||
name: "",
|
||||
email: "",
|
||||
phone: "",
|
||||
role: "",
|
||||
joinDate: "",
|
||||
});
|
||||
|
||||
const handleChange = (e) => {
|
||||
setForm({ ...form, [e.target.name]: e.target.value });
|
||||
};
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await databases.createDocument(
|
||||
databaseId,
|
||||
membersCollectionId,
|
||||
ID.unique(),
|
||||
form
|
||||
);
|
||||
alert("Member added!");
|
||||
} catch (err) {
|
||||
console.error("Failed to add member:", err);
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit}>
|
||||
<input name="name" onChange={handleChange} placeholder="Name" />
|
||||
<input name="email" onChange={handleChange} placeholder="Email" />
|
||||
<input name="phone" onChange={handleChange} placeholder="Phone" />
|
||||
<input name="role" onChange={handleChange} placeholder="Role" />
|
||||
<input type="date" name="joinDate" onChange={handleChange} />
|
||||
<button type="submit">Add Member</button>
|
||||
</form>
|
||||
);
|
||||
}
|
59
src/app/components/MemberList.js
Normal file
59
src/app/components/MemberList.js
Normal file
@ -0,0 +1,59 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { databases } from "../lib/appwrite";
|
||||
import { databaseId, membersCollectionId } from "../lib/appwrite";
|
||||
import { getCurrentUserWithRole } from "../utils/auth";
|
||||
|
||||
export default function MemberList() {
|
||||
const [members, setMembers] = useState([]);
|
||||
const [user, setUser] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
getCurrentUserWithRole().then(setUser);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const getMembers = async () => {
|
||||
try {
|
||||
const res = await databases.listDocuments(
|
||||
databaseId,
|
||||
membersCollectionId
|
||||
);
|
||||
setMembers(res.documents); // <-- Add this line
|
||||
} catch (err) {
|
||||
console.error("Error fetching members:", err);
|
||||
}
|
||||
};
|
||||
|
||||
getMembers();
|
||||
}, []);
|
||||
|
||||
return (
|
||||
<div className="mt-8">
|
||||
<h2 className="text-xl font-semibold mb-4">All Members</h2>
|
||||
<table className="w-full border">
|
||||
<thead>
|
||||
<tr className="bg-gray-100">
|
||||
<th className="p-2 text-left">Name</th>
|
||||
<th className="p-2">Phone</th>
|
||||
<th className="p-2">Join Date</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
{members.map((m) => (
|
||||
<tr key={m.$id} className="border-t">
|
||||
<td className="p-2">{m.name}</td>
|
||||
<td className="p-2">{m.phone}</td>
|
||||
<td className="p-2">{m.joinDate}</td>
|
||||
<td className="p-2">{m.role}</td>
|
||||
</tr>
|
||||
))}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{/* Render role only if user is loaded */}
|
||||
{user ? <p className="mt-4">Role: {user.role}</p> : <p>Loading role...</p>}
|
||||
</div>
|
||||
);
|
||||
}
|
24
src/app/components/Navbar.jsx
Normal file
24
src/app/components/Navbar.jsx
Normal file
@ -0,0 +1,24 @@
|
||||
'use client';
|
||||
import { account } from "../lib/appwrite";
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function Navbar() {
|
||||
const router = useRouter();
|
||||
|
||||
const handleLogout = async () => {
|
||||
await account.deleteSession('current');
|
||||
router.push('/login');
|
||||
};
|
||||
|
||||
return (
|
||||
<nav className="bg-white shadow px-4 py-3 flex justify-between items-center">
|
||||
<span className="font-bold text-lg">Company Portal</span>
|
||||
<button
|
||||
onClick={handleLogout}
|
||||
className="bg-red-500 text-white px-4 py-1 rounded hover:bg-red-600"
|
||||
>
|
||||
Logout
|
||||
</button>
|
||||
</nav>
|
||||
);
|
||||
}
|
23
src/app/components/ProtectedRoute.js
Normal file
23
src/app/components/ProtectedRoute.js
Normal file
@ -0,0 +1,23 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect } from "react";
|
||||
import { useRouter } from "next/navigation";
|
||||
import { getCurrentUser, isAdmin } from "@/utils/auth";
|
||||
|
||||
export default function ProtectedRoute({ children, requireAdmin = false }) {
|
||||
const router = useRouter();
|
||||
|
||||
useEffect(() => {
|
||||
const protect = async () => {
|
||||
const user = await getCurrentUser();
|
||||
if (!user) {
|
||||
router.push("/login");
|
||||
} else if (requireAdmin && !isAdmin(user.email)) {
|
||||
router.push("/pages/unauthorized"); // Optional unauthorized page
|
||||
}
|
||||
};
|
||||
protect();
|
||||
}, [router, requireAdmin]);
|
||||
|
||||
return <>{children}</>;
|
||||
}
|
24
src/app/components/Sidebar.jsx
Normal file
24
src/app/components/Sidebar.jsx
Normal file
@ -0,0 +1,24 @@
|
||||
'use client';
|
||||
import Link from 'next/link';
|
||||
|
||||
export default function Sidebar() {
|
||||
return (
|
||||
<aside className="w-64 bg-gray-800 text-white p-4 hidden md:block">
|
||||
<h2 className="text-xl font-bold mb-6">Dashboard</h2>
|
||||
<ul className="space-y-4">
|
||||
<li>
|
||||
<Link href="/dashboard" className="hover:text-gray-300">Home</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/dashboard/members" className="hover:text-gray-300">Members</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/dashboard/assignments" className="hover:text-gray-300">Assignments</Link>
|
||||
</li>
|
||||
<li>
|
||||
<Link href="/dashboard/profile" className="hover:text-gray-300">My Profile</Link>
|
||||
</li>
|
||||
</ul>
|
||||
</aside>
|
||||
);
|
||||
}
|
44
src/app/components/TestMemberList.js
Normal file
44
src/app/components/TestMemberList.js
Normal file
@ -0,0 +1,44 @@
|
||||
"use client";
|
||||
import { useEffect, useState } from "react";
|
||||
import { databases, databaseId, membersCollectionId } from "../lib/appwrite";
|
||||
|
||||
const TestMemberList = () => {
|
||||
const [members, setMembers] = useState([]);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchMembers = async () => {
|
||||
try {
|
||||
const res = await databases.listDocuments(databaseId, membersCollectionId);
|
||||
setMembers(res.documents);
|
||||
} catch (err) {
|
||||
console.error("Error fetching members:", err);
|
||||
} finally {
|
||||
setLoading(false);
|
||||
}
|
||||
};
|
||||
|
||||
fetchMembers();
|
||||
}, []);
|
||||
|
||||
if (loading) return <p>Loading members...</p>;
|
||||
|
||||
return (
|
||||
<div className="p-4">
|
||||
<h2 className="text-xl font-bold mb-4">Team Members</h2>
|
||||
<ul className="space-y-2">
|
||||
{members.map((member) => (
|
||||
<li key={member.$id} className="border p-3 rounded shadow-sm">
|
||||
<p><strong>Name:</strong> {member.name}</p>
|
||||
<p><strong>Email:</strong> {member.email}</p>
|
||||
<p><strong>Phone:</strong> {member.phone}</p>
|
||||
<p><strong>Role:</strong> {member.role}</p>
|
||||
<p><strong>Joined:</strong> {new Date(member.joinDate).toDateString()}</p>
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default TestMemberList;
|
BIN
src/app/favicon.ico
Normal file
BIN
src/app/favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 25 KiB |
1
src/app/globals.css
Normal file
1
src/app/globals.css
Normal file
@ -0,0 +1 @@
|
||||
@import "tailwindcss";
|
27
src/app/layout.js
Normal file
27
src/app/layout.js
Normal file
@ -0,0 +1,27 @@
|
||||
import { Geist, Geist_Mono } from "next/font/google";
|
||||
import "./globals.css";
|
||||
|
||||
const geistSans = Geist({
|
||||
variable: "--font-geist-sans",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
const geistMono = Geist_Mono({
|
||||
variable: "--font-geist-mono",
|
||||
subsets: ["latin"],
|
||||
});
|
||||
|
||||
export const metadata = {
|
||||
title: "Appwrite + Next App",
|
||||
description: "Built with Next.js and Appwrite",
|
||||
};
|
||||
|
||||
export default function RootLayout({ children }) {
|
||||
return (
|
||||
<html lang="en">
|
||||
<body className={`${geistSans.variable} ${geistMono.variable}`}>
|
||||
{children}
|
||||
</body>
|
||||
</html>
|
||||
);
|
||||
}
|
16
src/app/lib/appwrite.js
Normal file
16
src/app/lib/appwrite.js
Normal file
@ -0,0 +1,16 @@
|
||||
import { Client, Account, Databases, ID,Query } from "appwrite";
|
||||
|
||||
const client = new Client();
|
||||
|
||||
client
|
||||
.setEndpoint("https://cloud.appwrite.io/v1")
|
||||
.setProject(process.env.NEXT_PUBLIC_APPWRITE_PROJECT_ID);
|
||||
|
||||
const account = new Account(client);
|
||||
const databases = new Databases(client);
|
||||
|
||||
// ✅ Import from .env
|
||||
const databaseId = process.env.NEXT_PUBLIC_APPWRITE_DATABASE_ID;
|
||||
const membersCollectionId = process.env.NEXT_PUBLIC_COLLECTION_MEMBERS_ID;
|
||||
|
||||
export { client, account, databases, ID, Query,databaseId, membersCollectionId };
|
69
src/app/login/page.js
Normal file
69
src/app/login/page.js
Normal file
@ -0,0 +1,69 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { account, ID } from "../lib/appwrite";
|
||||
|
||||
export default function AuthPage() {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [err, setErr] = useState('');
|
||||
const [isLogin, setIsLogin] = useState(true);
|
||||
|
||||
const handleAuth = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
if (isLogin) {
|
||||
await account.createEmailPasswordSession(email, password);
|
||||
router.push('/pages/dashboard');
|
||||
} else {
|
||||
await account.create(ID.unique(), email, password);
|
||||
// Automatically log in after sign up
|
||||
await account.createEmailPasswordSession(email, password);
|
||||
router.push('/pages/dashboard');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Auth error:', error);
|
||||
setErr(error.message || 'Something went wrong');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<form onSubmit={handleAuth} className="bg-white p-6 rounded shadow-md w-full max-w-sm">
|
||||
<h2 className="text-xl font-semibold mb-4">{isLogin ? 'Login' : 'Sign Up'}</h2>
|
||||
{err && <p className="text-red-500 mb-4">{err}</p>}
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Email"
|
||||
className="w-full mb-2 p-2 border rounded"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
className="w-full mb-4 p-2 border rounded"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
minLength="8"
|
||||
/>
|
||||
<button type="submit" className="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded w-full mb-4">
|
||||
{isLogin ? 'Login' : 'Sign Up'}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
onClick={() => {
|
||||
setIsLogin(!isLogin);
|
||||
setErr('');
|
||||
}}
|
||||
className="text-blue-500 hover:text-blue-700 text-sm"
|
||||
>
|
||||
{isLogin ? 'Need an account? Sign Up' : 'Already have an account? Login'}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
50
src/app/page.js
Normal file
50
src/app/page.js
Normal file
@ -0,0 +1,50 @@
|
||||
'use client';
|
||||
import { useState } from 'react';
|
||||
import { useRouter } from 'next/navigation';
|
||||
import { account } from "./lib/appwrite";
|
||||
|
||||
export default function LoginPage() {
|
||||
const router = useRouter();
|
||||
const [email, setEmail] = useState('');
|
||||
const [password, setPassword] = useState('');
|
||||
const [err, setErr] = useState('');
|
||||
|
||||
const handleLogin = async (e) => {
|
||||
e.preventDefault();
|
||||
try {
|
||||
await account.createEmailPasswordSession(email, password);
|
||||
router.push('/'); // Redirect to home
|
||||
} catch (error) {
|
||||
console.error('Login error:', error);
|
||||
setErr('Invalid credentials');
|
||||
}
|
||||
};
|
||||
|
||||
return (
|
||||
<div className="flex items-center justify-center min-h-screen">
|
||||
<form onSubmit={handleLogin} className="bg-white p-6 rounded shadow-md w-full max-w-sm">
|
||||
<h2 className="text-xl font-semibold mb-4">Login</h2>
|
||||
{err && <p className="text-red-500">{err}</p>}
|
||||
<input
|
||||
type="email"
|
||||
placeholder="Email"
|
||||
className="w-full mb-2 p-2 border rounded"
|
||||
value={email}
|
||||
onChange={(e) => setEmail(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<input
|
||||
type="password"
|
||||
placeholder="Password"
|
||||
className="w-full mb-4 p-2 border rounded"
|
||||
value={password}
|
||||
onChange={(e) => setPassword(e.target.value)}
|
||||
required
|
||||
/>
|
||||
<button className="bg-blue-500 hover:bg-blue-600 text-white py-2 px-4 rounded w-full">
|
||||
Login
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
);
|
||||
}
|
168
src/app/page.module.css
Normal file
168
src/app/page.module.css
Normal file
@ -0,0 +1,168 @@
|
||||
.page {
|
||||
--gray-rgb: 0, 0, 0;
|
||||
--gray-alpha-200: rgba(var(--gray-rgb), 0.08);
|
||||
--gray-alpha-100: rgba(var(--gray-rgb), 0.05);
|
||||
|
||||
--button-primary-hover: #383838;
|
||||
--button-secondary-hover: #f2f2f2;
|
||||
|
||||
display: grid;
|
||||
grid-template-rows: 20px 1fr 20px;
|
||||
align-items: center;
|
||||
justify-items: center;
|
||||
min-height: 100svh;
|
||||
padding: 80px;
|
||||
gap: 64px;
|
||||
font-family: var(--font-geist-sans);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.page {
|
||||
--gray-rgb: 255, 255, 255;
|
||||
--gray-alpha-200: rgba(var(--gray-rgb), 0.145);
|
||||
--gray-alpha-100: rgba(var(--gray-rgb), 0.06);
|
||||
|
||||
--button-primary-hover: #ccc;
|
||||
--button-secondary-hover: #1a1a1a;
|
||||
}
|
||||
}
|
||||
|
||||
.main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 32px;
|
||||
grid-row-start: 2;
|
||||
}
|
||||
|
||||
.main ol {
|
||||
font-family: var(--font-geist-mono);
|
||||
padding-left: 0;
|
||||
margin: 0;
|
||||
font-size: 14px;
|
||||
line-height: 24px;
|
||||
letter-spacing: -0.01em;
|
||||
list-style-position: inside;
|
||||
}
|
||||
|
||||
.main li:not(:last-of-type) {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.main code {
|
||||
font-family: inherit;
|
||||
background: var(--gray-alpha-100);
|
||||
padding: 2px 4px;
|
||||
border-radius: 4px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.ctas {
|
||||
display: flex;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.ctas a {
|
||||
appearance: none;
|
||||
border-radius: 128px;
|
||||
height: 48px;
|
||||
padding: 0 20px;
|
||||
border: none;
|
||||
border: 1px solid transparent;
|
||||
transition:
|
||||
background 0.2s,
|
||||
color 0.2s,
|
||||
border-color 0.2s;
|
||||
cursor: pointer;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
font-size: 16px;
|
||||
line-height: 20px;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
a.primary {
|
||||
background: var(--foreground);
|
||||
color: var(--background);
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
a.secondary {
|
||||
border-color: var(--gray-alpha-200);
|
||||
min-width: 158px;
|
||||
}
|
||||
|
||||
.footer {
|
||||
grid-row-start: 3;
|
||||
display: flex;
|
||||
gap: 24px;
|
||||
}
|
||||
|
||||
.footer a {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.footer img {
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
/* Enable hover only on non-touch devices */
|
||||
@media (hover: hover) and (pointer: fine) {
|
||||
a.primary:hover {
|
||||
background: var(--button-primary-hover);
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
a.secondary:hover {
|
||||
background: var(--button-secondary-hover);
|
||||
border-color: transparent;
|
||||
}
|
||||
|
||||
.footer a:hover {
|
||||
text-decoration: underline;
|
||||
text-underline-offset: 4px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (max-width: 600px) {
|
||||
.page {
|
||||
padding: 32px;
|
||||
padding-bottom: 80px;
|
||||
}
|
||||
|
||||
.main {
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
.main ol {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.ctas {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ctas a {
|
||||
font-size: 14px;
|
||||
height: 40px;
|
||||
padding: 0 16px;
|
||||
}
|
||||
|
||||
a.secondary {
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
.footer {
|
||||
flex-wrap: wrap;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: dark) {
|
||||
.logo {
|
||||
filter: invert();
|
||||
}
|
||||
}
|
30
src/app/pages/dashboard/page.js
Normal file
30
src/app/pages/dashboard/page.js
Normal file
@ -0,0 +1,30 @@
|
||||
'use client';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { account } from"../../lib/appwrite";
|
||||
import { useRouter } from 'next/navigation';
|
||||
|
||||
export default function DashboardPage() {
|
||||
const router = useRouter();
|
||||
const [user, setUser] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
const fetchUser = async () => {
|
||||
try {
|
||||
const res = await account.get();
|
||||
setUser(res);
|
||||
} catch (err) {
|
||||
router.push('/login'); // Not logged in, redirect
|
||||
}
|
||||
};
|
||||
fetchUser();
|
||||
}, [router]);
|
||||
|
||||
if (!user) return <p className="text-center mt-10">Checking auth...</p>;
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold mb-4">Welcome, {user.name || user.email} 👋</h1>
|
||||
<p>This is your dashboard.</p>
|
||||
</div>
|
||||
);
|
||||
}
|
16
src/app/user/layout.js
Normal file
16
src/app/user/layout.js
Normal file
@ -0,0 +1,16 @@
|
||||
// app/user/layout.js
|
||||
import React from 'react';
|
||||
import Navbar from "../components/Navbar"; // Adjust path if needed
|
||||
import Sidebar from "../components/Sidebar"; // Adjust path if needed
|
||||
|
||||
export default function UserLayout({ children }) {
|
||||
return (
|
||||
<div className="flex">
|
||||
<Sidebar />
|
||||
<div className="flex-1">
|
||||
<Navbar />
|
||||
<main className="p-4">{children}</main>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
22
src/app/user/page.js
Normal file
22
src/app/user/page.js
Normal file
@ -0,0 +1,22 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { getCurrentUserWithRole } from "../utils/auth";
|
||||
|
||||
export default function UserDashboard() {
|
||||
const [user, setUser] = useState(null);
|
||||
|
||||
useEffect(() => {
|
||||
getCurrentUserWithRole().then(setUser);
|
||||
}, []);
|
||||
|
||||
if (!user) return <p>Loading...</p>;
|
||||
|
||||
return (
|
||||
<div className="p-6">
|
||||
<h1 className="text-2xl font-bold">Welcome, {user.name}</h1>
|
||||
<p>Email: {user.email}</p>
|
||||
<p>Role: {user.role}</p>
|
||||
</div>
|
||||
);
|
||||
}
|
67
src/app/user/profile/page.js
Normal file
67
src/app/user/profile/page.js
Normal file
@ -0,0 +1,67 @@
|
||||
'use client';
|
||||
|
||||
import { useEffect, useState } from "react";
|
||||
import { getCurrentUser } from "../../utils/auth";
|
||||
import { databases } from "../../lib/appwrite";
|
||||
|
||||
export default function UserProfilePage() {
|
||||
const [profile, setProfile] = useState(null);
|
||||
const [form, setForm] = useState(null);
|
||||
const [docId, setDocId] = useState(null);
|
||||
const [loading, setLoading] = useState(true);
|
||||
|
||||
useEffect(() => {
|
||||
async function fetchProfile() {
|
||||
const user = await getCurrentUser();
|
||||
const res = await databases.listDocuments(
|
||||
process.env.NEXT_PUBLIC_DB_ID,
|
||||
process.env.NEXT_PUBLIC_MEMBERS_COLLECTION_ID,
|
||||
[`query.equal("userId", ["${user.$id}"])`]
|
||||
);
|
||||
|
||||
const data = res.documents[0];
|
||||
setDocId(data.$id);
|
||||
setProfile(data);
|
||||
setForm({ name: data.name, phone: data.phone });
|
||||
setLoading(false);
|
||||
}
|
||||
|
||||
fetchProfile();
|
||||
}, []);
|
||||
|
||||
const handleChange = (e) => setForm({ ...form, [e.target.name]: e.target.value });
|
||||
|
||||
const handleSubmit = async (e) => {
|
||||
e.preventDefault();
|
||||
await databases.updateDocument(
|
||||
process.env.NEXT_PUBLIC_DB_ID,
|
||||
process.env.NEXT_PUBLIC_MEMBERS_COLLECTION_ID,
|
||||
docId,
|
||||
form
|
||||
);
|
||||
alert("Profile updated!");
|
||||
};
|
||||
|
||||
if (loading) return <p>Loading...</p>;
|
||||
|
||||
return (
|
||||
<form onSubmit={handleSubmit} className="p-6 bg-white rounded shadow space-y-4">
|
||||
<h2 className="text-xl font-bold">Your Profile</h2>
|
||||
<input
|
||||
type="text"
|
||||
name="name"
|
||||
value={form.name}
|
||||
onChange={handleChange}
|
||||
className="input"
|
||||
/>
|
||||
<input
|
||||
type="text"
|
||||
name="phone"
|
||||
value={form.phone}
|
||||
onChange={handleChange}
|
||||
className="input"
|
||||
/>
|
||||
<button type="submit" className="btn-primary">Update</button>
|
||||
</form>
|
||||
);
|
||||
}
|
35
src/app/utils/auth.js
Normal file
35
src/app/utils/auth.js
Normal file
@ -0,0 +1,35 @@
|
||||
import { Client, Account, Databases, Query } from "appwrite";
|
||||
|
||||
const client = new Client()
|
||||
.setEndpoint("https://cloud.appwrite.io/v1") // Update with your Appwrite endpoint
|
||||
.setProject("67e1445400053dca1d9b");
|
||||
|
||||
const account = new Account(client);
|
||||
const databases = new Databases(client);
|
||||
|
||||
export async function getCurrentUserWithRole() {
|
||||
try {
|
||||
const user = await account.get();
|
||||
|
||||
const dbId = "67e1452b00016444b37f";
|
||||
const collectionId = "67f0f1200006897dc192";
|
||||
|
||||
const response = await databases.listDocuments(dbId, collectionId, [
|
||||
Query.equal("userId", user.$id),
|
||||
]);
|
||||
|
||||
console.log("Query result:", response); // 🔍 Check this in console
|
||||
|
||||
const userDoc = response.documents[0];
|
||||
|
||||
return {
|
||||
name: user.name,
|
||||
email: user.email,
|
||||
role: userDoc?.role || "unknown",
|
||||
};
|
||||
} catch (error) {
|
||||
console.error("Error fetching user with role:", error);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user