diff --git a/front/packages/ui/src/admin/index.tsx b/front/packages/ui/src/admin/index.tsx index be715d35..0c92aa37 100644 --- a/front/packages/ui/src/admin/index.tsx +++ b/front/packages/ui/src/admin/index.tsx @@ -32,19 +32,28 @@ import UserI from "@material-symbols/svg-400/rounded/account_circle.svg"; import Admin from "@material-symbols/svg-400/rounded/shield_person.svg"; import MoreVert from "@material-symbols/svg-400/rounded/more_vert.svg"; import Delete from "@material-symbols/svg-400/rounded/delete.svg"; -import { useQueryClient } from "@tanstack/react-query"; +import { useMutation, useQueryClient } from "@tanstack/react-query"; const UserGrid = ({ isLoading, - slug, + id, username, avatar, isAdmin, ...props -}: WithLoading<{ slug: string; username: string; avatar: string; isAdmin: boolean }>) => { +}: WithLoading<{ id: string; username: string; avatar: string; isAdmin: boolean }>) => { const { css } = useYoshiki(); const { t } = useTranslation(); const queryClient = useQueryClient(); + const { mutateAsync } = useMutation({ + mutationFn: async (update: Partial) => + await queryFn({ + path: ["users", id], + method: "PATCH", + body: update, + }), + onSettled: async () => await queryClient.invalidateQueries({ queryKey: ["users"] }), + }); return ( @@ -62,6 +71,35 @@ const UserGrid = ({

{username}

+ + + mutateAsync({ + permissions: ["overall.read"], + }) + } + /> + + mutateAsync({ + permissions: [ + "overall.read", + "overall.write", + "overall.create", + "overall.delete", + "admin.read", + "admin.write", + "admin.create", + "admin.delete", + ], + }) + } + /> + { - await queryFn({ path: ["users", slug], method: "DELETE" }); + await queryFn({ path: ["users", id], method: "DELETE" }); await queryClient.invalidateQueries({ queryKey: ["users"] }); }, style: "destructive", @@ -109,7 +147,7 @@ const UserList = () => { {(user) => ( { alignItems: "center", })} > -

{t("errors.unauthorized", { permission: missing.join(", ") })}

+

{t("errors.unauthorized", { permission: missing?.join(", ") })}

); }; diff --git a/front/translations/en.json b/front/translations/en.json index 6c0c4a39..d3f6bc4f 100644 --- a/front/translations/en.json +++ b/front/translations/en.json @@ -214,6 +214,7 @@ "label": "Users", "adminUser": "Admin", "regularUser": "User", + "set-permissions": "Set permissions", "delete": "Delete user" } } diff --git a/front/translations/fr.json b/front/translations/fr.json index 7cbe3b29..4f1afab2 100644 --- a/front/translations/fr.json +++ b/front/translations/fr.json @@ -214,6 +214,7 @@ "label": "Comptes", "adminUser": "Admin", "regularUser": "Utilisateur", + "set-permissions": "Definir les permissions", "delete": "Supprimer l'utilisateur" } }