-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(native-app): add app widgets to home screen (#15902)
* feat: first version of vehicle module for home screen * feat: add base for air discount module on home screen * feat: first version of license widget * feat: fix routing to vehicles and air discount * feat: allow override styling for walletItems * fix: correct size for all modules based on screensize * feat: first version of home-options * fix: better coordination for sizes of licenses * feat: UI for home options screen ready * feat: add empty states for home screen widgets * feat: add loading states for cards * chore: remove unused illustration * feat: temp adding another illustration for card until better solution * fix: finalize empty states for home screen widgets * feat: show mileage vehicles first in vehicles module * feat: disable pressable heading if no data, move inbox query into widget * chore: rename singular to plural to match applications name * feat: add minHeight for vehicle cards in vehicle module * fix: add seconds to appLock label in settings * feat: move all data fetching and validation to home screen * fix: should be plural for licenses and vehicles everywhere * feat: skip fetching data on home screen if widgets are disabled * fix: remove duplicate translations * fix: update feature flags to be plural in all places * fix: don't set initializedWidget until queries have loaded * fix: inbox check * fix: spelling of initialised * feat: resetting homescreen preferences on logout * fix: final touches * fix: rename preferences flags to be shorter * fix: import preferences separately * fix: renaming children to items * feat: remove reset call even later * fix: see all in widgets should be variant heading5 --------- Co-authored-by: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bab1072
commit d1fbbda
Showing
53 changed files
with
1,298 additions
and
247 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified
BIN
-8.86 KB
(30%)
apps/native/app/src/assets/illustrations/le-retirement-s3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
167 changes: 167 additions & 0 deletions
167
apps/native/app/src/screens/home/air-discount-module.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,167 @@ | ||
import { | ||
Typography, | ||
Heading, | ||
ChevronRight, | ||
ViewPager, | ||
EmptyCard, | ||
GeneralCardSkeleton, | ||
} from '@ui' | ||
|
||
import React from 'react' | ||
import { FormattedMessage, useIntl } from 'react-intl' | ||
import { Image, SafeAreaView, TouchableOpacity } from 'react-native' | ||
import styled, { useTheme } from 'styled-components/native' | ||
import { ApolloError } from '@apollo/client' | ||
|
||
import illustrationSrc from '../../assets/illustrations/le-jobs-s2.png' | ||
import { navigateTo } from '../../lib/deep-linking' | ||
import { | ||
GetAirDiscountQuery, | ||
useGetAirDiscountQuery, | ||
} from '../../graphql/types/schema' | ||
import { AirDiscountCard } from '@ui/lib/card/air-discount-card' | ||
import { screenWidth } from '../../utils/dimensions' | ||
|
||
const Host = styled.View` | ||
margin-bottom: ${({ theme }) => theme.spacing[2]}px; | ||
` | ||
|
||
interface AirDiscountModuleProps { | ||
data: GetAirDiscountQuery | undefined | ||
loading: boolean | ||
error?: ApolloError | undefined | ||
} | ||
|
||
const validateAirDiscountInitialData = ({ | ||
data, | ||
loading, | ||
}: { | ||
data: GetAirDiscountQuery | undefined | ||
loading: boolean | ||
}) => { | ||
if (loading) { | ||
return true | ||
} | ||
|
||
const noRights = | ||
data?.airDiscountSchemeDiscounts?.filter( | ||
(item) => item.user.fund?.credit === 0 && item.user.fund.used === 0, | ||
).length === data?.airDiscountSchemeDiscounts?.length | ||
|
||
// Only show widget initially if the user has air discount rights | ||
if (!noRights) { | ||
return true | ||
} | ||
|
||
return false | ||
} | ||
|
||
const AirDiscountModule = React.memo( | ||
({ data, loading, error }: AirDiscountModuleProps) => { | ||
const theme = useTheme() | ||
const intl = useIntl() | ||
|
||
if (error && !data) { | ||
return null | ||
} | ||
|
||
const noRights = | ||
data?.airDiscountSchemeDiscounts?.filter( | ||
(item) => item.user.fund?.credit === 0 && item.user.fund.used === 0, | ||
).length === data?.airDiscountSchemeDiscounts?.length | ||
|
||
const discounts = data?.airDiscountSchemeDiscounts?.filter( | ||
({ user }) => !(user.fund?.used === 0 && user.fund.credit === 0), | ||
) | ||
|
||
const count = discounts?.length ?? 0 | ||
|
||
const items = discounts?.slice(0, 3).map(({ discountCode, user }) => ( | ||
<AirDiscountCard | ||
key={`loftbru-item-${discountCode}`} | ||
name={user.name} | ||
code={discountCode} | ||
credit={user.fund?.credit} | ||
text={intl.formatMessage( | ||
{ id: 'airDiscount.remainingFares' }, | ||
{ | ||
remaining: user.fund?.credit, | ||
total: user.fund?.total, | ||
}, | ||
)} | ||
style={ | ||
count > 1 | ||
? { | ||
width: screenWidth - theme.spacing[2] * 4, | ||
marginLeft: theme.spacing[2], | ||
} | ||
: { | ||
width: '100%', | ||
} | ||
} | ||
/> | ||
)) | ||
|
||
return ( | ||
<SafeAreaView | ||
style={{ | ||
marginHorizontal: theme.spacing[2], | ||
marginBottom: theme.spacing[2], | ||
}} | ||
> | ||
<Host> | ||
<TouchableOpacity | ||
disabled={count === 0} | ||
onPress={() => navigateTo(`/air-discount`)} | ||
> | ||
<Heading | ||
button={ | ||
count === 0 ? null : ( | ||
<TouchableOpacity | ||
onPress={() => navigateTo('/air-discount')} | ||
style={{ | ||
flexDirection: 'row', | ||
alignItems: 'center', | ||
}} | ||
> | ||
<Typography variant="heading5" color={theme.color.blue400}> | ||
<FormattedMessage id="button.seeAll" /> | ||
</Typography> | ||
<ChevronRight /> | ||
</TouchableOpacity> | ||
) | ||
} | ||
> | ||
<FormattedMessage id="homeOptions.airDiscount" /> | ||
</Heading> | ||
</TouchableOpacity> | ||
{loading && !data ? ( | ||
<GeneralCardSkeleton height={146} /> | ||
) : ( | ||
<> | ||
{noRights && ( | ||
<EmptyCard | ||
text={intl.formatMessage({ | ||
id: 'airDiscount.emptyListDescription', | ||
})} | ||
image={ | ||
<Image source={illustrationSrc} resizeMode="contain" /> | ||
} | ||
link={null} | ||
/> | ||
)} | ||
{count === 1 && items} | ||
{count >= 2 && <ViewPager>{items}</ViewPager>} | ||
</> | ||
)} | ||
</Host> | ||
</SafeAreaView> | ||
) | ||
}, | ||
) | ||
|
||
export { | ||
AirDiscountModule, | ||
useGetAirDiscountQuery, | ||
validateAirDiscountInitialData, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.