Skip to content

Commit

Permalink
IS-2842: Move søk to side
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed Nov 28, 2024
1 parent daac3b7 commit 780b985
Show file tree
Hide file tree
Showing 9 changed files with 105 additions and 207 deletions.
36 changes: 0 additions & 36 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 0 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@
"nav-frontend-chevron": "1.0.28",
"nav-frontend-chevron-style": "1.0.4",
"nav-frontend-core": "5.0.11",
"nav-frontend-ekspanderbartpanel": "3.0.56",
"nav-frontend-ekspanderbartpanel-style": "1.0.42",
"nav-frontend-grid": "1.0.50",
"nav-frontend-grid-style": "1.0.2",
"nav-frontend-ikoner-assets": "2.0.10",
Expand Down
101 changes: 34 additions & 67 deletions src/components/NavigationBar.tsx
Original file line number Diff line number Diff line change
@@ -1,85 +1,52 @@
import React, { ReactElement } from 'react';
import { NavLink } from 'react-router-dom';
import styled from 'styled-components';
import { useLocation, useNavigate } from 'react-router-dom';
import { MoteoversiktLink } from '@/components/MoteoversiktLink';
import {
enhetOversiktRoutePath,
minOversiktRoutePathRoutePath,
minOversiktRoutePath,
sokSykmeldtRoutePath,
} from '@/routers/AppRouter';
import { Box, Heading, HStack, Tabs } from '@navikt/ds-react';
import { useFeatureToggles } from '@/data/unleash/unleashQueryHooks';
import { MagnifyingGlassIcon } from '@navikt/aksel-icons';

const texts = {
enhetensOversikt: 'Enhetens oversikt',
minOversikt: 'Min oversikt',
sokSykmeldt: 'Søk etter sykmeldt',
};

const LinkStyled = styled(NavLink)`
padding: 0;
background-color: transparent;
border: none;
font-weight: 600;
font-size: 20px;
cursor: pointer;
color: black;
border-bottom: 0.1em transparent solid;
border-bottom-color: transparent;
text-decoration: none;
&.active {
border-bottom-color: #0c5ea8;
}
&:visited {
color: black;
}
&:focus {
outline: none;
}
&:hover {
border-bottom-color: #0c5ea8;
}
`;

const NavigationBarDiv = styled.div`
background: white;
width: 100%;
margin: auto;
margin-bottom: 1em;
`;

const NavigationBarContent = styled.div`
width: calc(100% - 10%);
margin: auto;
padding-top: 1em;
padding-bottom: 1em;
display: flex;
> :not(:last-child) {
margin-right: 1em;
}
`;

export const NavigationBar = (): ReactElement => {
const { toggles } = useFeatureToggles();
const navigate = useNavigate();
const { pathname } = useLocation();

return (
<NavigationBarDiv>
<NavigationBarContent>
<LinkStyled
className={({ isActive }) => (isActive ? 'active' : '')}
to={minOversiktRoutePathRoutePath}
>
{texts.minOversikt}
</LinkStyled>
<LinkStyled
className={({ isActive }) => (isActive ? 'active' : '')}
to={enhetOversiktRoutePath}
>
{texts.enhetensOversikt}
</LinkStyled>
<Box className="mb-4" background="surface-default">
<HStack className="w-11/12 m-auto">
<Tabs value={pathname} onChange={(value) => navigate(value)}>
<Tabs.List>
<Tabs.Tab
value={minOversiktRoutePath}
label={<Heading size="small">{texts.minOversikt}</Heading>}
></Tabs.Tab>
<Tabs.Tab
value={enhetOversiktRoutePath}
label={<Heading size="small">{texts.enhetensOversikt}</Heading>}
></Tabs.Tab>
{toggles.isSokEnabled && (
<Tabs.Tab
value={sokSykmeldtRoutePath}
icon={<MagnifyingGlassIcon />}
label={<Heading size="small">{texts.sokSykmeldt}</Heading>}
></Tabs.Tab>
)}
</Tabs.List>
</Tabs>
<div className="ml-auto self-center">
<MoteoversiktLink />
</div>
</NavigationBarContent>
</NavigationBarDiv>
</HStack>
</Box>
);
};
12 changes: 12 additions & 0 deletions src/components/sokperson/SokContainer.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import React from 'react';
import { NavigationBar } from '@/components/NavigationBar';
import SokPerson from '@/components/sokperson/SokPerson';

export default function SokContainer() {
return (
<div className="flex flex-col mx-8">
<NavigationBar />
<SokPerson />
</div>
);
}
120 changes: 52 additions & 68 deletions src/components/sokperson/SokPerson.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
Button,
Heading,
HStack,
Modal,
TextField,
VStack,
} from '@navikt/ds-react';
Expand All @@ -18,7 +17,6 @@ import { isNumeric, removePunctuation } from '@/utils/stringUtil';
import { parseDateString } from '@/utils/dateUtils';

