Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore(j-s): Court Autofill #15421

Merged
merged 3 commits into from
Jul 3, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ import {
EventType,
isCompletedCase,
isIndictmentCase,
isRequestCase,
isRestrictionCase,
isTrafficViolationCase,
NotificationType,
Expand Down Expand Up @@ -448,9 +449,9 @@ export class CaseService {
const theCase = await this.caseModel.create(
{
...caseToCreate,
state: isIndictmentCase(caseToCreate.type)
? CaseState.DRAFT
: CaseState.NEW,
state: isRequestCase(caseToCreate.type)
? CaseState.NEW
: CaseState.DRAFT,
},
{ transaction },
)
Expand Down Expand Up @@ -1207,7 +1208,7 @@ export class CaseService {
if (updatedCase.courtCaseNumber) {
if (updatedCase.courtCaseNumber !== theCase.courtCaseNumber) {
// New court case number
if (isIndictmentCase(updatedCase.type)) {
if (isIndictment) {
await this.addMessagesForIndictmentCourtCaseConnectionToQueue(
updatedCase,
user,
Expand All @@ -1222,7 +1223,7 @@ export class CaseService {
}

if (
!isIndictmentCase(updatedCase.type) &&
!isIndictment &&
updatedCase.defenderEmail !== theCase.defenderEmail
) {
// New defender email
Expand All @@ -1232,7 +1233,7 @@ export class CaseService {
}

if (
isIndictmentCase(updatedCase.type) &&
isIndictment &&
![
CaseState.DRAFT,
CaseState.SUBMITTED,
Expand Down Expand Up @@ -1326,7 +1327,9 @@ export class CaseService {
creatingProsecutorId: user.id,
prosecutorId:
user.role === UserRole.PROSECUTOR ? user.id : undefined,
courtId: user.institution?.defaultCourtId,
courtId: isRequestCase(caseToCreate.type)
? user.institution?.defaultCourtId
: undefined,
prosecutorsOfficeId: user.institution?.id,
} as CreateCaseDto,
transaction,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import {
EventType,
isIndictmentCase,
isProsecutionUser,
isRequestCase,
isRestrictionCase,
isTrafficViolationCase,
NotificationType,
Expand Down Expand Up @@ -353,14 +354,16 @@ export class InternalCaseService {
.create(
{
...caseToCreate,
state: isIndictmentCase(caseToCreate.type)
? CaseState.DRAFT
: CaseState.NEW,
state: isRequestCase(caseToCreate.type)
? CaseState.NEW
: CaseState.DRAFT,
origin: CaseOrigin.LOKE,
creatingProsecutorId: creator.id,
prosecutorId:
creator.role === UserRole.PROSECUTOR ? creator.id : undefined,
courtId: creator.institution?.defaultCourtId,
courtId: isRequestCase(caseToCreate.type)
? creator.institution?.defaultCourtId
: undefined,
prosecutorsOfficeId: creator.institution?.id,
},
{ transaction },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,10 @@ query CurrentUser {
canConfirmIndictment
institution {
id
created
modified
name
type
name
defaultCourtId
gudjong marked this conversation as resolved.
Show resolved Hide resolved
policeCaseNumberPrefix
active
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PageLayout,
ProsecutorCaseInfo,
SectionHeading,
UserContext,
} from '@island.is/judicial-system-web/src/components'
import RequiredStar from '@island.is/judicial-system-web/src/components/RequiredStar/RequiredStar'
import {
Expand All @@ -27,6 +28,7 @@ import {
import {
useCase,
useDefendants,
useOnceOn,
} from '@island.is/judicial-system-web/src/utils/hooks'
import { isProcessingStepValidIndictments } from '@island.is/judicial-system-web/src/utils/validate'

Expand All @@ -35,14 +37,38 @@ import { strings } from './processing.strings'
import * as styles from './Processing.css'

const Processing: FC = () => {
const { workingCase, setWorkingCase, isLoadingWorkingCase, caseNotFound } =
useContext(FormContext)
const { transitionCase } = useCase()
const { user } = useContext(UserContext)
const {
workingCase,
setWorkingCase,
isLoadingWorkingCase,
caseNotFound,
isCaseUpToDate,
refreshCase,
} = useContext(FormContext)
const { updateCase, transitionCase } = useCase()
const { formatMessage } = useIntl()
const { updateDefendant, updateDefendantState } = useDefendants()
const router = useRouter()
const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase)

const initialize = useCallback(async () => {
if (!workingCase.court) {
await updateCase(workingCase.id, {
courtId: user?.institution?.defaultCourtId,
})
refreshCase()
}
gudjong marked this conversation as resolved.
Show resolved Hide resolved
}, [
refreshCase,
updateCase,
user?.institution?.defaultCourtId,
workingCase.court,
workingCase.id,
])

useOnceOn(isCaseUpToDate, initialize)
gudjong marked this conversation as resolved.
Show resolved Hide resolved

const handleNavigationTo = useCallback(
async (destination: string) => {
if (workingCase.state === CaseState.NEW) {
Expand Down
Loading