Skip to content

Commit

Permalink
fix(j-s): Date of Birth Validation (#17083)
Browse files Browse the repository at this point in the history
Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
  • Loading branch information
gudjong and kodiakhq[bot] authored Nov 28, 2024
1 parent 0de2db5 commit 253bfe7
Show file tree
Hide file tree
Showing 11 changed files with 81 additions and 62 deletions.
17 changes: 7 additions & 10 deletions apps/judicial-system/backend/src/app/formatters/indictmentPdf.ts
Original file line number Diff line number Diff line change
Expand Up @@ -113,16 +113,13 @@ export const createIndictment = async (
addEmptyLines(doc, 2)
addNormalPlusCenteredText(
doc,
formatMessage(
indictment.signature,
{
prosecutorsOfficeName:
lowercase(theCase.prosecutorsOffice?.name)
.replace('lögreglustjórinn', 'lögreglustjórans')
.replace('saksóknari', 'saksóknara') ?? '',
date: formatDate(nowFactory(), 'PPP'),
} ?? '',
),
formatMessage(indictment.signature, {
prosecutorsOfficeName:
lowercase(theCase.prosecutorsOffice?.name)
.replace('lögreglustjórinn', 'lögreglustjórans')
.replace('saksóknari', 'saksóknara') ?? '',
date: formatDate(nowFactory(), 'PPP'),
}),
)

doc.end()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -183,13 +183,13 @@ export interface UpdateCase
courtRecordSignatoryId?: string | null
courtRecordSignatureDate?: Date | null
parentCaseId?: string | null
arraignmentDate?: UpdateDateLog | null
courtDate?: UpdateDateLog | null
postponedIndefinitelyExplanation?: string | null
indictmentReturnedExplanation?: string | null
indictmentDeniedExplanation?: string | null
indictmentHash?: string | null
civilDemands?: string | null
arraignmentDate?: UpdateDateLog
courtDate?: UpdateDateLog
postponedIndefinitelyExplanation?: string
civilDemands?: string
}

type DateLogKeys = keyof Pick<UpdateCase, 'arraignmentDate' | 'courtDate'>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
interface Value {
value?: string
value?: string | null
}

type NationalIdTransformer = ({ value }: Value) => string | undefined
type NationalIdTransformer = ({ value }: Value) => string | undefined | null

export const nationalIdTransformer: NationalIdTransformer = ({ value }) =>
value?.replace(/-/g, '')
export const nationalIdTransformer: NationalIdTransformer = ({ value }) => {
if (!value) {
return value
}

return value.replace(/-/g, '')
}
54 changes: 34 additions & 20 deletions apps/judicial-system/web/src/components/Inputs/InputAdvocate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,20 @@ interface PropertyValidation {
}
}

interface LawyerUpdate {
defenderName: string | null
defenderNationalId: string | null
defenderEmail: string | null
defenderPhoneNumber: string | null
}

interface SpokespersonUpdate {
spokespersonName: string | null
spokespersonNationalId: string | null
spokespersonEmail: string | null
spokespersonPhoneNumber: string | null
}

