Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(error): handle failed saveLocation #1684

Merged
merged 1 commit into from
Oct 21, 2024
Merged
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
24 changes: 17 additions & 7 deletions tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,31 @@ import { Tooltip } from 'app/(admin)/components/Tooltip'
import { saveLocation } from 'app/(admin)/edit/[id]/components/MetaSettings/actions'
import { usePointSearch } from 'app/(admin)/hooks/usePointSearch'
import { SubmitButton } from 'components/Form/SubmitButton'
import { FormEvent } from 'react'
import { TLocation } from 'types/meta'
import { TBoardID } from 'types/settings'

function Address({ bid, location }: { bid: TBoardID; location?: TLocation }) {
const { pointItems, selectedPoint, setSelectedPoint } =
usePointSearch(location)
const { addToast } = useToast()

const handleSubmit = async (event: FormEvent<HTMLFormElement>) => {
event.preventDefault()

try {
await saveLocation(bid, selectedPoint?.value)
addToast('Adresse oppdatert!')
} catch (error) {
adrianflatner marked this conversation as resolved.
Show resolved Hide resolved
addToast({
content: 'Noe gikk galt under lagring av adresse.',
variant: 'info',
})
}
}

return (
<form
action={() => {
saveLocation(bid, selectedPoint?.value)
addToast('Adresse oppdatert!')
}}
className="box flex flex-col"
>
<form onSubmit={handleSubmit} className="box flex flex-col">
<div className="flex flex-row items-center gap-2">
<Heading3 margin="bottom">Adresse</Heading3>
<Tooltip
Expand Down