Skip to content

Commit

Permalink
client
Browse files Browse the repository at this point in the history
  • Loading branch information
mnnkhndlwl committed Aug 4, 2023
1 parent 455fe5e commit d82d2d3
Show file tree
Hide file tree
Showing 10 changed files with 79 additions and 62 deletions.
4 changes: 2 additions & 2 deletions client/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<link rel="icon" type="image/svg+xml" href="/vite.png" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Vite + React</title>
<title>Task Manager</title>
</head>
<body>
<div id="root"></div>
Expand Down
Binary file added client/public/vite.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion client/public/vite.svg

This file was deleted.

14 changes: 6 additions & 8 deletions client/src/App.jsx
Original file line number Diff line number Diff line change
@@ -1,27 +1,25 @@
import './App.css';
import "./App.css";
import { BrowserRouter, Routes, Route } from "react-router-dom";
import Login from './pages/Login';
import Login from "./pages/Login";
import Home from "./pages/Home";
import { useSelector } from "react-redux";
import Signin from './pages/Signin';
import Signin from "./pages/Signin";

function App() {

const { currentUser } = useSelector((state) => state.user);

return (
<>
<BrowserRouter>
<BrowserRouter>
<Routes>
<Route path="/">
<Route index element={currentUser ? <Home /> : <Login />} />
<Route path="signin" element={<Signin />} />
</Route>
</Routes>

</BrowserRouter>
</>
)
);
}

export default App
export default App;
25 changes: 12 additions & 13 deletions client/src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
import * as React from 'react';
import AppBar from '@mui/material/AppBar';
import Box from '@mui/material/Box';
import Toolbar from '@mui/material/Toolbar';
import Typography from '@mui/material/Typography';
import Button from '@mui/material/Button';
import * as React from "react";
import AppBar from "@mui/material/AppBar";
import Box from "@mui/material/Box";
import Toolbar from "@mui/material/Toolbar";
import Typography from "@mui/material/Typography";
import Button from "@mui/material/Button";
import { logout } from "../redux/userSlice";
import { useDispatch } from "react-redux";
import { useSelector } from 'react-redux';

export default function Navbar() {

const dispatch = useDispatch();
const { currentUser } = useSelector((state) => state.user);

const handleLogout = async (e) => {
e.preventDefault();
dispatch(logout());
localStorage.clear();
dispatch(logout());
localStorage.clear();
};

return (
Expand All @@ -27,9 +24,11 @@ export default function Navbar() {
Task manager
</Typography>

<Button color="inherit" onClick={handleLogout}>Logout</Button>
<Button color="inherit" onClick={handleLogout}>
Logout
</Button>
</Toolbar>
</AppBar>
</Box>
);
}
}
32 changes: 25 additions & 7 deletions client/src/components/TaskCard.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,24 +12,39 @@ import { userRequest } from "../utils/config";
import Modal from "@mui/material/Modal";
import TextField from "@mui/material/TextField";
import Box from "@mui/material/Box";
import { useState } from "react";
import { useFormik } from "formik";
import Button from "@mui/material/Button";
import LinearProgress from "@mui/material/LinearProgress";

const TaskCard = ({ title, desc, isCompleted, index, fetchOrders, id }) => {
const [open, setOpen] = React.useState(false);
const handleOpen = () => setOpen(true);
const handleClose = () => setOpen(false);
const [loading, setLoading] = useState(false);

const handleChanged = async (event) => {
await userRequest.patch(`/api/task/update/${id}`, {
isCompleted: event.target.checked,
});
fetchOrders();
setLoading(true);
try {
await userRequest.patch(`/api/task/update/${id}`, {
isCompleted: event.target.checked,
});
fetchOrders();
setLoading(false);
} catch (error) {
setLoading(false);
}
};

const handleDelete = async () => {
await userRequest.delete(`/api/task/delete/${id}`);
fetchOrders();
try {
setLoading(true);
await userRequest.delete(`/api/task/delete/${id}`);
fetchOrders();
setLoading(false);
} catch (error) {
setLoading(false);
}
};

const style = {
Expand All @@ -51,19 +66,22 @@ const TaskCard = ({ title, desc, isCompleted, index, fetchOrders, id }) => {
},
onSubmit: async ({ title, desc }) => {
try {
setLoading(true);
const res = await userRequest.patch(`/api/task/update/${id}`, {
title: title,
desc: desc,
});
fetchOrders();
setLoading(false);
} catch (error) {
console.log(error);
setLoading(false);
}
},
});

