Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
oddsson committed Dec 5, 2024
1 parent d9cdddd commit 30119cc
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,20 +90,22 @@ const FileSection: FC<FileSection> = (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),
Expand All @@ -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) => {
Expand All @@ -141,7 +142,7 @@ const useFilePermissions = (workingCase: Case, user?: User) => {
canViewSentToPrisonAdminFiles:
isPrisonAdminUser(user) || isPublicProsecutorUser(user),
}),
[user],
[user, workingCase.hasCivilClaims],
)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -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'
Expand Down

0 comments on commit 30119cc

Please sign in to comment.