From 558f6d48c82e26b0cab9307bfc90705570101e3a Mon Sep 17 00:00:00 2001 From: emilielr <43408175+emilielr@users.noreply.github.com> Date: Tue, 17 Dec 2024 12:18:12 +0100 Subject: [PATCH] feat(settings): show error alert to user if firebase fail in edit and organization (#1760) * feat(error): show alert box instead of toast * feat(edit): show error to user if firebase fail * feat(organization): add alert on firebase error * chore(): rename variables * chore(): remove unused function * chore(): remove unneccessary if * chore(): refactor moveboard function --- .../edit/[id]/components/Footer/actions.ts | 7 +- .../edit/[id]/components/Footer/index.tsx | 29 +++-- .../[id]/components/MetaSettings/Adress.tsx | 24 +++- .../components/MetaSettings/FontSelect.tsx | 48 ++++++++ .../components/MetaSettings/Organization.tsx | 84 +++++++++++++ .../[id]/components/MetaSettings/Title.tsx | 55 +++++++++ .../[id]/components/MetaSettings/actions.ts | 29 +++-- .../[id]/components/MetaSettings/index.tsx | 116 +----------------- .../[id]/components/ThemeSelect/index.tsx | 7 +- .../components/CountiesSelect/index.tsx | 28 ++++- .../components/DefaultColumns/index.tsx | 19 +-- .../components/FontSelect/index.tsx | 29 ++++- .../organizations/components/Footer/index.tsx | 43 +++++-- tavla/app/(admin)/utils/index.ts | 18 --- 14 files changed, 354 insertions(+), 182 deletions(-) create mode 100644 tavla/app/(admin)/edit/[id]/components/MetaSettings/FontSelect.tsx create mode 100644 tavla/app/(admin)/edit/[id]/components/MetaSettings/Organization.tsx create mode 100644 tavla/app/(admin)/edit/[id]/components/MetaSettings/Title.tsx diff --git a/tavla/app/(admin)/edit/[id]/components/Footer/actions.ts b/tavla/app/(admin)/edit/[id]/components/Footer/actions.ts index 29b74ddf3..d958832da 100644 --- a/tavla/app/(admin)/edit/[id]/components/Footer/actions.ts +++ b/tavla/app/(admin)/edit/[id]/components/Footer/actions.ts @@ -1,5 +1,6 @@ 'use server' import { isEmptyOrSpaces } from 'app/(admin)/edit/utils' +import { TFormFeedback } from 'app/(admin)/utils' import { hasBoardEditorAccess, initializeAdminApp, @@ -13,7 +14,11 @@ import * as Sentry from '@sentry/nextjs' initializeAdminApp() -export async function setFooter(bid: TBoardID, data: FormData) { +export async function setFooter( + state: TFormFeedback | undefined, + bid: TBoardID, + data: FormData, +) { const access = hasBoardEditorAccess(bid) if (!access) return redirect('/') diff --git a/tavla/app/(admin)/edit/[id]/components/Footer/index.tsx b/tavla/app/(admin)/edit/[id]/components/Footer/index.tsx index 9f54d54f1..6e0fbb6a8 100644 --- a/tavla/app/(admin)/edit/[id]/components/Footer/index.tsx +++ b/tavla/app/(admin)/edit/[id]/components/Footer/index.tsx @@ -6,10 +6,11 @@ import { Heading3 } from '@entur/typography' import { SubmitButton } from 'components/Form/SubmitButton' import { TBoardID, TFooter } from 'types/settings' import { setFooter as setFooterAction } from './actions' -import { useState } from 'react' +import { useActionState, useState } from 'react' import { Tooltip } from '@entur/tooltip' import ClientOnlyTextField from 'app/components/NoSSR/TextField' -import { fireToastFeedback } from 'app/(admin)/utils' +import { getFormFeedbackForField, TFormFeedback } from 'app/(admin)/utils' +import { FormError } from 'app/(admin)/components/FormError' function Footer({ bid, @@ -23,13 +24,22 @@ function Footer({ const { addToast } = useToast() const [override, setOverride] = useState(footer?.override ?? false) - const setFooter = async (data: FormData) => { - const result = await setFooterAction(bid, data) - fireToastFeedback(addToast, result, 'Infomelding lagret!') + const setFooter = async ( + state: TFormFeedback | undefined, + data: FormData, + ) => { + const formFeedback = await setFooterAction(state, bid, data) + + if (!formFeedback) { + addToast('Infomelding lagret!') + } + return formFeedback } + const [footerState, footerFormAction] = useActionState(setFooter, undefined) + return ( -