Skip to content

Commit

Permalink
1381: Make name comparison more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
steffenkleinle committed Aug 1, 2024
1 parent efccde7 commit 19b5264
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 1 deletion.
1 change: 1 addition & 0 deletions administration/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
"date-fns": "^2.30.0",
"graphql": "^16.8.1",
"localforage": "^1.10.0",
"normalize-strings": "^1.1.1",
"notistack": "^3.0.1",
"pdf-lib": "^1.17.1",
"react": "^18.2.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { Alert, Typography, styled } from '@mui/material'

import { OrganizationInput } from '../../../generated/graphql'
import { normalizeName } from '../../../util/normalizeString'
import { useUpdateStateCallback } from '../hooks/useUpdateStateCallback'
import CheckboxForm from '../primitive-inputs/CheckboxForm'
import EmailForm from '../primitive-inputs/EmailForm'
Expand Down Expand Up @@ -98,7 +99,7 @@ const OrganizationForm: Form<State, Options, ValidatedInput, AdditionalProps> =
<Typography>
Bitte geben Sie hier die Daten der Person an, die ihr ehrenamtliches Engagement bestätigen kann.
</Typography>
{applicantName === state.contactName.shortText && (
{normalizeName(applicantName) === normalizeName(state.contactName.shortText) && (
<WarningContactPersonSamePerson severity='warning'>
Die Kontaktperson der Organisation und die antragsstellende Person scheinen identisch zu sein. Bitte beachten
Sie, dass Anträge auf dieser Grundlage nicht bewilligt werden können.
Expand Down
19 changes: 19 additions & 0 deletions administration/src/util/__tests__/normalizeString.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import normalizeString, { normalizeName } from '../normalizeString'

describe('normalizeString', () => {
it('should normalize search string', () => {
expect(normalizeString('Donauwörth')).toBe('donauworth')
expect(normalizeString('äöUEJJ')).toBe('aouejj')
})

it('should trim whitespaces', () => {
expect(normalizeString(' test ')).toBe('test')
})
})

describe('normalizeName', () => {
it('should normalize search string', () => {
expect(normalizeName('Dr. Hans-Peter Müller Lüdenscheid ')).toBe('drhanspetermullerludenscheid')
expect(normalizeName('Dr. Hans Peter Müller Lüdenscheid')).toBe('drhanspetermullerludenscheid')
})
})
6 changes: 6 additions & 0 deletions administration/src/util/normalizeString.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import normalizeStrings from 'normalize-strings'

const normalizeString = (str: string): string => normalizeStrings(str).toLowerCase().trim()
export const normalizeName = (name: string) => normalizeString(name).replaceAll(/[^a-zA-Z0-9]/g, '')

export default normalizeString
6 changes: 6 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 19b5264

Please sign in to comment.