-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
278 additions
and
369 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
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
115 changes: 0 additions & 115 deletions
115
packages/frontend/src/components/PageLayout/PageLayout.tsx
This file was deleted.
Oops, something went wrong.
169 changes: 169 additions & 0 deletions
169
packages/frontend/src/components/PageLayout/PageLayoutArbeidsFlate.tsx
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,169 @@ | ||
import { type FooterProps, type HeaderProps, Layout, type LayoutProps, RootProvider } from '@altinn/altinn-components'; | ||
import { useQueryClient } from '@tanstack/react-query'; | ||
import cx from 'classnames'; | ||
import { type ChangeEvent, useEffect, useState } from 'react'; | ||
import { Outlet, useLocation, useSearchParams } from 'react-router-dom'; | ||
import { useDialogs } from '../../api/useDialogs.tsx'; | ||
import { useParties } from '../../api/useParties.ts'; | ||
import { getSearchStringFromQueryParams } from '../../pages/Inbox/queryParams.ts'; | ||
import { useSavedSearches } from '../../pages/SavedSearches/useSavedSearches.ts'; | ||
import { useProfile } from '../../profile'; | ||
import { BetaBanner } from '../BetaBanner/BetaBanner'; | ||
import { useSearchString } from '../Header'; | ||
import { useAuth } from '../Login/AuthContext.tsx'; | ||
import { useSidebarMenu } from '../Sidebar/useSidebarMenu.tsx'; | ||
import { useSelectedDialogs } from './SelectedDialogs'; | ||
import styles from './pageLayout.module.css'; | ||
|
||
export const useUpdateOnLocationChange = (fn: () => void) => { | ||
const location = useLocation(); | ||
// biome-ignore lint/correctness/useExhaustiveDependencies: Full control of what triggers this code is needed | ||
useEffect(() => { | ||
fn(); | ||
}, [location, fn]); | ||
}; | ||
|
||
const Background: React.FC<{ children: React.ReactNode; isCompany: boolean }> = ({ children, isCompany }) => { | ||
const { inSelectionMode } = useSelectedDialogs(); | ||
return ( | ||
<div | ||
data-testid="pageLayout-background" | ||
className={cx(styles.background, { | ||
isCompany: isCompany, | ||
[styles.inSelectionMode]: inSelectionMode, | ||
})} | ||
> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export const ProtectedPageLayout = () => { | ||
const { isAuthenticated } = useAuth(); | ||
if (!isAuthenticated) { | ||
return null; | ||
} | ||
return <PageLayoutArbeidsFlate />; | ||
}; | ||
|
||
const footerLinks = [ | ||
{ | ||
href: 'https://info.altinn.no/om-altinn/', | ||
resourceId: 'footer.nav.about_altinn', | ||
}, | ||
{ | ||
href: 'https://info.altinn.no/om-altinn/driftsmeldinger/', | ||
resourceId: 'footer.nav.service_messages', | ||
}, | ||
{ | ||
href: 'https://info.altinn.no/om-altinn/personvern/', | ||
resourceId: 'footer.nav.privacy_policy', | ||
}, | ||
{ | ||
href: 'https://info.altinn.no/om-altinn/tilgjengelighet/', | ||
resourceId: 'footer.nav.accessibility', | ||
}, | ||
]; | ||
|
||
export const PageLayoutArbeidsFlate: React.FC = () => { | ||
const [searchParams] = useSearchParams(); | ||
const [searchValue, setSearchValue] = useState<string>(''); | ||
const queryClient = useQueryClient(); | ||
const { setSearchString } = useSearchString(); | ||
const { selectedProfile, selectedParties, parties, selectedPartyIds } = useParties(); | ||
const { currentPartySavedSearches } = useSavedSearches(selectedPartyIds); | ||
const { dialogsByView } = useDialogs(selectedParties); | ||
const itemsPerViewCount = { | ||
inbox: dialogsByView.inbox.filter((item) => !item.isSeenByEndUser).length, | ||
drafts: dialogsByView.drafts.length, | ||
sent: dialogsByView.sent.length, | ||
'saved-searches': currentPartySavedSearches?.length ?? 0, | ||
archive: dialogsByView.archive.length, | ||
bin: dialogsByView.bin.length, | ||
}; | ||
|
||
const sidebarMenu = useSidebarMenu({ itemsPerViewCount }); | ||
|
||
useProfile(); | ||
|
||
useUpdateOnLocationChange(() => { | ||
const searchString = getSearchStringFromQueryParams(searchParams); | ||
queryClient.setQueryData(['search'], () => searchString || ''); | ||
}); | ||
|
||
interface AccountMenuItem { | ||
type: 'person' | 'company'; | ||
name: string; | ||
id: string; | ||
groupId?: string; | ||
selected?: boolean; | ||
} | ||
|
||
const currentEndUser = selectedParties.find((party) => party.isCurrentEndUser); | ||
const accounts: AccountMenuItem[] = parties.map((party) => ({ | ||
id: party.party, | ||
name: party.name, | ||
type: party.partyType.toLowerCase() as AccountMenuItem['type'], | ||
})); | ||
|
||
const endUserAccount = currentEndUser | ||
? { id: currentEndUser.party, name: currentEndUser.name, type: 'person' } | ||
: { | ||
id: '', | ||
name: '', | ||
type: 'person', | ||
}; | ||
|
||
const headerProps: HeaderProps = { | ||
currentAccount: endUserAccount as HeaderProps['currentAccount'], | ||
menu: { | ||
menuLabel: 'Meny', | ||
items: [], | ||
accounts, | ||
changeLabel: 'Endre konto', | ||
backLabel: 'Tilbake', | ||
}, | ||
search: { | ||
expanded: false, | ||
name: 'search', | ||
placeholder: 'Søk', | ||
value: searchValue, | ||
onClear: () => setSearchValue(''), | ||
onChange: (event: ChangeEvent<HTMLInputElement>) => setSearchValue(event.target.value), | ||
onEnter: () => setSearchString(searchValue), | ||
}, | ||
}; | ||
|
||
const footerProps: FooterProps = { | ||
address: 'Altinn AS, Postboks 6783 St. Olavs plass, 0130 Oslo', | ||
menu: { | ||
items: footerLinks.map((link) => ({ | ||
id: link.resourceId, | ||
href: link.href, | ||
text: link.resourceId, | ||
})), | ||
}, | ||
}; | ||
|
||
const layoutProps: LayoutProps = { | ||
theme: selectedProfile, | ||
header: headerProps, | ||
footer: footerProps, | ||
sidebar: { | ||
theme: selectedProfile, | ||
menu: sidebarMenu, | ||
}, | ||
children: undefined, | ||
}; | ||
|
||
return ( | ||
<Background isCompany={selectedProfile === 'company'}> | ||
<BetaBanner /> | ||
<RootProvider> | ||
<Layout theme={selectedProfile} {...layoutProps}> | ||
<Outlet /> | ||
</Layout> | ||
</RootProvider> | ||
</Background> | ||
); | ||
}; |
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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
export { PageLayout } from './PageLayout'; | ||
export { PageLayoutArbeidsFlate } from './PageLayoutArbeidsFlate.tsx'; | ||
export * from './SelectedDialogs'; |
40 changes: 0 additions & 40 deletions
40
packages/frontend/src/components/PageLayout/pageLayout.module.css
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 |
---|---|---|
@@ -1,45 +1,5 @@ | ||
.pageLayout { | ||
display: grid; | ||
grid-template-areas: "sidebar main"; | ||
grid-template-columns: 226px 3fr; | ||
grid-template-rows: auto 1fr auto; | ||
grid-gap: 2rem; | ||
max-width: calc(1280px - 2rem); | ||
margin: 0 auto; | ||
padding-left: 1rem; | ||
padding-right: 1rem; | ||
} | ||
|
||
.background { | ||
min-height: 100vh; | ||
background: var(--background-color); | ||
overflow: auto; | ||
} | ||
|
||
.inSelectionMode.background { | ||
background: var(--grey); | ||
} | ||
|
||
.pageLayout > header { | ||
grid-area: header; | ||
} | ||
|
||
.pageLayout > main { | ||
grid-area: main; | ||
padding: 0; | ||
width: 100%; | ||
margin-right: auto; | ||
} | ||
|
||
.pageLayout > footer { | ||
grid-area: footer; | ||
} | ||
|
||
@media (max-width: 1024px) { | ||
.pageLayout { | ||
grid-template-areas: "main main"; | ||
grid-template-columns: 1fr 3fr; | ||
padding-left: 0; | ||
padding-right: 0; | ||
} | ||
} |
6 changes: 3 additions & 3 deletions
6
packages/frontend/src/components/PartyDropdown/PartyDropdown.tsx
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
Oops, something went wrong.