From fd4b3d71be039975b9d2fe58521f5ba15ee4b6e8 Mon Sep 17 00:00:00 2001 From: Alexandre Titeux Date: Tue, 19 Sep 2023 11:10:36 +0200 Subject: [PATCH] :goal_net: Add error handling for GRPC --- src/components/dashboard/UsersManagement.tsx | 222 +++++++++++------- .../backend/userService/useInviteUserRPC.tsx | 13 +- src/pages/ProfilePage.tsx | 147 +++++++----- src/providers/AuthProvider.tsx | 139 +++++------ 4 files changed, 303 insertions(+), 218 deletions(-) diff --git a/src/components/dashboard/UsersManagement.tsx b/src/components/dashboard/UsersManagement.tsx index f7bb435..5a59e04 100644 --- a/src/components/dashboard/UsersManagement.tsx +++ b/src/components/dashboard/UsersManagement.tsx @@ -1,12 +1,25 @@ -import React, { useState, useEffect } from 'react'; +import React, { useEffect, useState } from "react"; import { - Typography, TextField, Button, Grid, List, ListItem, ListItemText, Box, Select, MenuItem, Card, CardContent, Snackbar, Alert, IconButton -} from '@mui/material'; -import useGetUsersRPC from '@hooks/backend/userService/useGetUsersRPC'; -import useInviteUserRPC from '@hooks/backend/userService/useInviteUserRPC'; -import useChangeRightsRPC from '@hooks/backend/userService/useChangeRightsRPC'; -import useDeleteUserRPC from '@hooks/backend/userService/useDeleteUserRPC'; -import DeleteIcon from '@mui/icons-material/Delete'; + Alert, + Box, + Button, + Grid, + IconButton, + List, + ListItem, + ListItemText, + MenuItem, + Select, + Snackbar, + TextField, + Typography, +} from "@mui/material"; +import useGetUsersRPC from "@hooks/backend/userService/useGetUsersRPC"; +import useInviteUserRPC from "@hooks/backend/userService/useInviteUserRPC"; +import useChangeRightsRPC from "@hooks/backend/userService/useChangeRightsRPC"; +import useDeleteUserRPC from "@hooks/backend/userService/useDeleteUserRPC"; +import DeleteIcon from "@mui/icons-material/Delete"; +import { RpcError } from "@protobuf-ts/runtime-rpc"; interface User { email: string; @@ -16,13 +29,17 @@ interface User { } const UsersManagement: React.FC = () => { - const [selectedRights, setSelectedRights] = useState>({}); + const [selectedRights, setSelectedRights] = useState>( + {}, + ); const [email, setEmail] = useState(""); const [users, setUsers] = useState([]); const [open, setOpen] = React.useState(false); - const [alertText, setAlertText] = React.useState(''); - const [alertSeverity, setAlertSeverity] = useState<'success' | 'error'>('success'); + const [alertText, setAlertText] = React.useState(""); + const [alertSeverity, setAlertSeverity] = useState<"success" | "error">( + "success", + ); const { getUsers } = useGetUsersRPC(); const { inviteUser } = useInviteUserRPC(); @@ -32,16 +49,18 @@ const UsersManagement: React.FC = () => { const myButton = (email: string, right: boolean) => ( <>