Skip to content

Commit

Permalink
fix: Update Project Team tab to refresh on new user
Browse files Browse the repository at this point in the history
  • Loading branch information
David Code Howard committed Oct 12, 2023
1 parent 4dd0951 commit 4598bc0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 15 deletions.
6 changes: 3 additions & 3 deletions dev-client/src/components/common/UserList.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import {useMemo} from 'react';
import {ProjectMembership} from 'terraso-client-shared/project/projectSlice';

type ListProps = {
memberships: [string, [ProjectMembership, User]][];
memberships: [ProjectMembership, User][];
currentUserId?: string;
userAction: (membership: ProjectMembership) => () => void;
};
Expand Down Expand Up @@ -96,15 +96,15 @@ export default function UserList({
return (
<FlatList
data={memberships}
renderItem={({item: [_, [membership, user]]}) => (
renderItem={({item: [membership, user]}) => (
<UserItem
membership={membership}
user={user}
currentUserId={currentUserId}
onPress={userAction(membership)}
/>
)}
keyExtractor={([id, _]) => id}
keyExtractor={([membership, _]) => membership.id}
ItemSeparatorComponent={Divider}
/>
);
Expand Down
17 changes: 5 additions & 12 deletions dev-client/src/components/projects/ProjectTeamTab.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,13 @@ import UserList from '../common/UserList';
import {NativeStackScreenProps} from '@react-navigation/native-stack';
import {TabRoutes, TabStackParamList} from './constants';
import {useDispatch, useSelector} from '../../model/store';
import {useCallback, useState} from 'react';
import {useCallback, useMemo, useState} from 'react';

Check failure on line 7 in dev-client/src/components/projects/ProjectTeamTab.tsx

View workflow job for this annotation

GitHub Actions / lint

'useMemo' is defined but never used

Check failure on line 7 in dev-client/src/components/projects/ProjectTeamTab.tsx

View workflow job for this annotation

GitHub Actions / lint

'useState' is defined but never used
import {
ProjectMembership,
removeMembershipFromProject,
} from 'terraso-client-shared/project/projectSlice';
import {selectProjectMembershipsWithUsers} from 'terraso-client-shared/selectors';
import {useTranslation} from 'react-i18next';
import {User} from 'terraso-client-shared/account/accountSlice';
import {useNavigation} from '../../screens/AppScaffold';

type Props = NativeStackScreenProps<TabStackParamList, TabRoutes.TEAM>;
Expand All @@ -20,11 +20,8 @@ export default function ProjectTeamTab({route}: Props) {
const dispatch = useDispatch();
const navigation = useNavigation();
const currentUser = useSelector(state => state.account.currentUser);
let [members, setMembers] = useState(
route.params.memberships.reduce(
(x, y) => ({...x, [y[0].id]: y}),
{} as Record<string, [ProjectMembership, User]>,
),
const members = useSelector(state =>
selectProjectMembershipsWithUsers(state, route.params.projectId),
);

const removeMembership = useCallback(
Expand All @@ -36,10 +33,6 @@ export default function ProjectTeamTab({route}: Props) {
projectId: route.params.projectId,
}),
);
// TODO: This is just to get the project to update
let newMembers = {...members};
delete newMembers[membership.id];
setMembers(newMembers);
};
},
[dispatch, members, route.params.projectId],

Check failure on line 38 in dev-client/src/components/projects/ProjectTeamTab.tsx

View workflow job for this annotation

GitHub Actions / lint

React Hook useCallback has an unnecessary dependency: 'members'. Either exclude it or remove the dependency array
Expand All @@ -57,7 +50,7 @@ export default function ProjectTeamTab({route}: Props) {
}}
/>
<UserList
memberships={Object.entries(members)}
memberships={members}
currentUserId={currentUser.data?.id}
userAction={removeMembership}
/>
Expand Down

0 comments on commit 4598bc0

Please sign in to comment.