From b8443aaa6a0eb99dc871a52998b861ac2a125b0f Mon Sep 17 00:00:00 2001 From: Kazuma Tsuchiya Date: Tue, 19 Mar 2024 12:08:11 +0900 Subject: [PATCH 1/4] refactor: model type --- web/src/components/molecules/Accessibility/index.tsx | 5 +++-- web/src/components/molecules/Accessibility/types.ts | 7 ------- web/src/components/molecules/Model/types.ts | 4 ++-- .../components/organisms/Project/Accessibility/hooks.ts | 3 ++- 4 files changed, 7 insertions(+), 12 deletions(-) diff --git a/web/src/components/molecules/Accessibility/index.tsx b/web/src/components/molecules/Accessibility/index.tsx index 70602ce387..2520106e78 100644 --- a/web/src/components/molecules/Accessibility/index.tsx +++ b/web/src/components/molecules/Accessibility/index.tsx @@ -9,7 +9,8 @@ import Input from "@reearth-cms/components/atoms/Input"; import Select from "@reearth-cms/components/atoms/Select"; import Switch from "@reearth-cms/components/atoms/Switch"; import Table, { TableColumnsType } from "@reearth-cms/components/atoms/Table"; -import { PublicScope, Model } from "@reearth-cms/components/molecules/Accessibility/types"; +import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; +import { Model } from "@reearth-cms/components/molecules/Model/types"; import { useT } from "@reearth-cms/i18n"; type ModelDataType = { @@ -112,7 +113,7 @@ const Accessibility: React.FC = ({ - handleUpdatedModels({ id: m.id, public: publicState, key: m.key }) + handleUpdatedModels({ ...m, public: publicState }) } /> ), diff --git a/web/src/components/molecules/Accessibility/types.ts b/web/src/components/molecules/Accessibility/types.ts index 53e7b76497..edb9cbc2e7 100644 --- a/web/src/components/molecules/Accessibility/types.ts +++ b/web/src/components/molecules/Accessibility/types.ts @@ -1,8 +1 @@ export type PublicScope = "private" | "public"; // Add "limited" when functionality becomes available - -export type Model = { - id: string; - name?: string; - public: boolean; - key?: string; -}; diff --git a/web/src/components/molecules/Model/types.ts b/web/src/components/molecules/Model/types.ts index da1c2cac34..a1da0118cc 100644 --- a/web/src/components/molecules/Model/types.ts +++ b/web/src/components/molecules/Model/types.ts @@ -3,11 +3,11 @@ import { Schema, MetaDataSchema } from "@reearth-cms/components/molecules/Schema export type Model = { id: string; name: string; - description?: string; + description: string; key: string; schemaId: string; schema: Schema; - metadataSchema?: MetaDataSchema; + metadataSchema: MetaDataSchema; public: boolean; order?: number; }; diff --git a/web/src/components/organisms/Project/Accessibility/hooks.ts b/web/src/components/organisms/Project/Accessibility/hooks.ts index a27d53dc7e..d4eb9882ae 100644 --- a/web/src/components/organisms/Project/Accessibility/hooks.ts +++ b/web/src/components/organisms/Project/Accessibility/hooks.ts @@ -1,7 +1,8 @@ import { useCallback, useState, useEffect } from "react"; import Notification from "@reearth-cms/components/atoms/Notification"; -import { PublicScope, Model } from "@reearth-cms/components/molecules/Accessibility/types"; +import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; +import { Model } from "@reearth-cms/components/molecules/Model/types"; import { fromGraphQLModel } from "@reearth-cms/components/organisms/DataConverters/model"; import { useUpdateModelMutation, From 81f19aa0e3d63f42f94a20c7928de1f02567ba94 Mon Sep 17 00:00:00 2001 From: Kazuma Tsuchiya Date: Tue, 19 Mar 2024 14:45:01 +0900 Subject: [PATCH 2/4] refactor: workspace type --- .../Content/Table/DropdownRender/hooks.ts | 4 +- .../molecules/Content/Table/types.ts | 3 +- .../components/molecules/Integration/types.ts | 2 +- .../components/molecules/Workspace/types.ts | 4 +- .../components/organisms/CMSWrapper/hooks.ts | 32 ++++++++---- .../organisms/DataConverters/setting.ts | 20 +++---- .../Project/Content/ContentDetails/hooks.ts | 12 +++-- .../Project/Request/RequestDetails/hooks.ts | 5 +- .../organisms/Settings/General/hooks.ts | 5 +- .../organisms/Settings/Integration/hooks.ts | 4 +- .../organisms/Settings/Members/hooks.ts | 52 +++++++++---------- .../organisms/Workspace/Settings/hooks.ts | 6 ++- .../components/organisms/Workspace/hooks.ts | 6 ++- web/src/state/index.ts | 11 +--- 14 files changed, 92 insertions(+), 74 deletions(-) diff --git a/web/src/components/molecules/Content/Table/DropdownRender/hooks.ts b/web/src/components/molecules/Content/Table/DropdownRender/hooks.ts index 20c6444999..5cae600209 100644 --- a/web/src/components/molecules/Content/Table/DropdownRender/hooks.ts +++ b/web/src/components/molecules/Content/Table/DropdownRender/hooks.ts @@ -220,7 +220,9 @@ export default ( } else if (filter.type === "Person") { if (filter?.members?.length) { for (const member of Object.values(filter.members)) { - options.push({ value: member.user?.name, label: member.user?.name }); + if ("user" in member) { + options.push({ value: member.user?.name, label: member.user?.name }); + } } } } else if (filter.type === "Bool" || filter.type === "Checkbox") { diff --git a/web/src/components/molecules/Content/Table/types.ts b/web/src/components/molecules/Content/Table/types.ts index ec0cdf337b..b52eef5155 100644 --- a/web/src/components/molecules/Content/Table/types.ts +++ b/web/src/components/molecules/Content/Table/types.ts @@ -10,6 +10,7 @@ import { StringOperator, MultipleOperator, } from "@reearth-cms/components/molecules/View/types"; +import { Member } from "@reearth-cms/components/molecules/Workspace/types"; export type ColorType = "#BFBFBF" | "#52C41A" | "#FA8C16"; export type StateType = "DRAFT" | "PUBLIC" | "REVIEW"; @@ -26,7 +27,7 @@ export type DropdownFilterType = { title: string; type: FilterType; typeProperty: { values?: string[]; tags?: { color: string; id: string; name: string }[] }; - members: { user: { name: string } }[]; + members: Member[]; id: string; multiple: boolean; required: boolean; diff --git a/web/src/components/molecules/Integration/types.ts b/web/src/components/molecules/Integration/types.ts index 1337acd164..9cad4758b0 100644 --- a/web/src/components/molecules/Integration/types.ts +++ b/web/src/components/molecules/Integration/types.ts @@ -1,6 +1,6 @@ export type IntegrationMember = { id: string; - integration: Integration; + integration?: Integration; integrationRole: Role; invitedById: string; active: boolean; diff --git a/web/src/components/molecules/Workspace/types.ts b/web/src/components/molecules/Workspace/types.ts index 8b8f6ec065..bd55c4ffcf 100644 --- a/web/src/components/molecules/Workspace/types.ts +++ b/web/src/components/molecules/Workspace/types.ts @@ -31,8 +31,8 @@ export type MemberInput = { export type Role = "WRITER" | "READER" | "MAINTAINER" | "OWNER"; export type Workspace = { - id?: string; - name?: string; + id: string; + name: string; personal?: boolean; members?: Member[]; }; diff --git a/web/src/components/organisms/CMSWrapper/hooks.ts b/web/src/components/organisms/CMSWrapper/hooks.ts index cd70bd9c31..af9ee92a2c 100644 --- a/web/src/components/organisms/CMSWrapper/hooks.ts +++ b/web/src/components/organisms/CMSWrapper/hooks.ts @@ -4,14 +4,18 @@ import { useParams, useLocation, useNavigate } from "react-router-dom"; import { MenuInfo } from "@reearth-cms/components/atoms/Menu"; import Notification from "@reearth-cms/components/atoms/Notification"; import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; -import { Role, Workspace } from "@reearth-cms/components/molecules/Workspace/types"; -import { fromGraphQLMember } from "@reearth-cms/components/organisms/DataConverters/setting"; +import { Role } from "@reearth-cms/components/molecules/Workspace/types"; +import { + fromGraphQLMember, + fromGraphQLWorkspace, +} from "@reearth-cms/components/organisms/DataConverters/setting"; import { useCreateWorkspaceMutation, useGetMeQuery, useGetProjectQuery, ProjectPublicationScope, WorkspaceMember, + Workspace as GQLWorkspace, } from "@reearth-cms/gql/graphql-client-api"; import { useT } from "@reearth-cms/i18n"; import { useWorkspace, useProject, useUserId, useWorkspaceId } from "@reearth-cms/state"; @@ -43,17 +47,23 @@ export default () => { setCollapsed(collapse); }, []); - const workspaces = data?.me?.workspaces; + const workspaces = data?.me?.workspaces?.map(workspace => + fromGraphQLWorkspace(workspace as GQLWorkspace), + ); const workspace = workspaces?.find(workspace => workspace.id === workspaceId); - const personalWorkspace: Workspace = useMemo(() => { + const personalWorkspace = useMemo(() => { const foundWorkspace = workspaces?.find( workspace => workspace.id === data?.me?.myWorkspace?.id, ); - return { - id: foundWorkspace?.id, - name: foundWorkspace?.name, - members: foundWorkspace?.members?.map(member => fromGraphQLMember(member as WorkspaceMember)), - }; + return foundWorkspace + ? { + id: foundWorkspace.id, + name: foundWorkspace.name, + members: foundWorkspace.members?.map(member => + fromGraphQLMember(member as WorkspaceMember), + ), + } + : undefined; }, [data?.me?.myWorkspace?.id, workspaces]); const personal = workspaceId === data?.me?.myWorkspace?.id; @@ -83,7 +93,9 @@ export default () => { }); if (results.data?.createWorkspace) { Notification.success({ message: t("Successfully created workspace!") }); - setCurrentWorkspace(results.data.createWorkspace.workspace); + setCurrentWorkspace( + fromGraphQLWorkspace(results.data.createWorkspace.workspace as GQLWorkspace), + ); navigate(`/workspace/${results.data.createWorkspace.workspace.id}`); } refetch(); diff --git a/web/src/components/organisms/DataConverters/setting.ts b/web/src/components/organisms/DataConverters/setting.ts index 2e5fae781e..1f3515afdc 100644 --- a/web/src/components/organisms/DataConverters/setting.ts +++ b/web/src/components/organisms/DataConverters/setting.ts @@ -1,7 +1,4 @@ -import { - IntegrationMember, - Integration, -} from "@reearth-cms/components/molecules/Integration/types"; +import { Integration } from "@reearth-cms/components/molecules/Integration/types"; import { WorkspaceSettings, Member, @@ -71,13 +68,12 @@ export const fromGraphQLIntegration = (integration: GQLIntegration): Integration }, }); -export const fromGraphQLWorkspace = (workspace?: GQLWorkspace): Workspace | undefined => { - if (!workspace) return; +export const fromGraphQLWorkspace = (workspace: GQLWorkspace): Workspace => { return { - id: workspace?.id, - name: workspace?.name, - personal: workspace?.personal, - members: workspace?.members?.map(member => fromGraphQLMember(member)), + id: workspace.id, + name: workspace.name, + personal: workspace.personal, + members: workspace.members.map(member => fromGraphQLMember(member)), }; }; @@ -87,10 +83,10 @@ export const fromGraphQLMember = (member: WorkspaceMember): Member => { return { id: member.integrationId, active: member.active, - integration: member.integration && fromGraphQLIntegration(member.integration), + integration: member.integration ? fromGraphQLIntegration(member.integration) : undefined, invitedById: member.invitedById, integrationRole: member.role, - } as IntegrationMember; + }; case "WorkspaceUserMember": default: return { diff --git a/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts b/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts index dd72a4fe6d..688bf19781 100644 --- a/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts +++ b/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts @@ -16,7 +16,7 @@ import { RequestState, } from "@reearth-cms/components/molecules/Request/types"; import { Group, Field } from "@reearth-cms/components/molecules/Schema/types"; -import { Role, UserMember } from "@reearth-cms/components/molecules/Workspace/types"; +import { UserMember } from "@reearth-cms/components/molecules/Workspace/types"; import { fromGraphQLItem } from "@reearth-cms/components/organisms/DataConverters/content"; import { fromGraphQLModel } from "@reearth-cms/components/organisms/DataConverters/model"; import { fromGraphQLGroup } from "@reearth-cms/components/organisms/DataConverters/schema"; @@ -166,13 +166,15 @@ export default () => { : undefined; }, [userData]); - const myRole: Role = useMemo( - () => currentWorkspace?.members?.find(m => m.userId === me?.id)?.role, + const myRole = useMemo( + () => + currentWorkspace?.members?.find((m): m is UserMember => "userId" in m && m.userId === me?.id) + ?.role, [currentWorkspace?.members, me?.id], ); const showPublishAction = useMemo( - () => !currentProject?.requestRoles?.includes(myRole), + () => (myRole ? !currentProject?.requestRoles?.includes(myRole) : false), [currentProject?.requestRoles, myRole], ); @@ -415,7 +417,7 @@ export default () => { return ( currentWorkspace?.members ?.map(member => - member.__typename === "WorkspaceUserMember" && member.user + "userId" in member ? { userId: member.userId, user: member.user, diff --git a/web/src/components/organisms/Project/Request/RequestDetails/hooks.ts b/web/src/components/organisms/Project/Request/RequestDetails/hooks.ts index 256928c5f5..c21a2046f3 100644 --- a/web/src/components/organisms/Project/Request/RequestDetails/hooks.ts +++ b/web/src/components/organisms/Project/Request/RequestDetails/hooks.ts @@ -4,6 +4,7 @@ import { useNavigate, useParams } from "react-router-dom"; import Notification from "@reearth-cms/components/atoms/Notification"; import { User } from "@reearth-cms/components/molecules/AccountSettings/types"; import { Request } from "@reearth-cms/components/molecules/Request/types"; +import { UserMember } from "@reearth-cms/components/molecules/Workspace/types"; import { useDeleteRequestMutation, useApproveRequestMutation, @@ -44,7 +45,9 @@ export default () => { }, [userData]); const myRole = useMemo( - () => currentWorkspace?.members?.find(m => m.userId === me?.id)?.role, + () => + currentWorkspace?.members?.find((m): m is UserMember => "userId" in m && m.userId === me?.id) + ?.role, [currentWorkspace?.members, me?.id], ); diff --git a/web/src/components/organisms/Settings/General/hooks.ts b/web/src/components/organisms/Settings/General/hooks.ts index 22ec0b8685..7f4fefe8ae 100644 --- a/web/src/components/organisms/Settings/General/hooks.ts +++ b/web/src/components/organisms/Settings/General/hooks.ts @@ -5,6 +5,7 @@ import { WorkspaceSettings, TileInput, TerrainInput, + UserMember, } from "@reearth-cms/components/molecules/Workspace/types"; import { fromGraphQLWorkspaceSettings } from "@reearth-cms/components/organisms/DataConverters/setting"; import { @@ -97,7 +98,9 @@ export default () => { const { data: userData } = useGetMeQuery(); const hasPrivilege: boolean = useMemo(() => { - const myRole = currentWorkspace?.members?.find(m => m.userId === userData?.me?.id)?.role; + const myRole = currentWorkspace?.members?.find( + (m): m is UserMember => "userId" in m && m.userId === userData?.me?.id, + )?.role; return myRole === "OWNER" || myRole === "MAINTAINER"; }, [currentWorkspace?.members, userData?.me?.id]); diff --git a/web/src/components/organisms/Settings/Integration/hooks.ts b/web/src/components/organisms/Settings/Integration/hooks.ts index ac60fcb689..a1727c0ff9 100644 --- a/web/src/components/organisms/Settings/Integration/hooks.ts +++ b/web/src/components/organisms/Settings/Integration/hooks.ts @@ -51,7 +51,7 @@ export default (workspaceId?: string) => { ) .filter( (integrationMember): integrationMember is IntegrationMember => - !!integrationMember && + !!integrationMember?.integration && integrationMember.integration.name.toLowerCase().includes(searchTerm ?? ""), ); }, [workspace, searchTerm]); @@ -103,7 +103,7 @@ export default (workspaceId?: string) => { if (!workspaceId || !selectedIntegrationMember) return; const integration = await updateIntegrationToWorkspaceMutation({ variables: { - integrationId: selectedIntegrationMember?.integration.id, + integrationId: selectedIntegrationMember?.integration?.id || "", workspaceId, role: role as GQLRole, }, diff --git a/web/src/components/organisms/Settings/Members/hooks.ts b/web/src/components/organisms/Settings/Members/hooks.ts index 19070e3e1a..67b9927561 100644 --- a/web/src/components/organisms/Settings/Members/hooks.ts +++ b/web/src/components/organisms/Settings/Members/hooks.ts @@ -3,13 +3,14 @@ import { useCallback, useEffect, useMemo, useState } from "react"; import Notification from "@reearth-cms/components/atoms/Notification"; import { User } from "@reearth-cms/components/molecules/Member/types"; import { UserMember, MemberInput } from "@reearth-cms/components/molecules/Workspace/types"; +import { fromGraphQLWorkspace } from "@reearth-cms/components/organisms/DataConverters/setting"; import { useGetWorkspacesQuery, useAddUsersToWorkspaceMutation, useUpdateMemberOfWorkspaceMutation, Role, useRemoveMemberFromWorkspaceMutation, - Workspace, + Workspace as GQLWorkspace, useGetUserBySearchLazyQuery, MemberInput as GQLMemberInput, } from "@reearth-cms/gql/graphql-client-api"; @@ -35,31 +36,34 @@ export default () => { const [searchedUser, changeSearchedUser] = useState(); const [searchedUserList, changeSearchedUserList] = useState([]); - const { data, loading } = useGetWorkspacesQuery(); - const me = { id: data?.me?.id, myWorkspace: data?.me?.myWorkspace?.id }; - const workspaces = data?.me?.workspaces as Workspace[]; - const workspaceId = currentWorkspace?.id; + const { data } = useGetWorkspacesQuery(); + const me = useMemo( + () => ({ id: data?.me?.id, myWorkspace: data?.me?.myWorkspace?.id }), + [data?.me?.id, data?.me?.myWorkspace?.id], + ); + const workspaces = useMemo( + () => data?.me?.workspaces?.map(workspace => fromGraphQLWorkspace(workspace as GQLWorkspace)), + [data?.me?.workspaces], + ); + const workspaceId = useMemo(() => currentWorkspace?.id, [currentWorkspace?.id]); const isOwner = useMemo( - () => currentWorkspace?.members?.find(m => m.userId === me?.id && m.role === "OWNER"), + () => + currentWorkspace?.members?.find( + m => "userId" in m && m.userId === me?.id && m.role === "OWNER", + ), [currentWorkspace?.members, me?.id], ); useEffect(() => { - setOwner(isOwner); + setOwner(!!isOwner); }, [isOwner]); useEffect(() => { - if (!workspaceId) return; - if (!currentWorkspace) { - setWorkspace( - workspaceId - ? workspaces?.find(t => t.id === workspaceId) - : data?.me?.myWorkspace ?? undefined, - ); + if (workspaceId && !currentWorkspace) { + setWorkspace(workspaces?.find(workspace => workspace.id === workspaceId)); } - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [currentWorkspace, setWorkspace, workspaces, data?.me]); + }, [currentWorkspace, setWorkspace, workspaces, data?.me, workspaceId]); const [searchUserQuery, { data: searchUserData }] = useGetUserBySearchLazyQuery({ fetchPolicy: "no-cache", @@ -91,7 +95,7 @@ export default () => { const workspaceUserMembers = useMemo((): UserMember[] | undefined => { return currentWorkspace?.members ?.map(member => - member && member.__typename === "WorkspaceUserMember" && member.user + "userId" in member ? { userId: member.userId, user: member.user, @@ -121,7 +125,7 @@ export default () => { Notification.error({ message: t("Failed to add one or more members.") }); return; } - setWorkspace(workspace); + setWorkspace(fromGraphQLWorkspace(workspace as GQLWorkspace)); if (result.data) { Notification.success({ message: t("Successfully added member(s) to the workspace!") }); @@ -149,7 +153,7 @@ export default () => { }); const workspace = results.data?.updateUserOfWorkspace?.workspace; if (workspace) { - setWorkspace(workspace); + setWorkspace(fromGraphQLWorkspace(workspace as GQLWorkspace)); } } }, @@ -170,7 +174,7 @@ export default () => { Notification.error({ message: t("Failed to delete member from the workspace.") }); return; } - setWorkspace(workspace); + setWorkspace(fromGraphQLWorkspace(workspace as GQLWorkspace)); Notification.success({ message: t("Successfully removed member from the workspace!") }); }, [workspaceId, removeMemberFromWorkspaceMutation, setWorkspace, t], @@ -199,8 +203,6 @@ export default () => { return { me, owner, - workspaces, - currentWorkspace, searchedUser, handleSearchTerm, changeSearchedUser, @@ -210,16 +212,14 @@ export default () => { handleUserAdd, handleUsersAddToWorkspace, handleMemberOfWorkspaceUpdate, + selectedMember, + roleModalShown, handleMemberRemoveFromWorkspace, handleRoleModalClose, handleRoleModalOpen, handleMemberAddModalClose, handleMemberAddModalOpen, MemberAddModalShown, - setSelectedMember, - selectedMember, - roleModalShown, - loading, workspaceUserMembers, }; }; diff --git a/web/src/components/organisms/Workspace/Settings/hooks.ts b/web/src/components/organisms/Workspace/Settings/hooks.ts index 62802dc952..98094e8a28 100644 --- a/web/src/components/organisms/Workspace/Settings/hooks.ts +++ b/web/src/components/organisms/Workspace/Settings/hooks.ts @@ -2,9 +2,11 @@ import { useCallback } from "react"; import { useNavigate } from "react-router-dom"; import Notification from "@reearth-cms/components/atoms/Notification"; +import { fromGraphQLWorkspace } from "@reearth-cms/components/organisms/DataConverters/setting"; import { useUpdateWorkspaceMutation, useDeleteWorkspaceMutation, + Workspace as GQLWorkspace, } from "@reearth-cms/gql/graphql-client-api"; import { useT } from "@reearth-cms/i18n"; import { useWorkspace } from "@reearth-cms/state"; @@ -34,7 +36,9 @@ export default () => { if (res.errors || !res.data?.updateWorkspace) { Notification.error({ message: t("Failed to update workspace.") }); } else { - setCurrentWorkspace(res.data.updateWorkspace.workspace); + setCurrentWorkspace( + fromGraphQLWorkspace(res.data.updateWorkspace.workspace as GQLWorkspace), + ); Notification.success({ message: t("Successfully updated workspace!") }); } }, diff --git a/web/src/components/organisms/Workspace/hooks.ts b/web/src/components/organisms/Workspace/hooks.ts index 825009924b..9932355284 100644 --- a/web/src/components/organisms/Workspace/hooks.ts +++ b/web/src/components/organisms/Workspace/hooks.ts @@ -3,10 +3,12 @@ import { useNavigate } from "react-router-dom"; import Notification from "@reearth-cms/components/atoms/Notification"; import { Project } from "@reearth-cms/components/molecules/Workspace/types"; +import { fromGraphQLWorkspace } from "@reearth-cms/components/organisms/DataConverters/setting"; import { useGetProjectsQuery, useCreateProjectMutation, useCreateWorkspaceMutation, + Workspace as GQLWorkspace, } from "@reearth-cms/gql/graphql-client-api"; import { useT } from "@reearth-cms/i18n"; import { useWorkspace } from "@reearth-cms/state"; @@ -110,7 +112,9 @@ export default () => { }); if (results.data?.createWorkspace) { Notification.success({ message: t("Successfully created workspace!") }); - setCurrentWorkspace(results.data.createWorkspace.workspace); + setCurrentWorkspace( + fromGraphQLWorkspace(results.data.createWorkspace.workspace as GQLWorkspace), + ); navigate(`/workspace/${results.data.createWorkspace.workspace.id}`); } refetch(); diff --git a/web/src/state/index.ts b/web/src/state/index.ts index 7d6d1acebc..4017dd2391 100644 --- a/web/src/state/index.ts +++ b/web/src/state/index.ts @@ -3,16 +3,7 @@ import { atomWithStorage } from "jotai/utils"; import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; import { Model } from "@reearth-cms/components/molecules/Model/types"; -import { Role } from "@reearth-cms/components/molecules/Workspace/types"; - -export type Workspace = { - id: string; - name: string; - members?: Array; - assets?: any; - projects?: any; - personal?: boolean; -}; +import { Role, Workspace } from "@reearth-cms/components/molecules/Workspace/types"; const workspace = atom(undefined); export const useWorkspace = () => useAtom(workspace); From 0d12d5fc05de49239f0079ba9c4ba9a9014efe7d Mon Sep 17 00:00:00 2001 From: Kazuma Tsuchiya Date: Tue, 19 Mar 2024 15:20:27 +0900 Subject: [PATCH 3/4] refactor: project type --- .../components/molecules/Common/Header/index.tsx | 4 +--- web/src/components/molecules/Common/Header/types.ts | 13 ------------- .../molecules/ProjectList/ProjectList.tsx | 10 +++++----- web/src/components/molecules/Workspace/index.tsx | 8 ++++---- web/src/components/molecules/Workspace/types.ts | 6 +++++- web/src/components/organisms/CMSWrapper/hooks.ts | 3 +-- web/src/state/index.ts | 13 +------------ 7 files changed, 17 insertions(+), 40 deletions(-) delete mode 100644 web/src/components/molecules/Common/Header/types.ts diff --git a/web/src/components/molecules/Common/Header/index.tsx b/web/src/components/molecules/Common/Header/index.tsx index 8d884ed761..5404b6f83d 100644 --- a/web/src/components/molecules/Common/Header/index.tsx +++ b/web/src/components/molecules/Common/Header/index.tsx @@ -12,9 +12,7 @@ import { useT } from "@reearth-cms/i18n"; import HeaderDropdown from "./Dropdown"; -export type { User } from "./types"; - -export interface Props { +interface Props { username?: string; personalWorkspace?: Workspace; currentWorkspace?: Workspace; diff --git a/web/src/components/molecules/Common/Header/types.ts b/web/src/components/molecules/Common/Header/types.ts deleted file mode 100644 index 3bec7daaec..0000000000 --- a/web/src/components/molecules/Common/Header/types.ts +++ /dev/null @@ -1,13 +0,0 @@ -export type User = { - name: string; -}; - -export type Team = { - id?: string; - name?: string; -}; - -export type Project = { - id?: string; - name?: string; -}; diff --git a/web/src/components/molecules/ProjectList/ProjectList.tsx b/web/src/components/molecules/ProjectList/ProjectList.tsx index f9b82274c6..bfbc1f7d5c 100644 --- a/web/src/components/molecules/ProjectList/ProjectList.tsx +++ b/web/src/components/molecules/ProjectList/ProjectList.tsx @@ -4,15 +4,15 @@ import Button from "@reearth-cms/components/atoms/Button"; import Icon from "@reearth-cms/components/atoms/Icon"; import Loading from "@reearth-cms/components/atoms/Loading"; import ProjectCard from "@reearth-cms/components/molecules/ProjectList/ProjectCard"; -import { Project as ProjectType } from "@reearth-cms/components/molecules/Workspace/types"; +import { Project } from "@reearth-cms/components/molecules/Workspace/types"; import { useT } from "@reearth-cms/i18n"; -export interface Props { +interface Props { className?: string; - projects?: ProjectType[]; + projects?: Project[]; loading?: boolean; onProjectModalOpen: () => void; - onProjectNavigation: (project: ProjectType) => void; + onProjectNavigation: (project: Project) => void; } const ProjectList: React.FC = ({ @@ -43,7 +43,7 @@ const ProjectList: React.FC = ({ ) : ( - {projects.map((project: ProjectType) => ( + {projects.map(project => ( void; onProjectModalOpen: () => void; - onProjectNavigation: (project: ProjectType) => void; + onProjectNavigation: (project: Project) => void; onWorkspaceModalClose: () => void; onWorkspaceModalOpen: () => void; onWorkspaceCreate: (data: { name: string }) => Promise; diff --git a/web/src/components/molecules/Workspace/types.ts b/web/src/components/molecules/Workspace/types.ts index bd55c4ffcf..5440fb943a 100644 --- a/web/src/components/molecules/Workspace/types.ts +++ b/web/src/components/molecules/Workspace/types.ts @@ -1,10 +1,14 @@ +import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; import { IntegrationMember } from "@reearth-cms/components/molecules/Integration/types"; export type Project = { id: string; name: string; description?: string; - requestRoles?: Role[] | null; + alias?: string; + scope?: PublicScope; + assetPublic?: boolean; + requestRoles?: Role[]; }; export type User = { diff --git a/web/src/components/organisms/CMSWrapper/hooks.ts b/web/src/components/organisms/CMSWrapper/hooks.ts index af9ee92a2c..1f48038a39 100644 --- a/web/src/components/organisms/CMSWrapper/hooks.ts +++ b/web/src/components/organisms/CMSWrapper/hooks.ts @@ -4,7 +4,6 @@ import { useParams, useLocation, useNavigate } from "react-router-dom"; import { MenuInfo } from "@reearth-cms/components/atoms/Menu"; import Notification from "@reearth-cms/components/atoms/Notification"; import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; -import { Role } from "@reearth-cms/components/molecules/Workspace/types"; import { fromGraphQLMember, fromGraphQLWorkspace, @@ -129,7 +128,7 @@ export default () => { scope: convertScope(project.publication?.scope), alias: project.alias, assetPublic: project.publication?.assetPublic, - requestRoles: project.requestRoles as Role[], + requestRoles: project.requestRoles ?? undefined, }); } } else { diff --git a/web/src/state/index.ts b/web/src/state/index.ts index 4017dd2391..ebab40df0d 100644 --- a/web/src/state/index.ts +++ b/web/src/state/index.ts @@ -1,9 +1,8 @@ import { atom, useAtom } from "jotai"; import { atomWithStorage } from "jotai/utils"; -import { PublicScope } from "@reearth-cms/components/molecules/Accessibility/types"; import { Model } from "@reearth-cms/components/molecules/Model/types"; -import { Role, Workspace } from "@reearth-cms/components/molecules/Workspace/types"; +import { Workspace, Project } from "@reearth-cms/components/molecules/Workspace/types"; const workspace = atom(undefined); export const useWorkspace = () => useAtom(workspace); @@ -14,16 +13,6 @@ export const useWorkspaceId = () => useAtom(workspaceId); const userId = atomWithStorage("userId", undefined); export const useUserId = () => useAtom(userId); -export type Project = { - id: string; - name: string; - description?: string; - alias: string; - scope?: PublicScope; - assetPublic?: boolean; - requestRoles?: Role[]; -}; - const project = atom(undefined); export const useProject = () => useAtom(project); From 14fb4b9ba2d9ac1ef02012896542f5cd0f15e3ea Mon Sep 17 00:00:00 2001 From: Kazuma Tsuchiya Date: Tue, 19 Mar 2024 16:52:10 +0900 Subject: [PATCH 4/4] fix: showPublishAction --- .../organisms/Project/Content/ContentDetails/hooks.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts b/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts index 7ea4f203ed..5f54ad6330 100644 --- a/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts +++ b/web/src/components/organisms/Project/Content/ContentDetails/hooks.ts @@ -173,7 +173,7 @@ export default () => { ); const showPublishAction = useMemo( - () => (myRole ? !currentProject?.requestRoles?.includes(myRole) : false), + () => (myRole ? !currentProject?.requestRoles?.includes(myRole) : true), [currentProject?.requestRoles, myRole], );