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

add recovered/vaccinated option to checkin #355

Merged
merged 7 commits into from
Oct 14, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions lib/api/companies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,14 @@ export const CompanyTypeOptions = {
}

export const CoronaTestOptions = {
0: 'kein Test notwendig',
24: 'maximal 24 Stunden alter Test notwendig',
48: 'maximal 48 Stunden alter Test notwendig',
}
0: 'NO_TEST',
1: 'RECOVERED_OR_VACCINATED',
24: '24_HOUR_TEST_NEEDED',
48: '48_HOUR_TEST_NEEDED',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe it's time to rewrite this into propper enums?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is saved as number on the database. Actually tried to use recovered as key first but didn't work. So somehow we need the keys to be a number.

} as const

export type CoronaTestOptionsValues =
typeof CoronaTestOptions[keyof typeof CoronaTestOptions]

export interface CompanyRes {
id: string
Expand Down
25 changes: 25 additions & 0 deletions lib/models/area.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { AreaRes, CoronaTestOptions, CoronaTestOptionsValues } from '~lib/api'

export const getAreaCoronaTestOption = (
area: Partial<AreaRes> = {}
): CoronaTestOptionsValues | null => {
const { companyNeedToShowCoronaTest: value } = area

switch (value) {
case 0:
case 1:
case 24:
case 48: {
return CoronaTestOptions[value]
}
default: {
return null
}
}
}
Comment on lines +8 to +19
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tried value in CoronaTestOptions and if (CoronaTestOptions[value]) but return value still showed any. This is what I could come up with without using typecasting.


export const getAreaShouldAskForTest = (area: Partial<AreaRes>): boolean => {
const option = getAreaCoronaTestOption(area)

return option === '24_HOUR_TEST_NEEDED' || option === '48_HOUR_TEST_NEEDED'
}
2 changes: 1 addition & 1 deletion locales/useLocaleObject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const useLocaleObject = <K extends string, V extends unknown>(
const placeholder = `[${key}]` as Result[K]

const value = currentLocale[key]
const valueEnv = currentLocale[`${key}_${BUILD_VARIANT}`]
const valueEnv = currentLocale[`${key}_${BUILD_VARIANT}` as K]
const localeResult = options.useEnv && valueEnv != null ? valueEnv : value

if (localeResult == null) {
Expand Down
2 changes: 1 addition & 1 deletion pages/checkin.de.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFormal, isRcvrEnv, isCareEnv, isHealthEnv } from '~lib/config'
import { isFormal, isCareEnv, isHealthEnv } from '~lib/config'

const de = {
pageTitle: 'Checkin...',
Expand Down
2 changes: 1 addition & 1 deletion pages/checkin.en.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFormal, isRcvrEnv, isCareEnv, isHealthEnv } from '~lib/config'
import { isFormal, isCareEnv, isHealthEnv } from '~lib/config'
import de from './checkin.de'

const en: typeof de = {
Expand Down
2 changes: 1 addition & 1 deletion pages/checkin.pl.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { isFormal, isRcvrEnv, isCareEnv, isHealthEnv } from '~lib/config'
import { isFormal, isCareEnv, isHealthEnv } from '~lib/config'
import de from './checkin.de'

const pl: typeof de = {
Expand Down
1 change: 1 addition & 0 deletions pages/checkin.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,7 @@ export default function CheckinPage() {
<p>{t('address')}</p>
<p>
{t('dataProtection1')}
{isRcvrEnv ? ' ' : null}
{isRcvrEnv ? <b>recover</b> : null}
{isRcvrEnv ? ' ' : null}
{isRcvrEnv ? t('dataProtection2_rcvr') : t('dataProtection2')}
Expand Down
2 changes: 1 addition & 1 deletion ui/blocks/LanguageSwitcher.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const LanguageSwitcher: React.FC = () => {

setTimeout(() => router.reload(), 300)
},
[]
[router, persistLocale]
)

return (
Expand Down
17 changes: 11 additions & 6 deletions ui/blocks/Onboarding/Onboarding.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import { Box, Button, Checkbox, Radio, Input, Text } from '~ui/core'

import useLocaleObject from '~locales/useLocaleObject'
import OnboardingLocales from '~ui/blocks/Onboarding/Onboarding.locales'
import { getAreaShouldAskForTest } from '~lib/models/area'

type OnboardingProps = {
area: AreaRes
Expand Down Expand Up @@ -67,6 +68,8 @@ export const Onboarding: React.FC<OnboardingProps> = ({
area.companyNeedToShowCoronaTest
} ${t('provideTestLabel2')}.`

const shouldShowProvideTest = getAreaShouldAskForTest(area)

return (
<div>
<Formik
Expand Down Expand Up @@ -112,12 +115,14 @@ export const Onboarding: React.FC<OnboardingProps> = ({
{area.companyNeedToShowCoronaTest > 0 && !area.testExemption && (
<>
<Box height={3} />
<Radio
name="providedHealthDocument"
label={provide_test_label}
value={GuestHealthDocumentEnum.tested}
hideError={true}
/>
{shouldShowProvideTest && (
<Radio
name="providedHealthDocument"
label={provide_test_label}
value={GuestHealthDocumentEnum.tested}
hideError={true}
/>
)}
<Radio
name="providedHealthDocument"
label={t('hadCoronaLabel')}
Expand Down
16 changes: 10 additions & 6 deletions ui/modals/BusinessDataModal.locales.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ export const de = {
...validatorsLocalesDE,
...CompanyTypeOptions,

coronaTestSelectOptions0: 'kein Test notwendig',
coronaTestSelectOptions24: 'maximal 24 Stunden alter Test notwendig',
coronaTestSelectOptions48: 'maximal 48 Stunden alter Test notwendig',
coronaTestSelectOptions0: 'Kein Nachweis notwendig',
coronaTestSelectOptions24: 'Genesen, Geimpt oder Getested (24 Stunden)',
coronaTestSelectOptions48: 'Genesen, Geimpt oder Getested (48 Stunden)',
coronaTestSelectOptionsRecovered: 'Genesen oder Geimpt',

or: 'oder',

Expand Down Expand Up @@ -95,9 +96,12 @@ export const en: typeof de = {
public_building: 'public building',
educational_institution: 'educational institution',

coronaTestSelectOptions0: 'no test necessary',
coronaTestSelectOptions24: 'maximum 24 hours old test necessary',
coronaTestSelectOptions48: 'maximum 48 hours old test necessary',
coronaTestSelectOptions0: 'No proof required',
coronaTestSelectOptions24:
'Proof of recovery, Vaccination or test (24 hours)',
coronaTestSelectOptions48:
'Proof of recovery, Vaccination or test (48 hours)',
coronaTestSelectOptionsRecovered: 'Proof of recovery or vaccination',
}

export default { de, en }
6 changes: 5 additions & 1 deletion ui/modals/BusinessDataModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,14 @@ export const BusinessDataModal: React.FC<BusinessDataModalProps> = ({
educational_institution: t('educational_institution'),
}

const coronaTestSelectOptions: typeof CoronaTestOptions = {
const coronaTestSelectOptions: Record<
keyof typeof CoronaTestOptions,
string
> = {
'0': t('coronaTestSelectOptions0'),
'24': t('coronaTestSelectOptions24'),
'48': t('coronaTestSelectOptions48'),
'1': t('coronaTestSelectOptionsRecovered'),
}

const BusinessSchema = Yup.object().shape({
Expand Down