This commit is contained in:
frontend perkafean
2024-09-08 06:48:45 +00:00
parent f109947d40
commit 112837b20e

View File

@@ -19,14 +19,15 @@ const RoundedRectangle = ({
percentage, percentage,
fontSize = "15px", fontSize = "15px",
loading = false, loading = false,
children, // Assuming this is a React component or JSX
isChildren,
}) => { }) => {
const containerStyle = { const containerStyle = {
display: "flex", display: "flex",
flexDirection: "column", flexDirection: "column",
alignItems: "flex-start", alignItems: "flex-start",
justifyContent: "center", justifyContent: "center",
width: "calc(100% / 2 - 10px)", width: !children && !isChildren && "calc(100% / 2 - 10px)",
maxWidth: "250px",
height: "auto", height: "auto",
borderRadius: "15px", borderRadius: "15px",
padding: "20px", padding: "20px",
@@ -41,7 +42,9 @@ const RoundedRectangle = ({
fontWeight: "bold", fontWeight: "bold",
marginBottom: "10px", marginBottom: "10px",
width: "100%", width: "100%",
backgroundColor: loading ? "rgb(85 85 85)" : "inherit", backgroundColor: loading
? "rgb(85 85 85)"
: !isChildren && !children && "inherit",
color: loading ? "transparent" : "inherit", color: loading ? "transparent" : "inherit",
}; };
@@ -61,8 +64,8 @@ const RoundedRectangle = ({
color: loading ? "transparent" : "inherit", color: loading ? "transparent" : "inherit",
backgroundColor: loading ? "rgb(85 85 85)" : "transparent", backgroundColor: loading ? "rgb(85 85 85)" : "transparent",
overflow: "hidden", overflow: "hidden",
textOverflow: "ellipsis", // Add ellipsis for overflow text textOverflow: "ellipsis",
whiteSpace: "nowrap", // Prevent text from wrapping whiteSpace: "nowrap",
}; };
const percentageStyle = { const percentageStyle = {
@@ -80,13 +83,10 @@ const RoundedRectangle = ({
return ( return (
<div style={containerStyle} onClick={onClick}> <div style={containerStyle} onClick={onClick}>
<div style={titleStyle}>{title}</div> <div style={titleStyle}>{title}</div>
{!children && (
<div style={valueAndPercentageContainerStyle}> <div style={valueAndPercentageContainerStyle}>
<div style={valueStyle}>{loading ? "Loading..." : value}</div> <div style={valueStyle}>{loading ? "Loading..." : value}</div>
<div <div style={percentageStyle}>
style={{
...percentageStyle,
}}
>
{loading ? "" : percentage} {loading ? "" : percentage}
{percentage != undefined && !loading && "%"} {percentage != undefined && !loading && "%"}
{percentage != undefined && !loading && ( {percentage != undefined && !loading && (
@@ -96,6 +96,8 @@ const RoundedRectangle = ({
)} )}
</div> </div>
</div> </div>
)}
{children && <div>{children}</div>} {/* Properly render children */}
</div> </div>
); );
}; };
@@ -188,6 +190,15 @@ const App = ({ cafeId }) => {
const filterTexts = ["1 day", "7 days", "30 days", "365 days"]; const filterTexts = ["1 day", "7 days", "30 days", "365 days"];
const comparisonText = const comparisonText =
filterTexts[["daily", "weekly", "monthly", "yearly"].indexOf(filter)]; filterTexts[["daily", "weekly", "monthly", "yearly"].indexOf(filter)];
const formatDate = (isoDateString) => {
const date = new Date(isoDateString);
return date.toLocaleDateString("en-US", {
year: "numeric",
month: "long",
day: "numeric",
hour: "numeric",
});
};
return ( return (
<div className={styles.Transactions} style={{ backgroundColor: "#cfcfcf" }}> <div className={styles.Transactions} style={{ backgroundColor: "#cfcfcf" }}>
@@ -290,18 +301,58 @@ const App = ({ cafeId }) => {
</div> </div>
<div style={{ flex: 1, marginLeft: "20px" }}> <div style={{ flex: 1, marginLeft: "20px" }}>
{filteredItems.map((item, index) => ( {filteredItems.map((item, index) => (
<div <div
style={{ display: "flex", alignItems: "center", margin: "10px" }} key={index}
style={{
display: "flex",
alignItems: "center",
margin: "10px",
}}
> >
<div style={{ marginRight: "5px", fontSize: "1.2em", color: colors[index] }}></div> <div
<h5 style={{ margin: 0, textAlign: "left" }}> style={{
{item.name} marginRight: "5px",
</h5> fontSize: "1.2em",
color: colors[index],
}}
>
</div>
<h5 style={{ margin: 0, textAlign: "left" }}>{item.name}</h5>
</div> </div>
))} ))}
</div> </div>
</div> </div>
<h3 className={styles["Transactions-title"]}>Stock changes</h3>
{analytics.materialMutations?.length > 0 &&
analytics?.materialMutations.map((item, index) => (
<RoundedRectangle
key={index}
bgColor="rgb(59 59 59 / 41%)"
title={item.name}
>
<div
style={{
display: "flex",
flexWrap: "wrap",
justifyContent: "left",
padding: "20px",
}}
>
{item.mutations.map((mutation, mutationIndex) => (
<RoundedRectangle
bgColor="rgb(59 59 59 / 41%)"
key={mutationIndex}
isChildren={true}
title={`from ${mutation.oldStock} to ${mutation.newStock}`}
value={formatDate(mutation.changeDate)}
/>
))}
</div>
</RoundedRectangle>
))}
</div> </div>
</div> </div>
); );