feat: Implement multi-tenancy with default organization, global courses, user profiles, and new UI components like OrganizationSelector and Combobox.

This commit is contained in:
2026-01-16 12:15:15 -03:00
parent 663950aa0e
commit 2dffbd8b71
20 changed files with 942 additions and 153 deletions
+2 -2
View File
@@ -20,9 +20,9 @@ export default function AuthHeader() {
)}
{user && (
<>
<div className="w-8 h-8 rounded-full bg-white/10 border border-white/20 flex items-center justify-center font-bold text-xs">
<Link href="/profile" className="w-8 h-8 rounded-full bg-white/10 border border-white/20 flex items-center justify-center font-bold text-xs hover:border-blue-500/50 transition-colors">
{user.full_name.charAt(0)}
</div>
</Link>
<button onClick={logout} className="p-2 hover:bg-white/10 rounded-full transition-colors">
<LogOut size={16} />
</button>
+91
View File
@@ -0,0 +1,91 @@
"use client";
import React, { useState, useRef, useEffect } from "react";
import { Search, ChevronDown, Check } from "lucide-react";
interface Option {
id: string;
name: string;
}
interface ComboboxProps {
options: Option[];
value: string;
onChange: (value: string) => void;
placeholder?: string;
}
export default function Combobox({ options, value, onChange, placeholder = "Search..." }: ComboboxProps) {
const [isOpen, setIsOpen] = useState(false);
const [search, setSearch] = useState("");
const containerRef = useRef<HTMLDivElement>(null);
const filteredOptions = options.filter(option =>
option.name.toLowerCase().includes(search.toLowerCase())
);
const selectedOption = options.find(o => o.id === value);
useEffect(() => {
const handleClickOutside = (e: MouseEvent) => {
if (containerRef.current && !containerRef.current.contains(e.target as Node)) {
setIsOpen(false);
}
};
document.addEventListener("mousedown", handleClickOutside);
return () => document.removeEventListener("mousedown", handleClickOutside);
}, []);
return (
<div className="relative" ref={containerRef}>
<div
onClick={() => setIsOpen(!isOpen)}
className="flex items-center justify-between w-full bg-black/40 border border-white/10 rounded-lg px-4 py-2.5 cursor-pointer hover:border-white/20 transition-all focus-within:ring-2 focus-within:ring-blue-500/50"
>
<span className={selectedOption ? "text-white" : "text-gray-500"}>
{selectedOption ? selectedOption.name : placeholder}
</span>
<ChevronDown size={18} className={`text-gray-500 transition-transform ${isOpen ? "rotate-180" : ""}`} />
</div>
{isOpen && (
<div className="absolute top-full left-0 right-0 mt-2 z-[110] bg-[#1a1d23] border border-white/10 rounded-lg shadow-2xl overflow-hidden glass-card animate-in fade-in slide-in-from-top-2 duration-200">
<div className="p-2 border-b border-white/5 bg-white/5">
<div className="relative">
<Search size={14} className="absolute left-3 top-1/2 -translate-y-1/2 text-gray-400" />
<input
autoFocus
type="text"
className="w-full bg-black/20 border-none rounded-md pl-9 pr-4 py-2 text-sm focus:ring-0 placeholder:text-gray-600"
placeholder="Search..."
value={search}
onChange={(e) => setSearch(e.target.value)}
/>
</div>
</div>
<div className="max-h-60 overflow-y-auto p-1 custom-scrollbar">
{filteredOptions.length === 0 ? (
<div className="px-4 py-3 text-sm text-gray-500 text-center">No results found</div>
) : (
filteredOptions.map(option => (
<div
key={option.id}
onClick={() => {
onChange(option.id);
setIsOpen(false);
setSearch("");
}}
className={`flex items-center justify-between px-3 py-2 rounded-md cursor-pointer transition-colors ${value === option.id ? "bg-blue-600 text-white" : "hover:bg-white/5 text-gray-300"
}`}
>
<span className="text-sm font-medium">{option.name}</span>
{value === option.id && <Check size={14} />}
</div>
))
)}
</div>
</div>
)}
</div>
);
}
+55
View File
@@ -0,0 +1,55 @@
"use client";
import React, { useEffect, useRef } from "react";
import { X } from "lucide-react";
interface ModalProps {
isOpen: boolean;
onClose: () => void;
title: string;
children: React.ReactNode;
}
export default function Modal({ isOpen, onClose, title, children }: ModalProps) {
const modalRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const handleEscape = (e: KeyboardEvent) => {
if (e.key === "Escape") onClose();
};
if (isOpen) {
document.body.style.overflow = "hidden";
window.addEventListener("keydown", handleEscape);
}
return () => {
document.body.style.overflow = "unset";
window.removeEventListener("keydown", handleEscape);
};
}, [isOpen, onClose]);
if (!isOpen) return null;
return (
<div className="fixed inset-0 z-[100] flex items-center justify-center p-4 bg-black/60 backdrop-blur-sm animate-in fade-in duration-200">
<div
ref={modalRef}
className="w-full max-w-md glass-card bg-[#1a1d23] border border-white/10 rounded-2xl p-8 shadow-2xl animate-in zoom-in-95 duration-200"
>
<div className="flex justify-between items-center mb-6">
<h2 className="text-xl font-bold bg-gradient-to-r from-white to-gray-400 bg-clip-text text-transparent italic">
{title}
</h2>
<button
onClick={onClose}
className="p-2 hover:bg-white/5 rounded-full transition-colors text-gray-400 hover:text-white"
>
<X size={20} />
</button>
</div>
{children}
</div>
</div>
);
}
@@ -0,0 +1,67 @@
"use client";
import React, { useState } from "react";
import Modal from "./Modal";
import Combobox from "./Combobox";
import { Organization } from "@/lib/api";
interface OrganizationSelectorProps {
isOpen: boolean;
onClose: () => void;
organizations: Organization[];
onConfirm: (orgId: string | undefined) => void;
title: string;
actionLabel: string;
}
export default function OrganizationSelector({
isOpen,
onClose,
organizations,
onConfirm,
title,
actionLabel
}: OrganizationSelectorProps) {
const [selectedId, setSelectedId] = useState<string>("");
const handleConfirm = () => {
onConfirm(selectedId || undefined);
onClose();
};
return (
<Modal isOpen={isOpen} onClose={onClose} title={title}>
<div className="space-y-6">
<div>
<label className="block text-sm font-medium text-gray-400 mb-2">
Target Organization
</label>
<Combobox
options={organizations}
value={selectedId}
onChange={setSelectedId}
placeholder="Search or Select Organization..."
/>
<p className="mt-3 text-xs text-gray-500 italic">
Leave empty to use the Default Organization.
</p>
</div>
<div className="flex gap-3 pt-2">
<button
onClick={onClose}
className="flex-1 px-4 py-2.5 bg-white/5 hover:bg-white/10 border border-white/10 rounded-lg transition-all text-sm font-medium"
>
Cancel
</button>
<button
onClick={handleConfirm}
className="flex-[2] px-4 py-2.5 bg-blue-600 hover:bg-blue-500 text-white rounded-lg transition-all shadow-lg shadow-blue-500/20 font-bold text-sm"
>
{actionLabel}
</button>
</div>
</div>
</Modal>
);
}