Add searchable collaborator selector in admin products

This commit is contained in:
dwindown
2026-02-03 17:33:13 +07:00
parent 52b16dce07
commit 8be40dc0f9

View File

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