-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3fb1bf3
commit eb66776
Showing
6 changed files
with
69 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
58
next-tavla/app/(admin)/organizations/[id]/components/Info.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 0 additions & 32 deletions
32
next-tavla/src/Admin/scenarios/Organization/components/Info/FooterInfoInput.tsx
This file was deleted.
Oops, something went wrong.
32 changes: 0 additions & 32 deletions
32
next-tavla/src/Admin/scenarios/Organization/components/Info/index.tsx
This file was deleted.
Oops, something went wrong.
5 changes: 0 additions & 5 deletions
5
next-tavla/src/Admin/scenarios/Organization/components/Info/styles.module.css
This file was deleted.
Oops, something went wrong.