From 4af5b99a3a000449550b379632e3dbff26187a8f Mon Sep 17 00:00:00 2001 From: JeremiahUy Date: Fri, 22 Nov 2024 14:59:00 +0100 Subject: [PATCH] UPDATE: to use aksel components --- .../Process/Accordion/AddDocumentModal.tsx | 91 +++++++++---------- 1 file changed, 41 insertions(+), 50 deletions(-) diff --git a/apps/frontend/src/components/Process/Accordion/AddDocumentModal.tsx b/apps/frontend/src/components/Process/Accordion/AddDocumentModal.tsx index 634d10bc3..159453520 100644 --- a/apps/frontend/src/components/Process/Accordion/AddDocumentModal.tsx +++ b/apps/frontend/src/components/Process/Accordion/AddDocumentModal.tsx @@ -1,10 +1,8 @@ import { faMinusCircle } from '@fortawesome/free-solid-svg-icons' import { FontAwesomeIcon } from '@fortawesome/react-fontawesome' -import { Button } from '@navikt/ds-react' +import { Button, Modal } from '@navikt/ds-react' import { useStyletron } from 'baseui' import { ListItem } from 'baseui/list' -import { Modal, ModalBody, ModalFooter, ModalHeader, ROLE, SIZE } from 'baseui/modal' -import { OnChangeParams, Option, Select, TYPE } from 'baseui/select' import { Tooltip } from 'baseui/tooltip' import { ParagraphSmall } from 'baseui/typography' import { @@ -17,7 +15,7 @@ import { Formik, FormikProps, } from 'formik' -import { ChangeEvent, useEffect, useState } from 'react' +import { useEffect, useState } from 'react' import { getDefaultProcessDocument, searchDocuments } from '../../../api/GetAllApi' import { IAddDocumentToProcessFormValues, @@ -27,9 +25,9 @@ import { IProcess, } from '../../../constants' import { CodelistService, EListName, ICode } from '../../../service/Codelist' -import { useDebouncedState } from '../../../util' import { disableEnter } from '../../../util/helper-functions' import { Sensitivity } from '../../InformationType/Sensitivity' +import CustomSearchSelect from '../../common/AsyncSelectComponents' import { Error, ModalLabel } from '../../common/ModalSchema' import { Spinner } from '../../common/Spinner' import { addDocumentToProcessSchema } from '../../common/schemaValidation' @@ -100,32 +98,34 @@ const ListInformationTypes = (props: IListInformationTypesProps) => { export const AddDocumentModal = (props: TAddDocumentProps) => { const { isOpen, submit, addDefaultDocument, process, error } = props const [defaultDoc, setDefaultDoc] = useState() - const [documents, setDocuments] = useState([]) - const [documentSearch, setDocumentSearch] = useDebouncedState('', 400) - const [searchLoading, setSearchLoading] = useState(false) - const loading = !defaultDoc + const useSearchDocumentOption = async (searchParam: string) => { + if (searchParam && searchParam.length > 2) { + const dokumenter: IDocument[] = (await searchDocuments(searchParam)).content + + const searchResult = dokumenter + .filter((document) => !!document.informationTypes.length) + .map((dokument) => { + return { + ...dokument, + value: dokument.id, + label: dokument.name, + } + }) + + return searchResult + } + return [] + } + useEffect(() => { ;(async () => { setDefaultDoc(await getDefaultProcessDocument()) })() }, []) - useEffect(() => { - ;(async () => { - if (documentSearch && documentSearch.length > 2) { - setSearchLoading(true) - const res = await searchDocuments(documentSearch) - setDocuments(res.content) - setSearchLoading(false) - } - })() - }, [documentSearch]) - const onCloseModal = () => { - setDocumentSearch('') - setDocuments([]) props.onClose() } @@ -149,7 +149,12 @@ export const AddDocumentModal = (props: TAddDocumentProps) => { } return ( - + {loading && } {!loading && ( { return (
- Legg til opplysningstyper fra dokument - +
@@ -187,29 +191,16 @@ export const AddDocumentModal = (props: TAddDocumentProps) => { name="document" render={({ form }: FieldProps) => ( <> -