From 3aac8daf196fae500a2d550020d2151976d6d94c Mon Sep 17 00:00:00 2001 From: Ruidy Nemausat Date: Tue, 5 May 2020 15:39:31 +0200 Subject: [PATCH] error handling project and ticket submit forms --- Models/Ticket.cs | 2 +- Resources/Tickets/NewTicketDTO.cs | 2 +- Resources/Tickets/TicketDTO.cs | 2 +- Resources/Tickets/TicketDTORead.cs | 2 +- app.db | Bin 106496 -> 106496 bytes .../src/components/Modals/NewProjectModal.tsx | 19 ++++++++++--- .../src/components/Modals/NewTicketModal.tsx | 26 +++++++++++++----- client/src/utils/methods.ts | 5 ++++ 8 files changed, 43 insertions(+), 15 deletions(-) diff --git a/Models/Ticket.cs b/Models/Ticket.cs index 3ebeefb..a3a580d 100644 --- a/Models/Ticket.cs +++ b/Models/Ticket.cs @@ -28,7 +28,7 @@ namespace TicketManager.Models public Impact Impact { get; set; } = Impact.Undefined; public Difficulty Difficulty { get; set; } = Difficulty.Undefined; public Category Category { get; set; } = Category.Undefined; - public Guid CreatorId { get; set; } + public string CreatorId { get; set; } [Display(Name = "Project")] public Project Project { get; set; } diff --git a/Resources/Tickets/NewTicketDTO.cs b/Resources/Tickets/NewTicketDTO.cs index c1e01bb..92b3f96 100644 --- a/Resources/Tickets/NewTicketDTO.cs +++ b/Resources/Tickets/NewTicketDTO.cs @@ -22,7 +22,7 @@ namespace TicketManager.Resources public int Category { get; set; } [Required] - public Guid CreatorId { get; set; } + public string CreatorId { get; set; } [Required] public int ProjectId { get; set; } } diff --git a/Resources/Tickets/TicketDTO.cs b/Resources/Tickets/TicketDTO.cs index 46cfe75..8380a31 100644 --- a/Resources/Tickets/TicketDTO.cs +++ b/Resources/Tickets/TicketDTO.cs @@ -47,7 +47,7 @@ namespace TicketManager.Resources public string Category { get; set; } - public Guid CreatorId { get; set; } + public string CreatorId { get; set; } public ProjectDTORequest Project { get; set; } diff --git a/Resources/Tickets/TicketDTORead.cs b/Resources/Tickets/TicketDTORead.cs index 620a044..ee3a4f9 100644 --- a/Resources/Tickets/TicketDTORead.cs +++ b/Resources/Tickets/TicketDTORead.cs @@ -44,7 +44,7 @@ namespace TicketManager.Resources public string Category { get; set; } - public Guid CreatorId { get; set; } + public string CreatorId { get; set; } public List Notes { get; set; } = new List(); public List Files { get; set; } = new List(); diff --git a/app.db b/app.db index 26a5986d836fabfa37891b8817e4b20d4e32edcf..6fa35e26736f50d719eca8142e9a4f725f9461cf 100644 GIT binary patch delta 480 zcmZoTz}9epZ39by5IfH_2L9Rnf_!?sGkN8Brt$6FEGW>xvw2z!50kr`s-w3=BM+A(_e9sU^kSOw7`ZP__&&|8)jdetQP~b^I;-QT$K& z?Sbyl{%iaZ{Hyu<`E7s-wfNbjSs2Y3 zIVT6&i?VZQu`q@*GEGm^XVjS7)?ddcJ(+caITKIaWI=(B&BrFJ6)bxf4uWssBy`i7AcXbMQg#n-j8ASJORRUs42XU67M2Bvz(7UpIa7D#?JFt7q6 zCT5Tu7&$gSoTJ<}aPj-oR+e#9s>3YtGNg!py)ZGrg*xu?r{{JDq(3 WNDgGKJU<&NGb1C1%=F~>jB^3wt8`}o delta 352 zcmZoTz}9epZ39by02|LV2L9Rnf_!?sGkN8Brfn7!XyVyCEry55sYq4X(U>zdpeR2p zHMv9~B(=E2vqZgEAyJ_O$TTuAGSD?J(KWPCFf_3;1|kDJV@neYV{@2{vBBh=SiQ|c z@mB=2I2afhcsN5cle1Gxin*DXr5T}YXs+s(!{UpiuI3_6cAib^hte^BLy?02pXtfB*mh diff --git a/client/src/components/Modals/NewProjectModal.tsx b/client/src/components/Modals/NewProjectModal.tsx index a9acc2d..ad8fa35 100644 --- a/client/src/components/Modals/NewProjectModal.tsx +++ b/client/src/components/Modals/NewProjectModal.tsx @@ -1,9 +1,11 @@ import React, { FC, useState, FormEvent } from "react"; import { TextField } from "@material-ui/core"; +import Modal from "./Modal"; +import Preloader from "../Preloader"; import { useAuth0 } from "../../authentication/auth0"; import { ProjectService } from "../../services"; -import Modal from "./Modal"; import { getUID } from "../../authentication/helpers"; +import { today } from "../../utils/methods"; interface IProps { show: boolean; @@ -13,11 +15,13 @@ interface IProps { const NewProjectModal: FC = ({ show, handleClose }) => { const [title, setTitle] = useState(""); const [description, setDescription] = useState(""); - const [endingDate, setEndingDate] = useState(""); + const [endingDate, setEndingDate] = useState(today()); + const [loading, setLoading] = useState(false); const { getTokenSilently, user } = useAuth0(); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); + setLoading(true); let newProject = { title: title, description: description, @@ -27,11 +31,18 @@ const NewProjectModal: FC = ({ show, handleClose }) => { const token = await getTokenSilently(); const Projects = new ProjectService(token); - await Projects.add(newProject); + Projects.add(newProject).catch((err) => console.error(err)); + setLoading(false); + setTitle(""); + setDescription(""); + setEndingDate(today()); + handleClose(); }; - return ( + return loading ? ( + + ) : ( ({ })); const NewTicketModal: FC = ({ show, handleClose, allProjects }) => { - const [title, setTitle] = useState(""); - const [description, setDescription] = useState(""); - const [endingDate, setEndingDate] = useState(""); - + const { getTokenSilently, user } = useAuth0(); const { url } = useRouteMatch(); const id = url.split("/")[2]; const [projectId, setProjectId] = useState(id); + const [title, setTitle] = useState(""); + const [description, setDescription] = useState(""); + const [endingDate, setEndingDate] = useState(today()); const [categoryID, setCategoryID] = useState(1); const [impactID, setImpactID] = useState(1); const [difficultyID, setDifficultyID] = useState(1); - const { getTokenSilently, user } = useAuth0(); + const [loading, setLoading] = useState(false); const handleSubmit = async (e: FormEvent) => { e.preventDefault(); + setLoading(true); let newTicket = { title: title, description: description, @@ -56,12 +59,21 @@ const NewTicketModal: FC = ({ show, handleClose, allProjects }) => { const token = await getTokenSilently(); const Tickets = new TicketService(token); - await Tickets.add(newTicket); + Tickets.add(newTicket).catch((err) => console.error(err)); + setLoading(false); + setTitle(""); + setDescription(""); + setEndingDate(today()); + setCategoryID(1); + setImpactID(1); + setDifficultyID(1); handleClose(); }; const classes = useStyles(); - return ( + return loading ? ( + + ) : ( number = (endDate: string) => { }; export default getRemainingdays; + +/** + * get today date + */ +export const today = (): string => new Date().toISOString().split("T")[0];