From 39a6990057aea62227a3601e54d7188fa23f2e7e Mon Sep 17 00:00:00 2001 From: lavanyagarg112 Date: Sat, 24 May 2025 20:50:47 +0800 Subject: [PATCH 01/36] Add organisation settings page --- app/dashboard/page.tsx | 1 - app/settings/page.tsx | 33 ++++- .../organisation/settings/OrgSettings.tsx | 129 ++++++++++++++++++ .../settings/SettingsComponent.tsx | 11 ++ context/AuthContext.tsx | 2 +- 5 files changed, 171 insertions(+), 5 deletions(-) create mode 100644 components/organisation/settings/OrgSettings.tsx create mode 100644 components/organisation/settings/SettingsComponent.tsx diff --git a/app/dashboard/page.tsx b/app/dashboard/page.tsx index 486d7a8..c730522 100644 --- a/app/dashboard/page.tsx +++ b/app/dashboard/page.tsx @@ -1,4 +1,3 @@ -import { redirect } from "next/navigation"; import { getAuthUser } from "@/lib/auth"; export default async function DashboardPage() { diff --git a/app/settings/page.tsx b/app/settings/page.tsx index 2d5771f..f289a0f 100644 --- a/app/settings/page.tsx +++ b/app/settings/page.tsx @@ -1,8 +1,35 @@ -export default function SettingsPage() { +import { getAuthUser } from "@/lib/auth"; +import SettingsComponent from "@/components/organisation/settings/SettingsComponent"; + +export default async function SettingsPage() { + const user = await getAuthUser(); + if (!user) { + return null; + } + const organisation = user.organisation; + const role = organisation.role; + const isAdmin = role === "admin"; + const isMember = role === "employee"; + + if (isAdmin) { + return ( +
+ +
+ ); + } + + if (isMember) { + return ( +
+

Member Settings

+
+ ); + } + return (
-

Settings

-

Settings page content goes here.

+

Page should not reach here

); } diff --git a/components/organisation/settings/OrgSettings.tsx b/components/organisation/settings/OrgSettings.tsx new file mode 100644 index 0000000..6dfe879 --- /dev/null +++ b/components/organisation/settings/OrgSettings.tsx @@ -0,0 +1,129 @@ +"use client"; +import { useState } from "react"; + +export default function OrgSettings({ initialData }: { initialData: any }) { + const [name, setName] = useState(initialData.organisation_name); + const [description, setDescription] = useState(initialData.description); + const [aiEnabled, setAiEnabled] = useState(initialData.ai_enabled); + const [transferEmail, setTransferEmail] = useState(""); + const [isSaving, setIsSaving] = useState(false); + + const handleSubmit = async (e: React.FormEvent) => { + e.preventDefault(); + setIsSaving(true); + try { + // Call API to update organisation settings + // show success toast + } catch (err) { + // show error toast + } finally { + setIsSaving(false); + } + }; + + const handleTransfer = async () => { + if (!transferEmail) return; + // open confirmation modal... + // then call API to transfer ownership + }; + + return ( +
+
+

+ Organisation Settings +

+
+ {/* Organisation Name */} +
+ + setName(e.target.value)} + className="mt-1 block w-full rounded-md border border-gray-300 p-2 focus:border-purple-700 focus:ring focus:ring-blue-200" + /> +
+ + {/* Description */} +
+ +