Show templates from all brands when selected brand has no templates

This commit is contained in:
2025-03-08 14:34:49 -05:00
parent 31c838197a
commit 74454cdc7f

View File

@@ -138,7 +138,11 @@ const SearchableTemplateSelect: React.FC<SearchableTemplateSelectProps> = ({
// First filter by brand if selected // First filter by brand if selected
let brandFiltered = templates; let brandFiltered = templates;
if (selectedBrand) { if (selectedBrand) {
brandFiltered = templates.filter(t => t?.company === selectedBrand); // Check if the selected brand has any templates
const brandTemplates = templates.filter(t => t?.company === selectedBrand);
// If the selected brand has templates, use them; otherwise, show all templates
brandFiltered = brandTemplates.length > 0 ? brandTemplates : templates;
} }
// Then filter by search term if provided // Then filter by search term if provided
@@ -268,9 +272,23 @@ const SearchableTemplateSelect: React.FC<SearchableTemplateSelectProps> = ({
<ScrollArea className="max-h-[200px] overflow-y-auto" onWheel={handleWheel}> <ScrollArea className="max-h-[200px] overflow-y-auto" onWheel={handleWheel}>
{!searchTerm ? ( {!searchTerm ? (
selectedBrand ? ( selectedBrand ? (
groupedTemplates[selectedBrand]?.length > 0 ? (
<CommandGroup heading={brands.find(b => b.id === selectedBrand)?.name || selectedBrand}> <CommandGroup heading={brands.find(b => b.id === selectedBrand)?.name || selectedBrand}>
{groupedTemplates[selectedBrand]?.map(template => renderCommandItem(template))} {groupedTemplates[selectedBrand]?.map(template => renderCommandItem(template))}
</CommandGroup> </CommandGroup>
) : (
// If selected brand has no templates, show all brands
Object.entries(groupedTemplates).map(([companyId, companyTemplates]) => {
const brand = brands.find(b => b.id === companyId);
const companyName = brand ? brand.name : companyId;
return (
<CommandGroup key={companyId} heading={companyName}>
{companyTemplates.map(template => renderCommandItem(template))}
</CommandGroup>
);
})
)
) : ( ) : (
Object.entries(groupedTemplates).map(([companyId, companyTemplates]) => { Object.entries(groupedTemplates).map(([companyId, companyTemplates]) => {
const brand = brands.find(b => b.id === companyId); const brand = brands.find(b => b.id === companyId);