Skip to content

Commit

Permalink
fix(header): structured navigation header (#1240)
Browse files Browse the repository at this point in the history
* feat(header): optional buttons in header

* feat(header): add AdminHeader to all pages

* fix(pages): refactor contrast

* feat(header): add icons

* fix(create board): change button to primary button

* feat(create board): remove create board component from boards

* fix(style): gap between header and body

* fix(header): icons before text

* chore(header): remove options prop from header

* chore(header): icon to create board

* chore(header): remove prop from create board
  • Loading branch information
natashatikhonova authored Sep 26, 2023
1 parent 54e0211 commit cc97354
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 29 deletions.
14 changes: 8 additions & 6 deletions next-tavla/pages/edit/[id].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,14 @@ function AdminPage({
id: string
}) {
return (
<Contrast className={classes.root}>
<ToastProvider>
<AdminHeader user={user} />
<Edit initialBoard={board} documentId={id} user={user} />
</ToastProvider>
</Contrast>
<div className={classes.root}>
<AdminHeader user={user} />
<Contrast>
<ToastProvider>
<Edit initialBoard={board} documentId={id} user={user} />
</ToastProvider>
</Contrast>
</div>
)
}

Expand Down
26 changes: 18 additions & 8 deletions next-tavla/pages/edit/boards.tsx
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import classes from 'styles/pages/admin.module.css'
import { Contrast } from '@entur/layout'
import { ToastProvider } from '@entur/alert'
import { Header } from 'components/Header'
import { Boards } from 'Admin/scenarios/Boards'
import { TBoard } from 'types/settings'
import { getBoardsForUser } from 'Admin/utils/firebase'
import { verifyUserSession } from 'Admin/utils/auth'
import { IncomingNextMessage } from 'types/next'
import { AdminHeader } from 'Admin/components/AdminHeader'
import { DecodedIdToken } from 'firebase-admin/lib/auth/token-verifier'

export async function getServerSideProps({
req,
Expand All @@ -27,18 +28,27 @@ export async function getServerSideProps({
return {
props: {
boards: boards,
user: user,
},
}
}

function OverviewPage({ boards }: { boards: TBoard[] }) {
function OverviewPage({
boards,
user,
}: {
boards: TBoard[]
user: DecodedIdToken | null
}) {
return (
<Contrast className={classes.root}>
<ToastProvider>
<Header />
<Boards boards={boards} />
</ToastProvider>
</Contrast>
<div className={classes.root}>
<AdminHeader user={user} />
<Contrast>
<ToastProvider>
<Boards boards={boards} />
</ToastProvider>
</Contrast>
</div>
)
}

Expand Down
12 changes: 9 additions & 3 deletions next-tavla/src/Admin/components/AdminHeader/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ import dynamic from 'next/dynamic'
import { PrimaryButton } from '@entur/button'
import Link from 'next/link'
import classes from './styles.module.css'
import { CreateBoard } from '../CreateBoard'
import { UserIcon } from '@entur/icons'

function AdminHeader({ user }: { user: DecodedIdToken | null }) {
return (
Expand All @@ -21,9 +23,13 @@ function AdminHeader({ user }: { user: DecodedIdToken | null }) {
</Link>
<div className={classes.buttons}>
{user && (
<PrimaryButton as={Link} href="/edit/boards">
Mine Tavler
</PrimaryButton>
<>
<CreateBoard />
<PrimaryButton as={Link} href="/edit/boards">
<UserIcon />
Mine Tavler
</PrimaryButton>
</>
)}
<Login user={user} />
</div>
Expand Down
9 changes: 5 additions & 4 deletions next-tavla/src/Admin/components/CreateBoard/index.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { Button } from '@entur/button'
import { PrimaryButton } from '@entur/button'
import { useState } from 'react'
import Link from 'next/link'
import { AddIcon } from '@entur/icons'

function CreateBoard() {
const [loading, isLoading] = useState(false)
return (
<Button
<PrimaryButton
as={Link}
href="/api/board"
replace
onClick={() => isLoading(true)}
variant="primary"
disabled={loading}
loading={loading}
>
<AddIcon />
Opprett ny tavle
</Button>
</PrimaryButton>
)
}
export { CreateBoard }
6 changes: 1 addition & 5 deletions next-tavla/src/Admin/scenarios/Boards/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { isEmpty } from 'lodash'
import { IllustratedInfo } from 'Admin/components/IllustratedInfo'
import { TableHeader } from './components/TableHeader'
import { TableRows } from './components/TableRows'
import { CreateBoard } from 'Admin/components/CreateBoard'

function Boards({ boards }: { boards: TBoard[] }) {
const [settings, dispatch] = useReducer(settingsReducer, {
Expand All @@ -28,10 +27,7 @@ function Boards({ boards }: { boards: TBoard[] }) {
<SettingsContext.Provider value={settings}>
<SettingsDispatchContext.Provider value={dispatch}>
<div className={classes.boards}>
<div className={classes.header}>
<Heading1>Mine Tavler</Heading1>
<CreateBoard />
</div>
<Heading1>Mine Tavler</Heading1>
<Search />
<BoardTable />
</div>
Expand Down
12 changes: 9 additions & 3 deletions next-tavla/src/Admin/scenarios/Login/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { PrimaryButton, SecondarySquareButton } from '@entur/button'
import { BackArrowIcon, CloseIcon } from '@entur/icons'
import { BackArrowIcon, CloseIcon, LogOutIcon, UserIcon } from '@entur/icons'
import { Modal } from '@entur/modal'
import { TLoginPage } from 'Admin/types/login'
import { DecodedIdToken } from 'firebase-admin/lib/auth/token-verifier'
Expand All @@ -19,7 +19,11 @@ function Login({ user }: { user: DecodedIdToken | null }) {

if (user) {
// return early if user is already logged in
return <PrimaryButton onClick={logout}>Logg ut</PrimaryButton>
return (
<PrimaryButton onClick={logout}>
<LogOutIcon /> Logg ut
</PrimaryButton>
)
}

const pushPage = (page: TLoginPage) => {
Expand All @@ -34,7 +38,9 @@ function Login({ user }: { user: DecodedIdToken | null }) {

return (
<>
<PrimaryButton onClick={open}>Logg inn</PrimaryButton>
<PrimaryButton onClick={open}>
<UserIcon /> Logg inn
</PrimaryButton>
<Modal
open={isOpen}
size="small"
Expand Down
3 changes: 3 additions & 0 deletions next-tavla/src/Shared/styles/pages/admin.module.css
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
.root {
display: flex;
flex-direction: column;
gap: 1em;
padding: 1em;
margin: 0 5em;
}

0 comments on commit cc97354

Please sign in to comment.