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

(Fix) FIxed the view all tabs on stock management dashboard , under inventory alerts, issuing and receiving #248

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
17 changes: 14 additions & 3 deletions src/stock-home/stock-home-inventory-card.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from '@carbon/react';
import { navigate, useLayoutType } from '@openmrs/esm-framework';
import styles from './stock-home-detail-card.scss';
import { WarningHex } from '@carbon/react/icons';
import { useStockInventory } from './stock-home-inventory-expiry.resource';
import { useStockInventoryItems } from './stock-home-inventory-items.resource';
import ExpiredStockModal from './stock-home-inventory-expiry.component';

const StockHomeInventoryCard = () => {
const { t } = useTranslation();
Expand All @@ -14,6 +15,8 @@ const StockHomeInventoryCard = () => {
const { items: expiryItems, isLoading: inventoryLoading } = useStockInventory();
const { items: stockItems, isLoading } = useStockInventoryItems();

const [isModalOpen, setModalOpen] = useState(false);

if (isLoading || inventoryLoading) return <></>;

if (stockItems?.length === 0) {
Expand Down Expand Up @@ -52,12 +55,13 @@ const StockHomeInventoryCard = () => {
<div className={styles.cardText}>
<p>EXPIRING STOCK</p>
<p>
<strong>{item?.drugName}</strong> {item?.dispensingUnitName}
<strong>{item?.drugName}</strong> Batch No: {item?.batchNo} Quantity: {item?.quantity}{' '}
{item?.dispensingUnitName}
</p>
</div>
</div>
))}
<Button
{/* <Button
onClick={() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets clean out on unused code if its nolonger necessary

navigate({
to: `${window.getOpenmrsSpaBase()}stock-management/expired-stock`,
Expand All @@ -66,7 +70,14 @@ const StockHomeInventoryCard = () => {
kind="ghost"
>
View All
</Button> */}

<Button onClick={() => setModalOpen(true)} kind="ghost">
View All
</Button>

{/* Expired Stock Modal */}
<ExpiredStockModal open={isModalOpen} onClose={() => setModalOpen(false)} expiredStock={mergedArray} />
</>
);
};
Expand Down
64 changes: 64 additions & 0 deletions src/stock-home/stock-home-inventory-expiry.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
import React from 'react';
import { Modal, Table, TableHead, TableRow, TableHeader, TableBody, TableCell, TableContainer } from '@carbon/react';

const ExpiredStockModal = ({ open, onClose, expiredStock }) => {
const headers = [
{ key: 'drugName', header: 'Drug Name' },
{ key: 'batchNo', header: 'Batch No' },
{ key: 'quantity', header: 'Quantity' },
{ key: 'dispensingUnitName', header: 'Unit' },
{ key: 'expiration', header: 'Expiration Date' },
];

const formatDate = (dateString) => {
if (!dateString) return 'N/A';
const date = new Date(dateString);
return new Intl.DateTimeFormat('en-GB', {
year: 'numeric',
month: 'short',
day: '2-digit',
}).format(date);
};

return (
<Modal
open={open}
onRequestClose={onClose}
modalHeading="Expired Stock"
primaryButtonText="Close"
onSecondarySubmit={onClose}
size="lg"
>
<div>
{expiredStock.length > 0 ? (
<TableContainer>
<Table>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header.key}>{header.header}</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{expiredStock.map((item, index) => (
<TableRow key={index}>
<TableCell>{item?.drugName || 'N/A'}</TableCell>
<TableCell>{item?.batchNo || 'N/A'}</TableCell>
<TableCell>{item?.quantity || 'N/A'}</TableCell>
<TableCell>{item?.dispensingUnitName || 'N/A'}</TableCell>
<TableCell>{formatDate(item?.expiration)}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
) : (
<p>No expired stock data available.</p>
)}
</div>
</Modal>
);
};

export default ExpiredStockModal;
12 changes: 10 additions & 2 deletions src/stock-home/stock-home-issuing-card.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from '@carbon/react';
import { navigate, useLayoutType } from '@openmrs/esm-framework';
import styles from './stock-home-detail-card.scss';
import { ResourceRepresentation } from '../core/api/api';
import { DocumentImport } from '@carbon/react/icons';
import { useStockIssuing } from './stock-home-issuing.resource';
import IssuingStockModal from './stock-home-issuing-modal.component';

const StockHomeIssuingCard = () => {
const { t } = useTranslation();
Expand All @@ -16,6 +17,8 @@ const StockHomeIssuingCard = () => {
totalCount: true,
});

const [isModalOpen, setModalOpen] = useState(false);

if (isLoading) return <></>;

if (items?.length === 0) {
Expand Down Expand Up @@ -64,7 +67,7 @@ const StockHomeIssuingCard = () => {
</div>
</div>
))}
<Button
{/* <Button
onClick={() => {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove unused code

navigate({
to: `${window.getOpenmrsSpaBase()}stock-management/requisitions`,
Expand All @@ -73,7 +76,12 @@ const StockHomeIssuingCard = () => {
kind="ghost"
>
View All
</Button> */}
<Button onClick={() => setModalOpen(true)} kind="ghost">
View All
</Button>

<IssuingStockModal open={isModalOpen} onClose={() => setModalOpen(false)} issuingStock={items} />
</>
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use openmrs/esm-framework modal utilities

);
};
Expand Down
56 changes: 56 additions & 0 deletions src/stock-home/stock-home-issuing-modal.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
import React from 'react';
import { Modal, Table, TableHead, TableRow, TableHeader, TableBody, TableCell, TableContainer } from '@carbon/react';

