Skip to content

Commit 5a6ccae

Browse files
fix: show settings based on permissions and spaceShortcode hook cleanup (#765)
1 parent f4c25fb commit 5a6ccae

File tree

13 files changed

+104
-90
lines changed

13 files changed

+104
-90
lines changed

apps/platform/trpc/routers/spaceRouter/spaceRouter.ts

Lines changed: 44 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -166,37 +166,53 @@ export const spaceRouter = router({
166166

167167
const spaceIdsDedupe = Array.from(new Set([...memberSpaceIds]));
168168

169-
const orgMemberSpaces = await db.query.spaces.findMany({
170-
where: and(
171-
eq(spaces.orgId, org.id),
172-
or(eq(spaces.type, 'open'), inArray(spaces.id, spaceIdsDedupe))
173-
),
174-
columns: {
175-
publicId: true,
176-
shortcode: true,
177-
name: true,
178-
description: true,
179-
type: true,
180-
avatarTimestamp: true,
181-
convoPrefix: true,
182-
inheritParentPermissions: true,
183-
color: true,
184-
icon: true,
185-
personalSpace: true
186-
},
187-
with: {
188-
parentSpace: {
189-
columns: {
190-
publicId: true
191-
}
169+
const orgMemberSpaces = await db.query.spaces
170+
.findMany({
171+
where: and(
172+
eq(spaces.orgId, org.id),
173+
or(eq(spaces.type, 'open'), inArray(spaces.id, spaceIdsDedupe))
174+
),
175+
columns: {
176+
id: true,
177+
publicId: true,
178+
shortcode: true,
179+
name: true,
180+
description: true,
181+
type: true,
182+
avatarTimestamp: true,
183+
convoPrefix: true,
184+
inheritParentPermissions: true,
185+
color: true,
186+
icon: true,
187+
personalSpace: true
192188
},
193-
subSpaces: {
194-
columns: {
195-
publicId: true
189+
with: {
190+
parentSpace: {
191+
columns: {
192+
publicId: true
193+
}
194+
},
195+
subSpaces: {
196+
columns: {
197+
publicId: true
198+
}
196199
}
197200
}
198-
}
199-
});
201+
})
202+
.then((spaces) =>
203+
spaces.map((space) => {
204+
// if the space is private, or the space id is in the array, then they can see Settings
205+
if (
206+
space.type === 'private' ||
207+
(space.type === 'open' && spaceIdsDedupe.includes(space.id))
208+
) {
209+
return { ...space, canSeeSettings: true };
210+
} else {
211+
// otherwise, they can't see Settings
212+
return { ...space, canSeeSettings: false };
213+
}
214+
})
215+
);
200216

201217
const orgMemberPersonalSpaceQuery = await db.query.orgMembers.findFirst({
202218
where: eq(orgMembers.id, org.memberId),

apps/platform/trpc/routers/spaceRouter/spaceSettingsRouter.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export const spaceSettingsRouter = router({
2929
if (!spaceMembershipResponse.role) {
3030
throw new TRPCError({
3131
code: 'FORBIDDEN',
32-
message: 'You are not a member of this Space'
32+
message: "You don't have access to settings for this space"
3333
});
3434
}
3535

apps/web/src/app/[orgShortcode]/[spaceShortcode]/settings/page.tsx

Lines changed: 29 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ import { z } from 'zod';
7676

7777
export default function SettingsPage() {
7878
const orgShortcode = useOrgShortcode();
79-
const spaceShortcode = useSpaceShortcode();
79+
const spaceShortcode = useSpaceShortcode(true);
8080

8181
const [showSaved, setShowSaved] = useState(false);
8282

@@ -100,9 +100,15 @@ export default function SettingsPage() {
100100
<div className="flex w-full flex-col items-center overflow-y-auto">
101101
<div className="flex max-w-screen-md flex-col gap-8 p-4">
102102
{isLoading ? (
103-
<div>Loading...</div>
103+
<div className="flex items-center justify-center gap-2 text-center font-bold">
104+
<SpinnerGap
105+
className="size-4 animate-spin"
106+
size={16}
107+
/>
108+
<span>Loading...</span>
109+
</div>
104110
) : !spaceSettings?.settings ? (
105-
<div>Space Not Found</div>
111+
<div>{`You don't have access to settings for this space`}</div>
106112
) : (
107113
<div className="flex w-full flex-col gap-8 p-0">
108114
<div className="border-base-5 flex w-full flex-row items-center justify-between gap-4 border-b pb-2">
@@ -121,16 +127,12 @@ export default function SettingsPage() {
121127

122128
<div className="flex flex-col gap-1">
123129
<NameField
124-
orgShortcode={orgShortcode}
125-
spaceShortcode={spaceShortcode}
126130
initialValue={spaceSettings?.settings?.name}
127131
showSaved={setShowSaved}
128132
isSpaceAdmin={isSpaceAdmin}
129133
/>
130134

131135
<DescriptionField
132-
orgShortcode={orgShortcode}
133-
spaceShortcode={spaceShortcode}
134136
initialValue={spaceSettings?.settings?.description ?? ''}
135137
showSaved={setShowSaved}
136138
isSpaceAdmin={isSpaceAdmin}
@@ -164,22 +166,16 @@ export default function SettingsPage() {
164166
</div>
165167
</div>
166168
<ColorField
167-
orgShortcode={orgShortcode}
168-
spaceShortcode={spaceShortcode}
169169
initialValue={spaceSettings?.settings?.color}
170170
showSaved={setShowSaved}
171171
isSpaceAdmin={isSpaceAdmin}
172172
/>
173173
<VisibilityField
174-
orgShortcode={orgShortcode}
175-
spaceShortcode={spaceShortcode}
176174
initialValue={spaceSettings?.settings?.type}
177175
showSaved={setShowSaved}
178176
isSpaceAdmin={isSpaceAdmin}
179177
/>
180178
<Workflows
181-
orgShortcode={orgShortcode}
182-
spaceShortcode={spaceShortcode}
183179
showSaved={setShowSaved}
184180
isSpaceAdmin={isSpaceAdmin}
185181
/>
@@ -196,18 +192,16 @@ export default function SettingsPage() {
196192
}
197193

198194
function NameField({
199-
orgShortcode,
200-
spaceShortcode,
201195
initialValue,
202196
showSaved,
203197
isSpaceAdmin
204198
}: {
205-
orgShortcode: string;
206-
spaceShortcode: string;
207199
initialValue: string;
208200
isSpaceAdmin: boolean;
209201
showSaved: (value: boolean) => void;
210202
}) {
203+
const orgShortcode = useOrgShortcode();
204+
const spaceShortcode = useSpaceShortcode(true);
211205
const { mutateAsync: setSpaceName, isSuccess: setSpaceNameSuccess } =
212206
platform.spaces.settings.setSpaceName.useMutation();
213207
const [editName, setEditName] = useState(initialValue);
@@ -254,11 +248,14 @@ function NameField({
254248
label="Space Name"
255249
value={editName}
256250
onChange={(e) => setEditName(e.target.value)}
251+
onBlur={() => setShowEditNameField(false)}
257252
/>
258253
</div>
259254
) : (
260255
<div className="flex flex-row items-center gap-2">
261-
<span className="font-display text-lg">{initialValue}</span>
256+
<span className="font-display text-lg">
257+
{editName ?? initialValue}
258+
</span>
262259
<Button
263260
variant={'ghost'}
264261
size={'icon-sm'}
@@ -275,18 +272,16 @@ function NameField({
275272
}
276273

277274
function DescriptionField({
278-
orgShortcode,
279-
spaceShortcode,
280275
initialValue,
281276
showSaved,
282277
isSpaceAdmin
283278
}: {
284-
orgShortcode: string;
285-
spaceShortcode: string;
286279
initialValue: string;
287280
isSpaceAdmin: boolean;
288281
showSaved: (value: boolean) => void;
289282
}) {
283+
const orgShortcode = useOrgShortcode();
284+
const spaceShortcode = useSpaceShortcode(true);
290285
const {
291286
mutateAsync: setSpaceDescription,
292287
isSuccess: setSpaceDescriptionSuccess
@@ -336,14 +331,15 @@ function DescriptionField({
336331
label="Description"
337332
value={editDescription}
338333
onChange={(e) => setEditDescription(e.target.value)}
334+
onBlur={() => setShowEditDescriptionField(false)}
339335
/>
340336
</div>
341337
) : (
342338
<div className="flex flex-row items-center gap-2">
343339
{initialValue === '' ? (
344340
<span className="text-base-10 text-xs">Description</span>
345341
) : (
346-
<span className="">{initialValue}</span>
342+
<span>{editDescription ?? initialValue}</span>
347343
)}
348344
<Button
349345
variant={'ghost'}
@@ -361,18 +357,17 @@ function DescriptionField({
361357
}
362358

363359
function ColorField({
364-
orgShortcode,
365-
spaceShortcode,
366360
initialValue,
367361
showSaved,
368362
isSpaceAdmin
369363
}: {
370-
orgShortcode: string;
371-
spaceShortcode: string;
372364
initialValue: string;
373365
isSpaceAdmin: boolean;
374366
showSaved: (value: boolean) => void;
375367
}) {
368+
const orgShortcode = useOrgShortcode();
369+
const spaceShortcode = useSpaceShortcode(true);
370+
376371
const { mutateAsync: setSpaceColor } =
377372
platform.spaces.settings.setSpaceColor.useMutation();
378373
const [activeColor, setActiveColor] = useState(initialValue);
@@ -436,18 +431,17 @@ function ColorField({
436431
}
437432

438433
function VisibilityField({
439-
orgShortcode,
440-
spaceShortcode,
441434
initialValue,
442435
showSaved,
443436
isSpaceAdmin
444437
}: {
445-
orgShortcode: string;
446-
spaceShortcode: string;
447438
initialValue: string;
448439
isSpaceAdmin: boolean;
449440
showSaved: (value: boolean) => void;
450441
}) {
442+
const orgShortcode = useOrgShortcode();
443+
const spaceShortcode = useSpaceShortcode(true);
444+
451445
const { data: canAddSpace } = platform.org.iCanHaz.space.useQuery(
452446
{
453447
orgShortcode: orgShortcode
@@ -554,16 +548,15 @@ function VisibilityField({
554548
}
555549

556550
function Workflows({
557-
orgShortcode,
558-
spaceShortcode,
559551
showSaved,
560552
isSpaceAdmin
561553
}: {
562-
orgShortcode: string;
563-
spaceShortcode: string;
564554
isSpaceAdmin: boolean;
565555
showSaved: (value: boolean) => void;
566556
}) {
557+
const orgShortcode = useOrgShortcode();
558+
const spaceShortcode = useSpaceShortcode(true);
559+
567560
const { data: spaceWorkflows, isLoading: workflowsLoading } =
568561
platform.spaces.workflows.getSpacesWorkflows.useQuery({
569562
orgShortcode: orgShortcode,
@@ -1586,6 +1579,7 @@ function DeleteWorkflowModal({
15861579
);
15871580
}
15881581

1582+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
15891583
function Tags({
15901584
orgShortcode,
15911585
spaceShortcode

apps/web/src/app/[orgShortcode]/_components/sidebar-content.tsx

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -122,17 +122,21 @@ function SpaceItem({
122122
{spaceData.name ?? 'Unnamed Space'}
123123
</span>
124124
</Link>
125-
<div className="w-0 overflow-hidden transition-all group-hover:w-8">
126-
<DropdownMenu>
127-
<DropdownMenuTrigger asChild>
128-
<Button
129-
size="icon-sm"
130-
variant="ghost">
131-
<DotsThree />
132-
</Button>
133-
</DropdownMenuTrigger>
134-
<DropdownMenuContent>
135-
{/* TODO: Add in with the notifications
125+
{spaceData.canSeeSettings && (
126+
<div className="w-0 overflow-hidden transition-all group-hover:w-8">
127+
{/* <DropdownMenu>
128+
<DropdownMenuTrigger asChild> */}
129+
<Button
130+
size="icon-sm"
131+
variant="ghost"
132+
onClick={() =>
133+
router.push(`/${orgShortCode}/${spaceData.shortcode}/settings`)
134+
}>
135+
<DotsThree />
136+
</Button>
137+
{/* </DropdownMenuTrigger>
138+
<DropdownMenuContent>
139+
TODO: Add in with the notifications
136140
<DropdownMenuSub>
137141
<DropdownMenuSubTrigger>Notifications</DropdownMenuSubTrigger>
138142
<DropdownMenuPortal>
@@ -152,16 +156,16 @@ function SpaceItem({
152156
</DropdownMenuPortal>
153157
</DropdownMenuSub>
154158
<DropdownMenuSeparator />
155-
*/}
156-
<DropdownMenuItem
159+
<DropdownMenuItem
157160
onSelect={() => {
158161
router.push(`/${orgShortCode}/${spaceData.shortcode}/settings`);
159162
}}>
160163
Space Settings
161164
</DropdownMenuItem>
162165
</DropdownMenuContent>
163-
</DropdownMenu>
164-
</div>
166+
</DropdownMenu> */}
167+
</div>
168+
)}
165169
</div>
166170
);
167171
}

apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/reply-box.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ export function ReplyBox({
5757
const { draft, setDraft, resetDraft } = useDraft(convoId);
5858
const [editorText, setEditorText] = useState(draft.content);
5959
const orgShortcode = useOrgShortcode();
60-
const spaceShortcode = useSpaceShortcode(false);
60+
const spaceShortcode = useSpaceShortcode();
6161
const [replyTo] = useAtom(replyToMessageAtom);
6262
const [emailIdentity, setEmailIdentity] = useAtom(emailIdentityAtom);
6363
const addConvoToCache = useUpdateConvoMessageList$Cache();

apps/web/src/app/[orgShortcode]/convo/[convoId]/_components/top-bar.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,7 +446,7 @@ const DeleteButton = memo(function DeleteButton({
446446
const removeConvoFromList = useDeleteConvo$Cache();
447447
const { scopedNavigate } = useOrgScopedRouter();
448448
const currentConvo = useCurrentConvoId();
449-
const spaceShortcode = useSpaceShortcode(false);
449+
const spaceShortcode = useSpaceShortcode();
450450

451451
const { mutate: deleteConvo, isPending: deletingConvo } =
452452
platform.convos.deleteConvo.useMutation({
@@ -522,7 +522,7 @@ function DeleteModal({
522522
const orgShortcode = useOrgShortcode();
523523
const { scopedNavigate } = useOrgScopedRouter();
524524
const currentConvo = useCurrentConvoId();
525-
const spaceShortcode = useSpaceShortcode(false);
525+
const spaceShortcode = useSpaceShortcode();
526526
const removeConvoFromList = useDeleteConvo$Cache();
527527

528528
// const { mutate: hideConvo, isPending: hidingConvo } =

apps/web/src/app/[orgShortcode]/convo/_components/convo-list-base.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export function ConvoListBase({
3232
linkBase
3333
}: ConvoListBaseProps) {
3434
const orgShortcode = useOrgShortcode();
35-
const spaceShortcode = useSpaceShortcode(false);
35+
const spaceShortcode = useSpaceShortcode();
3636
const [selections, setSelections] = useAtom(convoListSelection);
3737
const [lastSelected, setLastSelected] = useAtom(lastSelectedConvo);
3838

0 commit comments

Comments
 (0)