show idNumber input on hjärntorget

This commit is contained in:
Jonathan Edenström 2021-11-27 20:00:13 +01:00
parent fc8d2a36fd
commit 649865784b
7 changed files with 29 additions and 42 deletions

View File

@ -70,29 +70,21 @@ export const Login = () => {
)
const [loginMethodId, setLoginMethodId] = useSettingsStorage('loginMethodId')
const loginBankIdSameDevice = useFeature('LOGIN_BANK_ID_SAME_DEVICE')
const loginBankIdSameDeviceWithoutId = useFeature(
'LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID'
)
const { currentSchoolPlatform, changeSchoolPlatform } = useContext(
SchoolPlatformContext
)
console.log({ loginBankIdSameDevice })
const { t } = useTranslation()
const valid = Personnummer.valid(personalIdNumber)
const loginMethods = [
{
id: 'thisdevice',
title: t('auth.bankid.OpenOnThisDevice'),
enabled: loginBankIdSameDevice,
},
{
id: 'otherdevice',
title: t('auth.bankid.OpenOnAnotherDevice'),
enabled: true,
},
{ id: 'testuser', title: t('auth.loginAsTestUser'), enabled: true },
{ id: 'thisdevice', title: t('auth.bankid.OpenOnThisDevice') },
{ id: 'otherdevice', title: t('auth.bankid.OpenOnAnotherDevice') },
{ id: 'testuser', title: t('auth.loginAsTestUser') },
] as const
const loginHandler = async () => {
@ -106,11 +98,6 @@ export const Login = () => {
}
}, [api])
/* Helpers */
const handleInput = (text: string) => {
setPersonalIdNumber(text)
}
const getSchoolPlatformName = () => {
return schoolPlatforms.find((item) => item.id === currentSchoolPlatform)
?.displayName
@ -163,16 +150,18 @@ export const Login = () => {
const styles = useStyleSheet(themedStyles)
const enabledLoginMethods = loginMethods.filter((method) => method.enabled)
const currentLoginMethod =
enabledLoginMethods.find((method) => method.id === loginMethodId) ||
enabledLoginMethods[0]
loginMethods.find((method) => method.id === loginMethodId) ||
loginMethods[0]
const showInputField =
loginMethodId === 'otherdevice' ||
(loginMethodId === 'thisdevice' && !loginBankIdSameDeviceWithoutId)
return (
<>
<View style={styles.loginForm}>
{loginMethodId === 'otherdevice' && (
{showInputField && (
<Input
accessible={true}
label={t('general.socialSecurityNumber')}
@ -183,12 +172,10 @@ export const Login = () => {
accessoryRight={(props) => (
<TouchableWithoutFeedback
accessible={true}
onPress={() => handleInput('')}
onPress={() => setPersonalIdNumber('')}
accessibilityHint={t(
'login.a11y_clear_social_security_input_field',
{
defaultValue: 'Rensa fältet för personnummer',
}
{ defaultValue: 'Rensa fältet för personnummer' }
)}
>
<CloseOutlineIcon {...props} />
@ -197,7 +184,7 @@ export const Login = () => {
keyboardType="numeric"
onSubmitEditing={(event) => startLogin(event.nativeEvent.text)}
caption={error || ''}
onChangeText={(text) => handleInput(text)}
onChangeText={setPersonalIdNumber}
placeholder={t('auth.placeholder_SocialSecurityNumber')}
/>
)}
@ -254,7 +241,7 @@ export const Login = () => {
{t('auth.chooseLoginMethod')}
</Text>
<List
data={enabledLoginMethods}
data={loginMethods}
ItemSeparatorComponent={Divider}
renderItem={({ item, index }) => (
<ListItem

View File

@ -1,5 +1,5 @@
import { Features, FeatureType } from '@skolplattformen/api'
import React from 'react'
import { FeatureType, Features } from '@skolplattformen/api'
import { FeatureFlagsContext } from '../context/feature/featureContext'
export const useFeature = (name: FeatureType) => {

View File

@ -1,6 +1,6 @@
import { Features } from '@skolplattformen/api'
export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE: false,
FOOD_MENU: false
}
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: false,
FOOD_MENU: false,
}

View File

@ -18,7 +18,7 @@ const init = (
const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
: wrapToughCookie(cookieManagerImpl as ToughCookieJar)
return new ApiHjarntorget(fetchImpl, cookieManager, options)
return new ApiHjarntorget(fetchImpl as any, cookieManager, options)
}
export default init

View File

@ -1,6 +1,6 @@
import { Features } from '@skolplattformen/api'
export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE: true,
FOOD_MENU: true,
}
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: true,
FOOD_MENU: true,
}

View File

@ -18,7 +18,7 @@ const init = (
const cookieManager = ((cookieManagerImpl as RNCookieManager).get)
? wrapReactNativeCookieManager(cookieManagerImpl as RNCookieManager)
: wrapToughCookie(cookieManagerImpl as ToughCookieJar)
return new ApiSkolplattformen(fetchImpl, cookieManager, options)
return new ApiSkolplattformen(fetchImpl as any, cookieManager, options)
}
export default init

View File

@ -1,6 +1,6 @@
export interface Features {
LOGIN_BANK_ID_SAME_DEVICE: boolean;
FOOD_MENU: boolean;
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: boolean
FOOD_MENU: boolean
}
export type FeatureType = keyof Features;
export type FeatureType = keyof Features