From 056849e51c539d0bc409a31f5332dac4beeabe40 Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Mon, 24 Feb 2020 10:27:13 +0100 Subject: [PATCH] use switch statement in error controller. Added submit button in modal form. Changed appusers endpoint to users --- .gitignore | 3 +- Controllers/AppUsersController.cs | 4 +-- README.md | 1 + Scripts/apiQueries.sh | 1 + Scripts/authentication.sh | 1 + client/src/components/Modal.tsx | 10 +++--- client/src/components/UsersModal.tsx | 32 +++++++++++++++++++- client/src/controllers/ErrorController.tsx | 12 ++++++-- client/src/controllers/ProjectController.tsx | 5 ++- 9 files changed, 56 insertions(+), 13 deletions(-) create mode 100755 Scripts/apiQueries.sh create mode 100755 Scripts/authentication.sh diff --git a/.gitignore b/.gitignore index 01d8a9f..b033101 100644 --- a/.gitignore +++ b/.gitignore @@ -7,5 +7,4 @@ app.db* .DS_Store app.db client/node_modules -client/src/pages/TestPage.tsx -Scripts/ +client/src/pages/TestPage.tsx \ No newline at end of file diff --git a/Controllers/AppUsersController.cs b/Controllers/AppUsersController.cs index 34a1f72..d3ed49a 100644 --- a/Controllers/AppUsersController.cs +++ b/Controllers/AppUsersController.cs @@ -9,8 +9,8 @@ using Microsoft.AspNetCore.Authorization; namespace TicketManager.Controllers { - [Authorize] - [Route("api/v1/[controller]")] + // [Authorize] + [Route("api/v1/users")] [ApiController] public class UsersController : ControllerBase { diff --git a/README.md b/README.md index 01870bc..17b770b 100644 --- a/README.md +++ b/README.md @@ -46,3 +46,4 @@ - [ ] logging - [ ] check useRef, useReducer, dispatch - [ ] error page redirect when offline. +- [ ] ticket/files/activities list placeholders when empty diff --git a/Scripts/apiQueries.sh b/Scripts/apiQueries.sh new file mode 100755 index 0000000..08cee4e --- /dev/null +++ b/Scripts/apiQueries.sh @@ -0,0 +1 @@ +curl --insecure https://localhost:5001/api/v1/ \ No newline at end of file diff --git a/Scripts/authentication.sh b/Scripts/authentication.sh new file mode 100755 index 0000000..3c54e42 --- /dev/null +++ b/Scripts/authentication.sh @@ -0,0 +1 @@ +dotnet add package Microsoft.AspNetCore.Authentication.JwtBearer \ No newline at end of file diff --git a/client/src/components/Modal.tsx b/client/src/components/Modal.tsx index d826e40..73595e6 100644 --- a/client/src/components/Modal.tsx +++ b/client/src/components/Modal.tsx @@ -11,14 +11,14 @@ export const Modal: FC = ({ handleClose, show, children }) => { return (
{children}
- {/*
+
-
*/} +
); }; diff --git a/client/src/components/UsersModal.tsx b/client/src/components/UsersModal.tsx index 24ab07a..0cf92a5 100644 --- a/client/src/components/UsersModal.tsx +++ b/client/src/components/UsersModal.tsx @@ -1,8 +1,11 @@ -import React, { FC, useState, ChangeEvent } from "react"; +import React, { FC, useState, ChangeEvent, useEffect } from "react"; import { Modal } from "./Modal"; import { AvatarList } from "./AvatarList"; import { User } from "../types/User"; import { FilterBar } from "./FilterBar"; +import { HttpResponse } from "../types/HttpResponse"; +import { get } from "../utils/http"; +import { Constants } from "../utils/Constants"; interface IProps { show: boolean; @@ -17,6 +20,32 @@ export const UsersModal: FC = ({ show, handleClose, users }) => { ) => { setFilterText(e.target.value); }; + const [allUsers, setAllUsers] = useState(); + + async function httpGet(): Promise { + try { + const response: HttpResponse = await get( + `${Constants.usersURI}` + ); + if (response.parsedBody !== undefined) { + setAllUsers(response.parsedBody); + // setIsLoading(false); + } + } catch (ex) { + // setHasError(true); + // setError(ex); + } + } + + useEffect(() => { + // if (id !== undefined) { + httpGet(); + // } else { + // setHasError(true); + // setError("Bad Request"); + // } + }, []); + return (
@@ -40,6 +69,7 @@ export const UsersModal: FC = ({ show, handleClose, users }) => { handleChange={handleChange} />
+ {/*
{allUsers}
*/}
    {users.map((u: User) => ( diff --git a/client/src/controllers/ErrorController.tsx b/client/src/controllers/ErrorController.tsx index e36007a..4376691 100644 --- a/client/src/controllers/ErrorController.tsx +++ b/client/src/controllers/ErrorController.tsx @@ -6,6 +6,14 @@ interface IProps { } export const ErrorController: FC = ({ error }) => { - if (error === "Not Found") return ; - return <>; + switch (error) { + case "Bad Request": + return ; + + case "Not Found": + return ; + + default: + return ; + } }; diff --git a/client/src/controllers/ProjectController.tsx b/client/src/controllers/ProjectController.tsx index c43e9e6..e6d37fe 100644 --- a/client/src/controllers/ProjectController.tsx +++ b/client/src/controllers/ProjectController.tsx @@ -13,7 +13,7 @@ export const ProjectController: FC = () => { const [project, setProject] = useState({} as Project); const [isLoading, setIsLoading] = useState(true); const [hasError, setHasError] = useState(false); - const [error, setError] = useState(); + const [error, setError] = useState(""); const { id } = useParams(); async function httpGet(id: string): Promise { @@ -34,6 +34,9 @@ export const ProjectController: FC = () => { useEffect(() => { if (id !== undefined) { httpGet(id); + } else { + setHasError(true); + setError("Bad Request"); } }, [id]);