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

Farkhondeh dev2 #32

Merged
merged 4 commits into from
Dec 11, 2024
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
36 changes: 36 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
"@emotion/styled": "^11.13.5",
"axios": "^1.6.7",
"framer-motion": "^6.5.1",
"node": "^22.12.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
"react-icons": "^5.4.0",
Expand Down
34 changes: 23 additions & 11 deletions src/pages/Alarms.jsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,48 @@
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);
fetch('http://localhost:8000/api/v1/inventory')
.then((response) => {
if (!response.ok) {
throw new Error('Network response was not ok');
}
return response.json();
})
.then((data) => {
FilterData(data.data);
})
.catch((error) => {
console.error('Error fetching data:', error);
});
}, []);

const FilterData = (drugsData) => {
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 expirationDate = new Date(drug.expirationDate);
if (isNaN(expirationDate)) return false;
const today = new Date();

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

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

return (
<>
Expand All @@ -41,21 +53,21 @@ export default function Alarms() {
imagepath="../images/low-stock.png"
filterTitle="LowStock"
filterData={lowStockData}
targetPage="Medication"
targetPage="dashboard"
/>
<Alarmbutton
message={`No Stock on ${noStockData.length} products`}
imagepath="../images/out-of-stock.png"
filterTitle="No Stock"
filterData={noStockData}
targetPage="Medication"
targetPage="dashboard"
/>
<Alarmbutton
message={`Expiration soon on ${expiringsoonData.length} products`}
imagepath="../images/expire-soon.png"
filterTitle="Expire"
filterData={expiringsoonData}
targetPage="Medication"
targetPage="dashboard"
/>
</div>
</>
Expand Down
125 changes: 103 additions & 22 deletions src/pages/AllDrugs.jsx
Original file line number Diff line number Diff line change
@@ -1,60 +1,134 @@
import styled from 'styled-components';
import { IoIosSearch } from 'react-icons/io';
import { FaFilter } from 'react-icons/fa';
import { drugData } from '../../data';
//import { drugData } from '../../data';
import { TbBellFilled } from 'react-icons/tb';
import { useEffect, useState } from 'react';
import FilterSearch from './FilterSearch';
import Alarms from './Alarms';
import { useLocation } from 'react-router-dom';

const AllDrugs = () => {
const columnLabels = [
'name',
'generic',
'genericName',
'class',
'quantity',
'expiration date',
'lot #',
'ndc #',
'expirationDate',
'lot',
'ndcNumber',
'view/edit/delete',
];

const [data, setData] = useState([]);
const [filterData, setFilterData] = useState([]);
const [loading, setLoading] = useState(true);
const [error, setError] = useState(false);
const [searchsection, setSearchSection] = useState(false);
const [alarmSection, setAlarmSection] = useState(false);

const location = useLocation();
const { alarmFilterData: alarmFilterData } = location.state || {};

useEffect(() => {
fetch('http://localhost:8000/api/v1/inventory')
.then((response) => {
if (!response) {
throw new error('Network response was not ok');
}
return response.json();
})
.then((data) => {
if (alarmFilterData) {
// Use the passed alarm filter if available
setFilterData(alarmFilterData);
} else {
setData(data.data);
setFilterData(data.data);
}

setLoading(false);
})
.catch((error) => setError(error.message));
}, [alarmFilterData]);

const toggleSearch = () => {
setSearchSection((prevState) => !prevState);
};

const handleFilter = (filteredData) => {
setFilterData(filteredData);
};

if (loading) return <p>Loading...</p>;
if (error) return <p>Error: {error}</p>;

const toggleAlarm = () => {
setAlarmSection((preState) => !preState);
};

return (
<Wrapper>
{/* */}

<div className="centered-container">
<div className="bell-icon-box">
<button className="bell-button">
<button className="bell-button" onClick={toggleAlarm}>
<TbBellFilled className="bell-icon" />
</button>
</div>
<div className="filter-search-box">
<div className="left-filter-box">
<button className="filter-button">
<button className="filter-button" onClick={toggleSearch}>
<FaFilter className="filter-icon" />
</button>
</div>
<div></div>
<div className="search-box">
<div className="search-icon">
<IoIosSearch />
</div>
<input type="text" placeholder="Search ..." className="search-input" />
<input
type="text"
placeholder="Search by drug name ..."
className="search-input"
/>
</div>
</div>
<div className="blank"></div>
</div>
{/* */}
<div className="grid-container">
{/* Render column headers */}
{columnLabels.map((label, index) => (
<div key={index} className="grid-item grid-header">
{label}
<div className="advanced-search">
{searchsection && (
<div>
<br />
<FilterSearch data={data} onFilter={handleFilter} />
</div>
))}
{/* Render rows dynamically */}
{drugData.map((drug, rowIndex) =>
columnLabels.map((label, colIndex) => (
<div key={`${rowIndex}-${colIndex}`} className="grid-item">
{drug[label] || ''}
)}
</div>
{/* */}
{!alarmSection && (
<div className="grid-container">
{/* Render column headers */}
{columnLabels.map((label, index) => (
<div key={index} className="grid-item grid-header">
{label}
</div>
))
))}
{/* Render rows dynamically */}
{filterData.map((drug, rowIndex) =>
columnLabels.map((label, colIndex) => (
<div key={`${rowIndex}-${colIndex}`} className="grid-item">
{drug[label] || ''}
</div>
))
)}
</div>
)}
<div className="Alarm-container">
{alarmSection && (
<div>
{' '}
<Alarms />{' '}
</div>
)}
</div>
</Wrapper>
Expand Down Expand Up @@ -154,4 +228,11 @@ const Wrapper = styled.section`
background-color: var(--color-green-med);
color: var(--color-blue-dark);
}
.advanced-search {
align-items: center;
justify-content: center;
background-color: #f5f5f5;
border-radius: 8px;
box-shadow: 1px 4px 6px rgba(0, 0, 0, 0.1);
}
`;
Loading
Loading