Skip to content

Commit

Permalink
chore(footer): relocated component
Browse files Browse the repository at this point in the history
  • Loading branch information
oyvindgrutle committed Dec 8, 2023
1 parent 3fb1bf3 commit eb66776
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 70 deletions.
10 changes: 10 additions & 0 deletions next-tavla/app/(admin)/organizations/[id]/actions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
'use server'

import { setOrganziationFooterInfo } from 'Admin/utils/firebase'
import { revalidatePath } from 'next/cache'
import { TOrganizationID } from 'types/settings'

export async function setInfo(oid: TOrganizationID, info: string) {
await setOrganziationFooterInfo(info, oid)
revalidatePath('/')
}
58 changes: 58 additions & 0 deletions next-tavla/app/(admin)/organizations/[id]/components/Info.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
'use client'

import { Button } from '@entur/button'
import { TextField } from '@entur/form'
import { Heading2, LeadParagraph } from '@entur/typography'
import { TOrganization } from 'types/settings'
import { setInfo } from '../actions'
import {
TFormFeedback,
getFormFeedbackForError,
getFormFeedbackForField,
} from 'app/(admin)/utils'
import { FirebaseError } from 'firebase/app'
import { useFormState } from 'react-dom'

function Info({ organization }: { organization: TOrganization }) {
const submit = async (
previousState: TFormFeedback | undefined,
data: FormData,
) => {
const info = data.get('info') as string
const oid = data.get('oid') as string

try {
setInfo(oid, info)
} catch (e: unknown) {
if (e instanceof FirebaseError) {
return getFormFeedbackForError(e)
}
}
}

const [state, action] = useFormState(submit, undefined)

return (
<div className="flexColumn g-1 w-100">
<Heading2>Legg til informasjon</Heading2>
<LeadParagraph>
Her kan du legge til informasjon som vil vises på alle tavlene
til organisasjonen.
</LeadParagraph>
<form action={action} className="flexColumn g-1">
<input type="hidden" name="oid" value={organization.id} />
<TextField
name="info"
label="Informasjon"
defaultValue={organization.footer}
{...getFormFeedbackForField('email', state)}
/>
<Button className="w-100" variant="secondary" type="submit">
Lagre
</Button>
</form>
</div>
)
}

export { Info }
2 changes: 1 addition & 1 deletion next-tavla/app/(admin)/organizations/[id]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { UploadLogo } from 'Admin/scenarios/Organization/components/UploadLogo'
import { MemberAdministration } from 'Admin/scenarios/Organization/components/MemberAdministration'
import { permanentRedirect } from 'next/navigation'
import { getUserFromSessionCookie } from 'Admin/utils/formActions'
import { Info } from 'Admin/scenarios/Organization/components/Info'
import { Info } from './components/Info'

initializeAdminApp()

Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

0 comments on commit eb66776

Please sign in to comment.