This repository has been archived by the owner on Jun 10, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: link group suggestions (#10127)
* feat: gorup suggestions for users * fixed typo Co-authored-by: Eddie Jaoude <eddie@jaoudestudios.com> * fix: new group cannot be added * refactor: groupSearchLink pages * refactor: groupSearchLink pages * fix:9878 group suggestion link * fix:9878 group suggestion link --------- Co-authored-by: Eddie Jaoude <eddie@jaoudestudios.com>
- Loading branch information
1 parent
69ec08e
commit 3de1e09
Showing
3 changed files
with
89 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useState } from "react"; | ||
import { Combobox } from "@headlessui/react"; | ||
import Label from "./form/Label"; | ||
|
||
function GroupLinkSearch({ selectedGroup, handleGroupSelection, groups }) { | ||
const [query, setQuery] = useState(""); | ||
|
||
const handleGroupChange = (e) => { | ||
setQuery(e.target.value); | ||
const currentValue = e.target.value; | ||
if (!groups.includes(currentValue)) { | ||
handleGroupSelection(currentValue); | ||
} | ||
}; | ||
|
||
const filteredGroup = | ||
query === "" | ||
? groups.length > 0 && groups.slice(0, 5) | ||
: groups.length > 0 && | ||
groups | ||
.filter((group) => { | ||
return group.toLowerCase().includes(query.toLowerCase()); | ||
}) | ||
.slice(0, 5); | ||
|
||
return ( | ||
<Combobox value={selectedGroup} onChange={handleGroupSelection}> | ||
<Label htmlFor="search-groups">Group</Label> | ||
<Combobox.Input | ||
name="search-group" | ||
onChange={handleGroupChange} | ||
className={ | ||
"border-2 transition-all duration-250 ease-linear rounded px-6 py-2 mb-2 block w-full dark:bg-primary-high hover:border-tertiary-medium focus:ring-0 focus:border-tertiary-medium focus:outline-0" | ||
} | ||
/> | ||
<Combobox.Options | ||
className={ | ||
"border-2 rounded border-tertiary-medium dark:bg-primary-medium" | ||
} | ||
> | ||
{filteredGroup.length > 0 && | ||
filteredGroup.map((group) => { | ||
return ( | ||
<Combobox.Option | ||
key={group} | ||
value={group} | ||
className={ | ||
"px-3 py-2 flex items-center dark:hover:bg-tertiary-medium/60 hover:bg-secondary-low/40" | ||
} | ||
> | ||
{group !== "" && <span>{group}</span>} | ||
</Combobox.Option> | ||
); | ||
})} | ||
</Combobox.Options> | ||
</Combobox> | ||
); | ||
} | ||
|
||
export default GroupLinkSearch; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters