Skip to content

Commit

Permalink
900: add field nuernberg pass id
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahsporck committed May 23, 2023
1 parent ba29594 commit c9d6ba1
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 4 deletions.
69 changes: 69 additions & 0 deletions administration/src/cards/extensions/NuernbergPassIdExtension.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
import { FormGroup, InputGroup, Intent } from '@blueprintjs/core'

import { Extension } from './extensions'

const nuernbergPassIdNumberLength = 10

type NuernbergPassIdState = { nuernbergPassId: number }
class NuernbergPassIdExtension extends Extension<NuernbergPassIdState, null> {
public readonly name = NuernbergPassIdExtension.name

setInitialState() {}
createForm(onUpdate: () => void) {
return (
<FormGroup
label='Nürnberg-Pass-ID'
labelFor='nuernberg-pass-id-input'
intent={this.isValid() ? undefined : Intent.DANGER}>
<InputGroup
id='nuernberg-pass-id-input'
placeholder='12345678'
intent={this.isValid() ? undefined : Intent.DANGER}
value={this.state?.nuernbergPassId.toString() ?? ''}
maxLength={nuernbergPassIdNumberLength}
onChange={event => {
const value = event.target.value
if (value.length > nuernbergPassIdNumberLength) {
return
}

const parsedNumber = Number.parseInt(value)

if (isNaN(parsedNumber)) {
this.state = null
onUpdate()
return
}

this.state = {
nuernbergPassId: parsedNumber,
}
onUpdate()
}}
/>
</FormGroup>
)
}

causesInfiniteLifetime() {
return false
}

isValid() {
return (
this.state !== null &&
this.state.nuernbergPassId > 0 &&
this.state.nuernbergPassId < 10 ** nuernbergPassIdNumberLength
)
}

fromString(state: string) {
this.state = { nuernbergPassId: parseInt(state, 10) }
}

toString() {
return this.state ? `${this.state.nuernbergPassId}` : ''
}
}

export default NuernbergPassIdExtension
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,12 @@ class NuernbergPassNumberExtension extends Extension<NuernbergPassNumberState, n
setInitialState() {}
createForm(onUpdate: () => void) {
return (
<FormGroup label='Passnummer' labelFor='nuernberg-pass-input' intent={this.isValid() ? undefined : Intent.DANGER}>
<FormGroup
label='Nuernberg-Pass-Nummer'
labelFor='nuernberg-pass-number-input'
intent={this.isValid() ? undefined : Intent.DANGER}>
<InputGroup
id='nuernberg-pass-input'
id='nuernberg-pass-number-input'
placeholder='12345678'
intent={this.isValid() ? undefined : Intent.DANGER}
value={this.state?.passNumber.toString() ?? ''}
Expand Down
2 changes: 2 additions & 0 deletions administration/src/cards/extensions/extensions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { ReactElement } from 'react'
import { CardExtensions } from '../../generated/card_pb'
import BavariaCardTypeExtension from './BavariaCardTypeExtension'
import BirthdayExtension from './BirthdayExtension'
import NuernbergPassIdExtension from './NuernbergPassIdExtension'
import NuernbergPassNumberExtension from './NuernbergPassNumberExtension'
import RegionExtension from './RegionExtension'

Expand All @@ -28,5 +29,6 @@ export type ExtensionClass =
| typeof BavariaCardTypeExtension
| typeof BirthdayExtension
| typeof NuernbergPassNumberExtension
| typeof NuernbergPassIdExtension
| typeof RegionExtension
export type ExtensionInstance = InstanceType<ExtensionClass>
4 changes: 2 additions & 2 deletions administration/src/project-configs/nuernberg/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ const config: ProjectConfig = {
card: {
nameColumnName: 'Name',
expiryColumnName: 'Ablaufdatum',
extensionColumnNames: ['Geburtsdatum', 'Passnummer', null],
extensionColumnNames: ['Geburtsdatum', 'Passnummer', 'Pass-ID', null],
defaultValidity: { years: 1 },
extensions: [BirthdayExtension, NuernbergPassNumberExtension, RegionExtension],
extensions: [BirthdayExtension, NuernbergPassNumberExtension, NuernbergPassIdExtension, RegionExtension],
},
dataPrivacyHeadline: dataPrivacyBaseHeadline,
dataPrivacyContent: DataPrivacyBaseText,
Expand Down

0 comments on commit c9d6ba1

Please sign in to comment.