From 30119cc885aae75f85f33e3d6221ab81852fe8d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=8Dvar=20Oddsson?= Date: Thu, 5 Dec 2024 14:55:57 +0000 Subject: [PATCH] Refactor --- .../IndictmentCaseFilesList.tsx | 33 ++++++++++--------- .../ServiceAnnouncement.tsx | 2 +- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx index cc9364c25d42..1d4b85ad60aa 100644 --- a/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx +++ b/apps/judicial-system/web/src/components/IndictmentCaseFilesList/IndictmentCaseFilesList.tsx @@ -90,20 +90,22 @@ const FileSection: FC = (props: FileSection) => { } const useFilteredCaseFiles = (caseFiles?: CaseFile[] | null) => { - const filterByCategories = ( - categories: CaseFileCategory | CaseFileCategory[], - ) => { - const categoryArray = Array.isArray(categories) ? categories : [categories] + return useMemo(() => { + const filterByCategories = ( + categories: CaseFileCategory | CaseFileCategory[], + ) => { + const categoryArray = Array.isArray(categories) + ? categories + : [categories] - return ( - caseFiles?.filter( - (file) => file.category && categoryArray.includes(file.category), - ) ?? [] - ) - } + return ( + caseFiles?.filter( + (file) => file.category && categoryArray.includes(file.category), + ) ?? [] + ) + } - return useMemo( - () => ({ + return { indictments: filterByCategories(CaseFileCategory.INDICTMENT), criminalRecords: filterByCategories(CaseFileCategory.CRIMINAL_RECORD), costBreakdowns: filterByCategories(CaseFileCategory.COST_BREAKDOWN), @@ -121,9 +123,8 @@ const useFilteredCaseFiles = (caseFiles?: CaseFile[] | null) => { sentToPrisonAdminFiles: filterByCategories( CaseFileCategory.SENT_TO_PRISON_ADMIN_FILE, ), - }), - [caseFiles], - ) + } + }, [caseFiles]) } const useFilePermissions = (workingCase: Case, user?: User) => { @@ -141,7 +142,7 @@ const useFilePermissions = (workingCase: Case, user?: User) => { canViewSentToPrisonAdminFiles: isPrisonAdminUser(user) || isPublicProsecutorUser(user), }), - [user], + [user, workingCase.hasCivilClaims], ) } diff --git a/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx b/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx index 8dac19a8c448..f70fe17e3e35 100644 --- a/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx +++ b/apps/judicial-system/web/src/components/ServiceAnnouncement/ServiceAnnouncement.tsx @@ -1,4 +1,4 @@ -import { FC, useEffect, useState } from 'react' +import { FC } from 'react' import { IntlShape, MessageDescriptor, useIntl } from 'react-intl' import { AlertMessage, Box, LoadingDots, Text } from '@island.is/island-ui/core'