Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds support for searching for OrganizationSelector and fix scroll for dropdown in sheet #9620

Merged
merged 6 commits into from
Dec 31, 2024
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/components/ui/autocomplete.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ interface AutocompleteProps {
options: AutoCompleteOption[];
value: string;
onChange: (value: string) => void;
onSearch?: (value: string) => void;
placeholder?: string;
noOptionsMessage?: string;
disabled?: boolean;
Expand All @@ -36,14 +37,15 @@ export default function Autocomplete({
options,
value,
onChange,
onSearch,
placeholder = "Select...",
noOptionsMessage = "No options found",
disabled,
}: AutocompleteProps) {
const [open, setOpen] = React.useState(false);

return (
<Popover open={open} onOpenChange={setOpen}>
<Popover open={open} onOpenChange={setOpen} modal={true}>
<PopoverTrigger asChild>
<Button
title={
Expand All @@ -70,6 +72,7 @@ export default function Autocomplete({
<CommandInput
placeholder="Search option..."
disabled={disabled}
onValueChange={onSearch}
className="outline-none border-none ring-0 shadow-none"
/>
<CommandList>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import Autocomplete from "@/components/ui/autocomplete";
import { Button } from "@/components/ui/button";
import InputWithError from "@/components/ui/input-with-error";

import useDebouncedState from "@/hooks/useDebouncedState";

import { ORGANIZATION_LEVELS } from "@/common/constants";

import routes from "@/Utils/request/api";
Expand All @@ -32,6 +34,7 @@ interface AutoCompleteOption {
export default function OrganizationSelector(props: OrganizationSelectorProps) {
const { onChange, required } = props;
const [selectedLevels, setSelectedLevels] = useState<Organization[]>([]);
const [searchQuery, setSearchQuery] = useDebouncedState("", 500);

const headers = props.authToken
? {
Expand All @@ -42,11 +45,12 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
: {};

const { data: getAllOrganizations } = useQuery<OrganizationResponse>({
queryKey: ["organizations-root"],
queryKey: ["organizations-root", searchQuery],
queryFn: query(routes.organization.list, {
queryParams: {
org_type: "govt",
parent: "",
name: searchQuery || undefined,
},
...headers,
}),
Expand All @@ -58,11 +62,13 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
queryKey: [
"organizations-current",
selectedLevels[selectedLevels.length - 1]?.id,
searchQuery,
],
queryFn: query(routes.organization.list, {
queryParams: {
parent: selectedLevels[selectedLevels.length - 1]?.id,
org_type: "govt",
name: searchQuery || undefined,
},
...headers,
}),
Expand Down Expand Up @@ -153,6 +159,7 @@ export default function OrganizationSelector(props: OrganizationSelectorProps) {
onChange={(value: string) =>
handleLevelChange(value, selectedLevels.length)
}
onSearch={setSearchQuery}
/>
</InputWithError>
</div>
Expand Down
Loading