From 2706d73d63088f10aeadb3ac1473c398384a7358 Mon Sep 17 00:00:00 2001 From: nina992 Date: Fri, 14 Apr 2023 14:10:46 +0300 Subject: [PATCH 1/3] refactor: Purge reearth-web of reference to team-Setting page --- src/app.tsx | 12 +-- .../AssetModal/AssetContainer/index.tsx | 2 +- .../molecules/Common/AssetModal/index.tsx | 6 +- .../molecules/Common/ProjectMenu/index.tsx | 6 +- .../molecules/EarthEditor/Header/index.tsx | 4 +- .../Settings/Account/PasswordModal/index.tsx | 2 +- .../molecules/Settings/Navigation/index.tsx | 20 ++-- .../Settings/Project/DangerSection/Modal.tsx | 8 +- .../Settings/Project/DangerSection/index.tsx | 11 ++- .../molecules/Settings/SettingPage/index.tsx | 6 +- .../Workspace/AddMemberModal/index.tsx | 8 +- .../Workspace/DangerSection/Modal.tsx | 18 ++-- .../Workspace/DangerSection/index.tsx | 10 +- .../Workspace/MembersSection/index.tsx | 22 ++--- .../Workspace/ProfileSection/index.tsx | 16 ++-- .../WorkspaceList/WorkspaceCell/index.tsx | 18 ++-- .../WorkspaceList/WorkspaceList/index.tsx | 36 ++++---- .../organisms/Common/AssetContainer/hooks.ts | 21 +++-- .../organisms/Common/AssetContainer/index.tsx | 4 +- .../organisms/Common/AssetModal/index.tsx | 4 +- .../organisms/Settings/Account/index.tsx | 2 +- .../Settings/Project/Dataset/index.tsx | 2 +- .../Settings/Project/Public/index.tsx | 4 +- .../organisms/Settings/Project/index.tsx | 6 +- .../organisms/Settings/ProjectList/hooks.ts | 28 +++--- .../organisms/Settings/ProjectList/index.tsx | 10 +- .../organisms/Settings/SettingPage/hooks.ts | 30 +++--- .../organisms/Settings/SettingPage/index.tsx | 10 +- .../Settings/Workspace/Asset/hooks.ts | 4 +- .../Settings/Workspace/Asset/index.tsx | 10 +- .../organisms/Settings/Workspace/hooks.ts | 92 +++++++++---------- .../organisms/Settings/Workspace/index.tsx | 32 ++++--- .../Settings/WorkspaceList/index.tsx | 22 +++-- .../pages/Settings/ProjectList/index.tsx | 4 +- .../pages/Settings/Workspace/Asset/index.tsx | 4 +- .../pages/Settings/Workspace/index.tsx | 4 +- .../pages/Settings/WorkspaceList/index.tsx | 4 +- 37 files changed, 264 insertions(+), 238 deletions(-) diff --git a/src/app.tsx b/src/app.tsx index eeb0e7595..a8934b0e9 100644 --- a/src/app.tsx +++ b/src/app.tsx @@ -41,9 +41,9 @@ function AppRoutes() { { path: "/settings", element: }, { path: "/settings/account", element: }, { path: "/settings/workspaces", element: }, - { path: "/settings/workspaces/:teamId", element: }, - { path: "/settings/workspaces/:teamId/projects", element: }, - { path: "/settings/workspaces/:teamId/asset", element: }, + { path: "/settings/workspaces/:workspaceId", element: }, + { path: "/settings/workspaces/:workspaceId/projects", element: }, + { path: "/settings/workspaces/:workspaceId/asset", element: }, { path: "/settings/projects/:projectId", element: }, { path: "/settings/projects/:projectId/public", element: }, { path: "/settings/projects/:projectId/dataset", element: }, @@ -80,9 +80,9 @@ const StyledRouter = styled(Router)` // Redirections for breaking changes in URLs const redirects = [ - ["/settings/workspace/:teamId", "/settings/workspaces/:teamId"], - ["/settings/workspace/:teamId/projects", "/settings/workspaces/:teamId/projects"], - ["/settings/workspace/:teamId/asset", "/settings/workspaces/:teamId/asset"], + ["/settings/workspace/:workspaceId", "/settings/workspaces/:workspaceId"], + ["/settings/workspace/:workspaceId/projects", "/settings/workspaces/:workspaceId/projects"], + ["/settings/workspace/:workspaceId/asset", "/settings/workspaces/:workspaceId/asset"], ["/settings/project/:projectId", "/settings/projects/:projectId"], ["/settings/project/:projectId/public", "/settings/projects/:projectId/public"], ["/settings/project/:projectId/dataset", "/settings/projects/:projectId/dataset"], diff --git a/src/components/molecules/Common/AssetModal/AssetContainer/index.tsx b/src/components/molecules/Common/AssetModal/AssetContainer/index.tsx index 3eb4aaa2d..ce7d05dce 100644 --- a/src/components/molecules/Common/AssetModal/AssetContainer/index.tsx +++ b/src/components/molecules/Common/AssetModal/AssetContainer/index.tsx @@ -30,7 +30,7 @@ export type Asset = AssetType; export type AssetSortType = SortType; export type Props = { - teamId?: string; + workspaceId?: string; initialAssetUrl?: string | null; allowDeletion?: boolean; className?: string; diff --git a/src/components/molecules/Common/AssetModal/index.tsx b/src/components/molecules/Common/AssetModal/index.tsx index ac44b94e0..d48cad750 100644 --- a/src/components/molecules/Common/AssetModal/index.tsx +++ b/src/components/molecules/Common/AssetModal/index.tsx @@ -22,7 +22,7 @@ export type AssetSortType = SortType; export type Props = { className?: string; - teamId?: string; + workspaceId?: string; initialAssetUrl?: string | null; videoOnly?: boolean; isOpen?: boolean; @@ -34,7 +34,7 @@ export type Props = { type Tabs = "assets" | "url"; const AssetModal: React.FC = ({ - teamId, + workspaceId, initialAssetUrl, videoOnly, isOpen, @@ -119,7 +119,7 @@ const AssetModal: React.FC = ({ }> {selectedTab === "assets" && AssetContainer && ( = ({ currentProject, teamId }) => { +const ProjectMenu: React.FC = ({ currentProject, workspaceId }) => { const documentationUrl = window.REEARTH_CONFIG?.documentationUrl; const t = useT(); const theme = useTheme(); @@ -56,7 +56,7 @@ const ProjectMenu: React.FC = ({ currentProject, teamId }) => { diff --git a/src/components/molecules/EarthEditor/Header/index.tsx b/src/components/molecules/EarthEditor/Header/index.tsx index eb6db3ab5..4f827a9ca 100644 --- a/src/components/molecules/EarthEditor/Header/index.tsx +++ b/src/components/molecules/EarthEditor/Header/index.tsx @@ -52,7 +52,9 @@ const Header: React.FC = ({ return currentProjectStatus === "unpublished" ? true : false; }, [currentProjectStatus]); - const center = currentProject && ; + const center = currentProject && ( + + ); const right = ( diff --git a/src/components/molecules/Settings/Account/PasswordModal/index.tsx b/src/components/molecules/Settings/Account/PasswordModal/index.tsx index c1e63e673..f2a7a17cd 100644 --- a/src/components/molecules/Settings/Account/PasswordModal/index.tsx +++ b/src/components/molecules/Settings/Account/PasswordModal/index.tsx @@ -24,7 +24,7 @@ type Props = { name: string; isArchived: boolean; }; - team?: { + workspace?: { id: string; name: string; }; diff --git a/src/components/molecules/Settings/Navigation/index.tsx b/src/components/molecules/Settings/Navigation/index.tsx index 52c733dbd..78b1d6eb1 100644 --- a/src/components/molecules/Settings/Navigation/index.tsx +++ b/src/components/molecules/Settings/Navigation/index.tsx @@ -9,7 +9,7 @@ import { styled } from "@reearth/theme"; import fonts from "@reearth/theme/fonts"; import { metricsSizes } from "@reearth/theme/metrics"; -type Team = { +type Workspace = { id?: string; name?: string; }; @@ -21,11 +21,11 @@ type Project = { }; type Props = { - team?: Team; + workspace?: Workspace; project?: Project; }; -const Navigation: React.FC = ({ team, project }) => { +const Navigation: React.FC = ({ workspace, project }) => { const t = useT(); return ( @@ -41,22 +41,24 @@ const Navigation: React.FC = ({ team, project }) => { - {team && ( + {workspace && ( + to={`/settings/workspaces/${workspace.id}`} + key={workspace.id} + name={workspace.name as string}> )} - + {project && !project.isArchived && ( void; deleteProject?: () => void; @@ -30,7 +30,7 @@ type Props = { const DangerModal: React.FC = ({ actionType, project, - teamId, + workspaceId, isVisible, archiveProject, deleteProject, @@ -46,8 +46,8 @@ const DangerModal: React.FC = ({ if (actionType === "delete") deleteProject?.(); if (actionType === "archive") archiveProject?.(true); if (actionType === "unarchive") archiveProject?.(false); - navigate(`/settings/workspaces/${teamId}/projects`); - }, [navigate, archiveProject, deleteProject, actionType, teamId, project, disabled]); + navigate(`/settings/workspaces/${workspaceId}/projects`); + }, [project, disabled, actionType, deleteProject, archiveProject, navigate, workspaceId]); useEffect(() => { if (text == project?.name) { diff --git a/src/components/molecules/Settings/Project/DangerSection/index.tsx b/src/components/molecules/Settings/Project/DangerSection/index.tsx index d153af512..efca3a394 100644 --- a/src/components/molecules/Settings/Project/DangerSection/index.tsx +++ b/src/components/molecules/Settings/Project/DangerSection/index.tsx @@ -15,12 +15,17 @@ export type Props = { name: string; isArchived: boolean; }; - teamId?: string; + workspaceId?: string; archiveProject?: (archived: boolean) => void; deleteProject?: () => void; }; -const DangerSection: React.FC = ({ project, teamId, archiveProject, deleteProject }) => { +const DangerSection: React.FC = ({ + project, + workspaceId, + archiveProject, + deleteProject, +}) => { const [isOpen, setIsOpen] = useState(false); const [actionType, setActionType] = useState("archive"); @@ -83,7 +88,7 @@ const DangerSection: React.FC = ({ project, teamId, archiveProject, delet = ({ } center={ currentProject && ( - + ) } /> @@ -62,7 +62,7 @@ const SettingPage: React.FC = ({ !loading && hasMoreItems && onScrollToBottom(e, onScroll); }}> - + @@ -74,7 +74,7 @@ const SettingPage: React.FC = ({ /> {isOpen && ( - + )} diff --git a/src/components/molecules/Settings/Workspace/AddMemberModal/index.tsx b/src/components/molecules/Settings/Workspace/AddMemberModal/index.tsx index 69e62f61a..f02c1d850 100644 --- a/src/components/molecules/Settings/Workspace/AddMemberModal/index.tsx +++ b/src/components/molecules/Settings/Workspace/AddMemberModal/index.tsx @@ -20,7 +20,7 @@ export type Props = { searchedUser?: User; searchUser: (nameOrEmail: string) => void; changeSearchedUser: (user: User | undefined) => void; - addMembersToTeam?: (userIds: string[]) => Promise; + addMembersToWorkspace?: (userIds: string[]) => Promise; }; const AddMemberModal: React.FC = ({ @@ -29,7 +29,7 @@ const AddMemberModal: React.FC = ({ searchedUser, searchUser, changeSearchedUser, - addMembersToTeam, + addMembersToWorkspace, }) => { const t = useT(); const theme = useTheme(); @@ -69,12 +69,12 @@ const AddMemberModal: React.FC = ({ }, [setUsers, setNameOrEmail, changeSearchedUser, close]); const add = useCallback(async () => { - await addMembersToTeam?.(users.map(({ id }) => id)); + await addMembersToWorkspace?.(users.map(({ id }) => id)); changeSearchedUser(undefined); setUsers([]); setNameOrEmail(""); close(); - }, [addMembersToTeam, users, setUsers, setNameOrEmail, changeSearchedUser, close]); + }, [addMembersToWorkspace, users, changeSearchedUser, close]); return ( void; + deleteWorkspace?: () => void; onClose?: () => void; }; -const DangerModal: React.FC = ({ team, isVisible, deleteTeam, onClose }) => { +const DangerModal: React.FC = ({ workspace, isVisible, deleteWorkspace, onClose }) => { const [disabled, setDisabled] = useState(true); const [text, setText] = useState(); const navigate = useNavigate(); const t = useT(); const handleDeletion = useCallback(() => { - if (team && deleteTeam && !disabled) { - deleteTeam(); + if (workspace && deleteWorkspace && !disabled) { + deleteWorkspace(); navigate(`/settings/workspaces`); } - }, [navigate, team, deleteTeam, disabled]); + }, [navigate, workspace, deleteWorkspace, disabled]); useEffect(() => { - setDisabled(text !== team?.name); - }, [text, team]); + setDisabled(text !== workspace?.name); + }, [text, workspace]); const theme = useTheme(); return ( - {team?.name} + {workspace?.name} {t(`This action cannot be undone.`)} diff --git a/src/components/molecules/Settings/Workspace/DangerSection/index.tsx b/src/components/molecules/Settings/Workspace/DangerSection/index.tsx index 209a2cf44..6801520a3 100644 --- a/src/components/molecules/Settings/Workspace/DangerSection/index.tsx +++ b/src/components/molecules/Settings/Workspace/DangerSection/index.tsx @@ -9,14 +9,14 @@ import { styled } from "@reearth/theme"; import Modal from "./Modal"; export type Props = { - team?: { + workspace?: { id: string; name: string; }; - deleteTeam?: () => void; + deleteWorkspace?: () => void; }; -const DangerSection: React.FC = ({ team, deleteTeam }) => { +const DangerSection: React.FC = ({ workspace, deleteWorkspace }) => { const [isOpen, setIsOpen] = useState(false); const t = useT(); @@ -37,9 +37,9 @@ const DangerSection: React.FC = ({ team, deleteTeam }) => { /> setIsOpen(false)} /> diff --git a/src/components/molecules/Settings/Workspace/MembersSection/index.tsx b/src/components/molecules/Settings/Workspace/MembersSection/index.tsx index 3dc8d2edc..6520fc57b 100644 --- a/src/components/molecules/Settings/Workspace/MembersSection/index.tsx +++ b/src/components/molecules/Settings/Workspace/MembersSection/index.tsx @@ -18,7 +18,7 @@ export type Me = { export type User = UserType; -type TeamMember = { +type WorkspaceMember = { user?: User; userId: string; role: Role; @@ -27,14 +27,14 @@ type TeamMember = { type Props = { me?: Me; owner?: boolean; - members?: TeamMember[]; + members?: WorkspaceMember[]; searchedUser?: User; personal?: boolean; searchUser: (nameOrEmail: string) => void; changeSearchedUser: (user: User | undefined) => void; - addMembersToTeam: (userIds: string[]) => Promise; - updateMemberOfTeam: (userId: string, role: Role) => void; - removeMemberFromTeam: (userId: string) => void; + addMembersToWorkspace: (userIds: string[]) => Promise; + updateMemberOfWorkspace: (userId: string, role: Role) => void; + removeMemberFromWorkspace: (userId: string) => void; }; const MembersSection: React.FC = ({ @@ -45,9 +45,9 @@ const MembersSection: React.FC = ({ personal, searchUser, changeSearchedUser, - addMembersToTeam, - updateMemberOfTeam, - removeMemberFromTeam, + addMembersToWorkspace, + updateMemberOfWorkspace, + removeMemberFromWorkspace, }) => { const t = useT(); @@ -81,8 +81,8 @@ const MembersSection: React.FC = ({ role={role} owner={owner} isMyself={me?.id === user.id} - onChangeRole={role => updateMemberOfTeam(user.id, role)} - onRemove={() => removeMemberFromTeam(user.id)} + onChangeRole={role => updateMemberOfWorkspace(user.id, role)} + onRemove={() => removeMemberFromWorkspace(user.id)} /> ) : null, )} @@ -94,7 +94,7 @@ const MembersSection: React.FC = ({ searchedUser={searchedUser} searchUser={searchUser} changeSearchedUser={changeSearchedUser} - addMembersToTeam={addMembersToTeam} + addMembersToWorkspace={addMembersToWorkspace} /> )} diff --git a/src/components/molecules/Settings/Workspace/ProfileSection/index.tsx b/src/components/molecules/Settings/Workspace/ProfileSection/index.tsx index aaa1c3437..923c7081c 100644 --- a/src/components/molecules/Settings/Workspace/ProfileSection/index.tsx +++ b/src/components/molecules/Settings/Workspace/ProfileSection/index.tsx @@ -7,20 +7,20 @@ import { useT } from "@reearth/i18n"; import { styled } from "@reearth/theme"; export type Props = { - currentTeam?: { + currentWorkspace?: { id: string; name: string; // description: string; personal?: boolean; }; - updateTeamName?: (name?: string) => void; + updateWorkspaceName?: (name?: string) => void; updateProjectDescription?: (description: string) => void; owner?: boolean; }; const ProfileSection: React.FC = ({ - currentTeam, - updateTeamName, + currentWorkspace, + updateWorkspaceName, // updateProjectDescription, owner, }) => { @@ -29,13 +29,13 @@ const ProfileSection: React.FC = ({ return (
- {currentTeam?.personal || owner === false ? ( - + {currentWorkspace?.personal || owner === false ? ( + ) : ( // {/* void; + onSelect?: (t: Workspace) => void; }; -const WorkspaceCell: React.FC = ({ className, team, personal, onSelect }) => { +const WorkspaceCell: React.FC = ({ className, workspace, personal, onSelect }) => { const t = useT(); - const teamMembers = team.members; + const workspaceMembers = workspace.members; const theme = useTheme(); return ( @@ -28,9 +28,9 @@ const WorkspaceCell: React.FC = ({ className, team, personal, onSelect }) className={className} direction="column" justify="space-between" - onClick={() => onSelect?.(team)}> + onClick={() => onSelect?.(workspace)}> - {team.name ? team.name : t("No Title Workspace")} + {workspace.name ? workspace.name : t("No Title Workspace")} {personal ? ( @@ -41,7 +41,7 @@ const WorkspaceCell: React.FC = ({ className, team, personal, onSelect }) ) : ( - {teamMembers.map(member => ( + {workspaceMembers.map(member => ( ))} diff --git a/src/components/molecules/Settings/WorkspaceList/WorkspaceList/index.tsx b/src/components/molecules/Settings/WorkspaceList/WorkspaceList/index.tsx index e825e48ec..648c4ef91 100644 --- a/src/components/molecules/Settings/WorkspaceList/WorkspaceList/index.tsx +++ b/src/components/molecules/Settings/WorkspaceList/WorkspaceList/index.tsx @@ -3,27 +3,27 @@ import React, { useMemo } from "react"; import Button from "@reearth/components/atoms/Button"; import Text from "@reearth/components/atoms/Text"; import WorkspaceCell from "@reearth/components/molecules/Settings/WorkspaceList/WorkspaceCell"; -import { Team as TeamType } from "@reearth/gql/graphql-client-api"; +import { Team as WorkspaceType } from "@reearth/gql/graphql-client-api"; import { useT } from "@reearth/i18n"; import { styled, useTheme } from "@reearth/theme"; -export type Team = TeamType; +export type Workspace = WorkspaceType; export type Props = { title?: string; - teams?: Team[]; - currentTeam?: { + workspaces?: Workspace[]; + currentWorkspace?: { id: string; name: string; }; filterQuery?: string; - onWorkspaceSelect?: (team: Team) => void; + onWorkspaceSelect?: (workspace: Workspace) => void; onCreationButtonClick?: () => void; }; const WorkspaceList: React.FC = ({ - teams, - currentTeam, + workspaces, + currentWorkspace, title, filterQuery, onWorkspaceSelect, @@ -33,9 +33,9 @@ const WorkspaceList: React.FC = ({ const filteredWorkspaces = useMemo( () => filterQuery - ? teams?.filter(t => t.name.toLowerCase().indexOf(filterQuery.toLowerCase()) !== -1) - : teams, - [filterQuery, teams], + ? workspaces?.filter(t => t.name.toLowerCase().indexOf(filterQuery.toLowerCase()) !== -1) + : workspaces, + [filterQuery, workspaces], ); const theme = useTheme(); @@ -53,20 +53,20 @@ const WorkspaceList: React.FC = ({ /> - {filteredWorkspaces?.map(team => { - return team.id === currentTeam?.id ? ( + {filteredWorkspaces?.map(workspace => { + return workspace.id === currentWorkspace?.id ? ( ) : ( ); })} diff --git a/src/components/organisms/Common/AssetContainer/hooks.ts b/src/components/organisms/Common/AssetContainer/hooks.ts index 21d4247cb..caf864fc6 100644 --- a/src/components/organisms/Common/AssetContainer/hooks.ts +++ b/src/components/organisms/Common/AssetContainer/hooks.ts @@ -52,24 +52,25 @@ function pagination( }; } -export default (teamId?: string, initialAssetUrl?: string | null, allowDeletion?: boolean) => { +export default (workspaceId?: string, initialAssetUrl?: string | null, allowDeletion?: boolean) => { const t = useT(); const [, setNotification] = useNotification(); const [sort, setSort] = useState<{ type?: AssetSortType; reverse?: boolean }>(); const [searchTerm, setSearchTerm] = useState(); const gqlCache = useApolloClient().cache; - + console.log("inside assets"); + console.log(workspaceId, pagination(sort), toGQLEnum(sort?.type), searchTerm); const { data, refetch, loading, fetchMore, networkStatus } = useGetAssetsQuery({ variables: { - teamId: teamId ?? "", + teamId: workspaceId ?? "", pagination: pagination(sort), sort: toGQLEnum(sort?.type), keyword: searchTerm, }, notifyOnNetworkStatusChange: true, - skip: !teamId, + skip: !workspaceId, }); - + console.log("data", data); const hasMoreAssets = data?.assets.pageInfo?.hasNextPage || data?.assets.pageInfo?.hasPreviousPage; @@ -93,11 +94,11 @@ export default (teamId?: string, initialAssetUrl?: string | null, allowDeletion? const createAssets = useCallback( (files: FileList) => (async () => { - if (!teamId) return; + if (!workspaceId) return; const results = await Promise.all( Array.from(files).map(async file => { - const result = await createAssetMutation({ variables: { teamId, file } }); + const result = await createAssetMutation({ variables: { teamId: workspaceId, file } }); if (result.errors || !result.data?.createAsset) { setNotification({ type: "error", @@ -114,14 +115,14 @@ export default (teamId?: string, initialAssetUrl?: string | null, allowDeletion? await refetch(); } })(), - [createAssetMutation, setNotification, refetch, teamId, t], + [createAssetMutation, setNotification, refetch, workspaceId, t], ); const [removeAssetMutation] = useRemoveAssetMutation(); const removeAssets = useCallback( (assetIds: string[]) => (async () => { - if (!teamId) return; + if (!workspaceId) return; const results = await Promise.all( assetIds.map(async assetId => { const result = await removeAssetMutation({ @@ -144,7 +145,7 @@ export default (teamId?: string, initialAssetUrl?: string | null, allowDeletion? selectAsset([]); } })(), - [removeAssetMutation, teamId, setNotification, t], + [removeAssetMutation, workspaceId, setNotification, t], ); const handleSortChange = useCallback( diff --git a/src/components/organisms/Common/AssetContainer/index.tsx b/src/components/organisms/Common/AssetContainer/index.tsx index 9f93a4392..df22ec139 100644 --- a/src/components/organisms/Common/AssetContainer/index.tsx +++ b/src/components/organisms/Common/AssetContainer/index.tsx @@ -12,7 +12,7 @@ export type Asset = AssetType; export type Props = AssetContainerProps; const AssetContainer: React.FC = ({ - teamId, + workspaceId, initialAssetUrl, onAssetUrlSelect, videoOnly, @@ -36,7 +36,7 @@ const AssetContainer: React.FC = ({ handleSortChange, handleSearchTerm, removeAssets, - } = useHooks(teamId, initialAssetUrl, allowDeletion); + } = useHooks(workspaceId, initialAssetUrl, allowDeletion); useEffect(() => { onURLShow?.(assets); diff --git a/src/components/organisms/Common/AssetModal/index.tsx b/src/components/organisms/Common/AssetModal/index.tsx index 3888d6d4c..ee128d001 100644 --- a/src/components/organisms/Common/AssetModal/index.tsx +++ b/src/components/organisms/Common/AssetModal/index.tsx @@ -9,7 +9,7 @@ import AssetContainer from "../AssetContainer"; export type Props = PropsType; const AssetModal: React.FC = ({ - teamId, + workspaceId, initialAssetUrl, isOpen, videoOnly, @@ -18,7 +18,7 @@ const AssetModal: React.FC = ({ }) => { return ( = () => { } = useHooks(); return ( - + {me && ( diff --git a/src/components/organisms/Settings/Project/Dataset/index.tsx b/src/components/organisms/Settings/Project/Dataset/index.tsx index ffeae8609..1ba6c7600 100644 --- a/src/components/organisms/Settings/Project/Dataset/index.tsx +++ b/src/components/organisms/Settings/Project/Dataset/index.tsx @@ -27,7 +27,7 @@ const Dataset: React.FC = ({ projectId }) => { return ( = ({ projectId }) => { } = useHooks({ projectId }); return ( - + {!project?.isArchived ? ( <> @@ -60,7 +60,7 @@ const Public: React.FC = ({ projectId }) => { toggleAssetModal={toggleAssetModal} assetModal={ = ({ projectId }) => { } = useHooks({ projectId }); return ( - + {!project?.isArchived ? ( = ({ projectId }) => { toggleAssetModal={toggleAssetModal} assetModal={ = ({ projectId }) => { )} diff --git a/src/components/organisms/Settings/ProjectList/hooks.ts b/src/components/organisms/Settings/ProjectList/hooks.ts index 93fd1cb5a..8140fccc0 100644 --- a/src/components/organisms/Settings/ProjectList/hooks.ts +++ b/src/components/organisms/Settings/ProjectList/hooks.ts @@ -26,7 +26,7 @@ export type ProjectNodes = NonNullable { +export default (workspaceId: string) => { const [, setNotification] = useNotification(); const [currentWorkspace, setWorkspace] = useWorkspace(); const [, setProject] = useProject(); @@ -43,10 +43,12 @@ export default (teamId: string) => { }); const [createScene] = useCreateSceneMutation(); - if (currentWorkspace && currentWorkspace.id !== teamId) { - teamId = currentWorkspace?.id; + if (currentWorkspace && currentWorkspace.id !== workspaceId) { + workspaceId = currentWorkspace?.id; } - const team = teamId ? data?.me?.teams.find(team => team.id === teamId) : data?.me?.myTeam; + const workspace = workspaceId + ? data?.me?.teams.find(workspace => workspace.id === workspaceId) + : data?.me?.myTeam; const { data: projectData, @@ -54,16 +56,16 @@ export default (teamId: string) => { fetchMore, networkStatus, } = useGetProjectsQuery({ - variables: { teamId: teamId ?? "", last: projectPerPage }, - skip: !teamId, + variables: { teamId: workspaceId ?? "", last: projectPerPage }, + skip: !workspaceId, notifyOnNetworkStatusChange: true, }); useEffect(() => { - if (team?.id && !currentWorkspace?.id) { - setWorkspace(team); + if (workspace?.id && !currentWorkspace?.id) { + setWorkspace(workspace); } - }, [currentWorkspace, team, setWorkspace]); + }, [currentWorkspace, workspace, setWorkspace]); const projectNodes = projectData?.projects.edges.map(e => e.node) as ProjectNodes; @@ -115,10 +117,10 @@ export default (teamId: string) => { // Submit Form const createProject = useCallback( async (data: { name: string; description: string; imageUrl: string | null }) => { - if (!teamId) return; + if (!workspaceId) return; const project = await createNewProject({ variables: { - teamId, + teamId: workspaceId, visualizer: Visualizer.Cesium, name: data.name, description: data.description, @@ -151,7 +153,7 @@ export default (teamId: string) => { setModalShown(false); refetch(); }, - [createNewProject, createScene, t, refetch, setNotification, teamId], + [createNewProject, createScene, t, refetch, setNotification, workspaceId], ); const selectProject = useCallback( @@ -187,7 +189,7 @@ export default (teamId: string) => { totalProjects, loadingProjects: loadingProjects ?? isRefetchingProjects, hasMoreProjects, - teamId, + workspaceId, loading, modalShown, openModal, diff --git a/src/components/organisms/Settings/ProjectList/index.tsx b/src/components/organisms/Settings/ProjectList/index.tsx index e20be9d5b..bdc03f414 100644 --- a/src/components/organisms/Settings/ProjectList/index.tsx +++ b/src/components/organisms/Settings/ProjectList/index.tsx @@ -13,10 +13,10 @@ import { useT } from "@reearth/i18n"; import useHooks from "./hooks"; type Props = { - teamId: string; + workspaceId: string; }; -const ProjectList: React.FC = ({ teamId }) => { +const ProjectList: React.FC = ({ workspaceId }) => { const t = useT(); const { loading, @@ -34,7 +34,7 @@ const ProjectList: React.FC = ({ teamId }) => { toggleAssetModal, onAssetSelect, handleGetMoreProjects, - } = useHooks(teamId); + } = useHooks(workspaceId); type Tab = "Working"; const headers = { @@ -43,7 +43,7 @@ const ProjectList: React.FC = ({ teamId }) => { return ( @@ -71,7 +71,7 @@ const ProjectList: React.FC = ({ teamId }) => { selectedAsset={selectedAsset} assetModal={ { skip: !projectId, }); const sceneId = sceneData?.scene?.id; - const teamId = params.teamId ?? sceneData?.scene?.teamId; + const workspaceId = params.workspaceId ?? sceneData?.scene?.teamId; const { data: teamsData } = useGetTeamsQuery(); const user: User = { name: teamsData?.me?.name ?? "", }; - const teams = teamsData?.me?.teams; + const workspaces = teamsData?.me?.teams; useEffect(() => { if (!currentWorkspace) { - setWorkspace(teamId ? teams?.find(t => t.id === teamId) : teamsData?.me?.myTeam ?? undefined); + setWorkspace( + workspaceId + ? workspaces?.find(t => t.id === workspaceId) + : teamsData?.me?.myTeam ?? undefined, + ); } // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentWorkspace, setWorkspace, teams, teamsData?.me]); + }, [currentWorkspace, setWorkspace, workspaces, teamsData?.me]); const { data } = useGetProjectWithSceneIdQuery({ variables: { projectId: projectId ?? "" }, @@ -81,18 +85,18 @@ export default (params: Params) => { }, [project, setProject]); const handleWorkspaceChange = useCallback( - (teamId: string) => { - const team = teams?.find(team => team.id === teamId); + (workspaceId: string) => { + const workspace = workspaces?.find(workspace => workspace.id === workspaceId); - if (team) { - setWorkspace(team); + if (workspace) { + setWorkspace(workspace); if (params.projectId) { navigate("/settings/account"); } } }, - [teams, setWorkspace, params.projectId, navigate], + [workspaces, setWorkspace, params.projectId, navigate], ); const [createTeamMutation] = useCreateTeamMutation(); @@ -102,9 +106,9 @@ export default (params: Params) => { variables: { name: data.name }, refetchQueries: ["GetTeams"], }); - const team = results.data?.createTeam?.team; + const workspace = results.data?.createTeam?.team; if (results) { - setWorkspace(team); + setWorkspace(workspace); } }, [createTeamMutation, setWorkspace], @@ -112,7 +116,7 @@ export default (params: Params) => { return { user, - teams, + workspaces, currentWorkspace, currentProject, sceneId, diff --git a/src/components/organisms/Settings/SettingPage/index.tsx b/src/components/organisms/Settings/SettingPage/index.tsx index 5d501fe8a..da46a9eb5 100644 --- a/src/components/organisms/Settings/SettingPage/index.tsx +++ b/src/components/organisms/Settings/SettingPage/index.tsx @@ -6,7 +6,7 @@ import MoleculesSettingPage from "@reearth/components/molecules/Settings/Setting import useHooks from "./hooks"; type Props = { - teamId?: string; + workspaceId?: string; projectId?: string; children?: ReactNode; loading?: boolean; @@ -15,7 +15,7 @@ type Props = { }; const SettingPage: React.FC = ({ - teamId, + workspaceId, projectId, children, loading, @@ -26,7 +26,7 @@ const SettingPage: React.FC = ({ const { user, - teams = [], + workspaces = [], currentWorkspace, currentProject, sceneId, @@ -36,14 +36,14 @@ const SettingPage: React.FC = ({ openModal, handleModalClose, } = useHooks({ - teamId, + workspaceId, projectId, }); return ( { @@ -27,7 +27,7 @@ export default (params: Params) => { } = assetHooks(currentWorkspace?.id); useEffect(() => { - if (params.teamId && currentWorkspace?.id && params.teamId !== currentWorkspace.id) { + if (params.workspaceId && currentWorkspace?.id && params.workspaceId !== currentWorkspace.id) { navigate(`/settings/workspaces/${currentWorkspace?.id}/asset`); } }, [params, currentWorkspace, navigate]); diff --git a/src/components/organisms/Settings/Workspace/Asset/index.tsx b/src/components/organisms/Settings/Workspace/Asset/index.tsx index 080cc4155..48f162c6b 100644 --- a/src/components/organisms/Settings/Workspace/Asset/index.tsx +++ b/src/components/organisms/Settings/Workspace/Asset/index.tsx @@ -8,17 +8,17 @@ import { useT } from "@reearth/i18n"; import useHooks from "./hooks"; type Props = { - teamId: string; + workspaceId: string; }; -const Asset: React.FC = ({ teamId }: Props) => { +const Asset: React.FC = ({ workspaceId }: Props) => { const t = useT(); - const { currentProject, currentWorkspace } = useHooks({ teamId }); + const { currentProject, currentWorkspace } = useHooks({ workspaceId }); return ( - + - + ); }; diff --git a/src/components/organisms/Settings/Workspace/hooks.ts b/src/components/organisms/Settings/Workspace/hooks.ts index e4c1b0bba..766c339b0 100644 --- a/src/components/organisms/Settings/Workspace/hooks.ts +++ b/src/components/organisms/Settings/Workspace/hooks.ts @@ -18,7 +18,7 @@ import { useT } from "@reearth/i18n"; import { useWorkspace, useProject, useNotification } from "@reearth/state"; type Params = { - teamId: string; + workspaceId: string; }; export default (params: Params) => { @@ -39,7 +39,7 @@ export default (params: Params) => { const { data, loading, refetch } = useGetTeamsQuery(); const me = { id: data?.me?.id, myTeam: data?.me?.myTeam.id }; - const teams = data?.me?.teams as Team[]; + const workspaces = data?.me?.teams as Team[]; const handleModalClose = useCallback( (r?: boolean) => { @@ -52,12 +52,12 @@ export default (params: Params) => { ); useEffect(() => { - if (params.teamId && currentWorkspace?.id && params.teamId !== currentWorkspace.id) { + if (params.workspaceId && currentWorkspace?.id && params.workspaceId !== currentWorkspace.id) { navigate(`/settings/workspaces/${currentWorkspace?.id}`); } }, [params, currentWorkspace, navigate]); - const teamId = currentWorkspace?.id; + const workspaceId = currentWorkspace?.id; const [useGetUserBySearchQuery, { data: searchUserData }] = useGetUserBySearchLazyQuery(); @@ -71,20 +71,20 @@ export default (params: Params) => { ); const [createTeamMutation] = useCreateTeamMutation(); - const createTeam = useCallback( + const createWorkspace = useCallback( async (data: { name: string }) => { const results = await createTeamMutation({ variables: { name: data.name }, refetchQueries: ["GetTeams"], }); - const team = results.data?.createTeam?.team; + const workspace = results.data?.createTeam?.team; if (results.errors || !results.data?.createTeam) { setNotification({ type: "error", text: t("Failed to create workspace."), }); } else { - setWorkspace(team); + setWorkspace(workspace); setNotification({ type: "success", text: t("Sucessfully created a workspace!"), @@ -99,8 +99,8 @@ export default (params: Params) => { const updateName = useCallback( async (name?: string) => { - if (!teamId || !name) return; - const results = await updateTeamMutation({ variables: { teamId, name } }); + if (!workspaceId || !name) return; + const results = await updateTeamMutation({ variables: { teamId: workspaceId, name } }); if (results.errors) { setNotification({ type: "error", @@ -114,15 +114,15 @@ export default (params: Params) => { }); } }, - [teamId, updateTeamMutation, t, setNotification, setWorkspace], + [workspaceId, updateTeamMutation, t, setNotification, setWorkspace], ); const [deleteTeamMutation] = useDeleteTeamMutation({ refetchQueries: ["GetTeams"], }); - const deleteTeam = useCallback(async () => { - if (!teamId) return; - const result = await deleteTeamMutation({ variables: { teamId } }); + const deleteWorkspace = useCallback(async () => { + if (!workspaceId) return; + const result = await deleteTeamMutation({ variables: { teamId: workspaceId } }); if (result.errors || !result.data?.deleteTeam) { setNotification({ type: "error", @@ -133,30 +133,30 @@ export default (params: Params) => { type: "info", text: t("Workspace was successfully deleted."), }); - setWorkspace(teams[0]); + setWorkspace(workspaces[0]); } - }, [teamId, deleteTeamMutation, setNotification, t, setWorkspace, teams]); + }, [workspaceId, deleteTeamMutation, setNotification, t, setWorkspace, workspaces]); const [addMemberToTeamMutation] = useAddMemberToTeamMutation(); - const addMembersToTeam = useCallback( + const addMembersToWorkspace = useCallback( async (userIds: string[]) => { const results = await Promise.all( userIds.map(async userId => { - if (!teamId) return; + if (!workspaceId) return; const result = await addMemberToTeamMutation({ - variables: { userId, teamId, role: Role.Reader }, + variables: { userId, teamId: workspaceId, role: Role.Reader }, refetchQueries: ["GetTeams"], }); - const team = result.data?.addMemberToTeam?.team; - if (result.errors || !team) { + const workspace = result.data?.addMemberToTeam?.team; + if (result.errors || !workspace) { setNotification({ type: "error", text: t("Failed to add one or more members."), }); return; } - setWorkspace(team); + setWorkspace(workspace); }), ); if (results) { @@ -166,17 +166,17 @@ export default (params: Params) => { }); } }, - [teamId, addMemberToTeamMutation, setWorkspace, setNotification, t], + [workspaceId, addMemberToTeamMutation, setWorkspace, setNotification, t], ); const [updateMemberOfTeamMutation] = useUpdateMemberOfTeamMutation(); - const updateMemberOfTeam = useCallback( + const updateMemberOfWorkspace = useCallback( async (userId: string, role: RoleUnion) => { - if (teamId) { + if (workspaceId) { const results = await updateMemberOfTeamMutation({ variables: { - teamId, + teamId: workspaceId, userId, role: { READER: Role.Reader, @@ -185,46 +185,46 @@ export default (params: Params) => { }[role], }, }); - const team = results.data?.updateMemberOfTeam?.team; - if (team) { - setWorkspace(team); + const workspace = results.data?.updateMemberOfTeam?.team; + if (workspace) { + setWorkspace(workspace); } } }, - [teamId, setWorkspace, updateMemberOfTeamMutation], + [workspaceId, setWorkspace, updateMemberOfTeamMutation], ); const [removeMemberFromTeamMutation] = useRemoveMemberFromTeamMutation(); - const removeMemberFromTeam = useCallback( + const removeMemberFromWorkspace = useCallback( async (userId: string) => { - if (!teamId) return; + if (!workspaceId) return; const result = await removeMemberFromTeamMutation({ - variables: { teamId, userId }, + variables: { teamId: workspaceId, userId }, refetchQueries: ["GetTeams"], }); - const team = result.data?.removeMemberFromTeam?.team; - if (result.errors || !team) { + const workspace = result.data?.removeMemberFromTeam?.team; + if (result.errors || !workspace) { setNotification({ type: "error", text: t("Failed to delete member from the workspace."), }); return; } - setWorkspace(team); + setWorkspace(workspace); setNotification({ type: "success", text: t("Successfully removed member from the workspace."), }); }, - [teamId, removeMemberFromTeamMutation, setWorkspace, t, setNotification], + [workspaceId, removeMemberFromTeamMutation, setWorkspace, t, setNotification], ); const selectWorkspace = useCallback( - (team: Team) => { - if (team.id) { - setWorkspace(team); - navigate(`/settings/workspaces/${team.id}`); + (workspace: Team) => { + if (workspace.id) { + setWorkspace(workspace); + navigate(`/settings/workspaces/${workspace.id}`); } }, [navigate, setWorkspace], @@ -232,18 +232,18 @@ export default (params: Params) => { return { me, - teams, + workspaces, currentWorkspace, currentProject, searchedUser, changeSearchedUser, - createTeam, + createWorkspace, updateName, - deleteTeam, + deleteWorkspace, searchUser, - addMembersToTeam, - updateMemberOfTeam, - removeMemberFromTeam, + addMembersToWorkspace, + updateMemberOfWorkspace, + removeMemberFromWorkspace, selectWorkspace, openModal, modalShown, diff --git a/src/components/organisms/Settings/Workspace/index.tsx b/src/components/organisms/Settings/Workspace/index.tsx index 71dc74feb..e078877e1 100644 --- a/src/components/organisms/Settings/Workspace/index.tsx +++ b/src/components/organisms/Settings/Workspace/index.tsx @@ -9,23 +9,23 @@ import SettingPage from "@reearth/components/organisms/Settings/SettingPage"; import useHooks from "./hooks"; type Props = { - teamId: string; + workspaceId: string; }; -const WorkspaceSettings: React.FC = ({ teamId }) => { +const WorkspaceSettings: React.FC = ({ workspaceId }) => { const { me, currentWorkspace, currentProject, searchedUser, changeSearchedUser, - deleteTeam, + deleteWorkspace, updateName, searchUser, - addMembersToTeam, - updateMemberOfTeam, - removeMemberFromTeam, - } = useHooks({ teamId }); + addMembersToWorkspace, + updateMemberOfWorkspace, + removeMemberFromWorkspace, + } = useHooks({ workspaceId }); const [owner, setOwner] = useState(false); const members = currentWorkspace?.members; @@ -46,9 +46,13 @@ const WorkspaceSettings: React.FC = ({ teamId }) => { }, [checkOwner]); return ( - + - + {!currentWorkspace?.personal && ( = ({ teamId }) => { searchedUser={searchedUser} changeSearchedUser={changeSearchedUser} searchUser={searchUser} - addMembersToTeam={addMembersToTeam} - updateMemberOfTeam={updateMemberOfTeam} - removeMemberFromTeam={removeMemberFromTeam} + addMembersToWorkspace={addMembersToWorkspace} + updateMemberOfWorkspace={updateMemberOfWorkspace} + removeMemberFromWorkspace={removeMemberFromWorkspace} /> )} - {me.myTeam !== teamId && } + {me.myTeam !== workspaceId && ( + + )} ); }; diff --git a/src/components/organisms/Settings/WorkspaceList/index.tsx b/src/components/organisms/Settings/WorkspaceList/index.tsx index a8cb2a9d7..ce18a351a 100644 --- a/src/components/organisms/Settings/WorkspaceList/index.tsx +++ b/src/components/organisms/Settings/WorkspaceList/index.tsx @@ -12,32 +12,36 @@ import useHooks from "../Workspace/hooks"; // Components type Props = { - teamId: string; + workspaceId: string; }; -const WorkspaceList: React.FC = ({ teamId }) => { +const WorkspaceList: React.FC = ({ workspaceId }) => { const t = useT(); const { - teams, + workspaces, currentWorkspace, - createTeam, + createWorkspace, selectWorkspace, openModal, modalShown, handleModalClose, loading, - } = useHooks({ teamId }); + } = useHooks({ workspaceId }); return ( - + - + {loading && } ); diff --git a/src/components/pages/Settings/ProjectList/index.tsx b/src/components/pages/Settings/ProjectList/index.tsx index defe951c9..c2b93bcfd 100644 --- a/src/components/pages/Settings/ProjectList/index.tsx +++ b/src/components/pages/Settings/ProjectList/index.tsx @@ -9,8 +9,8 @@ export interface Props { } const ProjectList: React.FC = () => { - const { teamId = "" } = useParams(); - return ; + const { workspaceId = "" } = useParams(); + return ; }; export default withAuthenticationRequired(ProjectList); diff --git a/src/components/pages/Settings/Workspace/Asset/index.tsx b/src/components/pages/Settings/Workspace/Asset/index.tsx index 653467a6a..4a209dc57 100644 --- a/src/components/pages/Settings/Workspace/Asset/index.tsx +++ b/src/components/pages/Settings/Workspace/Asset/index.tsx @@ -9,10 +9,10 @@ export type Props = { }; const AssetPage: React.FC = () => { - const { teamId = "" } = useParams(); + const { workspaceId = "" } = useParams(); return ( - + ); }; diff --git a/src/components/pages/Settings/Workspace/index.tsx b/src/components/pages/Settings/Workspace/index.tsx index ca9136b5c..46a8a5718 100644 --- a/src/components/pages/Settings/Workspace/index.tsx +++ b/src/components/pages/Settings/Workspace/index.tsx @@ -9,10 +9,10 @@ export type Props = { }; const WorkspacePage: React.FC = () => { - const { teamId = "" } = useParams(); + const { workspaceId = "" } = useParams(); return ( - + ); }; diff --git a/src/components/pages/Settings/WorkspaceList/index.tsx b/src/components/pages/Settings/WorkspaceList/index.tsx index bb2070b6c..9dad823fa 100644 --- a/src/components/pages/Settings/WorkspaceList/index.tsx +++ b/src/components/pages/Settings/WorkspaceList/index.tsx @@ -9,10 +9,10 @@ export type Props = { }; const WorkspaceList: React.FC = () => { - const { teamId = "" } = useParams(); + const { workspaceId = "" } = useParams(); return ( - + ); }; From 8c6118d52685ca04fe0de04c4b0503b3d11f420c Mon Sep 17 00:00:00 2001 From: nina992 Date: Fri, 14 Apr 2023 14:36:05 +0300 Subject: [PATCH 2/3] pr-fix1 --- src/components/organisms/Dashboard/index.tsx | 2 +- src/components/organisms/EarthEditor/PropertyPane/index.tsx | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/components/organisms/Dashboard/index.tsx b/src/components/organisms/Dashboard/index.tsx index 772623395..62c9446a9 100644 --- a/src/components/organisms/Dashboard/index.tsx +++ b/src/components/organisms/Dashboard/index.tsx @@ -67,7 +67,7 @@ const Dashboard: React.FC = ({ workspaceId }) => { toggleAssetModal={handleAssetModalToggle} assetModal={ = ({ mode }) => { } = useHooks(mode); const AssetModalComponent: ComponentType = useCallback( - ({ ...props }) => , + ({ ...props }) => , [workspaceId], ); From 97f4fc6aa1f76deb96938ed511a97a928f3751a1 Mon Sep 17 00:00:00 2001 From: nina992 Date: Tue, 18 Apr 2023 11:06:36 +0300 Subject: [PATCH 3/3] pr-fix1 --- .../molecules/Settings/WorkspaceList/WorkspaceCell/index.tsx | 2 +- src/components/organisms/Common/AssetContainer/hooks.ts | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/components/molecules/Settings/WorkspaceList/WorkspaceCell/index.tsx b/src/components/molecules/Settings/WorkspaceList/WorkspaceCell/index.tsx index 478210b70..1bdfac224 100644 --- a/src/components/molecules/Settings/WorkspaceList/WorkspaceCell/index.tsx +++ b/src/components/molecules/Settings/WorkspaceList/WorkspaceCell/index.tsx @@ -15,7 +15,7 @@ export type Props = { className?: string; workspace: Workspace; personal: boolean; - onSelect?: (t: Workspace) => void; + onSelect?: (workspace: Workspace) => void; }; const WorkspaceCell: React.FC = ({ className, workspace, personal, onSelect }) => { diff --git a/src/components/organisms/Common/AssetContainer/hooks.ts b/src/components/organisms/Common/AssetContainer/hooks.ts index caf864fc6..5573fcb58 100644 --- a/src/components/organisms/Common/AssetContainer/hooks.ts +++ b/src/components/organisms/Common/AssetContainer/hooks.ts @@ -58,8 +58,6 @@ export default (workspaceId?: string, initialAssetUrl?: string | null, allowDele const [sort, setSort] = useState<{ type?: AssetSortType; reverse?: boolean }>(); const [searchTerm, setSearchTerm] = useState(); const gqlCache = useApolloClient().cache; - console.log("inside assets"); - console.log(workspaceId, pagination(sort), toGQLEnum(sort?.type), searchTerm); const { data, refetch, loading, fetchMore, networkStatus } = useGetAssetsQuery({ variables: { teamId: workspaceId ?? "", @@ -70,7 +68,6 @@ export default (workspaceId?: string, initialAssetUrl?: string | null, allowDele notifyOnNetworkStatusChange: true, skip: !workspaceId, }); - console.log("data", data); const hasMoreAssets = data?.assets.pageInfo?.hasNextPage || data?.assets.pageInfo?.hasPreviousPage;