Open-source agentic AI Search Execution Platform. Track AI visibility, find opportunities, and let agents turn signals into prioritized actions and drafted fixes across ChatGPT, Claude, Gemini, Google AI Overviews, Google AI Mode, Perplexity, Grok, and Microsoft Copilot.
TypeScript aeoai-agentai-searchanswer-engine-optimizationbrand-monitoringchatgptclaudecopilotdockergeminigeogoogle-ai-overviewsgrokmcpnextjsopen-sourceperplexityseosupabasetypescript
feat: replace inert Project tab with working Organization tab (closes #753) (#825)
Maqbool Ahmed5c3c106cef9c
diff --git a/web/messages/en.json b/web/messages/en.jsonindex f4c0561c5..0653b37ec 100644--- a/web/messages/en.json+++ b/web/messages/en.json@@ -1311,7 +1311,6 @@"theme": "Theme","themeDescription": "Choose light or dark mode for the dashboard.","general": "General",- "project": "Project","apiKeys": "API Keys","team": "Team","notifications": "Notifications",@@ -1329,8 +1328,6 @@"pulseNoBrands": "No active brands yet — add a brand to configure its Daily Pulse.","billing": "Billing","danger": "Danger Zone",- "projectName": "Project Name",- "domain": "Domain","displayName": "Display Name","email": "Email","save": "Save changes",@@ -1422,7 +1419,20 @@"integrations_disconnect": "Disconnect","integrations_disconnectDescription": "The stored connection is removed for the whole organization. You can reconnect at any time.","removeMember": "Remove team member",- "invitationActions": "Invitation actions"+ "invitationActions": "Invitation actions",+ "organization": "Organization",+ "org_title": "Organization",+ "org_description": "Manage your organization name and view plan details.",+ "org_name": "Organization Name",+ "org_namePlaceholder": "Acme Inc.",+ "org_slug": "Slug",+ "org_slugHint": "Used in API and integration references. Contact support to change it.",+ "org_plan": "Plan",+ "org_members": "Members",+ "org_adminOnly": "Only admins can rename the organization.",+ "org_loadFailed": "Could not load organization details.",+ "org_saveFailed": "Could not save organization name. Please try again.",+ "accountSaveFailed": "Could not save account details. Please try again."},"brands": {"title": "Brands",diff --git a/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx b/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsxindex c7c2f1cfd..6a5c70415 100644--- a/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx+++ b/web/src/app/[locale]/(dashboard)/dashboard/settings/page.tsx@@ -19,11 +19,15 @@ import { ApiKeysSection } from '@/components/settings/api-keys-section';import { AgentSection } from '@/components/settings/agent-section';import { NotificationsSection } from '@/components/settings/notifications-section';import { IntegrationsSection } from '@/components/settings/integrations-section';+import { OrganizationSection } from '@/components/settings/organization-section';+import { updateAccountName } from '@/lib/actions/organization';+import { Loader2 } from 'lucide-react';+import { toast } from 'sonner';type Section =| 'account'| 'theme'- | 'project'+ | 'organization'| 'team'| 'notifications'| 'integrations'@@ -45,10 +49,13 @@ export default function SettingsPage() {if (tabParam === 'notifications') return 'notifications';// OAuth popups land back here after the Composio consent flow (#577).if (tabParam === 'integrations') return 'integrations';+ // Legacy deep-link: ?tab=project now maps to the new organization tab.+ if (tabParam === 'organization' || tabParam === 'project') return 'organization';return 'account';});const [displayName, setDisplayName] = useState('');const [email, setEmail] = useState('');+ const [savingName, setSavingName] = useState(false);useEffect(() => {const supabase = createClient();@@ -65,10 +72,22 @@ export default function SettingsPage() {router.refresh();}+ async function handleSaveAccount() {+ setSavingName(true);+ try {+ await updateAccountName(displayName);+ toast.success(t('saved'));+ } catch (err) {+ toast.error(err instanceof Error ? err.message : t('accountSaveFailed'));+ } finally {+ setSavingName(false);+ }+ }+const navItems: { id: Section; label: string }[] = [{ id: 'account', label: t('account') },{ id: 'theme', label: t('theme') },- { id: 'project', label: t('project') },+ { id: 'organization', label: t('organization') },{ id: 'team', label: t('team') },{ id: 'notifications', label: t('notifications') },{ id: 'integrations', label: t('integrations') },@@ -137,7 +156,10 @@ export default function SettingsPage() {disabled/></div>- <Button>{t('save')}</Button>+ <Button onClick={handleSaveAccount} disabled={savingName || !displayName.trim()}>+ {savingName && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}+ {t('save')}+ </Button><Separator className="my-2" /><Buttonvariant="outline"@@ -165,26 +187,8 @@ export default function SettingsPage() {</div>)}- {/* Project */}- {active === 'project' && (- <Card>- <CardHeader>- <CardTitle>{t('project')}</CardTitle>- <CardDescription>Configure your project settings.</CardDescription>- </CardHeader>- <CardContent className="space-y-4">- <div className="space-y-2">- <Label htmlFor="projectName">{t('projectName')}</Label>- <Input id="projectName" placeholder="My Brand" />- </div>- <div className="space-y-2">- <Label htmlFor="domain">{t('domain')}</Label>- <Input id="domain" placeholder="example.com" />- </div>- <Button>{t('save')}</Button>- </CardContent>- </Card>- )}+ {/* Organization */}+ {active === 'organization' && <OrganizationSection />}{/* Team */}{active === 'team' && <TeamSection />}diff --git a/web/src/components/settings/organization-section.tsx b/web/src/components/settings/organization-section.tsxnew file mode 100644index 000000000..5887bd21e--- /dev/null+++ b/web/src/components/settings/organization-section.tsx@@ -0,0 +1,152 @@+'use client';++import { useCallback, useEffect, useState } from 'react';+import { useTranslations } from 'next-intl';+import { toast } from 'sonner';+import { Card, CardContent, CardDescription, CardHeader, CardTitle } from '@/components/ui/card';+import { Button } from '@/components/ui/button';+import { Input } from '@/components/ui/input';+import { Label } from '@/components/ui/label';+import { Skeleton } from '@/components/ui/skeleton';+import { Separator } from '@/components/ui/separator';+import { Loader2, Lock } from 'lucide-react';+import { useUserRole } from '@/hooks/use-user-role';+import {+ getOrganization,+ updateOrganizationName,+ type OrganizationInfo,+} from '@/lib/actions/organization';++/**+ * Settings → Organization.+ *+ * Replaces the inert "Project" tab (#753). Admins can rename the+ * organisation; all other fields are read-only. The slug is intentionally+ * not exposed for editing — it is used in external integrations and must+ * remain stable.+ *+ * Follows the TeamSection / AgentSection pattern exactly:+ * - load via useEffect / useCallback+ * - Skeleton while loading+ * - admin-gate via useUserRole().canAdmin+ * - toast on success / error, saving spinner on the button+ */+export function OrganizationSection() {+ const t = useTranslations('settings');+ const { canAdmin } = useUserRole();++ const [org, setOrg] = useState<OrganizationInfo | null>(null);+ const [loading, setLoading] = useState(true);+ const [nameInput, setNameInput] = useState('');+ const [saving, setSaving] = useState(false);++ const loadOrg = useCallback(async () => {+ try {+ const data = await getOrganization();+ setOrg(data);+ setNameInput(data.name);+ } catch {+ toast.error(t('org_loadFailed'));+ } finally {+ setLoading(false);+ }+ }, [t]);++ useEffect(() => {+ void loadOrg();+ }, [loadOrg]);++ async function handleSave() {+ if (!canAdmin) return;+ setSaving(true);+ try {+ await updateOrganizationName(nameInput);+ setOrg((prev) => (prev ? { ...prev, name: nameInput.trim() } : prev));+ toast.success(t('saved'));+ } catch (err) {+ toast.error(err instanceof Error ? err.message : t('org_saveFailed'));+ } finally {+ setSaving(false);+ }+ }++ if (loading) {+ return (+ <Card>+ <CardHeader>+ <Skeleton className="h-5 w-32" />+ <Skeleton className="h-4 w-64 mt-1" />+ </CardHeader>+ <CardContent className="space-y-4">+ <Skeleton className="h-9 w-full" />+ <Skeleton className="h-9 w-full" />+ <Skeleton className="h-9 w-24" />+ </CardContent>+ </Card>+ );+ }++ return (+ <div className="space-y-6">+ <Card>+ <CardHeader>+ <CardTitle>{t('org_title')}</CardTitle>+ <CardDescription>{t('org_description')}</CardDescription>+ </CardHeader>+ <CardContent className="space-y-4">+ {/* Organization name — editable by admins only */}+ <div className="space-y-2">+ <Label htmlFor="org-name">{t('org_name')}</Label>+ {canAdmin ? (+ <Input+ id="org-name"+ value={nameInput}+ onChange={(e) => setNameInput(e.target.value)}+ maxLength={100}+ placeholder={t('org_namePlaceholder')}+ />+ ) : (+ <Input id="org-name" value={org?.name ?? ''} disabled />+ )}+ </div>++ {/* Slug — always read-only */}+ <div className="space-y-2">+ <Label htmlFor="org-slug">{t('org_slug')}</Label>+ <Input id="org-slug" value={org?.slug ?? ''} disabled />+ <p className="text-xs text-muted-foreground">{t('org_slugHint')}</p>+ </div>++ <Separator />++ {/* Read-only stats */}+ <div className="grid grid-cols-2 gap-4 text-sm">+ <div>+ <p className="text-muted-foreground">{t('org_plan')}</p>+ <p className="font-medium capitalize">{org?.plan ?? '—'}</p>+ </div>+ <div>+ <p className="text-muted-foreground">{t('org_members')}</p>+ <p className="font-medium">{org?.memberCount ?? '—'}</p>+ </div>+ </div>++ {canAdmin ? (+ <Button+ onClick={handleSave}+ disabled={saving || !nameInput.trim() || nameInput.trim() === org?.name}+ >+ {saving && <Loader2 className="mr-2 h-4 w-4 animate-spin" />}+ {t('save')}+ </Button>+ ) : (+ <div className="flex items-center gap-2 text-sm text-muted-foreground">+ <Lock className="h-3.5 w-3.5" />+ <span>{t('org_adminOnly')}</span>+ </div>+ )}+ </CardContent>+ </Card>+ </div>+ );+}diff --git a/web/src/lib/actions/organization.ts b/web/src/lib/actions/organization.tsindex 144005bcc..5736dae87 100644--- a/web/src/lib/actions/organization.ts+++ b/web/src/lib/actions/organization.ts@@ -1,9 +1,145 @@'use server';import { createClient } from '@/lib/supabase/server';+import { supabaseAdmin } from '@/lib/supabase/admin';import { revalidatePath } from 'next/cache';import { slugify } from '@/lib/slug';+// ---------------------------------------------------------------------------+// Shared helpers (mirrors the pattern in team.ts)+// ---------------------------------------------------------------------------++async function getCurrentUserAndOrg() {+ const supabase = await createClient();+ const {+ data: { user },+ } = await supabase.auth.getUser();++ if (!user) throw new Error('Unauthorized');++ const { data: profile } = await supabase+ .from('profiles')+ .select('id, role, organization_id')+ .eq('id', user.id)+ .single();++ if (!profile?.organization_id) throw new Error('No organization');++ return { user, profile: profile as { id: string; role: string; organization_id: string } };+}++async function requireAdmin() {+ const { user, profile } = await getCurrentUserAndOrg();+ if (profile.role !== 'admin') {+ throw new Error('Only admins can manage organization settings');+ }+ return { user, profile };+}++// ---------------------------------------------------------------------------+// updateOrganizationName+// ---------------------------------------------------------------------------++/**+ * Rename the current user's organization.+ *+ * Rules (per issue #753):+ * - Admin-only (requireAdmin belt-and-braces on top of RLS).+ * - Trims whitespace, rejects empty, caps at 100 chars.+ * - Leaves `slug` untouched — renaming the display name should not break+ * any existing deep-links or external references that use the slug.+ */+export async function updateOrganizationName(name: string): Promise<void> {+ const { profile } = await requireAdmin();++ const trimmed = name.trim();+ if (!trimmed) throw new Error('Organization name cannot be empty');+ if (trimmed.length > 100) throw new Error('Organization name must be 100 characters or fewer');++ const { error } = await supabaseAdmin+ .from('organizations')+ .update({ name: trimmed })+ .eq('id', profile.organization_id);++ if (error) throw new Error(error.message);++ revalidatePath('/dashboard/settings');+}++// ---------------------------------------------------------------------------+// getOrganization — read the current org's name/slug/plan/member count+// ---------------------------------------------------------------------------++export interface OrganizationInfo {+ name: string;+ slug: string;+ memberCount: number;+ plan: string;+}++export async function getOrganization(): Promise<OrganizationInfo> {+ const { profile } = await getCurrentUserAndOrg();++ const { data: org, error } = await supabaseAdmin+ .from('organizations')+ .select('name, slug, plan')+ .eq('id', profile.organization_id)+ .single();++ if (error || !org) throw new Error(error?.message ?? 'Organization not found');++ const { count } = await supabaseAdmin+ .from('profiles')+ .select('*', { count: 'exact', head: true })+ .eq('organization_id', profile.organization_id);++ return {+ name: org.name as string,+ slug: org.slug as string,+ plan: (org.plan as string) ?? 'starter',+ memberCount: count ?? 0,+ };+}++// ---------------------------------------------------------------------------+// updateAccountName — write profiles.full_name + sync auth user_metadata+// ---------------------------------------------------------------------------++/**+ * Save the signed-in user's display name.+ *+ * Writes to two places so every consumer sees a consistent value:+ * 1. `profiles.full_name` — the column all app queries read.+ * 2. `auth.users.user_metadata.full_name` — so the Supabase JWT and+ * client-side `supabase.auth.getUser()` stay in sync without a+ * separate reload of the profile row.+ */+export async function updateAccountName(name: string): Promise<void> {+ const supabase = await createClient();+ const {+ data: { user },+ } = await supabase.auth.getUser();++ if (!user) throw new Error('Unauthorized');++ const trimmed = name.trim();+ if (!trimmed) throw new Error('Display name cannot be empty');++ // 1. Update the profiles row (the authoritative source for app queries).+ const { error: profileError } = await supabase+ .from('profiles')+ .update({ full_name: trimmed })+ .eq('id', user.id);++ if (profileError) throw new Error(profileError.message);++ // 2. Sync auth metadata so supabase.auth.getUser() reflects the new name+ // immediately (avoids a stale value until the next session refresh).+ await supabase.auth.updateUser({ data: { full_name: trimmed } });++ revalidatePath('/dashboard/settings');+}+export async function createOrganization(name: string) {const supabase = await createClient();