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

Created View Component , Add Employee #65

Merged
merged 6 commits into from
Jan 4, 2025
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
2 changes: 2 additions & 0 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import {
DispenseDrugByID,
} from './pages';

import { action as AdminAddUserAction } from './pages/AdminAddUser';
import { action as registerAction } from './pages/Register';
import { action as loginAction } from './pages/Login';
import { loader as dashboardLoader } from './pages/Dashboard';
Expand Down Expand Up @@ -58,6 +59,7 @@ const router = createBrowserRouter([
{
path: 'adduser',
element: <AdminAddUser />,
action: AdminAddUserAction,
},
{
path: 'dispense',
Expand Down
103 changes: 103 additions & 0 deletions src/components/Modal.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
import React from 'react';
import PropTypes from 'prop-types';

const Modal = ({ isOpen, onClose, record }) => {
if (!isOpen) return null;

return (
<div style={overlayStyle}>
<div style={modalStyle}>
<button onClick={onClose} style={closeButtonStyle}>
X
</button>
<h2 style={h2Style}>Medication Details</h2>
{Object.entries(record)
.filter(
([key]) => key.toUpperCase() !== '__V' && key.toUpperCase() !== 'CREATEDBY'
) // Exclude unwanted keys
.map(([key, value]) => (
<p style={pStyle} key={key}>
<strong>{key}:</strong> {value}
</p>
))}
{/* <p style={pStyle}>
<strong>name:</strong> {record.name}
</p>
<p style={pStyle}>
<strong>genericName:</strong> {record.genericName}
</p>
<p style={pStyle}>
<strong>class:</strong> {record.class}
</p>
<p style={pStyle}>
<strong>quantity:</strong> {record.quantity}
</p>
<p style={pStyle}>
<strong>expirationDate:</strong> {record.expirationDate}
</p>
<p style={pStyle}>
<strong>lot:</strong> {record.lot}
</p>
<p style={pStyle}>
<strong>ndcNumber:</strong> {record.ndcNumber}
</p> */}
</div>
</div>
);
};

const overlayStyle = {
position: 'fixed',
top: 300,
left: 700,
right: 700,
bottom: 300,
backgroundColor: '#f5f5f5',
display: 'flex',
justifyContent: 'center',
alignItems: 'center',
border: 'solid',
};

const modalStyle = {
backgroundColor: 'white',
padding: '20px',
borderRadius: '8px',
minWidth: '60%',
minHeight: '80%',
border: 'solid',
};

const closeButtonStyle = {
position: 'absolute',
top: '10px',
right: '10px',
background: 'none',
border: 'none',
fontSize: '20px',
cursor: 'pointer',
};

const pStyle = {
fontSize: 14,
fontWeight: 'bold',
textAlign: 'left',
lineHeight: 1,
padding: '8px',
margin: '20px',
textTransform: 'uppercase',
};

const h2Style = {
alignItems: 'center',
padding: '0px',
margin: '40px',
color: 'blue',
};
Modal.propTypes = {
isOpen: PropTypes.bool.isRequired,
onClose: PropTypes.func.isRequired,
record: PropTypes.object.isRequired,
};

export default Modal;
106 changes: 75 additions & 31 deletions src/pages/AdminAddUser.jsx
Original file line number Diff line number Diff line change
@@ -1,59 +1,102 @@
import { Form, redirect, useNavigation } from 'react-router-dom';
import styled from 'styled-components';
import { FormRow, Logo } from '../components';
import customFetch from '../util/customFetch';
import { toast } from 'react-toastify';
import { useEffect } from 'react';

//formData - is an api, gives back an array of arrays, must have name same as database
export const action = async ({ request }) => {
const formData = await request.formData();
console.log(formData);
const data = Object.fromEntries(formData);
console.log(data);
try {
await customFetch.post('/auth/signup', data);
toast.success('Adding Employee Successful');

return redirect('/dashboard/UserManagement');
} catch (error) {
toast.error(error?.response?.data?.msg);
return error;
}
};

const AdminAddUser = () => {
useEffect(() => {
document.querySelector('form').reset();
}, []);

const navigation = useNavigation();

const isSubmitting = navigation.state === 'submitting';
return (
<Wrapper>
<form className="form">
<Form method="post" className="form" autoComplete="off" key={Date.now()}>
<Logo />
<h4>Add Employee</h4>
<h4>Add Employee </h4>
<FormRow
type="text"
name="name"
labelText="name"
defaultValue="DefaultName"
placeholder="NAME"
/>
<FormRow
type="text"
name="lastName"
labelText="lastname"
defaultValue="DefaultLastName"
placeholder="LAST NAME"
/>
<FormRow
type="text"
name="store"
labelText="store"
defaultValue="DefaultStore"
placeholder="STORE"
/>
<FormRow
type="text"
name="role"
labelText="role"
defaultValue="Admin"
placeholder="ROLE"
placeholder="name"
defaultValue=""
/>
<div className="form-row">
<label className="form-label" htmlFor="role">
store:
</label>
<select className="form-input" id="store" name="store" defaultValue="" required>
<option value="" disabled>
-- Choose a store --
</option>
<option value="Store 1">Store 1</option>
<option value="Store 2">Store 2</option>
</select>
</div>
<div className="form-row">
<label className="form-label" htmlFor="role">
role:
</label>
<select className="form-input" id="role" name="role" defaultValue="" required>
<option value="" disabled>
-- Choose a role --
</option>
<option value="admin">admin</option>
<option value="inventoryManager">inventoryManager</option>
<option value="clerk">clerk</option>
</select>
</div>
<FormRow
type="email"
name="email"
labelText="email"
defaultValue="[email protected]"
placeholder="EMAIL"
placeholder="email"
defaultValue=""
autoComplete="off"
/>
<FormRow
type="password"
name="password"
labelText="password"
placeholder="password"
defaultValue=""
autoComplete="new-password"
/>
<button type="submit" className="btn btn-block">
Send Permissions Email
<button type="submit" className="btn btn-block" disabled={isSubmitting}>
{isSubmitting ? 'submitting...' : 'submit'}
</button>
</form>
</Form>
</Wrapper>
);
};

export default AdminAddUser;

const Wrapper = styled.section`
min-height: 100vh;
display: grid;
align-items: center;
.logo {
display: block;
margin: 0 auto;
Expand All @@ -68,7 +111,6 @@ const Wrapper = styled.section`
}
.form-input {
background-color: var(--grey-50);
text-transform: uppercase;
}
h4 {
text-align: center;
Expand All @@ -87,4 +129,6 @@ const Wrapper = styled.section`
letter-spacing: var(--letter-spacing);
margin-left: 0.25rem;
}
.custom-select {
}
`;
38 changes: 35 additions & 3 deletions src/pages/AllDrugs.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,13 @@ import Pagination from '../components/Pagination';
import { useNavigate } from 'react-router-dom';
import { FaEye, FaEdit, FaTrash } from 'react-icons/fa';
import { useDashboardContext } from './Dashboard';
import Modal from '../components/Modal';

// import { TbChevronsDownLeft } from 'react-icons/tb';

const AllDrugs = () => {
const { user, store } = useDashboardContext();

const roleOfUser = user.role;
console.log(roleOfUser);
console.log(store);
Expand All @@ -27,9 +30,30 @@ const AllDrugs = () => {
'ndcNumber',
'view/edit/delete/dispense',
];
const [isModalOpen, setIsModalOpen] = useState(false);
const [record, setRecord] = useState({
name: '',
genericName: '',
class: '',
quantity: '',
expirationDate: '',
lot: '',
ndcNumber: '',
});
const openModal = () => {
setIsModalOpen(true);
};

const editNavigate = useNavigate();
const closeModal = () => {
setIsModalOpen(false);
};

const handleView = (drugId) => {
const selectedDrug = data.find((drug) => drug._id === drugId);
setRecord(selectedDrug);
openModal();
};
const editNavigate = useNavigate();
const handleEdit = (drugId) => {
editNavigate(`/dashboard/edit/${drugId}`);
};
Expand Down Expand Up @@ -69,6 +93,7 @@ const AllDrugs = () => {
setFilterData(alarmFilterData);
} else {
setData(data.data);
console.log(data.data);
setFilterData(data.data);
}

Expand Down Expand Up @@ -106,7 +131,6 @@ const AllDrugs = () => {
<FaFilter className="filter-icon" />
</button>
</div>
<div></div>
<div className="search-box">
<div className="search-icon">
<IoIosSearch />
Expand Down Expand Up @@ -134,9 +158,17 @@ const AllDrugs = () => {
<div key={`${rowIndex}-${colIndex}`} className="grid-item">
{label === 'view/edit/delete/dispense' ? (
<div className="actions">
<button className="action-button view">
<button
className="action-button view"
onClick={() => handleView(drug._id)}
>
<FaEye />
</button>
<Modal
isOpen={isModalOpen}
onClose={closeModal}
record={record}
/>
<button
className="action-button edit"
onClick={() => handleEdit(drug._id)}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/FilterSearch.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -209,11 +209,12 @@ const Wrapper = styled.section`
border-radius: 8px;
background-color: #fff;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
border: 'solid';
}
.grid-container {
display: grid;
grid-template-columns: repeat(2, 1fr);
grid-template-rows: repeat(4, 1fr);
grid-template-columns: 1fr 1fr; // repeat(2, 1fr);
grid-template-rows: repeat(2, 1fr);
padding: 1rem;
}
.date {
Expand Down
6 changes: 3 additions & 3 deletions src/pages/User.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const User = () => {
role: '',
});

const role = ['Admin', 'inventoryManager', 'clerk'];
const role = ['admin', 'inventoryManager', 'clerk'];
const store = ['Store 1', 'Store 2'];
const [loading, setLoading] = useState(true);
const token = localStorage.getItem('token');
Expand Down Expand Up @@ -89,7 +89,7 @@ const User = () => {
};

const handelPasswordChange = () => {
navigate(`/dashboard/UserChangePassword`);
navigate(`/dashboard/UserChangePassword`, { state: { userId: id } });
};

return (
Expand Down Expand Up @@ -119,7 +119,7 @@ const User = () => {
/>
</div>
<div className="form-row">
<label className="form-label">Roll: </label>
<label className="form-label">Role: </label>
<select
className="form-input"
id="role"
Expand Down
Loading
Loading