-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #333 from cultuurnet/feature/UIT-209-welcome-rewar…
…ds-filter Welcome rewards filter
- Loading branch information
Showing
15 changed files
with
142 additions
and
23 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.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
import { useRef } from 'react'; | ||
import { FlatList } from 'react-native'; | ||
|
||
import { useGetFamilyMembers } from '../../../onboarding/family/_queries'; | ||
import { TFamilyMember, TPassHolder } from '../../../profile/_models'; | ||
import Typography from '../../typography/Typography'; | ||
import * as Styled from './style'; | ||
|
||
type TProps = { | ||
selectedPassHolder: TPassHolder; | ||
setSelectedPassHolder: (selectedPassHolder: TPassHolder) => void; | ||
}; | ||
|
||
export const FamilyFilter = ({ selectedPassHolder, setSelectedPassHolder }: TProps) => { | ||
const listRef = useRef<FlatList>(); | ||
|
||
const { data: familyMembers = [] } = useGetFamilyMembers(); | ||
|
||
const handleSelectPassHolder = (nextSelectedPassHolder: TPassHolder, nextSelectedIndex: number) => { | ||
if (selectedPassHolder.id !== nextSelectedPassHolder.id) { | ||
setSelectedPassHolder(nextSelectedPassHolder); | ||
listRef.current.scrollToIndex({ animated: true, index: nextSelectedIndex }); | ||
} | ||
}; | ||
|
||
const handlePressPrev = () => { | ||
const currentIndex = findCurrentIndexByPassHolder(familyMembers, selectedPassHolder); | ||
const nextPassHolder = findBoundedPassHolderByIndex(familyMembers, currentIndex - 1); | ||
setSelectedPassHolder(nextPassHolder); | ||
}; | ||
|
||
const handleNextPrev = () => { | ||
const currentIndex = findCurrentIndexByPassHolder(familyMembers, selectedPassHolder); | ||
const nextPassHolder = findBoundedPassHolderByIndex(familyMembers, currentIndex + 1); | ||
setSelectedPassHolder(nextPassHolder); | ||
}; | ||
|
||
return ( | ||
<Styled.Container> | ||
<Styled.FilterPrevButton name="ChevronLeft" onPress={handlePressPrev} /> | ||
<FlatList | ||
ItemSeparatorComponent={Styled.Separator} | ||
data={familyMembers} | ||
horizontal | ||
keyExtractor={item => item.uitpasNumber} | ||
ref={listRef} | ||
renderItem={({ item: familyMember, index }) => ( | ||
<Styled.FilterItem | ||
isSelected={familyMember.passholder.id === selectedPassHolder.id} | ||
onPress={() => handleSelectPassHolder(familyMember.passholder, index)} | ||
> | ||
<Typography | ||
color={familyMember.passholder.id === selectedPassHolder.id ? 'neutral.0' : 'primary.100'} | ||
fontStyle="bold" | ||
size="small" | ||
> | ||
{familyMember.passholder.firstName} | ||
</Typography> | ||
</Styled.FilterItem> | ||
)} | ||
showsHorizontalScrollIndicator={false} | ||
/> | ||
<Styled.FilterNextButton name="ChevronRight" onPress={handleNextPrev} /> | ||
</Styled.Container> | ||
); | ||
}; | ||
|
||
const findBoundedPassHolderByIndex = (familyMembers: TFamilyMember[], index: number) => { | ||
return familyMembers[Math.min(Math.max(index, 0), familyMembers.length - 1)].passholder; | ||
}; | ||
|
||
const findCurrentIndexByPassHolder = (familyMembers: TFamilyMember[], passHolder: TPassHolder) => { | ||
return familyMembers.findIndex(member => member.passholder.id === passHolder.id); | ||
}; |
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,32 @@ | ||
import styled from 'styled-components/native'; | ||
|
||
import Icon from '../../icon/Icon'; | ||
import TouchableRipple from '../../touchableRipple/TouchableRipple'; | ||
|
||
export const Container = styled.View` | ||
flex-direction: row; | ||
align-items: center; | ||
background-color: ${({ theme }) => theme.palette.primary[700]}; | ||
padding-vertical: 8px; | ||
`; | ||
|
||
export const FilterPrevButton = styled(Icon)` | ||
margin-left: 3px; | ||
margin-right: 8px; | ||
`; | ||
|
||
export const FilterNextButton = styled(Icon)` | ||
margin-right: 3px; | ||
margin-left: 8px; | ||
`; | ||
|
||
export const FilterItem = styled(TouchableRipple)<{ isSelected: boolean }>` | ||
padding-horizontal: 16px; | ||
padding-vertical: 4px; | ||
background-color: ${({ isSelected, theme }) => (isSelected ? theme.palette.primary[900] : 'transparent')}}; | ||
border-radius: 20px; | ||
`; | ||
|
||
export const Separator = styled.View` | ||
width: 8px; | ||
`; |
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,2 @@ | ||
export * from './familyFilter/FamilyFilter'; | ||
export * from './familyMembersPoints/FamilyMembersPoints'; |
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
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
2 changes: 1 addition & 1 deletion
2
src/shopDetail/_components/redeemFamilyMembers/RedeemFamilyMembers.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
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