mirror of
https://github.com/docmost/docmost.git
synced 2025-11-20 15:31:08 +10:00
frontend permissions
* rework backend workspace permissions
This commit is contained in:
@ -1,5 +1,4 @@
|
||||
import { Group, Box, Button, TagsInput, Select } from "@mantine/core";
|
||||
import WorkspaceInviteSection from "@/features/workspace/components/members/components/workspace-invite-section.tsx";
|
||||
import React, { useState } from "react";
|
||||
import { MultiGroupSelect } from "@/features/group/components/multi-group-select.tsx";
|
||||
import { UserRole } from "@/lib/types.ts";
|
||||
|
||||
@ -4,12 +4,14 @@ import React from "react";
|
||||
import { getUserRoleLabel } from "@/features/workspace/types/user-role-data.ts";
|
||||
import InviteActionMenu from "@/features/workspace/components/members/components/invite-action-menu.tsx";
|
||||
import { IconInfoCircle } from "@tabler/icons-react";
|
||||
import { format } from "date-fns";
|
||||
import { formattedDate } from "@/lib/time.ts";
|
||||
import useUserRole from "@/hooks/use-user-role.tsx";
|
||||
|
||||
export default function WorkspaceInvitesTable() {
|
||||
const { data, isLoading } = useWorkspaceInvitationsQuery({
|
||||
limit: 100,
|
||||
});
|
||||
const { isAdmin } = useUserRole();
|
||||
|
||||
return (
|
||||
<>
|
||||
@ -44,12 +46,12 @@ export default function WorkspaceInvitesTable() {
|
||||
|
||||
<Table.Td>{getUserRoleLabel(invitation.role)}</Table.Td>
|
||||
|
||||
<Table.Td>
|
||||
{format(invitation.createdAt, "MM/dd/yyyy")}
|
||||
</Table.Td>
|
||||
<Table.Td>{formattedDate(invitation.createdAt)}</Table.Td>
|
||||
|
||||
<Table.Td>
|
||||
<InviteActionMenu invitationId={invitation.id} />
|
||||
{isAdmin && (
|
||||
<InviteActionMenu invitationId={invitation.id} />
|
||||
)}
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
))}
|
||||
|
||||
@ -10,10 +10,12 @@ import {
|
||||
getUserRoleLabel,
|
||||
userRoleData,
|
||||
} from "@/features/workspace/types/user-role-data.ts";
|
||||
import useUserRole from "@/hooks/use-user-role.tsx";
|
||||
|
||||
export default function WorkspaceMembersTable() {
|
||||
const { data, isLoading } = useWorkspaceMembersQuery({ limit: 100 });
|
||||
const changeMemberRoleMutation = useChangeMemberRoleMutation();
|
||||
const { isAdmin } = useUserRole();
|
||||
|
||||
const handleRoleChange = async (
|
||||
userId: string,
|
||||
@ -72,6 +74,7 @@ export default function WorkspaceMembersTable() {
|
||||
onChange={(newRole) =>
|
||||
handleRoleChange(user.id, user.role, newRole)
|
||||
}
|
||||
disabled={!isAdmin}
|
||||
/>
|
||||
</Table.Td>
|
||||
</Table.Tr>
|
||||
|
||||
@ -8,6 +8,7 @@ import { IWorkspace } from "@/features/workspace/types/workspace.types.ts";
|
||||
import { TextInput, Button } from "@mantine/core";
|
||||
import { useForm, zodResolver } from "@mantine/form";
|
||||
import { notifications } from "@mantine/notifications";
|
||||
import useUserRole from "@/hooks/use-user-role.tsx";
|
||||
|
||||
const formSchema = z.object({
|
||||
name: z.string().nonempty("Workspace name cannot be blank"),
|
||||
@ -23,6 +24,7 @@ export default function WorkspaceNameForm() {
|
||||
const [isLoading, setIsLoading] = useState(false);
|
||||
const [currentUser] = useAtom(currentUserAtom);
|
||||
const [, setWorkspace] = useAtom(workspaceAtom);
|
||||
const { isAdmin } = useUserRole();
|
||||
|
||||
const form = useForm<FormValues>({
|
||||
validate: zodResolver(formSchema),
|
||||
@ -46,6 +48,7 @@ export default function WorkspaceNameForm() {
|
||||
});
|
||||
}
|
||||
setIsLoading(false);
|
||||
form.resetDirty();
|
||||
}
|
||||
|
||||
return (
|
||||
@ -57,9 +60,17 @@ export default function WorkspaceNameForm() {
|
||||
variant="filled"
|
||||
{...form.getInputProps("name")}
|
||||
/>
|
||||
<Button mt="sm" type="submit" disabled={isLoading} loading={isLoading}>
|
||||
Save
|
||||
</Button>
|
||||
|
||||
{isAdmin && (
|
||||
<Button
|
||||
mt="sm"
|
||||
type="submit"
|
||||
disabled={isLoading || !form.isDirty()}
|
||||
loading={isLoading}
|
||||
>
|
||||
Save
|
||||
</Button>
|
||||
)}
|
||||
</form>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user