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

[ISSUE 21] - Display more item information about a selected item #76

Open
wants to merge 22 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
6950a97
feat: rename DeleteIconWithTooltip into IconWithTooltip to make the c…
kweeuhree Oct 17, 2024
65f72d0
feat: InfoCard component displays additional information about a sele…
kweeuhree Oct 17, 2024
22324f8
fix: update the mapping over daysUntilPurchaseOptions to be more read…
kweeuhree Oct 17, 2024
8b6642c
feat: implement IconWithTooltip in SingleList component
kweeuhree Oct 17, 2024
9289949
fix: update exports from components folder
kweeuhree Oct 17, 2024
134ba4f
test: update List test
kweeuhree Oct 17, 2024
927d0cd
feat: update ListItem
kweeuhree Oct 17, 2024
5ca6136
fix: remove redundant console.log
kweeuhree Oct 17, 2024
4b83bd5
update utils folder exports
kweeuhree Oct 17, 2024
497db6d
fix: correct kindOfSoon and notSoon statuses inside useUrgency hook
kweeuhree Oct 17, 2024
fd0f513
feat: update the way Typography component is displayed; change Grow t…
kweeuhree Oct 17, 2024
27664fc
test: update List test to mock calculateIsPurchased
kweeuhree Oct 17, 2024
9726593
test: introduce ListItem test that ensures that additional informatio…
kweeuhree Oct 17, 2024
3b59117
fix: return Tooltip component to the UrgencyStatusIcon
kweeuhree Oct 17, 2024
8fc10e1
fix: remove redundant title from UrgencyStatusIcon
kweeuhree Oct 17, 2024
23e1e18
Merge branch 'main' of https://github.com/the-collab-lab/tcl-75-smart…
kweeuhree Oct 17, 2024
b8d8095
fix: update List test
kweeuhree Oct 17, 2024
5a2b6f7
feat: add averagePurchaseInterval to each item doc in Firebase
kweeuhree Oct 17, 2024
bca8dd6
feat: update propmts inside InfoCard; abstract describeAveragePurchas…
kweeuhree Oct 17, 2024
77c1b19
feat: add logic that calculates average purchase interval of a select…
kweeuhree Oct 17, 2024
a7ddba0
feat: export getAveragePurchaseInterval function and create a unit te…
kweeuhree Oct 17, 2024
a82d8fa
fix: remove deprecated Grid component and replace with Grid2 component
kweeuhree Oct 18, 2024
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
10 changes: 9 additions & 1 deletion src/api/firebase.js
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ export async function addItem(listPath, { itemName, daysUntilNextPurchase }) {
dateNextPurchased: addDaysFromToday(daysUntilNextPurchase),
name: itemName,
totalPurchases: 0,
averagePurchaseInterval: 0,
});
}

Expand All @@ -178,13 +179,19 @@ export async function addItem(listPath, { itemName, daysUntilNextPurchase }) {
* @param {Date} updatedData.dateLastPurchased The date the item was last purchased.
* @param {Date} updatedData.dateNextPurchased The estimated date for the next purchase.
* @param {number} updatedData.totalPurchases The total number of times the item has been purchased.
* @param {number} updatedData.averagePurchaseInterval The average purchase interval of the item that has been purchased.
* @returns {Promise<string>} A message confirming the item was successfully updated.
* @throws {Error} If the item update fails.
*/
export async function updateItem(
listPath,
itemId,
{ dateLastPurchased, dateNextPurchased, totalPurchases },
{
dateLastPurchased,
dateNextPurchased,
totalPurchases,
averagePurchaseInterval,
},
) {
// reference the item path
const itemDocRef = doc(db, listPath, 'items', itemId);
Expand All @@ -194,6 +201,7 @@ export async function updateItem(
dateLastPurchased,
dateNextPurchased,
totalPurchases,
averagePurchaseInterval,
});
return 'item purchased';
} catch (error) {
Expand Down
12 changes: 6 additions & 6 deletions src/components/AddItems.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ export function AddItems({ items }) {
required={true}
/>

{Object.entries(daysUntilPurchaseOptions).map(([key, value]) => (
{Object.entries(daysUntilPurchaseOptions).map(([status, days]) => (
<RadioInputElement
key={key}
label={key}
id={key}
value={value}
required={true}
key={status}
label={status}
id={status}
value={days}
required={status}
/>
))}
<button type="submit">Submit</button>
Expand Down
18 changes: 0 additions & 18 deletions src/components/DeleteIconWithTooltip.jsx

This file was deleted.

27 changes: 27 additions & 0 deletions src/components/IconWithTooltip.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import { Tooltip, IconButton, Box } from '@mui/material';

export const tooltipStyle = {
fontSize: '1.5rem',
marginBlockStart: '0',
marginBlockEnd: '0',
};

export function IconWithTooltip({
icon,
onClick,
ariaLabel,
title,
placement,
}) {
return (
<Tooltip
title={<Box style={tooltipStyle}>{title}</Box>}
placement={placement}
arrow
>
<IconButton onClick={onClick} aria-label={ariaLabel}>
{icon}
</IconButton>
</Tooltip>
);
}
63 changes: 63 additions & 0 deletions src/components/InfoCard.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import { describeAveragePurchaseInterval } from '../utils';
import {
Box,
Card,
CardContent,
CardHeader,
Typography,
IconButton,
Collapse,
} from '@mui/material';
import CloseIcon from '@mui/icons-material/Close';

export const InfoCard = ({ item, toggleCard, show }) => {
const typographyOptions = {
totalPurchases: `You've purchased this item ${item.totalPurchases} times`,
averagePurchaseInterval: describeAveragePurchaseInterval(
item.averagePurchaseInterval,
),
dateCreated: `Item added on: ${item.dateCreated?.toDate().toLocaleString()}`,
dateLastPurchased: item.dateLastPurchased
? `Last bought on: ${item.dateLastPurchased?.toDate().toLocaleString()}`
: 'Not purchased yet',
dateNextPurchased: `Expected to buy again by: ${item.dateNextPurchased?.toDate().toLocaleString() ?? 'No estimate yet'}`,
};

return (
<Box width="100%">
<Collapse in={show}>
<Card variant="outlined">
<CardHeader
title={<Box style={{ fontSize: '2rem' }}>{item?.name}</Box>}
action={
<IconButton
aria-label="close"
onClick={toggleCard}
sx={(theme) => ({
position: 'absolute',
right: 20,
top: 15,
color: theme.palette.grey[700],
})}
>
<CloseIcon />
</IconButton>
}
/>
<CardContent sx={{ color: 'text.secondary' }}>
{Object.entries(typographyOptions).map(([key, option]) => (
<Typography
key={key}
variant="body2"
sx={{ color: 'text.secondary' }}
fontSize="large"
>
{option}
</Typography>
))}
</CardContent>
</Card>
</Collapse>
</Box>
);
};
Loading