Skip to content
This repository has been archived by the owner on Apr 25, 2023. It is now read-only.

Commit

Permalink
fix: showing members section for personal workspace (#85)
Browse files Browse the repository at this point in the history
* Cleanup code, fix where personal workspace page showed members section

* Pr review

Co-authored-by: KaWaite <flippindaisy@gmail.com>
  • Loading branch information
KaWaite and KaWaite committed Sep 15, 2021
1 parent da50f49 commit 8e78f94
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 33 deletions.
8 changes: 6 additions & 2 deletions src/components/organisms/Dashboard/hooks.ts
Expand Up @@ -44,12 +44,16 @@ export default (teamId?: string) => {

const teams = data?.me?.teams;
const team = teams?.find(team => team.id === teamId);
const personal = teamId === data?.me?.myTeam.id;

useEffect(() => {
if (team?.id && team.id !== currentTeam?.id) {
setCurrentTeam(team);
setCurrentTeam({
personal,
...team,
});
}
}, [currentTeam, team, setCurrentTeam]);
}, [currentTeam, team, setCurrentTeam, personal]);

const changeTeam = useCallback(
(teamId: string) => {
Expand Down
5 changes: 1 addition & 4 deletions src/components/organisms/EarthEditor/Header/hooks.ts
Expand Up @@ -85,10 +85,7 @@ export default () => {
const team = teams?.find(t => t.id === teamId);
if (!team) return;

setTeam({
id: team.id,
name: team.name,
});
setTeam(team);
}, [teams, currentTeam, teamId, setTeam]);

useEffect(() => {
Expand Down
28 changes: 3 additions & 25 deletions src/components/organisms/Settings/SettingPage/hooks.ts
Expand Up @@ -52,35 +52,13 @@ export default (params: Params) => {
name: teamsData?.me?.name ?? "",
};
const teams = teamsData?.me?.teams;
const team = teams?.find(team => team.id === teamId);

useEffect(() => {
if (!currentTeam && teamsData?.me) {
const { id, name = "" } = teamId
? teams?.find(t => t.id === teamId) ?? {}
: teamsData.me.myTeam;
if (id) {
setTeam({ id, name });
}
if (!currentTeam) {
setTeam(teamId ? teams?.find(t => t.id === teamId) : teamsData?.me?.myTeam ?? undefined);
}
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [currentTeam, team, setTeam, teams, teamsData?.me]);

// update team name
useEffect(() => {
if (currentTeam?.id && teams) {
const { name = "" } = teams?.find(t => t.id === currentTeam.id) ?? {};
if (currentTeam.name != name) {
setTeam({ id: currentTeam.id, name });
}
}
}, [currentTeam, setTeam, teams]);

useEffect(() => {
if (team?.id && !currentTeam?.id) {
setTeam(team);
}
}, [currentTeam, team, setTeam]);
}, [currentTeam, setTeam, teams, teamsData?.me]);

const { data } = useProjectQuery({
variables: { teamId: teamId ?? "" },
Expand Down
9 changes: 7 additions & 2 deletions src/components/organisms/Settings/Workspace/hooks.ts
Expand Up @@ -77,8 +77,13 @@ export default (params: Params) => {
const [updateTeamMutation] = useUpdateTeamMutation();

const updateName = useCallback(
(name: string) => teamId && updateTeamMutation({ variables: { teamId, name } }),
[teamId, updateTeamMutation],
async (name: string) => {
if (teamId) {
const results = await updateTeamMutation({ variables: { teamId, name } });
setTeam(results.data?.updateTeam?.team);
}
},
[teamId, updateTeamMutation, setTeam],
);

const [deleteTeamMutation] = useDeleteTeamMutation({
Expand Down

0 comments on commit 8e78f94

Please sign in to comment.