-
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 branch 'feat/UIT-198-delete-family-member' of github.com:cultuu…
…rnet/uitpas-mobile-app into feat/UIT-198-delete-family-member
- Loading branch information
Showing
18 changed files
with
308 additions
and
61 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { TMutationParams, usePubliqApi } from '../../../_hooks/usePubliqApi'; | ||
import { useGetMe } from '../../../profile/_queries/useGetMe'; | ||
|
||
export type TEditFamilyMemberParams = TMutationParams<{ | ||
icon: string; | ||
}>; | ||
|
||
export const useEditFamilyMember = (familyMemberId: string) => { | ||
const { data: user } = useGetMe(); | ||
const api = usePubliqApi(); | ||
|
||
return api.put<string, TEditFamilyMemberParams>( | ||
['family-member-edit'], | ||
`/passholders/${user.id}/family-members/${familyMemberId}`, | ||
); | ||
}; |
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
84 changes: 84 additions & 0 deletions
84
src/onboarding/family/editFamilyMember/EditFamilyMember.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,84 @@ | ||
import { useMemo, useState } from 'react'; | ||
import { useTranslation } from 'react-i18next'; | ||
import { FlatList } from 'react-native'; | ||
import { useSafeAreaInsets } from 'react-native-safe-area-context'; | ||
|
||
import * as Avatars from '../../../_assets/images/avatars'; | ||
import { Button, Typography } from '../../../_components'; | ||
import { queryClient } from '../../../_context'; | ||
import { TMainNavigationProp, TRootStackRouteProp } from '../../../_routing'; | ||
import { applyBarcodeMask, getAvatarByNameOrDefault, getValidAvatarNameOrDefault } from '../../../_utils'; | ||
import { useEditFamilyMember } from '../_queries'; | ||
import DeleteFamilyMember from '../deleteFamilyMember/DeleteFamilyMember'; | ||
import * as Styled from './style'; | ||
|
||
type TProps = { | ||
navigation: TMainNavigationProp<'Profile'>; | ||
route: TRootStackRouteProp<'EditFamilyMember'>; | ||
}; | ||
|
||
export const EditFamilyMember = ({ navigation, route }: TProps) => { | ||
const { member } = route.params; | ||
|
||
const [selectedAvatar, setSelectedAvatar] = useState(getValidAvatarNameOrDefault(member.icon)); | ||
const sortedAvatars = useMemo(() => { | ||
const avatars = Object.keys(Avatars).slice(); | ||
avatars.sort((item, item2) => { | ||
if (item.includes('Emoji') && !item2.includes('Emoji')) { | ||
return -1; | ||
} | ||
if (item2.includes('Emoji') && !item.includes('Emoji')) { | ||
return 1; | ||
} | ||
return item.localeCompare(item2); | ||
}); | ||
return avatars; | ||
}, []); | ||
const { mutateAsync: editFamilyMember, isLoading } = useEditFamilyMember(member.passholderId); | ||
|
||
const { bottom } = useSafeAreaInsets(); | ||
const { t } = useTranslation(); | ||
|
||
const handleSubmit = async () => { | ||
await editFamilyMember({ body: { icon: selectedAvatar } }); | ||
queryClient.invalidateQueries(['family-members']); | ||
navigation.goBack(); | ||
}; | ||
|
||
return ( | ||
<Styled.ScreenContainer> | ||
<FlatList | ||
ListFooterComponent={<DeleteFamilyMember familyMemberId={member.passholderId} name={member.firstName} />} | ||
ListFooterComponentStyle={{ width: '100%' }} | ||
ListHeaderComponent={ | ||
<Styled.Header> | ||
<Typography fontStyle="bold" numberOfLines={1} size="xxlarge"> | ||
{member.firstName} | ||
</Typography> | ||
<Styled.UitpasNumber color="primary.700" fontStyle="bold"> | ||
{applyBarcodeMask(member.uitpasNumber)} | ||
</Styled.UitpasNumber> | ||
<Styled.SelectedAvatarImage resizeMode="contain" source={getAvatarByNameOrDefault(selectedAvatar)} /> | ||
<Styled.Description color="primary.700" fontStyle="semibold"> | ||
{t('ONBOARDING.FAMILY.EDIT_MEMBER.DESCRIPTION')} | ||
</Styled.Description> | ||
</Styled.Header> | ||
} | ||
columnWrapperStyle={{ padding: 8 }} | ||
contentContainerStyle={{ alignItems: 'center', paddingHorizontal: 8 }} | ||
data={sortedAvatars} | ||
numColumns={5} | ||
renderItem={({ item: avatar }) => ( | ||
<Styled.AvatarItemBorder isSelected={avatar === selectedAvatar} onPress={() => setSelectedAvatar(avatar)}> | ||
<Styled.AvatarItemContainer> | ||
<Styled.AvatarItemImage resizeMode="contain" source={getAvatarByNameOrDefault(avatar)} /> | ||
</Styled.AvatarItemContainer> | ||
</Styled.AvatarItemBorder> | ||
)} | ||
/> | ||
<Styled.StickyFooter style={{ marginBottom: bottom + 16 }}> | ||
<Button label={t('ONBOARDING.FAMILY.EDIT_MEMBER.SAVE')} loading={isLoading} onPress={handleSubmit} /> | ||
</Styled.StickyFooter> | ||
</Styled.ScreenContainer> | ||
); | ||
}; |
Oops, something went wrong.