type InputType =
| 'defenderEmail'
| 'defenderPhoneNumber'
Expand Down Expand Up @@ -123,18 +137,18 @@ const InputAdvocate: FC<Props> = ({
isCivilClaim: boolean,
clientId?: string | null,
) => {
let updatedLawyer = {
defenderName: '',
defenderNationalId: '',
defenderEmail: '',
defenderPhoneNumber: '',
let updatedLawyer: LawyerUpdate = {
defenderName: null,
defenderNationalId: null,
defenderEmail: null,
defenderPhoneNumber: null,
}

let updatedSpokesperson = {
spokespersonName: '',
spokespersonNationalId: '',
spokespersonEmail: '',
spokespersonPhoneNumber: '',
let updatedSpokesperson: SpokespersonUpdate = {
spokespersonName: null,
spokespersonNationalId: null,
spokespersonEmail: null,
spokespersonPhoneNumber: null,
}

if (selectedOption) {
Expand All @@ -147,16 +161,16 @@ const InputAdvocate: FC<Props> = ({
)
updatedLawyer = {
defenderName: lawyer ? lawyer.name : label,
defenderNationalId: lawyer ? lawyer.nationalId : '',
defenderEmail: lawyer ? lawyer.email : '',
defenderPhoneNumber: lawyer ? lawyer.phoneNr : '',
defenderNationalId: lawyer ? lawyer.nationalId : null,
defenderEmail: lawyer ? lawyer.email : null,
defenderPhoneNumber: lawyer ? lawyer.phoneNr : null,
}

updatedSpokesperson = {
spokespersonName: lawyer ? lawyer.name : label,
spokespersonNationalId: lawyer ? lawyer.nationalId : '',
spokespersonEmail: lawyer ? lawyer.email : '',
spokespersonPhoneNumber: lawyer ? lawyer.phoneNr : '',
spokespersonNationalId: lawyer ? lawyer.nationalId : null,
spokespersonEmail: lawyer ? lawyer.email : null,
spokespersonPhoneNumber: lawyer ? lawyer.phoneNr : null,
}
}

Expand Down Expand Up @@ -226,17 +240,17 @@ const InputAdvocate: FC<Props> = ({
switch (property) {
case 'defenderEmail': {
return {
defenderEmail: value,
defenderEmail: value || null,
}
}
case 'defenderPhoneNumber': {
return { defenderPhoneNumber: value }
return { defenderPhoneNumber: value || null }
}
case 'spokespersonEmail': {
return { spokespersonEmail: value }
return { spokespersonEmail: value || null }
}
case 'spokespersonPhoneNumber': {
return { spokespersonPhoneNumber: value }
return { spokespersonPhoneNumber: value || null }
}
}
}, [])
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,16 +50,15 @@ const InputNationalId: FC<Props> = (props) => {
const inputValidator = validate([
[
evt.target.value,

isDateOfBirth ? ['date-of-birth'] : ['empty', 'national-id'],
],
])

if (!required) {
onBlur(inputValue)
} else if (inputValidator.isValid) {
if (inputValidator.isValid) {
setErrorMessage(undefined)
onBlur(inputValue)
} else if (!required && !evt.target.value) {
onBlur(inputValue)
} else {
setErrorMessage(inputValidator.errorMessage)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@ const Defendant = () => {
gender: defendant.gender,
name: defendant.name,
address: defendant.address,
nationalId: defendant.nationalId,
nationalId: defendant.nationalId || null,
noNationalId: defendant.noNationalId,
citizenship: defendant.citizenship,
})
Expand All @@ -361,7 +361,7 @@ const Defendant = () => {
gender: defendant.gender,
name: defendant.name,
address: defendant.address,
nationalId: defendant.nationalId,
nationalId: defendant.nationalId || null,
noNationalId: defendant.noNationalId,
citizenship: defendant.citizenship,
})
Expand Down Expand Up @@ -421,7 +421,7 @@ const Defendant = () => {
gender: undefined,
name: '',
address: '',
nationalId: '',
nationalId: null,
citizenship: '',
})

Expand All @@ -442,7 +442,7 @@ const Defendant = () => {
id: defendantId || uuid(),
gender: undefined,
name: '',
nationalId: '',
nationalId: null,
address: '',
citizenship: '',
} as TDefendant,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ const Processing: FC = () => {
const router = useRouter()
const isTrafficViolationCaseCheck = isTrafficViolationCase(workingCase)
const [civilClaimantNationalIdUpdate, setCivilClaimantNationalIdUpdate] =
useState<{ nationalId: string; civilClaimantId: string }>()
useState<{ nationalId: string | null; civilClaimantId: string }>()
const [hasCivilClaimantChoice, setHasCivilClaimantChoice] =
useState<boolean>()
const [nationalIdNotFound, setNationalIdNotFound] = useState<boolean>(false)
Expand Down Expand Up @@ -187,12 +187,12 @@ const Processing: FC = () => {
handleUpdateCivilClaimant({
caseId: workingCase.id,
civilClaimantId,
nationalId,
nationalId: nationalId || null,
})
} else {
const cleanNationalId = nationalId ? nationalId.replace('-', '') : ''
setCivilClaimantNationalIdUpdate({
nationalId: cleanNationalId,
nationalId: cleanNationalId || null,
civilClaimantId,
})
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ const Defendant = () => {
gender: defendant.gender,
name: defendant.name,
address: defendant.address,
nationalId: defendant.nationalId,
nationalId: defendant.nationalId || null,
noNationalId: defendant.noNationalId,
citizenship: defendant.citizenship,
})
Expand All @@ -104,7 +104,7 @@ const Defendant = () => {
gender: defendant.gender,
name: defendant.name,
address: defendant.address,
nationalId: defendant.nationalId,
nationalId: defendant.nationalId || null,
noNationalId: defendant.noNationalId,
citizenship: defendant.citizenship,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export const Defendant = () => {
gender: workingCase.defendants[0].gender,
name: workingCase.defendants[0].name,
address: workingCase.defendants[0].address,
nationalId: workingCase.defendants[0].nationalId,
nationalId: workingCase.defendants[0].nationalId || null,
noNationalId: workingCase.defendants[0].noNationalId,
citizenship: workingCase.defendants[0].citizenship,
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,15 +190,15 @@ const DefendantInfo: FC<Props> = (props) => {
onChange({
caseId: workingCase.id,
defendantId: defendant.id,
nationalId: value,
nationalId: value || null,
})
}
onChange={(value) =>
updateDefendantState(
{
caseId: workingCase.id,
defendantId: defendant.id,
nationalId: value,
nationalId: value || null,
},
setWorkingCase,
)
Expand Down
20 changes: 12 additions & 8 deletions apps/judicial-system/web/src/utils/validate.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,10 +262,9 @@ export const isHearingArrangementsStepValidIC = (
export const isProcessingStepValidIndictments = (
workingCase: Case,
): boolean => {
const defendantsAreValid = () =>
workingCase.defendants?.every((defendant) => {
return validate([[defendant.defendantPlea, ['empty']]]).isValid
})
const defendantsAreValid = workingCase.defendants?.every(
(defendant) => validate([[defendant.defendantPlea, ['empty']]]).isValid,
)

const hasCivilClaimSelected =
workingCase.hasCivilClaims !== null &&
Expand All @@ -275,9 +274,14 @@ export const isProcessingStepValidIndictments = (
? workingCase.civilClaimants?.every(
(civilClaimant) =>
civilClaimant.name &&
(civilClaimant.noNationalId ||
(civilClaimant.nationalId &&
civilClaimant.nationalId.replace('-', '').length === 10)),
validate([
[
civilClaimant.nationalId,
civilClaimant.noNationalId
? ['date-of-birth']
: ['empty', 'national-id'],
],
]).isValid,
)
: true

Expand All @@ -286,7 +290,7 @@ export const isProcessingStepValidIndictments = (
workingCase.court &&
hasCivilClaimSelected &&
allCivilClaimantsAreValid &&
defendantsAreValid(),
defendantsAreValid,
)
}

Expand Down

0 comments on commit 253bfe7

Please sign in to comment.