const texts = {
buttonText: 'Søk etter sykmeldt',
header: 'Søk etter sykmeldt',
info:
'Her kan du søke opp sykmeldte personer basert på initialer og fødselsdato.',
Expand All @@ -30,7 +28,6 @@ const texts = {
};

export default function SokPerson() {
const [isModalOpen, setIsModalOpen] = useState<boolean>(false);
const [nameInitials, setNameInitials] = useState<string>('');
const [birthdate, setBirthdate] = useState<string>('');
const {
Expand Down Expand Up @@ -70,70 +67,57 @@ export default function SokPerson() {
};

return (
<Box>
<Button onClick={() => setIsModalOpen(true)} size="small">
{texts.buttonText}
</Button>
<Modal
closeOnBackdropClick
className="w-[90%] max-w-[90%]"
open={isModalOpen}
aria-label={texts.buttonText}
onClose={() => setIsModalOpen(false)}
>
<Modal.Header>
<Heading level="2" size="medium">
{texts.header}
</Heading>
</Modal.Header>
<Modal.Body>
<VStack gap="4">
<BodyShort>{texts.info}</BodyShort>
<HStack gap="8" align="end">
<TextField
label="Initialer"
description="AB"
htmlSize={10}
type="text"
onChange={(e) => setNameInitials(e.target.value)}
error={
isFormError && !validInitials(nameInitials)
? texts.validation.initials
: undefined
}
/>
<TextField
label="Fødselsdato"
description="ddmmåå"
htmlSize={14}
type="text"
onChange={(e) => setBirthdate(e.target.value)}
error={
isFormError && parseBirthdate(birthdate) === null
? texts.validation.birthdate
: undefined
}
/>
<Button
onClick={handleSubmit}
loading={isLoading}
icon={<MagnifyingGlassIcon />}
type="submit"
>
Søk
</Button>
</HStack>
{searchResults && isSuccess && (
<SokPersonResultat sokeresultater={searchResults} />
)}
{isError && (
<Alert variant="error" size="small">
{texts.error}
</Alert>
)}
</VStack>
</Modal.Body>
</Modal>
</Box>
<>
<Box background="surface-default" padding="4">
<Heading level="2" size="medium">
{texts.header}
</Heading>
<VStack gap="4">
<BodyShort>{texts.info}</BodyShort>
<HStack gap="8" align="end">
<TextField
label="Initialer"
description="AB"
htmlSize={10}
type="text"
onChange={(e) => setNameInitials(e.target.value)}
error={
isFormError && !validInitials(nameInitials)
? texts.validation.initials
: undefined
}
/>
<TextField
label="Fødselsdato"
description="ddmmåå"
htmlSize={14}
type="text"
onChange={(e) => setBirthdate(e.target.value)}
error={
isFormError && parseBirthdate(birthdate) === null
? texts.validation.birthdate
: undefined
}
/>
<Button
onClick={handleSubmit}
loading={isLoading}
icon={<MagnifyingGlassIcon />}
type="submit"
>
Søk
</Button>
</HStack>
{isError && (
<Alert variant="error" size="small">
{texts.error}
</Alert>
)}
</VStack>
</Box>
{searchResults && isSuccess && (
<SokPersonResultat sokeresultater={searchResults} />
)}
</>
);
}
2 changes: 1 addition & 1 deletion src/components/sokperson/SokPersonResultat.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default function SokPersonResultat({
const personer = Object.entries(toPersonData(sokeresultater, []));

return personer.length === 0 ? (
<Box>
<Box background="surface-default" padding="4" className="mt-2">
<BodyShort>{texts.noResults.first}</BodyShort>
<BodyShort>{texts.noResults.second}</BodyShort>
</Box>
Expand Down
4 changes: 0 additions & 4 deletions src/components/toolbar/ToolbarWrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import React, { ReactElement, useState } from 'react';
import Toolbar from './Toolbar';
import { Label } from '@navikt/ds-react';
import { PAGINATED_NUMBER_OF_ITEMS } from '@/components/toolbar/PaginationContainer';
import SokPerson from '@/components/sokperson/SokPerson';
import { useFeatureToggles } from '@/data/unleash/unleashQueryHooks';

export interface ToolbarWrapperProps {
alleMarkert: boolean;
Expand Down Expand Up @@ -37,7 +35,6 @@ const ToolbarWrapper = (props: ToolbarWrapperProps): ReactElement => {
firstVisibleIndex: 0,
lastVisibleIndex: PAGINATED_NUMBER_OF_ITEMS,
});
const { toggles } = useFeatureToggles();

return (
<>
Expand All @@ -52,7 +49,6 @@ const ToolbarWrapper = (props: ToolbarWrapperProps): ReactElement => {
</Label>
)}
</div>
{toggles.isSokEnabled && <SokPerson />}
</div>
<Toolbar {...props} setPageInfo={setPageInfo} />
</>
Expand Down
Loading

0 comments on commit 780b985

Please sign in to comment.