From 61d189b3d35f6ba744eb7277460237959ef2f6ee Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Wed, 4 Mar 2020 10:54:35 +0100 Subject: [PATCH] handled project selector in newticketform --- Program.cs | 4 --- README.md | 1 + Resources/AppUser/NewAppUserDTO.cs | 3 +- Resources/Project/NewProjectDTO.cs | 2 ++ Resources/Tickets/NewTicketDTO.cs | 8 ++++-- client/src/VM/ProjectVM.ts | 12 ++++++-- client/src/components/Avatar.tsx | 8 +++++- client/src/components/NewTicketForm.tsx | 29 ++++++++++++++++---- client/src/components/NewTicketModal.tsx | 14 ++++++++-- client/src/components/NewTicketTabRouter.tsx | 5 ++-- client/src/components/TabRouter.tsx | 7 +++-- client/src/components/TicketList.tsx | 5 +++- client/src/components/UserTabRouter.tsx | 7 +++-- client/src/controllers/ProjectController.tsx | 18 +++++++++++- client/src/pages/ProjectPage.tsx | 5 +++- client/src/pages/UserPage.tsx | 4 --- 16 files changed, 97 insertions(+), 35 deletions(-) diff --git a/Program.cs b/Program.cs index 35c5cb4..475e324 100644 --- a/Program.cs +++ b/Program.cs @@ -1,7 +1,3 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Threading.Tasks; using Microsoft.AspNetCore.Hosting; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.Hosting; diff --git a/README.md b/README.md index a01d101..7a8d9ad 100644 --- a/README.md +++ b/README.md @@ -50,3 +50,4 @@ - [X] write dtos without circular dependencies. - [ ] use dtoRequest for PutProjects - [ ] render avatarlist after UserModal Update +- [ ] Form validators diff --git a/Resources/AppUser/NewAppUserDTO.cs b/Resources/AppUser/NewAppUserDTO.cs index 824e8fe..1b146e7 100644 --- a/Resources/AppUser/NewAppUserDTO.cs +++ b/Resources/AppUser/NewAppUserDTO.cs @@ -4,10 +4,11 @@ namespace TicketManager.Resources { public class NewAppUserDTO { + [Required] public string FirstName { get; set; } public string LastName { get; set; } public string Presentation { get; set; } - + [Required] [DataType(DataType.EmailAddress)] public string Email { get; set; } diff --git a/Resources/Project/NewProjectDTO.cs b/Resources/Project/NewProjectDTO.cs index e6d1bf9..8043069 100644 --- a/Resources/Project/NewProjectDTO.cs +++ b/Resources/Project/NewProjectDTO.cs @@ -8,7 +8,9 @@ namespace TicketManager.Resources [Required] public string Title { get; set; } public string Description { get; set; } + [Required] public DateTime EndingDate { get; set; } + [Required] public Guid ManagerId { get; set; } } } \ No newline at end of file diff --git a/Resources/Tickets/NewTicketDTO.cs b/Resources/Tickets/NewTicketDTO.cs index 45864d2..a8ebb28 100644 --- a/Resources/Tickets/NewTicketDTO.cs +++ b/Resources/Tickets/NewTicketDTO.cs @@ -8,10 +8,11 @@ namespace TicketManager.Resources { public class NewTicketDTO { + [Required] public string Title { get; set; } - + [Required] public string Description { get; set; } - + [Required] [DataType(DataType.Date)] public DateTime EndingDate { get; set; } @@ -20,8 +21,9 @@ namespace TicketManager.Resources public string Difficulty { get; set; } public string Category { get; set; } - + [Required] public Guid CreatorId { get; set; } + [Required] public int ProjectId { get; set; } } } \ No newline at end of file diff --git a/client/src/VM/ProjectVM.ts b/client/src/VM/ProjectVM.ts index 87faecc..3b89e72 100644 --- a/client/src/VM/ProjectVM.ts +++ b/client/src/VM/ProjectVM.ts @@ -6,7 +6,7 @@ import { User } from "../types/User"; import { getRemainingdays } from "../utils/methods"; export default class ProjectVM { - // public id: number; + public id: number; public title: string; public description: string; public creationDate: string; @@ -22,9 +22,14 @@ export default class ProjectVM { public ticketsTotalCount: number; public ticketsDone: number; public remainingDays: number; + public allProjects: Project[]; - public constructor(project: Project, allUsers: User[]) { - // this.id = project.id; + public constructor( + project: Project, + allUsers: User[], + allProjects: Project[] + ) { + this.id = project.id; this.title = project.title; this.description = project.description; this.creationDate = project.creationDate; @@ -44,5 +49,6 @@ export default class ProjectVM { ? 0 : this.tickets.filter(t => t.status === "Done").length; this.remainingDays = getRemainingdays(project.endingDate); + this.allProjects = allProjects; } } diff --git a/client/src/components/Avatar.tsx b/client/src/components/Avatar.tsx index 37c45c4..91dd6e9 100644 --- a/client/src/components/Avatar.tsx +++ b/client/src/components/Avatar.tsx @@ -6,7 +6,13 @@ interface IProps { export const Avatar: FC = ({ picture }) => { return ( <> - + user avatar ); }; diff --git a/client/src/components/NewTicketForm.tsx b/client/src/components/NewTicketForm.tsx index c105250..97e0108 100644 --- a/client/src/components/NewTicketForm.tsx +++ b/client/src/components/NewTicketForm.tsx @@ -1,4 +1,5 @@ import React, { FC } from "react"; +import { Project } from "../types/Project"; interface IProps { title: string; @@ -7,6 +8,9 @@ interface IProps { setDescription: React.Dispatch>; endingDate: string; setEndingDate: React.Dispatch>; + allProjects: Project[]; + projectId: string; + setProjectId: React.Dispatch>; } export const NewTicketForm: FC = ({ @@ -15,7 +19,10 @@ export const NewTicketForm: FC = ({ description, setDescription, endingDate, - setEndingDate + setEndingDate, + allProjects, + projectId, + setProjectId }) => { return ( <> @@ -62,13 +69,23 @@ export const NewTicketForm: FC = ({
- ) => { + e.preventDefault(); + setProjectId(e.target.value); + }} + > + - - - + {allProjects.map(p => ( + + ))}
diff --git a/client/src/components/NewTicketModal.tsx b/client/src/components/NewTicketModal.tsx index bce42ac..60d6a86 100644 --- a/client/src/components/NewTicketModal.tsx +++ b/client/src/components/NewTicketModal.tsx @@ -5,16 +5,23 @@ import { post } from "../utils/http"; import { Constants } from "../utils/Constants"; import { HttpResponse } from "../types/HttpResponse"; import { NewTicketForm } from "./NewTicketForm"; +import { Project } from "../types/Project"; interface IProps { show: boolean; handleClose(): void; + allProjects: Project[]; } -export const NewTicketModal: FC = ({ show, handleClose }) => { +export const NewTicketModal: FC = ({ + show, + handleClose, + allProjects +}) => { const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); const [endingDate, setEndingDate] = useState(""); + const [projectId, setProjectId] = useState("0"); const handleSubmit: (event: FormEvent) => void = async ( e: FormEvent @@ -25,7 +32,7 @@ export const NewTicketModal: FC = ({ show, handleClose }) => { description: description, endingDate: new Date(endingDate).toISOString(), creatorId: "20bf4b2a-7209-4826-96cd-29c2bc937a94", - projectId: 1 + projectId: parseInt(projectId) }; // console.log(newTicket); const response: HttpResponse = await post( @@ -63,6 +70,9 @@ export const NewTicketModal: FC = ({ show, handleClose }) => { setDescription={setDescription} endingDate={endingDate} setEndingDate={setEndingDate} + allProjects={allProjects} + projectId={projectId} + setProjectId={setProjectId} /> diff --git a/client/src/components/NewTicketTabRouter.tsx b/client/src/components/NewTicketTabRouter.tsx index 200651d..0b68000 100644 --- a/client/src/components/NewTicketTabRouter.tsx +++ b/client/src/components/NewTicketTabRouter.tsx @@ -1,7 +1,6 @@ import React, { FC } from "react"; import { useRouteMatch } from "react-router-dom"; import { TabRouterHeader } from "./TabRouterHeader"; -import { NewTicketForm } from "./NewTicketForm"; interface IProps { tabNames: string[]; @@ -28,14 +27,14 @@ export const NewTicketTabRouter: FC = ({
- + /> */}
); diff --git a/client/src/components/TabRouter.tsx b/client/src/components/TabRouter.tsx index 54c2142..8ecfaba 100644 --- a/client/src/components/TabRouter.tsx +++ b/client/src/components/TabRouter.tsx @@ -7,6 +7,7 @@ import { FileList } from "./AppFileList"; import { Ticket } from "../types/Ticket"; import { AppFile } from "../types/AppFile"; import { Activity } from "../types/Activity"; +import { Project } from "../types/Project"; interface IProps { tickets: Ticket[]; @@ -14,13 +15,15 @@ interface IProps { tabNames: string[]; files: AppFile[]; activities: Activity[]; + allProjects: Project[]; } export const TabRouter: FC = ({ tickets, tabNames, files, - activities + activities, + allProjects }) => { const { url } = useRouteMatch(); @@ -32,7 +35,7 @@ export const TabRouter: FC = ({ - + diff --git a/client/src/components/TicketList.tsx b/client/src/components/TicketList.tsx index 929850e..677af17 100644 --- a/client/src/components/TicketList.tsx +++ b/client/src/components/TicketList.tsx @@ -7,12 +7,14 @@ import { HttpResponse } from "../types/HttpResponse"; import { put } from "../utils/http"; import { Constants } from "../utils/Constants"; import { NewTicketModal } from "./NewTicketModal"; +import { Project } from "../types/Project"; type TicketListProps = { tickets: Ticket[]; + allProjects: Project[]; }; -export const TicketList: FC = ({ tickets }) => { +export const TicketList: FC = ({ tickets, allProjects }) => { const [filterText, setFilterText] = useState(""); const clearFilterText: (e: MouseEvent) => void = (e: MouseEvent) => { setFilterText(""); @@ -42,6 +44,7 @@ export const TicketList: FC = ({ tickets }) => { setShowNew(false); }} show={showNew} + allProjects={allProjects} />

Tickets

= ({ tickets, tabNames, projects }) => {
- {/* - - */} + + + ); diff --git a/client/src/controllers/ProjectController.tsx b/client/src/controllers/ProjectController.tsx index 0252cd5..3d30d04 100644 --- a/client/src/controllers/ProjectController.tsx +++ b/client/src/controllers/ProjectController.tsx @@ -13,6 +13,7 @@ import { User } from "../types/User"; export const ProjectController: FC = () => { const [project, setProject] = useState({} as Project); const [allUsers, setAllUsers] = useState([]); + const [allProjects, setAllProjects] = useState([]); const [isLoading, setIsLoading] = useState(true); const [hasError, setHasError] = useState(false); const [error, setError] = useState(""); @@ -48,10 +49,25 @@ export const ProjectController: FC = () => { } } + async function httpGetAllProjects(): Promise { + try { + const response: HttpResponse = await get( + `${Constants.projectsURI}` + ); + if (response.parsedBody !== undefined) { + setAllProjects((response.parsedBody as unknown) as Project[]); + } + } catch (ex) { + setHasError(true); + setError(ex); + } + } + useEffect(() => { if (id !== undefined) { httpGetProjects(id); httpGetAllUsers(); + httpGetAllProjects(); } else { setHasError(true); setError("Bad Request"); @@ -61,6 +77,6 @@ export const ProjectController: FC = () => { if (hasError) { return ; } - const viewModel = new ProjectVM(project, allUsers); + const viewModel = new ProjectVM(project, allUsers, allProjects); return isLoading ? : ; }; diff --git a/client/src/pages/ProjectPage.tsx b/client/src/pages/ProjectPage.tsx index f7b0219..464d0e4 100644 --- a/client/src/pages/ProjectPage.tsx +++ b/client/src/pages/ProjectPage.tsx @@ -13,6 +13,7 @@ interface IProps { export const ProjectPage: FC = ({ viewModel }) => { const { + // id, title, description, users, @@ -23,7 +24,8 @@ export const ProjectPage: FC = ({ viewModel }) => { ticketsTotalCount, remainingDays, files, - activities + activities, + allProjects } = viewModel; const tabNames: string[] = ["Tickets", "Files"]; //, "Activity"]; @@ -59,6 +61,7 @@ export const ProjectPage: FC = ({ viewModel }) => { tickets={tickets} files={files} activities={activities} + allProjects={allProjects} /> diff --git a/client/src/pages/UserPage.tsx b/client/src/pages/UserPage.tsx index 6641aad..2b908af 100644 --- a/client/src/pages/UserPage.tsx +++ b/client/src/pages/UserPage.tsx @@ -23,10 +23,6 @@ export const UserPage: FC = ({ viewModel }) => { tickets={tickets} /> - {/* // - // - // - // */} ); };