-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ba29594
commit c9d6ba1
Showing
4 changed files
with
78 additions
and
4 deletions.
There are no files selected for viewing
69 changes: 69 additions & 0 deletions
69
administration/src/cards/extensions/NuernbergPassIdExtension.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters