Skip to content

Commit

Permalink
chore: Remove mobile token restrictions
Browse files Browse the repository at this point in the history
  • Loading branch information
jorelosorio committed Feb 14, 2025
1 parent e4b19c6 commit 9ea72ce
Show file tree
Hide file tree
Showing 8 changed files with 38 additions and 139 deletions.
81 changes: 19 additions & 62 deletions src/select-travel-token-screen/SelectTravelTokenScreenComponent.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import {
import {StyleSheet, Theme, useThemeContext} from '@atb/theme';
import {ThemedTokenPhone, ThemedTokenTravelCard} from '@atb/theme/ThemedAssets';
import {useFareContracts} from '@atb/ticketing';
import {
dictionary,
getTextForLanguage,
TravelTokenTexts,
useTranslation,
} from '@atb/translations';
import {dictionary, TravelTokenTexts, useTranslation} from '@atb/translations';
import {animateNextChange} from '@atb/utils/animation';
import React, {useCallback, useEffect, useState} from 'react';
import {ActivityIndicator, View} from 'react-native';
Expand All @@ -37,7 +32,7 @@ type Props = {onAfterSave: () => void};

export const SelectTravelTokenScreenComponent = ({onAfterSave}: Props) => {
const styles = useStyles();
const {t, language} = useTranslation();
const {t} = useTranslation();
const {theme} = useThemeContext();

const {disable_travelcard} = useRemoteConfigContext();
Expand Down Expand Up @@ -71,27 +66,17 @@ export const SelectTravelTokenScreenComponent = ({onAfterSave}: Props) => {
);

// Filter for unique travel rights config types
const availableFareContractsTypes = availableTravelRights.map(
(travelRight) => {
const preassignedFareProduct = findReferenceDataById(
preassignedFareProducts,
isOfFareProductRef(travelRight) ? travelRight.fareProductRef : '',
);

return (
preassignedFareProduct &&
fareProductTypeConfigs.find(
(c) => c.type === preassignedFareProduct.type,
)
);
},
);
availableTravelRights.map((travelRight) => {
const preassignedFareProduct = findReferenceDataById(
preassignedFareProducts,
isOfFareProductRef(travelRight) ? travelRight.fareProductRef : '',
);

const fareProductConfigWhichRequiresTokenOnMobile =
availableFareContractsTypes.find(
(fareProductTypeConfig) =>
fareProductTypeConfig?.configuration.requiresTokenOnMobile === true,
return (
preassignedFareProduct &&
fareProductTypeConfigs.find((c) => c.type === preassignedFareProduct.type)
);
});

useEffect(() => {
// Whenever a user enters this screen, the onboarding is done.
Expand Down Expand Up @@ -122,14 +107,6 @@ export const SelectTravelTokenScreenComponent = ({onAfterSave}: Props) => {
const travelCardToken = tokens?.find((t) => t.type === 'travel-card');
const mobileTokens = tokens?.filter((t) => t.type === 'mobile');

// Shows an error message if switching to a t:card,
// but the current inspectable token is in the mobile AND
// requires mobile token
const requiresTokenOnMobile =
selectedType === 'travel-card' &&
inspectableToken?.type === 'mobile' &&
!!fareProductConfigWhichRequiresTokenOnMobile;

return (
<View style={styles.container}>
<FullScreenHeader
Expand Down Expand Up @@ -206,24 +183,6 @@ export const SelectTravelTokenScreenComponent = ({onAfterSave}: Props) => {
isMarkdown={false}
/>
)}
{requiresTokenOnMobile && (
<MessageInfoBox
type="error"
title={t(
TravelTokenTexts.toggleToken.notAllowedToUseTravelCardError.title,
)}
message={t(
TravelTokenTexts.toggleToken.notAllowedToUseTravelCardError.message(
getTextForLanguage(
fareProductConfigWhichRequiresTokenOnMobile.name,
language,
) ?? '',
),
)}
style={styles.errorMessageBox}
isMarkdown={false}
/>
)}
{selectedType === 'mobile' && mobileTokens?.length ? (
<RadioGroupSection<Token>
type="spacious"
Expand Down Expand Up @@ -254,16 +213,14 @@ export const SelectTravelTokenScreenComponent = ({onAfterSave}: Props) => {
{toggleMutation.isLoading ? (
<ActivityIndicator size="large" />
) : (
!requiresTokenOnMobile && (
<Button
expanded={true}
onPress={onSave}
text={t(TravelTokenTexts.toggleToken.saveButton)}
interactiveColor={theme.color.interactive[0]}
disabled={!selectedToken || (data?.toggleLimit ?? 0) < 1}
testID="confirmSelectionButton"
/>
)
<Button
expanded={true}
onPress={onSave}
text={t(TravelTokenTexts.toggleToken.saveButton)}
interactiveColor={theme.color.interactive[0]}
disabled={!selectedToken || (data?.toggleLimit ?? 0) < 1}
testID="confirmSelectionButton"
/>
)}
</ScrollView>
</View>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,6 @@ export const PreassignedFareContractSummary = ({
),
),
)}
{fareProductTypeConfig.configuration.requiresTokenOnMobile &&
summary(
t(PurchaseConfirmationTexts.validityTexts.harbor.onlyOnPhone),
)}
<GlobalMessage
style={styles.globalMessage}
globalMessageContext={
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import {
import React, {useEffect, useState} from 'react';
import {ScrollView, View} from 'react-native';
import {ProductSelection} from './components/ProductSelection';
import {PurchaseMessages} from './components/PurchaseMessages';
import {PurchaseMessage} from './components/PurchaseMessage.tsx';
import {StartTimeSelection} from './components/StartTimeSelection';
import {Summary} from './components/Summary';
import {TravellerSelection} from './components/TravellerSelection';
Expand Down Expand Up @@ -66,7 +66,7 @@ export const Root_PurchaseOverviewScreen: React.FC<Props> = ({

const analytics = useAnalyticsContext();

const {travellerSelectionMode, zoneSelectionMode, requiresTokenOnMobile} =
const {travellerSelectionMode, zoneSelectionMode} =
selection.fareProductTypeConfig.configuration;

const fareProductOnBehalfOfEnabled =
Expand Down Expand Up @@ -275,7 +275,7 @@ export const Root_PurchaseOverviewScreen: React.FC<Props> = ({
/>
) : (
<View style={styles.messages}>
<PurchaseMessages requiresTokenOnMobile={requiresTokenOnMobile} />
<PurchaseMessage />
<GlobalMessage
globalMessageContext={
GlobalMessageContextEnum.appPurchaseOverview
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import {MessageInfoBox} from '@atb/components/message-info-box';
import React from 'react';
import {useOtherDeviceIsInspectableWarning} from '@atb/modules/fare-contracts';

export const PurchaseMessage = () => {
const inspectableTokenWarningText = useOtherDeviceIsInspectableWarning();

return inspectableTokenWarningText ? (
<MessageInfoBox
type="warning"
message={inspectableTokenWarningText}
isMarkdown={true}
/>
) : null;
};

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,9 @@ export const TicketTabNav_PurchaseTabScreen = ({navigation}: Props) => {
const styles = useStyles();
const analytics = useAnalyticsContext();

const {tokens, mobileTokenStatus} = useMobileTokenContext();
const {tokens} = useMobileTokenContext();
const inspectableToken = tokens.find((t) => t.isInspectable);
const hasInspectableMobileToken = inspectableToken?.type === 'mobile';
const hasMobileTokenError =
mobileTokenStatus === 'fallback' || mobileTokenStatus === 'error';

if (must_upgrade_ticketing) return <UpgradeSplash />;

const onProductSelect = (fareProductTypeConfig: FareProductTypeConfig) => {
Expand All @@ -55,7 +52,6 @@ export const TicketTabNav_PurchaseTabScreen = ({navigation}: Props) => {
if (authenticationType !== 'phone') {
if (
fareProductTypeConfig.configuration.requiresLogin &&
fareProductTypeConfig.configuration.requiresTokenOnMobile &&
!hasInspectableMobileToken
) {
navigation.navigate('Root_LoginRequiredForFareProductScreen', {
Expand All @@ -70,24 +66,6 @@ export const TicketTabNav_PurchaseTabScreen = ({navigation}: Props) => {
});
return;
}
} else if (
fareProductTypeConfig.configuration.requiresTokenOnMobile &&
!hasInspectableMobileToken &&
!hasMobileTokenError
) {
navigation.navigate(
'Root_ActiveTokenOnPhoneRequiredForFareProductScreen',
{
nextScreen: {
screen: 'Root_PurchaseOverviewScreen',
params: {
selection,
mode: 'Ticket',
},
},
},
);
return;
}

navigation.navigate('Root_PurchaseOverviewScreen', {
Expand Down
5 changes: 0 additions & 5 deletions src/translations/screens/subscreens/PurchaseConfirmation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,6 @@ const PurchaseConfirmationTexts = {
'Applies for bus/tram in departure and destination zones',
'Gjeld for buss/trikk i sonene du reiser til og frå',
),
onlyOnPhone: _(
'Kun gyldig på mobil',
'Only valid on phone',
'Kun gyldig på mobil',
),
},
time: (validTime: string) =>
_(
Expand Down
5 changes: 0 additions & 5 deletions src/translations/screens/subscreens/PurchaseOverview.ts
Original file line number Diff line number Diff line change
Expand Up @@ -208,11 +208,6 @@ const PurchaseOverviewTexts = {
'This trip is free and does not require a ticket.',
'Denne reisa er gratis og krev ingen billett.',
),
messageRequiresMobile: _(
`Gjelder kun på mobil`,
`Only available on phone`,
`Gjeld kun på mobil`,
),
button: {
payment: _('Til betaling', 'To payment', 'Til betaling'),
sendToOthers: _('Gå videre', 'Continue', 'Gå vidare'),
Expand Down

0 comments on commit 9ea72ce

Please sign in to comment.