feat: 🎸 Bara visa Freja om det finns tillgängligt i api

This commit is contained in:
Kajetan Kazimierczak 2022-04-13 23:33:59 +02:00
parent 170b4da39a
commit 0c64f5ae35
4 changed files with 21 additions and 22 deletions

View File

@ -47,25 +47,11 @@ const BankId = () => (
const FrejaEid = () => (
<Image
style={themedStyles.icon}
source={require('../assets/freja_eid_low.png')}
source={require('../assets/freja_eid_low.png')}
accessibilityIgnoresInvertColors
/>
)
interface Logins {
BANKID_SAME_DEVICE: number
BANKID_ANOTHER_DEVICE: number
TEST_USER: number
}
const LoginMethods: Logins = {
BANKID_SAME_DEVICE: 0,
BANKID_ANOTHER_DEVICE: 2,
TEST_USER: 3,
}
export const Login = () => {
const { api } = useApi()
const [cancelLoginRequest, setCancelLoginRequest] = useState<
@ -84,6 +70,7 @@ export const Login = () => {
const loginBankIdSameDeviceWithoutId = useFeature(
'LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID'
)
const loginWithFrejaEnabled = useFeature('LOGIN_FREJA_EID')
const { currentSchoolPlatform, changeSchoolPlatform } = useContext(
SchoolPlatformContext
)
@ -95,10 +82,14 @@ export const Login = () => {
const loginMethods = [
{ id: 'thisdevice', title: t('auth.bankid.OpenOnThisDevice') },
{ id: 'otherdevice', title: t('auth.bankid.OpenOnAnotherDevice') },
{ id: 'testuser', title: t('auth.loginAsTestUser') },
{ id: 'freja', title: t('auth.freja.OpenOnThisDevice') },
{ id: 'testuser', title: t('auth.loginAsTestUser') },
] as const
if (loginMethodId === 'freja' && !loginWithFrejaEnabled) {
setLoginMethodId('thisdevice')
}
const loginHandler = async () => {
const user = await api.getUser()
await AppStorage.clearPersonalData(user)
@ -112,10 +103,10 @@ export const Login = () => {
}
}, [api])
const LoginProviderImage = () => {
const LoginProviderImage = () => {
//if(loginMethodId == 'testuser') return undefined
if(loginMethodId == 'freja') return FrejaEid()
return BankId()
if (loginMethodId == 'freja') return FrejaEid()
return BankId()
}
const getSchoolPlatformName = () => {
@ -292,7 +283,11 @@ export const Login = () => {
{t('auth.chooseLoginMethod')}
</Text>
<List
data={loginMethods}
data={
loginWithFrejaEnabled
? loginMethods
: loginMethods.filter((f) => f.id != 'freja')
}
ItemSeparatorComponent={Divider}
renderItem={({ item, index }) => (
<ListItem

View File

@ -2,6 +2,7 @@ import { Features } from '@skolplattformen/api'
export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: false,
LOGIN_FREJA_EID: false,
FOOD_MENU: false,
CLASS_LIST: false,
}

View File

@ -2,6 +2,7 @@ import { Features } from '@skolplattformen/api'
export const features: Features = {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: true,
LOGIN_FREJA_EID: true,
FOOD_MENU: true,
CLASS_LIST: true,
}

View File

@ -1,7 +1,9 @@
export interface Features {
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: boolean
LOGIN_BANK_ID_SAME_DEVICE_WITHOUT_ID: boolean,
LOGIN_FREJA_EID: boolean,
FOOD_MENU: boolean,
CLASS_LIST: boolean
CLASS_LIST: boolean,
}
export type FeatureType = keyof Features