diff --git a/src/components/Button.tsx b/src/components/Button.tsx index e03f81c..2809495 100644 --- a/src/components/Button.tsx +++ b/src/components/Button.tsx @@ -25,8 +25,8 @@ const StyledButton = styled.button` } `; -const Button: React.FC = (props) => { - return {props.children}; +const Button: React.FC = ({children, onClick}) => { + return {children}; }; export default Button; diff --git a/src/components/CreateTask.tsx b/src/components/CreateTask.tsx index 8e74560..77e4597 100644 --- a/src/components/CreateTask.tsx +++ b/src/components/CreateTask.tsx @@ -1,9 +1,10 @@ -import React, { ReactEventHandler, useState } from "react"; +import React, { useState } from "react"; import styled from "styled-components"; import "../../node_modules/bootstrap/dist/css/bootstrap.min.css"; import { connect } from "react-redux"; import * as actions from "../store/actions/actions"; import { withRouter } from "react-router-dom"; +import { RootState, TaddToDo } from "../types/types"; import dayjs from "dayjs"; const StyledTasks = styled.div` @@ -26,7 +27,29 @@ const StyledTasks = styled.div` } `; -const CreateTask = (props: any) => { +interface CreateTaskPropTypes { + isAuth: boolean; + idToken: string; + userId: string; + addToDo: ( + taskName: string, + taskDesc: string, + taskType: string, + isImportant: boolean, + date: string, + idToken: string, + userId: string + ) => void; + history: { push: Function }; +} + +const CreateTask: React.FC = ({ + isAuth, + idToken, + userId, + addToDo, + history, +}: CreateTaskPropTypes) => { const [taskName, setTaskName] = useState(""); const [taskDesc, setTaskDesc] = useState(""); const [taskType, setTaskType] = useState("bussiness"); @@ -35,27 +58,27 @@ const CreateTask = (props: any) => { const currDate = dayjs(new Date()).format("YYYY-MM-DD"); - const addTaskHandler = () => { + const addTaskHandler = (): void => { const isValid = formValidator(); if (isValid) { - if (props.isAuth) { - props.addToDo( + if (isAuth) { + addToDo( taskName, taskDesc, taskType, isImportant, date, - props.idToken, - props.userId + idToken, + userId ); clearFormHandler(); } else { - props.history.push("/login"); + history.push("/login"); } } }; - const clearFormHandler = () => { + const clearFormHandler = (): void => { setTaskName(""); setTaskDesc(""); setTaskType("bussiness"); @@ -63,15 +86,17 @@ const CreateTask = (props: any) => { setDate(""); }; - const radioButtonsHandler = (type: string) => { + const radioButtonsHandler = (type: string): void => { setTaskType(type); }; - const importantButtonsHandler = (e: any) => { + const importantButtonsHandler = ( + e: React.ChangeEvent + ): void => { if (e.target.value === "true") setIsImportant(true); }; - const formValidator = () => { + const formValidator = (): true | undefined => { if (taskName.length > 1 && taskDesc.length > 1 && date.length > 1) { return true; } else { @@ -83,7 +108,6 @@ const CreateTask = (props: any) => {

Create Task

-
{ onChange={(e) => setTaskName(e.target.value)} />
-
-
{ ); }; -interface RootState { - isAuth: boolean; - idToken: string; - userId: string; -} - const mapStateToProps = (state: RootState) => { return { isAuth: state.isAuth, @@ -202,7 +218,6 @@ const mapDispatchToProps = (dispatch: any) => { }; }; -export default connect( - mapStateToProps, - mapDispatchToProps -)(withRouter(CreateTask)); +export default withRouter( + connect(mapStateToProps, mapDispatchToProps)(CreateTask) +); diff --git a/src/components/Header.tsx b/src/components/Header.tsx index eeabcce..7a4d4bc 100644 --- a/src/components/Header.tsx +++ b/src/components/Header.tsx @@ -4,6 +4,7 @@ import { NavLink } from "react-router-dom"; import Button from "./Button"; import * as actions from "../store/actions/actions"; import { connect } from "react-redux"; +import { RootState } from "../types/types"; const StyledHeader = styled.div` height: 8%; @@ -41,7 +42,7 @@ interface Props { const Header: React.FC = (props: Props) => { - const logoutHandler = ()=>{ + const logoutHandler = (): void=>{ props.isAuth && props.logout(); } @@ -67,10 +68,6 @@ const Header: React.FC = (props: Props) => { ); }; -interface RootState { - isAuth: boolean; -} - const mapStateToProps = (state: RootState) => { return { isAuth: state.isAuth, diff --git a/src/components/Login.tsx b/src/components/Login.tsx index 82aae23..cfa6f5f 100644 --- a/src/components/Login.tsx +++ b/src/components/Login.tsx @@ -4,6 +4,7 @@ import styled from "styled-components"; import "../../node_modules/bootstrap/dist/css/bootstrap.min.css"; import * as actions from "../store/actions/actions"; import { Redirect } from "react-router-dom"; +import { RootState } from "../types/types"; const StyledForm = styled.div` width: 100%; @@ -89,11 +90,6 @@ const Login = (props: any) => { ); }; -interface RootState { - isAuth: boolean; - redirectTo: string; -} - const mapStateToProps = (state: RootState) => { return { isAuth: state.isAuth, diff --git a/src/components/SideDrawer.tsx b/src/components/SideDrawer.tsx index c7db587..a0ae9bf 100644 --- a/src/components/SideDrawer.tsx +++ b/src/components/SideDrawer.tsx @@ -57,73 +57,53 @@ interface Props { close: () => void; } -const SideDrawer = (props: Props) => { - return ( - -
    -
  • - - - All - -
  • -
  • - - - Finished - -
  • -
  • - - - On going - -
  • -
  • - - - Bussiness - -
  • -
  • - - - Personal - -
  • -
  • - - - Important - -
  • -
  • - - - Canceled - -
  • -
-
- ); -}; +const SideDrawer: React.FC = ({ close }: Props) => ( + +
    +
  • + + + All + +
  • +
  • + + + Finished + +
  • +
  • + + + On going + +
  • +
  • + + + Bussiness + +
  • +
  • + + + Personal + +
  • +
  • + + + Important + +
  • +
  • + + + Canceled + +
  • +
+
+); export default SideDrawer; diff --git a/src/components/TodoList.tsx b/src/components/TodoList.tsx index 604bd1f..e5e8506 100644 --- a/src/components/TodoList.tsx +++ b/src/components/TodoList.tsx @@ -1,4 +1,4 @@ -import React, { useEffect, useState } from "react"; +import React, { useEffect } from "react"; import * as actions from "../store/actions/actions"; import "../../node_modules/bootstrap/dist/css/bootstrap.min.css"; import { connect } from "react-redux"; @@ -34,7 +34,7 @@ const TodoList = (props: any) => { props.isAuth && props.loadToDos(props.userId, props.idToken); }, []); - const taskType = props.match.path.substring(1); + const taskType = props.match.path.substring(1).toLowerCase(); const finishTaskHandler = (hash: string, idToken: string) => props.finishToDo(hash, idToken, props.todos); @@ -82,7 +82,7 @@ const TodoList = (props: any) => {
); - } else if (taskType === "all" && todo.isFinished === false) { + } else if (taskType === "all") { return (
{ todo.isFinished === false && (dayjs(new Date()).diff(todo.date) < 0 || dayjs(new Date()).format("YYYY-MM-DD") === todo.date) && - taskType === "current" + taskType === "current" && todo.isCanceled === false ) { return (
{
); - } else if (todo.isCanceled === true && taskType === "Canceled") { + } else if (todo.isCanceled === true && taskType === "canceled") { return (
; + isLoading: boolean; +} + +export interface dispatchToProps { + loadToDos: Function; + finishToDo: Function; + deleteToDo: Function; + cancelToDo: Function; +} + +export interface ToDoDTO { + hash: string; + taskName: string; + taskDesc: string; + taskType: taskType; + isImportant: boolean; + date: string; + userId: string; + isFinished: boolean; + isCanceled: boolean; +} + +type taskType = "bussiness" | "personal"; + +export type TaddToDo = { + name: string; + desc: string; + type: string; + important: boolean; + date: string; + token: string; + userId: string; +}; + +type ActionAddToDo = { + type: "ADD_SUCCESS" | "ADD_FAIL"; + error?: string; +}; +export type Actions = ActionAddToDo;