Skip to content

Commit

Permalink
fix(edit): edit board page when meta field missing (#1538)
Browse files Browse the repository at this point in the history
  • Loading branch information
purusott authored Jun 5, 2024
1 parent 702847b commit 1feb940
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { DEFAULT_BOARD_NAME } from 'app/(admin)/utils/constants'
import { useToast } from '@entur/alert'
import { isEmptyOrSpaces } from 'app/(admin)/edit/utils'

function MetaSettings({ bid, meta }: { bid: TBoardID; meta: TMeta }) {
function MetaSettings({ bid, meta }: { bid: TBoardID; meta?: TMeta }) {
const { addToast } = useToast()
return (
<>
Expand All @@ -34,7 +34,7 @@ function MetaSettings({ bid, meta }: { bid: TBoardID; meta: TMeta }) {
<TextField
name="name"
className="w-full"
defaultValue={meta.title ?? DEFAULT_BOARD_NAME}
defaultValue={meta?.title ?? DEFAULT_BOARD_NAME}
label="Navn på tavlen"
maxLength={30}
/>
Expand All @@ -46,7 +46,7 @@ function MetaSettings({ bid, meta }: { bid: TBoardID; meta: TMeta }) {
</SubmitButton>
</div>
</form>
<Address bid={bid} location={meta.location} />
<Address bid={bid} location={meta?.location} />
<form
action={async (data: FormData) => {
const font = data.get('font') as TFontSize
Expand All @@ -56,7 +56,7 @@ function MetaSettings({ bid, meta }: { bid: TBoardID; meta: TMeta }) {
className="box flex flex-col justify-between"
>
<Heading3 margin="bottom">Tekststørrelse </Heading3>
<FontChoiceChip font={meta.fontSize ?? 'medium'} />
<FontChoiceChip font={meta?.fontSize ?? 'medium'} />
<div className="flex flex-row mt-8 justify-end">
<SubmitButton variant="secondary" className="max-sm:w-full">
Lagre tekststørrelse
Expand Down
5 changes: 3 additions & 2 deletions next-tavla/app/(admin)/edit/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Open } from './components/Buttons/Open'
import { Copy } from './components/Buttons/Copy'
import { Footer } from './components/Footer'
import { RefreshButton } from './components/RefreshButton'
import { DEFAULT_BOARD_NAME } from 'app/(admin)/utils/constants'

type TProps = {
params: { id: TBoardID }
Expand All @@ -25,7 +26,7 @@ export async function generateMetadata({ params }: TProps): Promise<Metadata> {
const { id } = params
const board = await getBoard(id)
return {
title: `${board.meta?.title} | Entur Tavla`,
title: `${board.meta?.title ?? DEFAULT_BOARD_NAME} | Entur Tavla`,
}
}

Expand Down Expand Up @@ -69,7 +70,7 @@ export default async function EditPage({ params }: TProps) {

const tile = await getWalkingDistanceTile(
formDataToTile(data, organization),
board.meta.location,
board.meta?.location,
)
if (!tile.placeId) return
await addTile(params.id, tile)
Expand Down

0 comments on commit 1feb940

Please sign in to comment.