Add searchable collaborator selector in admin products
This commit is contained in:
@@ -91,6 +91,7 @@ export default function AdminProducts() {
|
||||
const [filterType, setFilterType] = useState<string>('all');
|
||||
const [filterStatus, setFilterStatus] = useState<string>('all');
|
||||
const [collaborators, setCollaborators] = useState<CollaboratorProfile[]>([]);
|
||||
const [collaboratorSearch, setCollaboratorSearch] = useState('');
|
||||
|
||||
useEffect(() => {
|
||||
if (user && isAdmin) {
|
||||
@@ -132,6 +133,11 @@ export default function AdminProducts() {
|
||||
|
||||
// Get unique product types from actual products
|
||||
const productTypes = ['all', ...Array.from(new Set(products.map(p => p.type)))];
|
||||
const filteredCollaborators = collaborators.filter((c) => {
|
||||
const q = collaboratorSearch.trim().toLowerCase();
|
||||
if (!q) return true;
|
||||
return (c.name || '').toLowerCase().includes(q) || (c.email || '').toLowerCase().includes(q);
|
||||
});
|
||||
|
||||
const clearFilters = () => {
|
||||
setSearchQuery('');
|
||||
@@ -164,12 +170,14 @@ export default function AdminProducts() {
|
||||
profit_share_percentage: product.profit_share_percentage ?? 50,
|
||||
auto_grant_access: product.auto_grant_access ?? true,
|
||||
});
|
||||
setCollaboratorSearch('');
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
const handleNew = () => {
|
||||
setEditingProduct(null);
|
||||
setForm(emptyProduct);
|
||||
setCollaboratorSearch('');
|
||||
setDialogOpen(true);
|
||||
};
|
||||
|
||||
@@ -555,6 +563,15 @@ export default function AdminProducts() {
|
||||
</div>
|
||||
{form.type === 'webinar' && (
|
||||
<div className="space-y-4 border-2 border-border rounded-lg p-4">
|
||||
<div className="space-y-2">
|
||||
<Label>Cari Kolaborator</Label>
|
||||
<Input
|
||||
value={collaboratorSearch}
|
||||
onChange={(e) => setCollaboratorSearch(e.target.value)}
|
||||
placeholder="Cari nama atau email..."
|
||||
className="border-2"
|
||||
/>
|
||||
</div>
|
||||
<div className="space-y-2">
|
||||
<Label>Kolaborator (opsional)</Label>
|
||||
<Select
|
||||
@@ -566,13 +583,16 @@ export default function AdminProducts() {
|
||||
</SelectTrigger>
|
||||
<SelectContent>
|
||||
<SelectItem value="__none__">Tanpa kolaborator (solo)</SelectItem>
|
||||
{collaborators.map((c) => (
|
||||
{filteredCollaborators.map((c) => (
|
||||
<SelectItem key={c.id} value={c.id}>
|
||||
{(c.name || 'User') + (c.email ? ` (${c.email})` : '')}
|
||||
</SelectItem>
|
||||
))}
|
||||
</SelectContent>
|
||||
</Select>
|
||||
{collaboratorSearch && filteredCollaborators.length === 0 && (
|
||||
<p className="text-sm text-muted-foreground">Tidak ada kolaborator yang cocok.</p>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{!!form.collaborator_user_id && (
|
||||
|
||||
Reference in New Issue
Block a user