return (
<>
{loading ? <LinearProgress /> : <></>}
<Grid item key={index} xs={12} sm={8} md={4}>
<Card
sx={{
Expand Down
23 changes: 15 additions & 8 deletions client/src/pages/Home.jsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import Navbar from "../components/Navbar";
import * as React from "react";
import { useState } from "react";
import Box from "@mui/material/Box";
import Button from "@mui/material/Button";
import Modal from "@mui/material/Modal";
Expand All @@ -11,7 +12,8 @@ import Typography from "@mui/material/Typography";
import TextField from "@mui/material/TextField";
import Grid from "@mui/material/Grid";
import TaskCard from "../components/TaskCard";
import Container from '@mui/material/Container';
import Container from "@mui/material/Container";
import LinearProgress from "@mui/material/LinearProgress";

const style = {
position: "absolute",
Expand All @@ -28,7 +30,7 @@ const style = {
const stylecards = {
position: "absolute",
top: "25%",
m:5,
m: 5,
flexGrow: 1,
};

Expand All @@ -45,10 +47,13 @@ function Home() {
const handleClose = () => setOpen(false);
const [error, setError] = React.useState("");
const [tasks, setTasks] = React.useState([]);
const [loading, setLoading] = useState(false);

const fetchOrders = async () => {
setLoading(true);
const res = await userRequest.get(`/api/task/get`);
setTasks(res.data);
setLoading(false);
};

React.useEffect(() => {
Expand All @@ -60,11 +65,13 @@ function Home() {
validationSchema: TaskSchema,
onSubmit: async ({ title, desc }) => {
try {
setLoading(true);
const res = await userRequest.post("/api/task/add", {
title,
desc,
});
fetchOrders();
setLoading(false);
} catch (error) {
setError(error.response["data"]["message"]);
}
Expand All @@ -74,6 +81,7 @@ function Home() {
return (
<>
<Navbar />
{loading ? <LinearProgress /> : <></>}
<Button
sx={buttonstyle}
variant="contained"
Expand Down Expand Up @@ -134,23 +142,22 @@ function Home() {
<Typography sx={{ color: "red" }}>{error}</Typography>
</Box>
</Box>

</Modal>
<Container sx={{ py: 8,my: 5 }} maxWidth="md">
{/* End hero unit */}
<Grid container spacing={4}>
<Container sx={{ py: 8, my: 5 }} maxWidth="md">
{/* End hero unit */}
<Grid container spacing={4}>
{tasks.map((task, index) => (
<TaskCard
title={task.title}
id={task._id}
index={index}
key={task._id}
desc={task.desc}
isCompleted={task.isCompleted}
fetchOrders={fetchOrders}
/>
))}
</Grid>
</Container>
</Container>
</>
);
}
Expand Down
20 changes: 9 additions & 11 deletions client/src/pages/Login.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@ import Avatar from "@mui/material/Avatar";
import Button from "@mui/material/Button";
import CssBaseline from "@mui/material/CssBaseline";
import TextField from "@mui/material/TextField";
import FormControlLabel from "@mui/material/FormControlLabel";
import Checkbox from "@mui/material/Checkbox";
import { Link } from "react-router-dom";
import Paper from "@mui/material/Paper";
import Box from "@mui/material/Box";
Expand All @@ -16,9 +14,9 @@ import { createTheme, ThemeProvider } from "@mui/material/styles";
import { useFormik } from "formik";
import { LoginInitialValues, LoginSchema } from "../schemas/loginSchema";
import { useDispatch } from "react-redux";
import {publicRequest} from "../utils/config";
import { publicRequest } from "../utils/config";
import { loginFailure, loginStart, loginSuccess } from "../redux/userSlice";

import LinearProgress from "@mui/material/LinearProgress";

function Copyright(props) {
return (
Expand All @@ -43,6 +41,7 @@ function Copyright(props) {
const defaultTheme = createTheme();

function Login() {
const [loading, setLoading] = useState(false);
const [error, setError] = useState("");
const dispatch = useDispatch();

Expand All @@ -51,12 +50,14 @@ function Login() {
validationSchema: LoginSchema,
onSubmit: async ({ name, password }) => {
dispatch(loginStart());
setLoading(true);
try {
const res = await publicRequest.post("/api/users/login", {
name,
password,
});
dispatch(loginSuccess(res.data));
setLoading(false);
} catch (error) {
setError(error.response["data"]["message"]);
dispatch(loginFailure());
Expand All @@ -66,6 +67,7 @@ function Login() {

return (
<ThemeProvider theme={defaultTheme}>
{loading ? <LinearProgress /> : <></>}
<Grid container component="main" sx={{ height: "100vh" }}>
<CssBaseline />
<Grid
Expand Down Expand Up @@ -118,9 +120,7 @@ function Login() {
value={values.name}
error={touched.name && errors.name !== undefined}
helperText={
touched.name && errors.name !== undefined
? errors.name
: ""
touched.name && errors.name !== undefined ? errors.name : ""
}
/>
<TextField
Expand Down Expand Up @@ -149,15 +149,13 @@ function Login() {
</Button>
<Typography sx={{ color: "red" }}>{error}</Typography>
<Grid container>
<Grid item xs>
<Grid item xs>
<Link href="#" variant="body2">
Forgot password?
</Link>
</Grid>
<Grid item xs>
<Link to="/signin">
{"Don't have an account? Sign Up"}
</Link>
<Link to="/signin">{"Don't have an account? Sign Up"}</Link>
</Grid>
</Grid>
<Copyright sx={{ mt: 5 }} />
Expand Down
Loading

0 comments on commit d82d2d3

Please sign in to comment.