Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
22 changes: 22 additions & 0 deletions src/components/SearchField/SearchField.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React, { FC, FormEvent } from 'react';

import { Icon, TextField } from '@orfium/ictinus';

interface Props {
placeholder: string;
onSearch: (term: string) => void;
}

const SearchField: FC<Props> = ({ onSearch, placeholder }) => {
return (
<TextField
data-testid="search-field"
styleType={'filled'}
placeholder={placeholder}
leftIcon={<Icon name={'search'} color={'black'} />}
onInput={(event: FormEvent<HTMLInputElement>) => onSearch(event?.currentTarget?.value)}
/>
);
};

export default SearchField;
1 change: 1 addition & 0 deletions src/components/SearchField/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './SearchField';
1 change: 0 additions & 1 deletion src/hooks/api/userHooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ export const useSignIn = () => {

return useMutation<LoginResponse, AxiosError, LoginFormType>(
(params) => {
console.log(params);
const { request } = userAPI.single.signIn({
username: params.username,
password: params.password,
Expand Down
25 changes: 21 additions & 4 deletions src/pages/Layout/Layout.tsx
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
/** @jsxImportSource @emotion/react */
import React from 'react';
import React, { useState } from 'react';

import { IconButton } from '@orfium/ictinus';
import { TopBar } from 'App.style';
import { useResponsiveLayout } from 'hooks/useResponsiveSidebar';
import { debounce } from 'lodash';
import { useHistory } from 'react-router';

import Drawer from '../../components/Drawer';
import SearchField from '../../components/SearchField';
import { Header, Main, MainContainer, SideNav } from './Layout.style';

interface Props {
/** Component to load */
component?: React.FC;
component?: React.FC<{ searchTerm?: string }>;
}

const Layout: React.FC<Props> = ({ component: Component }) => {
const { responsiveProps, expanded, setExpanded } = useResponsiveLayout();
const [searchTerm, setSearchTerm] = useState('');

const history = useHistory();

const handleSearchTerm = (term: string) => {
setSearchTerm(term);
};

return (
<MainContainer {...responsiveProps}>
Expand All @@ -28,7 +38,12 @@ const Layout: React.FC<Props> = ({ component: Component }) => {
type="primary"
onClick={() => setExpanded((prevState) => !prevState)}
/>
<span>Tanzanian MHP Registry</span>
{history.location.pathname === '/patients' && (
<SearchField
placeholder={'Search by name, gender, patient ID...'}
onSearch={debounce(handleSearchTerm, 200)}
/>
)}
</TopBar>
</Header>
<SideNav>
Expand Down Expand Up @@ -57,7 +72,9 @@ const Layout: React.FC<Props> = ({ component: Component }) => {
]}
/>
</SideNav>
<Main css={{ flexDirection: 'column' }}>{Component && <Component />}</Main>
<Main css={{ flexDirection: 'column' }}>
{Component && <Component searchTerm={searchTerm} />}
</Main>
</MainContainer>
);
};
Expand Down
4 changes: 1 addition & 3 deletions src/pages/PatientDirectory/PatientDirectory.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ import {
} from './PatientDirectory.style';
import { SortingOptionsType } from './types';

const PatientDirectory: React.FC = () => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [searchTerm, setSearchTerm] = useState<string>('');
const PatientDirectory: React.FC<{ searchTerm?: string }> = ({ searchTerm }) => {
const [hospitalId, setHospitalId] = useState<number>();

const [sortingOption, setSortingOption] = useState<SortingOptionsType>('name');
Expand Down