const IssuingStockModal = ({ open, onClose, issuingStock }) => {
const headers = [
{ key: 'status', header: 'Status' },
{ key: 'sourceName', header: 'Source' },
{ key: 'destinationName', header: 'Destination' },
{ key: 'stockItemName', header: 'Stock Item' },
{ key: 'stockItemPackagingUOMName', header: 'Unit' },
{ key: 'quantity', header: 'Quantity' },
];

return (
<Modal
samsonmwanzia marked this conversation as resolved.
Show resolved Hide resolved
open={open}
onRequestClose={onClose}
modalHeading="Issued Stock"
primaryButtonText="Close"
onSecondarySubmit={onClose}
size="lg"
>
<div>
{issuingStock && issuingStock.length > 0 ? (
<TableContainer>
<Table>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header.key}>{header.header}</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{issuingStock.map((item, index) => (
<TableRow key={index}>
<TableCell>{item?.status || 'N/A'}</TableCell>
<TableCell>{item?.sourceName || 'N/A'}</TableCell>
<TableCell>{item?.destinationName || 'N/A'}</TableCell>
<TableCell>{item?.stockItemName || 'N/A'}</TableCell>
<TableCell>{item?.stockItemPackagingUOMName || 'N/A'}</TableCell>
<TableCell>{item?.quantity || 'N/A'}</TableCell>
</TableRow>
))}
</TableBody>
</Table>
</TableContainer>
) : (
<p>No issued stock data available.</p>
)}
</div>
</Modal>
);
};

export default IssuingStockModal;
12 changes: 10 additions & 2 deletions src/stock-home/stock-home-receiving-card.component.tsx
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import React from 'react';
import React, { useState } from 'react';
import { useTranslation } from 'react-i18next';
import { Button } from '@carbon/react';
import { navigate, useLayoutType } from '@openmrs/esm-framework';
import styles from './stock-home-detail-card.scss';
import { Delivery } from '@carbon/react/icons';
import { ResourceRepresentation } from '../core/api/api';
import { useStockReceiving } from './stock-home-receiving.resource';
import ReceivingStockModal from './stock-home-receiving-modal.component';

const StockHomeReceivingCard = () => {
const { t } = useTranslation();
Expand All @@ -16,6 +17,8 @@ const StockHomeReceivingCard = () => {
totalCount: true,
});

const [isModalOpen, setModalOpen] = useState(false);

if (isLoading) return <></>;

if (items?.length === 0) {
Expand Down Expand Up @@ -46,7 +49,7 @@ const StockHomeReceivingCard = () => {
</div>
)),
)}
<Button
{/* <Button
onClick={() => {
navigate({
to: `${window.getOpenmrsSpaBase()}stock-management/orders`,
Expand All @@ -55,7 +58,12 @@ const StockHomeReceivingCard = () => {
kind="ghost"
>
{t('receivedView', 'View All')}
</Button> */}
<Button onClick={() => setModalOpen(true)} kind="ghost">
{t('receivedView', 'View All')}
</Button>

<ReceivingStockModal open={isModalOpen} onClose={() => setModalOpen(false)} receivingStock={items} />
</>
);
};
Expand Down
58 changes: 58 additions & 0 deletions src/stock-home/stock-home-receiving-modal.component.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
import React from 'react';
import { Modal, Table, TableHead, TableRow, TableHeader, TableBody, TableCell, TableContainer } from '@carbon/react';

const ReceivingStockModal = ({ open, onClose, receivingStock }) => {
const headers = [
{ key: 'status', header: 'Status' },
{ key: 'sourceName', header: 'Source' },
{ key: 'destinationName', header: 'Destination' },
{ key: 'stockItemName', header: 'Stock Item' },
{ key: 'stockItemPackagingUOMName', header: 'Unit' },
{ key: 'quantity', header: 'Quantity' },
];

return (
<Modal
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lets use the stick to using the openmrs/esm-framework utilities for modal creation and management

open={open}
onRequestClose={onClose}
modalHeading="Received Stock"
primaryButtonText="Close"
onSecondarySubmit={onClose}
size="lg"
>
<div>
{receivingStock && receivingStock.length > 0 ? (
<TableContainer>
<Table>
<TableHead>
<TableRow>
{headers.map((header) => (
<TableHeader key={header.key}>{header.header}</TableHeader>
))}
</TableRow>
</TableHead>
<TableBody>
{receivingStock.map((item, index) =>
item?.stockOperationItems.map((stock, stockIndex) => (
<TableRow key={`${index}-${stockIndex}`}>
<TableCell>{item?.status || 'N/A'}</TableCell>
<TableCell>{item?.sourceName || 'N/A'}</TableCell>
<TableCell>{item?.destinationName || 'N/A'}</TableCell>
<TableCell>{stock?.stockItemName || 'N/A'}</TableCell>
<TableCell>{stock?.stockItemPackagingUOMName || 'N/A'}</TableCell>
<TableCell>{stock?.quantity || 'N/A'}</TableCell>
</TableRow>
)),
)}
</TableBody>
</Table>
</TableContainer>
) : (
<p>No received stock data available.</p>
)}
</div>
</Modal>
);
};

export default ReceivingStockModal;
Loading