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

feat(web): members setting #1186

Open
wants to merge 41 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
b6e9566
feat: workspace frontend
Oct 3, 2024
041ad6e
Merge branch 'main' into feat/workspace_setting
Oct 3, 2024
7ad31c6
feat: add functionality to workspaceSetting page
Oct 7, 2024
233c119
Merge branch 'main' into feat/workspace_setting
Oct 8, 2024
08cd5fe
feat: update t
Oct 8, 2024
e22188d
refactor: refactor code
Oct 8, 2024
0913193
fix: fix bug and add refactor with atom state
Oct 8, 2024
f39852c
refactor: delete useless gap
Oct 8, 2024
5a49b89
refactor: refactor miss name
Oct 8, 2024
ded91a0
update t
Oct 8, 2024
d5825d3
refactor: refactor according to design and add menu item
Oct 9, 2024
bc56bf1
Merge branch 'main' into feat/workspace_setting
ZTongci Oct 9, 2024
e3f84da
Revert "Merge branch 'main' into feat/workspace_setting"
Oct 9, 2024
914c889
Revert "Revert "Merge branch 'main' into feat/workspace_setting""
Oct 9, 2024
a65bb5c
refactor: fix statement for currentWorkspace
Oct 9, 2024
2a06e5d
refactor: use props to add borderbottom
ZTongci Oct 11, 2024
afe812e
refactor: use lazy load to page
ZTongci Oct 11, 2024
eee901e
refactor: add dynamic router for workspace and refactor derectory
ZTongci Oct 11, 2024
2ae6529
refactor: refactor by bot
ZTongci Oct 11, 2024
265cab3
refactor: refactor by bot
ZTongci Oct 11, 2024
efa9b6f
refactor: refactor by bot
ZTongci Oct 11, 2024
ef30fbe
refactor: fix router
ZTongci Oct 11, 2024
3390ee3
refactor: refactor folder name
ZTongci Oct 11, 2024
3e1d1e0
Merge branch 'feat/workspace_setting' into feat/members_setting
ZTongci Oct 11, 2024
1cacf90
refactor: refactor folder name
ZTongci Oct 11, 2024
bce3878
feat: add api
ZTongci Oct 11, 2024
708083c
refactor: update by main
Oct 21, 2024
965aab5
refactor: update by main
Oct 21, 2024
8cee8d1
feat: add member and update member
Oct 22, 2024
9ac9671
Merge branch 'main' into feat/members_setting
ZTongci Oct 22, 2024
131231d
update t
Oct 22, 2024
b3ad8b9
refactor: fix bug
Oct 23, 2024
0abf138
Merge branch 'main' into feat/members_setting
ZTongci Oct 24, 2024
6c38de6
update t
Oct 24, 2024
8c01682
refactor: refactor code by bot
Oct 24, 2024
7a80757
Merge branch 'main' into feat/members_setting
ZTongci Oct 24, 2024
b5edc6f
refactor: type
airslice Oct 24, 2024
20d4a34
Merge branch 'feat/members_setting' of github.com:reearth/reearth int…
airslice Oct 24, 2024
24296d6
refactor: set state
airslice Oct 24, 2024
d878fa6
refactor: fix type for dashboard
Oct 24, 2024
f013644
refactor: fix type for dashboard
Oct 24, 2024
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
@@ -1,10 +1,9 @@
import { Typography } from "@reearth/beta/lib/reearth-ui";
import { TeamMember } from "@reearth/services/gql";
import { styled } from "@reearth/services/theme";
import { FC } from "react";

import { Member } from "../../type";

