Skip to content

Commit

Permalink
feat(concept:changeRequest): add title field
Browse files Browse the repository at this point in the history
  • Loading branch information
terjesyl committed Oct 19, 2023
1 parent 92a7a5f commit 23cfdc7
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Checkbox } from '@digdir/design-system-react';
import { Checkbox, Heading, Textfield } from '@digdir/design-system-react';
import { BreadcrumbType, Breadcrumbs, Button, PageBanner } from '@catalog-frontend/ui';
import { useCatalogDesign } from '../../../../context/catalog-design';
import { localization as loc, getTranslateText as translate } from '@catalog-frontend/utils';
import { localization as loc } from '@catalog-frontend/utils';
import styles from './change-request-page.module.css';
import { useState } from 'react';
import { Concept, ISOLanguage } from '@catalog-frontend/types';
Expand Down Expand Up @@ -30,13 +30,14 @@ export const ChangeRequestForm = ({
const changeRequestId = changeRequest.id;
const catalogId = organization?.organizationId;
const pageSubtitle = organization?.name ?? organization.id;
const [changeRequestTitle, setChangeRequestTitle] = useState<string>(changeRequest.title ?? '');

const [selectedLanguages, setSelectedLanguages] = useState<ISOLanguage[]>(['nb', 'nn', 'en']);
const [isSubmitting, setIsSubmitting] = useState(false);

const handleSubmit = (values: Concept) => {
setIsSubmitting(true);
submitHandler(values);
submitHandler(values, changeRequestTitle);
setIsSubmitting(false);
};

Expand All @@ -48,16 +49,6 @@ export const ChangeRequestForm = ({
setSelectedLanguages(newSelectedLangs as ISOLanguage[]);
};

const getTitle = (text: string | string[]) => (text ? text : loc.concept.noName);
let changeRequestTitle = '';
if (changeRequestId) {
changeRequestTitle = changeRequestAsConcept?.anbefaltTerm?.navn
? getTitle(translate(changeRequestAsConcept?.anbefaltTerm?.navn))
: changeRequestId;
} else {
changeRequestTitle = loc.suggestionForNewConcept;
}

const breadcrumbList = changeRequestId
? ([
{
Expand Down Expand Up @@ -110,7 +101,20 @@ export const ChangeRequestForm = ({
))}
</Checkbox.Group>
</div>
<h1 className={styles.pageTitle}>{changeRequestTitle}</h1>
<Heading
level={2}
size='xsmall'
className={styles.pageTitle}
>
{changeRequestTitle}
</Heading>
<Textfield
className={styles.pageTitle}
type='text'
value={changeRequestTitle}
label={loc.title}
onChange={(e) => setChangeRequestTitle(e.target.value)}
/>
<Formik
initialValues={changeRequestAsConcept}
onSubmit={(values) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@ const ChangeRequestEditPage = ({
changeRequestId: changeRequest.id,
});

const submitHandler = (values: Concept) => {
const submitHandler = (values: Concept, title: string) => {
const changeRequestFromConcept: ChangeRequestUpdateBody = {
conceptId: changeRequest.conceptId,
operations: jsonpatch.compare(originalConcept, values) as JsonPatchOperation[],
title: '',
title: title,
};
changeRequestMutateHook
.mutateAsync(changeRequestFromConcept)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@ const NewConceptSuggestion = ({
}) => {
const changeRequestMutateHook = useCreateChangeRequest({ catalogId: organization.organizationId });

const submitHandler = (values: Concept) => {
const submitHandler = (values: Concept, title: string) => {
const changeRequestFromConcept: ChangeRequestUpdateBody = {
conceptId: changeRequest.conceptId,
operations: jsonpatch.compare(originalConcept, values) as JsonPatchOperation[],
title: '',
title: title,
};
changeRequestMutateHook.mutateAsync(changeRequestFromConcept).catch((error) => {
alert('Failed to submit change request.');
Expand Down
1 change: 1 addition & 0 deletions libs/utils/src/lib/language/nb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export const nb = {
unknown: 'Ukjent',
showMore: 'Vis flere',
showLess: 'Vis færre',
title: 'Tittel',

language: {
nb: 'Bokmål',
Expand Down

0 comments on commit 23cfdc7

Please sign in to comment.