error handling project and ticket submit forms

This commit is contained in:
Ruidy Nemausat 2020-05-05 15:39:31 +02:00
parent 302ca0c0ae
commit 3aac8daf19
8 changed files with 43 additions and 15 deletions

View file

@ -28,7 +28,7 @@ namespace TicketManager.Models
public Impact Impact { get; set; } = Impact.Undefined; public Impact Impact { get; set; } = Impact.Undefined;
public Difficulty Difficulty { get; set; } = Difficulty.Undefined; public Difficulty Difficulty { get; set; } = Difficulty.Undefined;
public Category Category { get; set; } = Category.Undefined; public Category Category { get; set; } = Category.Undefined;
public Guid CreatorId { get; set; } public string CreatorId { get; set; }
[Display(Name = "Project")] [Display(Name = "Project")]
public Project Project { get; set; } public Project Project { get; set; }

View file

@ -22,7 +22,7 @@ namespace TicketManager.Resources
public int Category { get; set; } public int Category { get; set; }
[Required] [Required]
public Guid CreatorId { get; set; } public string CreatorId { get; set; }
[Required] [Required]
public int ProjectId { get; set; } public int ProjectId { get; set; }
} }

View file

@ -47,7 +47,7 @@ namespace TicketManager.Resources
public string Category { get; set; } public string Category { get; set; }
public Guid CreatorId { get; set; } public string CreatorId { get; set; }
public ProjectDTORequest Project { get; set; } public ProjectDTORequest Project { get; set; }

View file

@ -44,7 +44,7 @@ namespace TicketManager.Resources
public string Category { get; set; } public string Category { get; set; }
public Guid CreatorId { get; set; } public string CreatorId { get; set; }
public List<Note> Notes { get; set; } = new List<Note>(); public List<Note> Notes { get; set; } = new List<Note>();
public List<File> Files { get; set; } = new List<File>(); public List<File> Files { get; set; } = new List<File>();

BIN
app.db

Binary file not shown.

View file

@ -1,9 +1,11 @@
import React, { FC, useState, FormEvent } from "react"; import React, { FC, useState, FormEvent } from "react";
import { TextField } from "@material-ui/core"; import { TextField } from "@material-ui/core";
import Modal from "./Modal";
import Preloader from "../Preloader";
import { useAuth0 } from "../../authentication/auth0"; import { useAuth0 } from "../../authentication/auth0";
import { ProjectService } from "../../services"; import { ProjectService } from "../../services";
import Modal from "./Modal";
import { getUID } from "../../authentication/helpers"; import { getUID } from "../../authentication/helpers";
import { today } from "../../utils/methods";
interface IProps { interface IProps {
show: boolean; show: boolean;
@ -13,11 +15,13 @@ interface IProps {
const NewProjectModal: FC<IProps> = ({ show, handleClose }) => { const NewProjectModal: FC<IProps> = ({ show, handleClose }) => {
const [title, setTitle] = useState(""); const [title, setTitle] = useState("");
const [description, setDescription] = useState(""); const [description, setDescription] = useState("");
const [endingDate, setEndingDate] = useState(""); const [endingDate, setEndingDate] = useState(today());
const [loading, setLoading] = useState(false);
const { getTokenSilently, user } = useAuth0(); const { getTokenSilently, user } = useAuth0();
const handleSubmit = async (e: FormEvent) => { const handleSubmit = async (e: FormEvent) => {
e.preventDefault(); e.preventDefault();
setLoading(true);
let newProject = { let newProject = {
title: title, title: title,
description: description, description: description,
@ -27,11 +31,18 @@ const NewProjectModal: FC<IProps> = ({ show, handleClose }) => {
const token = await getTokenSilently(); const token = await getTokenSilently();
const Projects = new ProjectService(token); const Projects = new ProjectService(token);
await Projects.add(newProject); Projects.add(newProject).catch((err) => console.error(err));
setLoading(false);
setTitle("");
setDescription("");
setEndingDate(today());
handleClose(); handleClose();
}; };
return ( return loading ? (
<Preloader />
) : (
<Modal <Modal
name="New Project" name="New Project"
show={show} show={show}

View file

@ -15,6 +15,8 @@ import Difficulty from "../../types/enums/difficulty";
import { TicketService } from "../../services"; import { TicketService } from "../../services";
import { useAuth0 } from "../../authentication/auth0"; import { useAuth0 } from "../../authentication/auth0";
import { getUID } from "../../authentication/helpers"; import { getUID } from "../../authentication/helpers";
import { today } from "../../utils/methods";
import Preloader from "../Preloader";
interface IProps { interface IProps {
show: boolean; show: boolean;
@ -29,20 +31,21 @@ const useStyles = makeStyles((theme: Theme) => ({
})); }));
const NewTicketModal: FC<IProps> = ({ show, handleClose, allProjects }) => { const NewTicketModal: FC<IProps> = ({ show, handleClose, allProjects }) => {
const [title, setTitle] = useState(""); const { getTokenSilently, user } = useAuth0();
const [description, setDescription] = useState("");
const [endingDate, setEndingDate] = useState("");
const { url } = useRouteMatch(); const { url } = useRouteMatch();
const id = url.split("/")[2]; const id = url.split("/")[2];
const [projectId, setProjectId] = useState(id); const [projectId, setProjectId] = useState(id);
const [title, setTitle] = useState("");
const [description, setDescription] = useState("");
const [endingDate, setEndingDate] = useState(today());
const [categoryID, setCategoryID] = useState(1); const [categoryID, setCategoryID] = useState(1);
const [impactID, setImpactID] = useState(1); const [impactID, setImpactID] = useState(1);
const [difficultyID, setDifficultyID] = useState(1); const [difficultyID, setDifficultyID] = useState(1);
const { getTokenSilently, user } = useAuth0(); const [loading, setLoading] = useState(false);
const handleSubmit = async (e: FormEvent) => { const handleSubmit = async (e: FormEvent) => {
e.preventDefault(); e.preventDefault();
setLoading(true);
let newTicket = { let newTicket = {
title: title, title: title,
description: description, description: description,
@ -56,12 +59,21 @@ const NewTicketModal: FC<IProps> = ({ show, handleClose, allProjects }) => {
const token = await getTokenSilently(); const token = await getTokenSilently();
const Tickets = new TicketService(token); 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(); handleClose();
}; };
const classes = useStyles(); const classes = useStyles();
return ( return loading ? (
<Preloader />
) : (
<Modal <Modal
name="New Ticket" name="New Ticket"
show={show} show={show}

View file

@ -5,3 +5,8 @@ const getRemainingdays: (endDate: string) => number = (endDate: string) => {
}; };
export default getRemainingdays; export default getRemainingdays;
/**
* get today date
*/
export const today = (): string => new Date().toISOString().split("T")[0];