2021-01-29 13:59:03 +00:00
|
|
|
import React from "react";
|
|
|
|
import { useTranslation } from "react-i18next";
|
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
ButtonVariant,
|
|
|
|
EmptyState,
|
|
|
|
EmptyStateBody,
|
|
|
|
Form,
|
|
|
|
InputGroup,
|
|
|
|
TextInput,
|
|
|
|
Title,
|
|
|
|
} from "@patternfly/react-core";
|
|
|
|
import { SearchIcon } from "@patternfly/react-icons";
|
|
|
|
import { useForm } from "react-hook-form";
|
2021-03-04 15:13:36 +00:00
|
|
|
import { useHistory, useRouteMatch } from "react-router-dom";
|
2021-01-29 13:59:03 +00:00
|
|
|
|
|
|
|
type SearchUserProps = {
|
|
|
|
onSearch: (search: string) => void;
|
|
|
|
};
|
|
|
|
|
|
|
|
export const SearchUser = ({ onSearch }: SearchUserProps) => {
|
|
|
|
const { t } = useTranslation("users");
|
|
|
|
const { register, handleSubmit } = useForm<{ search: string }>();
|
2021-03-04 15:13:36 +00:00
|
|
|
const { url } = useRouteMatch();
|
|
|
|
const history = useHistory();
|
|
|
|
|
|
|
|
const goToCreate = () => history.push(`${url}/add-user`);
|
|
|
|
|
2021-01-29 13:59:03 +00:00
|
|
|
return (
|
|
|
|
<EmptyState>
|
2021-03-04 18:49:05 +00:00
|
|
|
<Title data-testid="search-users-title" headingLevel="h4" size="lg">
|
2021-01-29 13:59:03 +00:00
|
|
|
{t("startBySearchingAUser")}
|
|
|
|
</Title>
|
|
|
|
<EmptyStateBody>
|
|
|
|
<Form onSubmit={handleSubmit((form) => onSearch(form.search))}>
|
|
|
|
<InputGroup>
|
|
|
|
<TextInput
|
|
|
|
type="text"
|
|
|
|
id="kc-user-search"
|
|
|
|
name="search"
|
|
|
|
ref={register()}
|
|
|
|
/>
|
|
|
|
<Button
|
|
|
|
variant={ButtonVariant.control}
|
|
|
|
aria-label={t("common:search")}
|
|
|
|
type="submit"
|
|
|
|
>
|
|
|
|
<SearchIcon />
|
|
|
|
</Button>
|
|
|
|
</InputGroup>
|
|
|
|
</Form>
|
|
|
|
</EmptyStateBody>
|
2021-03-04 18:49:05 +00:00
|
|
|
<Button data-testid="create-new-user" variant="link" onClick={goToCreate}>
|
2021-01-29 13:59:03 +00:00
|
|
|
{t("createNewUser")}
|
|
|
|
</Button>
|
|
|
|
</EmptyState>
|
|
|
|
);
|
|
|
|
};
|