diff --git a/client/components/profile/Group.tsx b/client/components/profile/Group.tsx index 7adebe9..a6339fb 100644 --- a/client/components/profile/Group.tsx +++ b/client/components/profile/Group.tsx @@ -1,24 +1,32 @@ import React from 'react'; -import { ActivityIndicator, FlatList, Text, View } from 'react-native'; +import { + ActivityIndicator, + FlatList, + Pressable, + Text, + View +} from 'react-native'; -import { useCareWalletContext } from '../../contexts/CareWalletContext'; -import { useUsers } from '../../services/user'; import { GroupRole, Role } from '../../types/group'; +import { User } from '../../types/user'; interface GroupProps { roles: GroupRole[]; rolesAreLoading: boolean; + setActiveUser: (userID: string) => void; + activeUser: string; + users: User[]; + usersAreLoading: boolean; } -export function Group({ roles, rolesAreLoading }: GroupProps) { - const { user: signedInUser } = useCareWalletContext(); - - const { users, usersAreLoading } = useUsers( - roles - ?.map((role) => role.user_id) - .filter((u) => u !== signedInUser.userID) || [] - ); - +export function Group({ + roles, + rolesAreLoading, + usersAreLoading, + users, + setActiveUser, + activeUser +}: GroupProps) { if (rolesAreLoading || usersAreLoading) { return ( @@ -38,20 +46,23 @@ export function Group({ roles, rolesAreLoading }: GroupProps) { return ( - user.user_id !== signedInUser.userID && + user.user_id !== activeUser && user.user_id !== (roles.find((role) => role.role === Role.PATIENT)?.user_id ?? '') )} - renderItem={({ item }) => ( - - - {item.first_name} - + renderItem={({ item, index }) => ( + setActiveUser(item.user_id)}> + + + {item.first_name} + + )} /> ); diff --git a/client/components/profile/Header.tsx b/client/components/profile/Header.tsx index 9a67207..6177c0e 100644 --- a/client/components/profile/Header.tsx +++ b/client/components/profile/Header.tsx @@ -5,18 +5,22 @@ import { useNavigation } from '@react-navigation/native'; import { styled } from 'nativewind'; import Ellipse from '../../assets/profile/ellipse.svg'; -import { useCareWalletContext } from '../../contexts/CareWalletContext'; import { AppStackNavigation } from '../../navigation/AppNavigation'; +import { GroupRole } from '../../types/group'; import { User } from '../../types/user'; import { ProfileTopHeader } from './ProfileTopHeader'; const StyledEllipse = styled(Ellipse); -export function Header({ user }: { user: User }) { - const { group } = useCareWalletContext(); +interface HeaderProps { + user: User | undefined; + role: GroupRole | undefined; +} + +export function Header({ user, role }: HeaderProps) { const navigate = useNavigation(); - if (!user || !group) return null; + if (!user) return null; return ( <> @@ -29,7 +33,7 @@ export function Header({ user }: { user: User }) { rightButtonText="Edit" /> - {`${group.role.charAt(0)}${group.role.slice(1).toLowerCase()} Caregiver`} + {`${role?.role.charAt(0)}${role?.role.slice(1).toLowerCase()} Caregiver`} {user.phone ? user.phone : user.email} diff --git a/client/screens/Profile.tsx b/client/screens/Profile.tsx index fab6afb..8cc764b 100644 --- a/client/screens/Profile.tsx +++ b/client/screens/Profile.tsx @@ -1,4 +1,4 @@ -import React from 'react'; +import React, { useState } from 'react'; import { ActivityIndicator, Text, View } from 'react-native'; import { CircleCard } from '../components/profile/CircleCard'; @@ -7,16 +7,19 @@ import { Header } from '../components/profile/Header'; import { useCareWalletContext } from '../contexts/CareWalletContext'; import { useAuth } from '../services/auth'; import { useGroup } from '../services/group'; -import { useUser } from '../services/user'; +import { useUsers } from '../services/user'; export default function Profile() { - const { user: carewalletUser, group } = useCareWalletContext(); - const { user, userIsLoading } = useUser(carewalletUser.userID); + const { user: signedInUser, group } = useCareWalletContext(); + const [activeUser, setActiveUser] = useState(signedInUser.userID); const { roles, rolesAreLoading } = useGroup(group.groupID); + const { users, usersAreLoading } = useUsers( + roles?.map((role) => role.user_id) ?? [] + ); const { signOutMutation } = useAuth(); - if (userIsLoading) { + if (rolesAreLoading || usersAreLoading) { return ( @@ -25,7 +28,7 @@ export default function Profile() { ); } - if (!user) { + if (!roles || !users) { return ( Could Not Load Profile... @@ -39,8 +42,18 @@ export default function Profile() { // TODO: Add ability to change user view if I click on another user? return ( -
- +
user.user_id === activeUser)} + role={roles.find((role) => role.user_id === activeUser)} + /> + Your Tasks diff --git a/docker-compose.yaml b/docker-compose.yaml index cb181ad..dae2306 100644 --- a/docker-compose.yaml +++ b/docker-compose.yaml @@ -1,9 +1,9 @@ services: db: image: postgres:14.1-alpine - restart: always + restart: unless-stopped healthcheck: - test: ['CMD', 'pg_isready', '-q', '-d', 'postgres', '-U', 'user'] + test: ["CMD", "pg_isready", "-q", "-d", "postgres", "-U", "user"] timeout: 45s interval: 10s retries: 10 @@ -12,7 +12,7 @@ services: - POSTGRES_DB=carewallet - POSTGRES_PASSWORD=pwd ports: - - '5434:5432' + - "5434:5432" volumes: - ./backend/db/migrations:/docker-entrypoint-initdb.d/ volumes: