From 8635cf75ed1f57516b75d0fbf50183d9914b429a Mon Sep 17 00:00:00 2001 From: SelmaBergstrand Date: Mon, 2 Dec 2024 15:03:11 +0100 Subject: [PATCH] chore(error): remove comments, unknown-errortype and columns-error-toast --- .../edit/[id]/components/MetaSettings/Adress.tsx | 14 ++------------ .../edit/[id]/components/MetaSettings/index.tsx | 3 --- .../components/DefaultColumns/index.tsx | 11 +++++------ .../organizations/components/FontSelect/index.tsx | 1 - tavla/app/(admin)/utils/handleError.ts | 5 ++--- tavla/app/(admin)/utils/index.ts | 15 ++++----------- 6 files changed, 13 insertions(+), 36 deletions(-) diff --git a/tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx b/tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx index 1a09a710a..e5b70abeb 100644 --- a/tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx +++ b/tavla/app/(admin)/edit/[id]/components/MetaSettings/Adress.tsx @@ -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' @@ -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 ( diff --git a/tavla/app/(admin)/edit/[id]/components/MetaSettings/index.tsx b/tavla/app/(admin)/edit/[id]/components/MetaSettings/index.tsx index 19b676bf8..615cd5883 100644 --- a/tavla/app/(admin)/edit/[id]/components/MetaSettings/index.tsx +++ b/tavla/app/(admin)/edit/[id]/components/MetaSettings/index.tsx @@ -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, @@ -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, diff --git a/tavla/app/(admin)/organizations/components/DefaultColumns/index.tsx b/tavla/app/(admin)/organizations/components/DefaultColumns/index.tsx index 5a48df256..fc3fb83e7 100644 --- a/tavla/app/(admin)/organizations/components/DefaultColumns/index.tsx +++ b/tavla/app/(admin)/organizations/components/DefaultColumns/index.tsx @@ -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' @@ -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) diff --git a/tavla/app/(admin)/organizations/components/FontSelect/index.tsx b/tavla/app/(admin)/organizations/components/FontSelect/index.tsx index 98b91cffa..dd770c873 100644 --- a/tavla/app/(admin)/organizations/components/FontSelect/index.tsx +++ b/tavla/app/(admin)/organizations/components/FontSelect/index.tsx @@ -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 ( diff --git a/tavla/app/(admin)/utils/handleError.ts b/tavla/app/(admin)/utils/handleError.ts index 9bb7b64ef..b3ab953c9 100644 --- a/tavla/app/(admin)/utils/handleError.ts +++ b/tavla/app/(admin)/utils/handleError.ts @@ -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 '.' @@ -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') } diff --git a/tavla/app/(admin)/utils/index.ts b/tavla/app/(admin)/utils/index.ts index 0064b5019..5723c3d11 100644 --- a/tavla/app/(admin)/utils/index.ts +++ b/tavla/app/(admin)/utils/index.ts @@ -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 { @@ -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',