Skip to content

Commit

Permalink
Merge pull request #27 from Code-the-Dream-School/farkhondeh-dev1
Browse files Browse the repository at this point in the history
Farkhondeh dev1
  • Loading branch information
ValeriGuerrero authored Dec 4, 2024
2 parents ab80cfc + 78a099b commit 252ae40
Show file tree
Hide file tree
Showing 13 changed files with 289 additions and 16 deletions.
2 changes: 2 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
{
}
10 changes: 8 additions & 2 deletions data.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ const drugData = [
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '3847762793088899',
threshold: '500',
},
{
name: 'salmeterol',
Expand All @@ -77,6 +78,7 @@ const drugData = [
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '12039493890',
threshold: '400',
},
{
name: 'Coumadin',
Expand All @@ -89,18 +91,20 @@ const drugData = [
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '345456575322',
threshold: '200',
},
{
name: 'Tamiflu',
generic: 'Oseltamivir',
class: 'Antiviral',
quantity: '50',
quantity: '0',
expiration: '01/20/2025',
lot: '4',
id: '556677',
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '23789477088734',
threshold: '20',
},
{
name: 'Cymbalta',
Expand All @@ -113,18 +117,20 @@ const drugData = [
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '347373877658',
threshold: '05',
},
{
name: 'Prozac',
generic: 'fluoxetine',
class: 'Antidepressant',
quantity: '10',
expiration: '01/15/2025',
expiration: '01/01/2025',
lot: '6',
id: '889900',
storeId: '1234567',
employeeId: 'inventorymanager1234567',
ndc: '34737387765800',
threshold: '05',
},
];
const drugFormData = [
Expand Down
Binary file added images/expire-soon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/low-stock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added images/out-of-stock.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 8 additions & 3 deletions src/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { createBrowserRouter, RouterProvider } from 'react-router-dom';
import {
AddDrug,
AdminAddUser,
Alerts,
Alarms,
Dashboard,
DispenseDrug,
Landing,
Expand All @@ -15,6 +15,7 @@ import {
Error,
EditDrug,
HomeLayout,
Medication,
} from './pages';

const router = createBrowserRouter([
Expand Down Expand Up @@ -43,8 +44,8 @@ const router = createBrowserRouter([
},

{
path: '/alerts',
element: <Alerts />,
path: '/Alarms',
element: <Alarms />,
},
{
path: '/adddrug',
Expand Down Expand Up @@ -74,6 +75,10 @@ const router = createBrowserRouter([
path: '/reports',
element: <Reports />,
},
{
path: '/Medication',
element: <Medication />,
},
]);

const App = () => {
Expand Down
25 changes: 25 additions & 0 deletions src/pages/AlarmButton.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { useNavigate } from 'react-router-dom';
import styles from './AlarmButton.module.css';

export default function AlarmButton({ message, imagepath, filterTitle, filterData, targetPage }) {
const Navigate = useNavigate();

function loadingPage() {
console.log(filterData);
Navigate(`/${targetPage}`, { state: { filterTitle, filterData } });
}

return (
<div className={styles.alarmitem}>
<img
src={imagepath}
alt={filterTitle}
className={styles.alarmicon}
onClick={loadingPage}
/>
<span className={styles.alarmtext} onClick={loadingPage}>
{message}
</span>
</div>
);
}
57 changes: 57 additions & 0 deletions src/pages/AlarmButton.module.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
.alarmcontainer {
margin-left: 30%;
margin-right: 30%;
display: flex;
justify-content: space-around;
flex-direction: column;
align-items: center;
width: 40%;
padding: 20px;
background-color: #f8f9fa;
}
/* Individual alert item */
.alarmitem {
display: flex;
align-items: center;
justify-content: flex-start;
width: 100%;
background-color: #ffffff;
border: 1px solid #ccc;
border-radius: 10px;
padding: 15px;
margin-bottom: 10px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}

/* Styling the icons */
.alarmicon {
width: 40px;
height: 40px;
margin-right: 15px; /* Space between the icon and the text */
}

/* Styling the text */
.alerttext {
font-size: 1rem;
font-weight: 500;
color: #333;
cursor: grab;
}

/* Button hover effects */
.alertitem:hover {
background-color: #e9ecef;
cursor: grab;
}

/* Responsive design */
@media (max-width: 768px) {
.alert-icon {
width: 30px; /* Smaller icon size for mobile */
height: 30px;
}

.alert-text {
font-size: 0.9rem; /* Adjust font size for smaller screens */
}
}
63 changes: 63 additions & 0 deletions src/pages/Alarms.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import React from 'react';
import Alarmbutton from './AlarmButton.jsx';
import { useEffect, useState } from 'react';
import { drugData } from '../../data.js';
import styles from './AlarmButton.module.css';

export default function Alarms() {
//const [rowData, setRowdata] = useState([]);

const [lowStockData, setLowStockData] = useState([]);
const [noStockData, setnoStockData] = useState([]);
const [expiringsoonData, setExpiringData] = useState([]);

useEffect(() => {
const drugsData = drugData.filter((drug) => drug.class);
const lowStockFilter = drugsData.filter((drug) => {
return parseInt(drug.quantity) !== 0 && drug.quantity <= drug.threshold;
});

setLowStockData(lowStockFilter); // Data drugs matching LowStuck

const noStockFilter = drugsData.filter((drug) => parseInt(drug.quantity) === 0);
setnoStockData(noStockFilter); // Data drugs matching no Stock

const expirationDateData = drugsData.filter((drug) => {
const expirationDate = new Date(drug.expiration);
const today = new Date();

return expirationDate - today < 30 * 24 * 60 * 60 * 1000; // 30 days in milliseconds
});

setExpiringData(expirationDateData); //Data for Date checking
}, []); // Dependencies

return (
<>
<h3></h3>
<div className={styles.alarmcontainer}>
<Alarmbutton
message={`Low Stock on ${lowStockData.length} products`}
imagepath="../images/low-stock.png"
filterTitle="LowStock"
filterData={lowStockData}
targetPage="Medication"
/>
<Alarmbutton
message={`No Stock on ${noStockData.length} products`}
imagepath="../images/out-of-stock.png"
filterTitle="No Stock"
filterData={noStockData}
targetPage="Medication"
/>
<Alarmbutton
message={`Expiration soon on ${expiringsoonData.length} products`}
imagepath="../images/expire-soon.png"
filterTitle="Expire"
filterData={expiringsoonData}
targetPage="Medication"
/>
</div>
</>
);
}
9 changes: 0 additions & 9 deletions src/pages/Alerts.jsx

This file was deleted.

63 changes: 63 additions & 0 deletions src/pages/FilterSearch.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//import React, { useState, useEffect } from 'react';
//import { drugData } from './data.jsx'; // Update path accordingly

export default function FilterSearch() {
// const [data, setData] = useState([]);
// // const [loading, setLoading] = useState(true);
// // const [error, setError] = useState(null);

// const fetchData = async () => {
// try {
// const response = await fetch('http://localhost:8000/api/v1/inventory');
// if (!response.ok) {
// throw new Error('Network response was not ok');
// }
// const result = await response.json();
// setData(result);
// } catch (error) {
// setError(error.message);
// } finally {
// setLoading(false);
// }
// }

const HandelSearch = () => {
//if()
//data.filter()
};
const HandelCancel = () => {};

// const [filteredDrugs, setFilteredDrugs] = useState([]);
// useEffect(() => {
// // Filter the data for a specific class
// let DrugData = drugData.filter((drug) => drug.class === 'DrugData');
// if (filter) Drugdata= drugData.filter((drug)=> d)
// setFilteredDrugs(DrugData); // Set filtered data in the state
// }, []);
return (
<>
<div>
<label htmlFor="drugname">Drug Name: </label>
<input name="drugname" />
</div>
<div>
<label htmlFor="batchCode">BatchCode: </label>
<input name="batchCode" />
</div>
<div>
<label htmlFor="ExpirationdateFrom">Expirationdate From: </label>
<input name="ExpirationdateFrom" />
<label htmlFor="Expirationdateto">Expirationdate To: </label>
<input name="Expirationdateto" />
</div>
<div>
<label htmlFor="type">Type of Drug:</label>
<input name="type" />
</div>
<div>
<button onClick={HandelSearch}>Search</button>
<button onClick={HandelCancel}>Cancel</button>
</div>
</>
);
}
61 changes: 61 additions & 0 deletions src/pages/Medication.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import React, { useState } from 'react';
import { useLocation } from 'react-router-dom';
import FilterSearch from './FilterSearch';

export default function Medication() {
const location = useLocation();
const { filterTitle, filterData } = location.state || {}; // Safeguard for missing state

console.log(location);
console.log('Filter Title:', filterTitle);
console.log('Filter Data:', filterData);

if (!filterData) {
return <p>No data available</p>;
}

const [searchsection, setsearchsection] = useState(false);
const toggleSearch = () => {
setsearchsection((prevState) => !prevState);
};

return (
<div>
<div>
<button onClick={toggleSearch}>Filter and search</button>
{searchsection && (
<div>
<FilterSearch />
</div>
)}
</div>
<h1>{filterTitle}</h1>
<table>
<thead>
<tr>
<th>Name</th>
<th>Generic</th>
<th>Class</th>
<th>Quantity</th>
<th>Threshold</th>
<th>Expiration</th>
<th>Batch</th>
</tr>
</thead>
<tbody>
{filterData.map((drug) => (
<tr key={drug.id}>
<td>{drug.name}</td>
<td>{drug.generic}</td>
<td>{drug.class}</td>
<td>{drug.quantity}</td>
<td>{drug.threshold}</td>
<td>{drug.expiration}</td>
<td>{drug.batch}</td>
</tr>
))}
</tbody>
</table>
</div>
);
}
Loading

0 comments on commit 252ae40

Please sign in to comment.