const ListItem: FC<{ member: Member }> = ({ member }) => {
const ListItem: FC<{ member: TeamMember }> = ({ member }) => {
return (
<StyledListItem>
<Avatar>
Expand Down
3 changes: 2 additions & 1 deletion web/src/beta/features/Dashboard/type.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { IconName } from "@reearth/beta/lib/reearth-ui";
import { TeamMember } from "@reearth/services/gql";
import { ProjectType } from "@reearth/types";

export type Project = {
Expand Down Expand Up @@ -47,7 +48,7 @@ export type Member = {
export type Workspace = {
id: string;
name: string;
members?: Member[];
members?: TeamMember[];
policyId?: string | null;
policy?: { id: string; name: string } | null;
personal?: boolean;
Expand Down
75 changes: 62 additions & 13 deletions web/src/beta/features/WorkspaceSetting/hooks.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { useWorkspaceFetcher } from "@reearth/services/api";
import { useMeFetcher, useWorkspaceFetcher } from "@reearth/services/api";
import { Role } from "@reearth/services/gql";
import { useCallback } from "react";

export type WorkspacePayload = {
name: string;
name?: string;
userId?: string;
teamId: string;
role?: Role;
Expand All @@ -24,7 +24,8 @@ export default () => {
useUpdateWorkspace,
useDeleteWorkspace,
useAddMemberToWorkspace,
useRemoveMemberFromWorkspace
useRemoveMemberFromWorkspace,
useUpdateMemberOfWorkspace
} = useWorkspaceFetcher();

// Fetch a specific workspace
Expand Down Expand Up @@ -52,9 +53,11 @@ export default () => {
const handleCreateWorkspace = useCallback(
async ({ name }: WorkspacePayload) => {
try {
const { status } = await useCreateWorkspace(name);
if (status === "success") {
console.log("Workspace created successfully");
if (name) {
const { status } = await useCreateWorkspace(name);
if (status === "success") {
console.log("Workspace created successfully");
}
}
ZTongci marked this conversation as resolved.
Show resolved Hide resolved
Comment on lines +58 to +60
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this console.log here, even when we need one we should handle it on api code.

} catch (error) {
console.error("Failed to create workspace:", error);
Expand All @@ -67,9 +70,11 @@ export default () => {
const handleUpdateWorkspace = useCallback(
async ({ teamId, name }: WorkspacePayload) => {
try {
const { status } = await useUpdateWorkspace(teamId, name);
if (status === "success") {
console.log("Workspace updated successfully");
if (name && teamId) {
const { status } = await useUpdateWorkspace(teamId, name);
if (status === "success") {
console.log("Workspace updated successfully");
}
}
Comment on lines +75 to +77
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

} catch (error) {
console.error("Failed to update workspace:", error);
Expand All @@ -82,9 +87,11 @@ export default () => {
const handleDeleteWorkspace = useCallback(
async (teamId: string) => {
try {
const { status } = await useDeleteWorkspace(teamId);
if (status === "success") {
console.log("Workspace deleted successfully");
if (teamId) {
const { status } = await useDeleteWorkspace(teamId);
if (status === "success") {
console.log("Workspace deleted successfully");
}
}
Comment on lines +92 to +94
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above

} catch (error) {
console.error("Failed to delete workspace:", error);
Expand Down Expand Up @@ -131,13 +138,55 @@ export default () => {
[useRemoveMemberFromWorkspace]
);

// update a member of workspace
const handleUpdateMemberOfWorkspace = useCallback(
async ({ teamId, userId, role }: WorkspacePayload) => {
try {
if (userId && role) {
const { status } = await useUpdateMemberOfWorkspace(
teamId,
userId,
role
);
if (status === "success") {
console.log("Member update successfully");
}
}
} catch (error) {
console.error("Failed to update member from workspace:", error);
}
},
Comment on lines +144 to +157
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same as above, i think api hooks already handled the errors and notifications, we don't need to to these again where we use the api hooks.

[useUpdateMemberOfWorkspace]
);

ZTongci marked this conversation as resolved.
Show resolved Hide resolved
const { useSearchUser } = useMeFetcher();
const handleSearchUser = useCallback(
(nameOrEmail: string) => {
try {
const { user, status } = useSearchUser(nameOrEmail, {
skip: !nameOrEmail
});
if (status === "success") {
console.log("Search Member successfully");
}
return { searchUser: user, searchUserStatus: status };
} catch (err) {
console.error("Failed to search user:", err);
return { error: err };
}
},
[useSearchUser]
);

ZTongci marked this conversation as resolved.
Show resolved Hide resolved
return {
handleFetchWorkspace,
handleFetchWorkspaces,
handleCreateWorkspace,
handleUpdateWorkspace,
handleDeleteWorkspace,
handleAddMemberToWorkspace,
handleRemoveMemberFromWorkspace
handleRemoveMemberFromWorkspace,
handleUpdateMemberOfWorkspace,
handleSearchUser
};
};
22 changes: 20 additions & 2 deletions web/src/beta/features/WorkspaceSetting/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,28 @@ import CursorStatus from "../CursorStatus";
import useProjectsHook from "../Dashboard/ContentsContainer/Projects/hooks";

import useWorkspaceHook from "./hooks";
import Members from "./innerPages/Members/Members";
import Workspace from "./innerPages/Workspaces/Workspaces";

type Props = {
tab: string;
workspaceId?: string;
};

enum TABS {
WORKSPACE = "workspace",
MEMBERS = "members"
}

const WorkspaceSetting: FC<Props> = ({ tab, workspaceId }) => {
const {
handleFetchWorkspaces,
handleUpdateWorkspace,
handleDeleteWorkspace
handleDeleteWorkspace,
handleAddMemberToWorkspace,
handleSearchUser,
handleUpdateMemberOfWorkspace,
handleRemoveMemberFromWorkspace
} = useWorkspaceHook();

const { filtedProjects } = useProjectsHook(workspaceId);
Expand All @@ -26,14 +36,22 @@ const WorkspaceSetting: FC<Props> = ({ tab, workspaceId }) => {

return (
<SettingBase tabs={tabs} tab={tab} workspaceId={workspaceId}>
{tab === "workspace" && (
{tab === TABS.WORKSPACE && (
<Workspace
handleFetchWorkspaces={handleFetchWorkspaces}
handleUpdateWorkspace={handleUpdateWorkspace}
handleDeleteWorkspace={handleDeleteWorkspace}
projectsCount={filtedProjects?.length}
/>
)}
{tab === TABS.MEMBERS && (
<Members
handleSearchUser={handleSearchUser}
handleAddMemberToWorkspace={handleAddMemberToWorkspace}
handleUpdateMemberOfWorkspace={handleUpdateMemberOfWorkspace}
handleRemoveMemberFromWorkspace={handleRemoveMemberFromWorkspace}
/>
)}
ZTongci marked this conversation as resolved.
Show resolved Hide resolved
<CursorStatus />
</SettingBase>
);
Expand Down
Loading
Loading