From 7240d90bc1558c031e769b0047b05eb66d552313 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=87=91=E4=BC=9F=E5=BC=BA?= Date: Thu, 18 May 2023 17:44:37 +0800 Subject: [PATCH] feat: customize permission detect --- web/app/components/explore/app-card/index.tsx | 14 ++++++++----- web/app/components/explore/app-list/index.tsx | 3 ++- web/app/components/explore/index.tsx | 20 ++++++++++++++++--- web/context/explore-context.ts | 2 ++ 4 files changed, 30 insertions(+), 9 deletions(-) diff --git a/web/app/components/explore/app-card/index.tsx b/web/app/components/explore/app-card/index.tsx index 97906abd7f..b212394ff4 100644 --- a/web/app/components/explore/app-card/index.tsx +++ b/web/app/components/explore/app-card/index.tsx @@ -17,14 +17,16 @@ const CustomizeBtn = ( export type AppCardProps = { app: App, + canCreate: boolean, onCreate: () => void, onAddToWorkspace: (appId: string) => void, } const AppCard = ({ app, + canCreate, onCreate, - onAddToWorkspace + onAddToWorkspace, }: AppCardProps) => { const { t } = useTranslation() const {app: appBasicInfo} = app @@ -47,10 +49,12 @@ const AppCard = ({ {t('explore.appCard.addToWorkspace')} - + {canCreate && ( + + )} diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx index 5fba971d59..c5ebc130a8 100644 --- a/web/app/components/explore/app-list/index.tsx +++ b/web/app/components/explore/app-list/index.tsx @@ -16,7 +16,7 @@ import Toast from '../../base/toast' const Apps: FC = ({ }) => { const { t } = useTranslation() - const { setControlUpdateInstalledApps } = useContext(ExploreContext) + const { setControlUpdateInstalledApps, hasEditPermission } = useContext(ExploreContext) const [currCategory, setCurrCategory] = React.useState('') const [allList, setAllList] = React.useState([]) const [isLoaded, setIsLoaded] = React.useState(false) @@ -95,6 +95,7 @@ const Apps: FC = ({ }) => { { setCurrApp(app) setIsShowCreateModal(true) diff --git a/web/app/components/explore/index.tsx b/web/app/components/explore/index.tsx index c098bcfa0e..5011d21dcd 100644 --- a/web/app/components/explore/index.tsx +++ b/web/app/components/explore/index.tsx @@ -1,8 +1,9 @@ 'use client' -import React, { FC } from 'react' +import React, { FC, useEffect } from 'react' import ExploreContext from '@/context/explore-context' import Sidebar from '@/app/components/explore/sidebar' - +import { useAppContext } from '@/context/app-context' +import { fetchMembers } from '@/service/common' export interface IExploreProps { children: React.ReactNode @@ -12,13 +13,26 @@ const Explore: FC = ({ children }) => { const [controlUpdateInstalledApps, setControlUpdateInstalledApps] = React.useState(0) + const { userProfile } = useAppContext() + const [hasEditPermission, setHasEditPermission] = React.useState(false) + + useEffect(() => { + (async () => { + const { accounts } = await fetchMembers({ url: '/workspaces/current/members', params: {}}) + if(!accounts) return + const currUser = accounts.find(account => account.id === userProfile.id) + setHasEditPermission(currUser?.role !== 'normal') + })() + }, []) + return (
diff --git a/web/context/explore-context.ts b/web/context/explore-context.ts index e819d30cb2..2476903c79 100644 --- a/web/context/explore-context.ts +++ b/web/context/explore-context.ts @@ -3,11 +3,13 @@ import { createContext } from 'use-context-selector' type IExplore = { controlUpdateInstalledApps: number setControlUpdateInstalledApps: (controlUpdateInstalledApps: number) => void + hasEditPermission: boolean } const ExploreContext = createContext({ controlUpdateInstalledApps: 0, setControlUpdateInstalledApps: () => { }, + hasEditPermission: false, }) export default ExploreContext