diff --git a/apps/service-catalog/app/actions/public-services/actions.ts b/apps/service-catalog/app/actions/public-services/actions.ts index 70248bf5e..e2b5bc273 100644 --- a/apps/service-catalog/app/actions/public-services/actions.ts +++ b/apps/service-catalog/app/actions/public-services/actions.ts @@ -1,8 +1,11 @@ 'use server'; -import { getAllPublicServices } from '@catalog-frontend/data-access'; +import { createPublicService, getAllPublicServices } from '@catalog-frontend/data-access'; +import { ServiceToBeCreated } from '@catalog-frontend/types'; import { authOptions, validateSession } from '@catalog-frontend/utils'; import { getServerSession } from 'next-auth'; +import { revalidatePath } from 'next/cache'; +import { redirect } from 'next/navigation'; export async function getPublicServices(catalogId: string) { const session = await getServerSession(authOptions); @@ -18,3 +21,33 @@ export async function getPublicServices(catalogId: string) { return; } } + +export async function createNewPublicService(catalogId: string, formData: FormData) { + const newPublicService: ServiceToBeCreated = { + catalogId: catalogId, + title: { + nb: formData.get('title.nb'), + }, + description: { + nb: formData.get('description.nb'), + }, + }; + + const session = await getServerSession(authOptions); + await validateSession(session); + let success = false; + try { + const response = await createPublicService(newPublicService, catalogId, `${session?.accessToken}`); + if (response.status !== 201) { + throw new Error(); + } + success = true; + } catch (error) { + return; + } finally { + if (success) { + revalidatePath(`/catalogs/${catalogId}/public-services`); + redirect(`/catalogs/${catalogId}/public-services`); + } + } +} diff --git a/apps/service-catalog/app/catalogs/[catalogId]/public-services/new/page.tsx b/apps/service-catalog/app/catalogs/[catalogId]/public-services/new/page.tsx index ce6804adb..909d46adc 100644 --- a/apps/service-catalog/app/catalogs/[catalogId]/public-services/new/page.tsx +++ b/apps/service-catalog/app/catalogs/[catalogId]/public-services/new/page.tsx @@ -1,13 +1,13 @@ -import { FormFieldCard } from '@catalog-frontend/ui'; +import { Params } from 'next/dist/shared/lib/router/utils/route-matcher'; +import ServiceForm from '../../../../components/service-form'; +import { Heading } from '@digdir/design-system-react'; -export default async function NewPublicServicePage() { +export default async function NewPublicServicePage({ params }: Params) { + const { catalogId } = params; return ( -
-

Opprett ny offentlig tjeneste

- +
+ Informasjon om tjenesten +
); } diff --git a/apps/service-catalog/app/components/service-form/index.tsx b/apps/service-catalog/app/components/service-form/index.tsx new file mode 100644 index 000000000..696ce4092 --- /dev/null +++ b/apps/service-catalog/app/components/service-form/index.tsx @@ -0,0 +1,87 @@ +'use client'; + +import { Tag, Textarea, Textfield } from '@digdir/design-system-react'; +import { Button, FormFieldCard } from '@catalog-frontend/ui'; + +import { localization } from '@catalog-frontend/utils'; + +import { Service } from '@catalog-frontend/types'; + +import styles from './service-form.module.css'; + +import { TrashIcon } from '@navikt/aksel-icons'; +import { createNewPublicService } from '../../actions/public-services/actions'; + +type ServiceFormProps = { + catalogId: string; + service?: Service; +}; + +export const ServiceForm = ({ catalogId, service }: ServiceFormProps) => { + const createPublicService = createNewPublicService.bind(null, catalogId); + + return ( + <> +
+
+
+
+ +
+ +

Tekst på bokmål

+ + Må fylles ut + +
+ } + type='text' + name='title.nb' + /> +
+ + +