Skip to content

Commit 8d9cf1c

Browse files
committed
User immer, Disable share permission in Space header
1 parent 1ff1f29 commit 8d9cf1c

File tree

5 files changed

+53
-41
lines changed

5 files changed

+53
-41
lines changed

apps/webapp/src/Components/EditorInfobar/Metadata.tsx

-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import { DataGroup, DataWrapper, MetadataWrapper } from '@mexit/shared'
1212
import { RelativeTime } from '@mexit/shared'
1313

1414
import { useMentions } from '../../Hooks/useMentions'
15-
import { usePermissions } from '../../Hooks/usePermissions'
1615
import { useContentStore } from '../../Stores/useContentStore'
1716
import { useEditorStore } from '../../Stores/useEditorStore'
1817
import { useMentionStore } from '../../Stores/useMentionsStore'
@@ -53,7 +52,6 @@ const Metadata = ({
5352
const mentionable = useMentionStore((s) => s.mentionable)
5453
const activeUsers = useRouteStore((s) => s.routes[location.pathname]?.users ?? [])
5554
const { getSharedUsersOfNodeOfSpace } = useMentions()
56-
const { accessWhenShared } = usePermissions()
5755

5856
const isEmpty =
5957
metadata &&

apps/webapp/src/Components/Mentions/PermissionModal.tsx

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import { useNodeShareAPI } from '../../Hooks/API/useNodeShareAPI'
1515
import { useFetchShareData } from '../../Hooks/useFetchShareData'
1616
import { getAccessValue, useMentions } from '../../Hooks/useMentions'
1717
import { useNamespaces } from '../../Hooks/useNamespaces'
18-
import { compareAccessLevel, getUserAccess, usePermissions } from '../../Hooks/usePermissions'
18+
import { getUserAccess, usePermissions } from '../../Hooks/usePermissions'
1919
import { useAuthStore } from '../../Stores/useAuth'
2020
import { useEditorStore } from '../../Stores/useEditorStore'
2121
import { useMentionStore } from '../../Stores/useMentionsStore'
@@ -86,7 +86,7 @@ export const PermissionModalContent = () => {
8686
useEffect(() => {
8787
if (open) {
8888
// Fetch all user details for the space
89-
fetchSharedUsers(id, 'space')
89+
fetchSharedUsers(context === 'space' ? id : node.namespace, 'space')
9090
}
9191
}, [open, context, id])
9292

apps/webapp/src/Components/Sidebar/Space/header.tsx

+10-2
Original file line numberDiff line numberDiff line change
@@ -109,9 +109,16 @@ const Header = ({ space, readOnly }: { space: SidebarSpace; readOnly?: boolean }
109109
const isNamespaceIconDisabled = isNamespaceReserved || isNamespaceReadonly || readOnly
110110
const isShared = space?.data?.granterID !== undefined
111111
const isReadonly = space?.data?.access === 'READ'
112+
const isWriteOnly = space?.data?.access === 'WRITE'
112113
const showTags = space?.popularTags && space?.popularTags.length > 0
113114
const showSeparator = showTags
114115

116+
const shareSpaceTooltip = () => {
117+
if (isWriteOnly) return "You don't have share permission"
118+
if (isReadonly) return 'You can only read the contents!'
119+
return 'Share Space'
120+
}
121+
115122
return (
116123
<>
117124
<SpaceHeader>
@@ -135,9 +142,10 @@ const Header = ({ space, readOnly }: { space: SidebarSpace; readOnly?: boolean }
135142
</SpaceTitle>
136143
{!isNamespaceReserved && (
137144
<IconButton
138-
highlight={isShared && !isReadonly}
139-
title={isReadonly ? 'You can only read the contents!' : 'Share Space'}
145+
highlight={isShared && !isReadonly && !isWriteOnly}
146+
title={shareSpaceTooltip()}
140147
icon={isReadonly ? 'ri:eye-line' : 'ri:share-line'}
148+
disabled={isWriteOnly}
141149
onClick={isReadonly ? undefined : onShareSpace}
142150
/>
143151
)}

apps/webapp/src/Stores/useRouteStore.ts

+16-12
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,11 @@ const useRouteStore = create<RouteStoreType>(
3434
routes: {},
3535
setRoute: (routes) => set({ routes }),
3636
addRouteInfo: (route, info) => {
37-
const routes = get().routes
38-
set({ routes: { ...routes, [route]: info } })
37+
set(
38+
produce((draft) => {
39+
draft.routes[route] = info
40+
})
41+
)
3942
},
4043
removePreviousRouteInfo: () => {
4144
const routes = get().routes
@@ -55,22 +58,23 @@ const useRouteStore = create<RouteStoreType>(
5558
if (routes[route]) {
5659
const users = routes[route].users
5760
const banners = routes[route].banners
58-
set({
59-
routes: {
60-
...routes,
61-
[route]: {
62-
users: [...users, userId],
63-
banners: [...banners.filter((f) => f !== BannerType.editor), BannerType.editor]
64-
}
65-
}
66-
})
61+
set(
62+
produce((draft) => {
63+
draft.routes[route]['users'] = [...users, userId]
64+
draft.routes[route]['banners'] = [...banners.filter((f) => f !== BannerType.editor), BannerType.editor]
65+
})
66+
)
6767
} else {
6868
const routeInfo: RouteInformation = {
6969
users: [userId],
7070
banners: [BannerType.editor]
7171
}
7272

73-
set({ routes: { ...routes, [route]: routeInfo } })
73+
set(
74+
produce((draft) => {
75+
draft.routes[route] = routeInfo
76+
})
77+
)
7478
}
7579
},
7680
removeUserFromRoute: (route, userId) => {

libs/shared/src/Style/Buttons.tsx

+25-23
Original file line numberDiff line numberDiff line change
@@ -41,26 +41,12 @@ export const Button = styled.button<ButtonProps>`
4141
}
4242
4343
&:disabled {
44-
background-color: ${({ theme }) => theme.colors.form.button.bg};
44+
/* background-color: ${({ theme }) => theme.colors.form.button.bg}; */
4545
color: ${({ theme }) => transparentize(0.5, theme.colors.form.button.fg)};
4646
cursor: not-allowed;
4747
pointer-events: none;
4848
}
4949
50-
${({ primary, transparent, theme }) =>
51-
!primary &&
52-
transparent &&
53-
css`
54-
background-color: transparent;
55-
&:hover {
56-
background-color: ${theme.colors.form.button.bg};
57-
}
58-
&:disabled {
59-
background-color: ${({ theme }) => theme.colors.gray[6]};
60-
cursor: default;
61-
}
62-
`}
63-
6450
${({ theme: { spacing }, large }) =>
6551
large
6652
? css`
@@ -108,6 +94,20 @@ export const Button = styled.button<ButtonProps>`
10894
}
10995
`
11096
: ''}
97+
98+
${({ primary, transparent, theme }) =>
99+
!primary &&
100+
transparent &&
101+
css`
102+
background-color: transparent;
103+
&:hover {
104+
background-color: ${theme.colors.form.button.bg};
105+
}
106+
&:disabled {
107+
background-color: ${({ theme }) => theme.colors.gray[6]};
108+
cursor: default;
109+
}
110+
`}
111111
`
112112

113113
export type IconButtonProps = {
@@ -147,14 +147,16 @@ export const IconButton = ({
147147
}
148148
singleton={singleton}
149149
>
150-
<Button
151-
transparent={transparent !== undefined ? transparent : true}
152-
disabled={disabled}
153-
onClick={onClick}
154-
highlight={highlight}
155-
>
156-
<Icon color={color} icon={icon} height={size} />
157-
</Button>
150+
<span>
151+
<Button
152+
transparent={transparent !== undefined ? transparent : true}
153+
disabled={disabled}
154+
onClick={onClick}
155+
highlight={highlight}
156+
>
157+
<Icon color={color} icon={icon} height={size} />
158+
</Button>
159+
</span>
158160
</ToolbarTooltip>
159161
)
160162
}

0 commit comments

Comments
 (0)