Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: user edit role working #761

Merged
merged 2 commits into from
Dec 29, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@ import { PopoverCloseStyled, PopoverItemStyled, PopoverTriggerStyled } from './s

interface PopoverRoleSettingsProps {
userId: string | undefined;
teamId?: string | undefined;
isTeamPage?: boolean;
isTeamCreator?: boolean;
}

const PopoverRoleSettings: React.FC<PopoverRoleSettingsProps> = React.memo(
({ userId, isTeamPage, isTeamCreator }) => {
({ userId, teamId, isTeamPage, isTeamCreator }) => {
const membersList = useRecoilValue(membersListState);
const setMembersList = useSetRecoilState(membersListState);

Expand All @@ -41,30 +42,31 @@ const PopoverRoleSettings: React.FC<PopoverRoleSettingsProps> = React.memo(
setMembersList(members);
};

const updateUser = (value: TeamUserRoles, teamUsers: TeamUser[]) => {
const userFound = teamUsers.find((member) => member.user._id === userId);
const updateUser = (value: TeamUserRoles, teamUser?: TeamUser) => {
if (teamUser && teamUser.team) {

if (userFound && userFound.team) {
const updateTeamUserRole: TeamUserUpdate = {
team: userFound.team,
team: teamUser.team,
user: userId,
role: value,
isNewJoiner: userFound.isNewJoiner,
isNewJoiner: teamUser.isNewJoiner,
};

mutate(updateTeamUserRole);
}
};

let updateUserRole = (value: TeamUserRoles) => {
updateUser(value, membersList);
const userFound = membersList.find((member) => member.user._id === userId);
updateUser(value, userFound);
};

if (router.pathname.includes('users')) {
updateUserRole = (value: TeamUserRoles) => {
const users = userTeamsList.flatMap((team) => team.users);
const teamUsers = userTeamsList.flatMap((team) => team.users);
const teamFound = teamUsers.find((teamUser) => teamUser.team === teamId);

updateUser(value, users);
updateUser(value, teamFound);
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,13 @@ const InnerContainer = styled(Flex, Box, {

type CardBodyProps = {
userId: string | undefined;
teamId?: string | undefined;
team: Team;
index?: number;
isTeamPage?: boolean;
};

const CardBody = React.memo<CardBodyProps>(({ userId, team, isTeamPage }) => {
const CardBody = React.memo<CardBodyProps>(({ userId, teamId, team, isTeamPage }) => {
const { data: session } = useSession();

const router = useRouter();
Expand Down Expand Up @@ -134,7 +135,7 @@ const CardBody = React.memo<CardBodyProps>(({ userId, team, isTeamPage }) => {
<Flex align="center" css={{ width: '$237' }} justify="end">
<RoleDescription role={userRole} />

<PopoverRoleSettings userId={userId} isTeamPage />
<PopoverRoleSettings userId={userId} isTeamPage teamId={teamId} />
</Flex>
) : (
<Flex align="center" css={{ width: '$237' }} justify="start">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ const ListOfCards = React.memo<ListOfCardsProp>(({ userId, isLoading }) => {
<ScrollableContent direction="column" gap="24" justify="start">
<Flex direction="column" gap="20">
{teamsOfUsers?.map((team: Team) => (
<CardBody key={team._id} team={team} userId={userId} isTeamPage={false} />
<CardBody
key={team._id}
team={team}
userId={userId}
isTeamPage={false}
teamId={team._id}
/>
))}
</Flex>
{isLoading && (
Expand Down