Skip to content

Commit

Permalink
chore(error): remove comments, unknown-errortype and columns-error-toast
Browse files Browse the repository at this point in the history
  • Loading branch information
SelmaBergstrand committed Dec 2, 2024
1 parent 670bc84 commit 8635cf7
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 36 deletions.
14 changes: 2 additions & 12 deletions tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { Tooltip } from '@entur/tooltip'
import { Heading3 } from '@entur/typography'
import { saveLocation as saveLocationAction } from 'app/(admin)/edit/[id]/components/MetaSettings/actions'
import { usePointSearch } from 'app/(admin)/hooks/usePointSearch'
import { getFormFeedbackForField } from 'app/(admin)/utils'
import { fireToastFeedback } from 'app/(admin)/utils'
import ClientOnly from 'app/components/NoSSR/ClientOnly'
import { SubmitButton } from 'components/Form/SubmitButton'

Expand All @@ -19,17 +19,7 @@ function Address({ bid, location }: { bid: TBoardID; location?: TLocation }) {

const saveLocation = async () => {
const result = await saveLocationAction(bid, selectedPoint?.value)

if (result === undefined) {
addToast('Adresse oppdatert!')
} else {
const content =
getFormFeedbackForField('general', result)?.feedback || ''
addToast({
content: content,
variant: 'info',
})
}
fireToastFeedback(addToast, result, 'Adresse oppdatert!')
}

return (
Expand Down
3 changes: 0 additions & 3 deletions tavla/app/(admin)/edit/[id]/components/MetaSettings/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ function MetaSettings({
useOrganizations(organization)
const [personal, setPersonal] = useState(organization ? false : true)

// Handle save title
const saveTitleWithParams = async (
state: TFormFeedback | undefined,
data: FormData,
Expand All @@ -52,13 +51,11 @@ function MetaSettings({
undefined,
)

// Handle save font
const saveFont = async (data: FormData) => {
const result = await saveFontAction(bid, data)
fireToastFeedback(addToast, result, 'Tekststørrelse lagret!')
}

// Handle move board
const moveBoard = async () => {
const result = await moveBoardAction(
bid,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,7 @@ import { Columns, TColumn } from 'types/column'
import { useToast } from '@entur/alert'
import { FilterChip } from '@entur/chip'
import { FormError } from 'app/(admin)/components/FormError'
import {
TFormFeedback,
fireToastFeedback,
getFormFeedbackForField,
} from 'app/(admin)/utils'
import { TFormFeedback, getFormFeedbackForField } from 'app/(admin)/utils'
import { SubmitButton } from 'components/Form/SubmitButton'
import { saveColumns as saveColumnsAction } from './actions'
import { Tooltip } from '@entur/tooltip'
Expand All @@ -35,7 +31,10 @@ function DefaultColumns({
if (!oid) return
const columns = data.getAll('columns') as TColumn[]
const result = await saveColumnsAction(state, oid, columns)
fireToastFeedback(addToast, result, 'Kolonner lagret!')
if (result === undefined) {
addToast('Kolonner lagret!')
}

return result
}
const [state, saveColumns] = useActionState(handleSaveColumns, undefined)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ function FontSelect({
const font = data.get('font') as TFontSize
const result = await setFontSizeAction(oid, font)
fireToastFeedback(addToast, result, 'Tekststørrelse lagret!')
return result
}

return (
Expand Down
5 changes: 2 additions & 3 deletions tavla/app/(admin)/utils/handleError.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/* eslint-disable no-console */
// TODO: Use a better logger than console
// TODO: switch console.log to Sentry.captureException
import { FirebaseError } from 'firebase/app'
import { getFormFeedbackForError } from '.'

Expand All @@ -9,7 +9,6 @@ export function handleError(e: unknown) {
return getFormFeedbackForError(e)
} else if (e instanceof Error) {
console.error(e.message)
return getFormFeedbackForError('general')
}
return getFormFeedbackForError('unknown')
return getFormFeedbackForError('general')
}
15 changes: 4 additions & 11 deletions tavla/app/(admin)/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -242,13 +242,6 @@ export function getFormFeedbackForError(
variant: 'error',
}
}
case 'unknown': {
return {
form_type: 'general',
feedback: 'En ukjent feil har oppstått.',
variant: 'error',
}
}
}

return {
Expand All @@ -260,14 +253,14 @@ export function getFormFeedbackForError(

export function fireToastFeedback(
addToast: (payload: AddToastPayload | string) => void,
result: TFormFeedback | undefined,
formFeedback: TFormFeedback | undefined,
successMessage: string,
) {
if (result === undefined) {
if (formFeedback === undefined) {
addToast(successMessage)
} else if (result.form_type === 'general') {
} else if (formFeedback.form_type === 'general') {
const content =
getFormFeedbackForField('general', result)?.feedback || ''
getFormFeedbackForField('general', formFeedback)?.feedback || ''
addToast({
content: content,
variant: 'info',
Expand Down

0 comments on commit 8635cf7

Please sign in to comment.