Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Donor page improvements #77 #115

Merged
merged 5 commits into from
Apr 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 47 additions & 7 deletions PantryNodeReact/src/pages/donor.tsx
AbhinavReddy-Dev marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import { useState } from 'react';
import Typography from '@mui/material/Typography';
import AddIcon from '@mui/icons-material/Add';
import { Button, Table, TableBody, TableHead, TableRow, TableContainer, Paper, TableCell, DialogTitle, TextField, DialogContent, Dialog, DialogActions } from '@mui/material';
import ArrowDownwardIcon from '@mui/icons-material/ArrowDownward';
import ArrowUpwardIcon from '@mui/icons-material/ArrowUpward';
Expand All @@ -22,18 +24,41 @@ var Donor = () => {

const [showModal, setShowModal] = useState<boolean>(false);
const [data, setData] = useState<Entry[]>(initialData);
const [emailError, setEmailError] = useState("");
const [isEmailError, setIsEmailError] = useState(false);
const [newEntry, setNewEntry] = useState<Entry>({ name: '', email: '', location: '' });
const [sortConfig, setSortConfig] = useState<SortConfig>({ key: null, direction: null });

const handleAddEntry = (e: React.FormEvent<HTMLFormElement>) => {
e.preventDefault();
console.log(data, "Forma data");
setData([...data, newEntry]);
setNewEntry({ name: '', email: '', location: '' });
setShowModal(false);
};

const handleChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setNewEntry({ ...newEntry, [e.target.name]: e.target.value });
console.log(e.target.value, "test");
};
const handleEmailChange = (e: React.ChangeEvent<HTMLInputElement>) => {
setNewEntry({ ...newEntry, [e.target.name]: e.target.value });
console.log(e.target.value, "email");
let emailValue = e.target.value;

if (emailValue.trim() === "") {
setEmailError("Email is required");
setIsEmailError(true);
return;
}
if (!/\S+@\S+\.\S+/.test(emailValue)) {
setEmailError("Email is invalid");
setIsEmailError(true);
return;
}
setEmailError("");
setIsEmailError(false);

};

const onSort = (key: keyof Entry) => {
Expand Down Expand Up @@ -64,9 +89,21 @@ var Donor = () => {

return <div>

<Button variant="contained" color="primary" onClick={() => setShowModal(true)}>
Add Entry
</Button>
<div style={{ width: '100%', display: 'flex' }}>
<div style={{ flex: '1', textAlign: 'left' }}>

<Typography variant="h6" align="left" sx={{ color: "#8c2332" }}>
<h2> Donor List</h2>
</Typography>
</div>

<div style={{ display: 'flex', flex: '1', textAlign: 'right', flexDirection: 'column', justifyContent: 'center' }}>
<Button variant="contained" color="primary" onClick={() => setShowModal(true)} sx={{ marginLeft: 'auto', paddingRight: 2 }} >
<AddIcon />Add Donor
</Button>
</div>
</div>


<Dialog open={showModal} onClose={() => setShowModal(false)}>
<DialogTitle>Add New Entry</DialogTitle>
Expand All @@ -86,7 +123,10 @@ var Donor = () => {
label="Email"
name="email"
value={newEntry.email}
onChange={handleChange}
autoComplete="email"
onChange={handleEmailChange}
error={Boolean(emailError)}
helperText={emailError}
fullWidth
/>
<TextField
Expand All @@ -102,15 +142,15 @@ var Donor = () => {
<Button onClick={() => setShowModal(false)} color="primary">
Cancel
</Button>
<Button type="submit" color="primary">
<Button type="submit" color="primary" disabled={isEmailError || newEntry.location == '' || newEntry.name == ''}>
Add
</Button>
</DialogActions>
</form>
</DialogContent>
</Dialog>

<TableContainer component={Paper} style={{ marginTop: '1rem' }}>
<TableContainer component={Paper} style={{ marginTop: '1rem', boxShadow: 'none' }}>
<Table>
<TableHead>
<TableRow>
Expand Down Expand Up @@ -154,7 +194,7 @@ var Donor = () => {
</TableBody>
</Table>
</TableContainer>
</div>;
</div >;
};

export default Donor;
5 changes: 2 additions & 3 deletions PantryNodeReact/src/pages/login.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,17 @@ import LockOutlinedIcon from "@mui/icons-material/LockOutlined";
import Typography from "@mui/material/Typography";
import Container from "@mui/material/Container";
import Copyright from "../Components/Copyright";

import { useAppDispatch, useAppSelector } from "../hooks";
import { login } from "../redux-features/user";
import CircularProgress from "@mui/material/CircularProgress";

import { useState } from "react";
import { useFormik } from "formik";

type LoginFormInput = {
interface LoginFormInput {
email?: string;
password?: string;
};

export default function Login() {
const [remember, setRemember] = useState(false);

Expand Down
2 changes: 1 addition & 1 deletion PantryNodeReact/src/pages/register.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import { useState } from "react";
import Success from "./success";
import { useFormik } from "formik";

type RegisterFormInput = {
interface RegisterFormInput {
firstName?: string;
lastName?: string;
phone?: string;
Expand Down
6 changes: 3 additions & 3 deletions PantryNodeReact/src/pages/stock.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import React from "react";
// import { useAppSelector,useAppDispatch } from '../hooks'
// import { login } from '../redux-features/user';

//import { useAppSelector,useAppDispatch } from '../hooks'
//import { login } from '../redux-features/user';

const Stock = () => {

return (
<div>
stock
Expand Down
8 changes: 3 additions & 5 deletions PantryNodeReact/src/redux-features/user.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
import { createSlice, createAsyncThunk } from '@reduxjs/toolkit'
//import { PayloadAction } from '@reduxjs/toolkit'
// import { PayloadAction } from '@reduxjs/toolkit'
import axiosInstance from '../util/axiosInstance'

//Docs: https://redux-toolkit.js.org/api/createAsyncThunk
//Docs: https://redux-toolkit.js.org/introduction/getting-started
// First, create the thunk
export const login = createAsyncThunk(
'user/login',
async (payload: FormData, { fulfillWithValue, rejectWithValue }) =>
axiosInstance.post("auth/login", payload)
.then((res: any) => fulfillWithValue(res))
.catch((err: any) => rejectWithValue(err))
.then((res: any) => fulfillWithValue(res))
.catch((err: any) => rejectWithValue(err))

)


const initialState = {
name: "",
email: "",
Expand Down