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

1804: Adding hint for birth date input for koblenz #1858

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
60 changes: 35 additions & 25 deletions administration/src/bp-modules/components/CustomDatePicker.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
import { DesktopDatePicker } from '@mui/x-date-pickers'
import { deDE } from '@mui/x-date-pickers/locales'
import React, { ReactElement } from 'react'
import styled from 'styled-components'

import useWindowDimensions from '../../hooks/useWindowDimensions'

const StyledDiv = styled.div`
display: flex;
align-items: center;
`
type CustomDatePickerProps = {
date: Date | null
onBlur: () => void
Expand All @@ -13,6 +18,7 @@ type CustomDatePickerProps = {
minDate?: Date
maxDate?: Date
disableFuture: boolean
sideComponent?: ReactElement
}

const CustomDatePicker = ({
Expand All @@ -24,38 +30,42 @@ const CustomDatePicker = ({
minDate,
maxDate,
disableFuture,
sideComponent,
}: CustomDatePickerProps): ReactElement => {
const { viewportSmall } = useWindowDimensions()
const formStyle = viewportSmall ? { fontSize: 16, padding: '9px 10px' } : { fontSize: 14, padding: '6px 10px' }
const textFieldBoxShadow =
'0 0 0 0 rgba(205, 66, 70, 0), 0 0 0 0 rgba(205, 66, 70, 0), inset 0 0 0 1px #cd4246, inset 0 0 0 1px rgba(17, 20, 24, 0.2), inset 0 1px 1px rgba(17, 20, 24, 0.3)'
return (
<DesktopDatePicker
views={['year', 'month', 'day']}
value={date}
format='dd.MM.yyyy'
slotProps={{
clearIcon: { fontSize: viewportSmall ? 'medium' : 'small' },
openPickerIcon: { fontSize: 'small' },
field: { clearable: true, onClear },
textField: {
placeholder: 'TT.MM.JJJJ',
error: !isValid,
spellCheck: false,
onBlur,
sx: {
width: '100%',
input: formStyle,
boxShadow: !isValid ? textFieldBoxShadow : undefined,
<StyledDiv>
<DesktopDatePicker
views={['year', 'month', 'day']}
value={date}
format='dd.MM.yyyy'
slotProps={{
clearIcon: { fontSize: viewportSmall ? 'medium' : 'small' },
openPickerIcon: { fontSize: 'small' },
field: { clearable: true, onClear },
textField: {
placeholder: 'TT.MM.JJJJ',
error: !isValid,
spellCheck: false,
onBlur,
sx: {
width: '100%',
input: formStyle,
boxShadow: !isValid ? textFieldBoxShadow : undefined,
},
},
},
}}
localeText={deDE.components.MuiLocalizationProvider.defaultProps.localeText}
disableFuture={disableFuture}
minDate={minDate}
maxDate={maxDate}
onChange={onChange}
/>
}}
localeText={deDE.components.MuiLocalizationProvider.defaultProps.localeText}
disableFuture={disableFuture}
minDate={minDate}
maxDate={maxDate}
onChange={onChange}
/>
{sideComponent}
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
</StyledDiv>
)
}

Expand Down
31 changes: 29 additions & 2 deletions administration/src/cards/extensions/BirthdayExtension.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
import { FormGroup } from '@blueprintjs/core'
import React, { ReactElement, useState } from 'react'
import { Classes, FormGroup, Tooltip } from '@blueprintjs/core'
import HelpOutlineIcon from '@mui/icons-material/HelpOutline'
import React, { ReactElement, useContext, useState } from 'react'
import styled from 'styled-components'

import CustomDatePicker from '../../bp-modules/components/CustomDatePicker'
import FormErrorMessage from '../../bp-modules/self-service/components/FormErrorMessage'
import { ProjectConfigContext } from '../../project-configs/ProjectConfigContext'
import PlainDate from '../../util/PlainDate'
import { Extension, ExtensionComponentProps } from './extensions'

const StyledToolTip = styled(Tooltip)`
border: 0;
`

const StyledHelpOutlineIcon = styled(HelpOutlineIcon)`
width: 20px;
height: auto;
margin-left: 16px;
color: #595959;
`

export const BIRTHDAY_EXTENSION_NAME = 'birthday'
export type BirthdayExtensionState = { [BIRTHDAY_EXTENSION_NAME]: PlainDate | null }

Expand All @@ -21,6 +35,8 @@ const BirthdayForm = ({
const [touched, setTouched] = useState(false)
const { birthday } = value
const showErrorMessage = touched || showRequired
const projectConfig = useContext(ProjectConfigContext)

const getErrorMessage = (): string | null => {
if (!birthday) {
return 'Bitte geben Sie ein gültiges Geburtsdatum an.'
Expand All @@ -45,6 +61,17 @@ const BirthdayForm = ({
isValid={isValid || !showErrorMessage}
maxDate={new Date()}
disableFuture
sideComponent={
<>
{projectConfig.projectId.includes('koblenz') && (
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
<StyledToolTip
className={Classes.TOOLTIP_INDICATOR}
content='Bei Minderjährigen unter 16 Jahren darf der KoblenzPass nur mit Einverständnis der Erziehungsberechtigten abgerufen werden.'>
bahaaTuffaha marked this conversation as resolved.
Show resolved Hide resolved
<StyledHelpOutlineIcon fontSize='small' />
</StyledToolTip>
)}
</>
}
/>
{showErrorMessage && <FormErrorMessage errorMessage={getErrorMessage()} />}
</FormGroup>
Expand Down