bananas-commerce-admin 0.17.16 → 0.17.17
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,18 +1,34 @@
|
|
|
1
|
-
import React from "react";
|
|
1
|
+
import React, { useMemo } from "react";
|
|
2
2
|
import { Stack, Typography } from "@mui/material";
|
|
3
3
|
import WidgetCard from "../../../components/WidgetCard";
|
|
4
|
+
import { useApi } from "../../../contexts/ApiContext";
|
|
4
5
|
import { useDashboardFilter } from "../../../contexts/DashboardFilterContext";
|
|
5
6
|
import { useI18n } from "../../../contexts/I18nContext";
|
|
7
|
+
import { useUser } from "../../../contexts/UserContext";
|
|
6
8
|
import { pluralizeGranularity } from "../../../types/dashboard";
|
|
9
|
+
import { hasPermission } from "../../../util/has_permission";
|
|
7
10
|
import SitesAmountsList from "../components/SitesAmountsList";
|
|
8
11
|
import { currencyFormat } from "../utils/amountToCurrencyString";
|
|
9
12
|
import { diffDatesByGranularityWithFilter } from "../utils/diffDatesByGranularity";
|
|
10
13
|
const PurchaseAmountWidget = ({ data, sx }) => {
|
|
11
14
|
const { t } = useI18n();
|
|
12
15
|
const { filter } = useDashboardFilter();
|
|
16
|
+
const api = useApi();
|
|
17
|
+
const { user } = useUser();
|
|
13
18
|
const purchaseAmounts = data.length;
|
|
14
19
|
const filteredAmount = diffDatesByGranularityWithFilter(filter);
|
|
15
|
-
|
|
20
|
+
const isFourColumn = useMemo(() => {
|
|
21
|
+
// Ugly check to see if the "Total Subscription Count" widget is present
|
|
22
|
+
if ("subscription.stats:total" in api.operations &&
|
|
23
|
+
"dashboard:stats:subscription:total" in api.contrib) {
|
|
24
|
+
const [{ component }] = Object.values(api.contrib["dashboard:stats:subscription:count"]);
|
|
25
|
+
if (component != null) {
|
|
26
|
+
return hasPermission(user, component.permission);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return false;
|
|
30
|
+
}, [api, user]);
|
|
31
|
+
return (React.createElement(WidgetCard, { gridColumn: { md: isFourColumn ? "span 3" : "span 4", sm: "span 1" }, gridRow: "span 1", sx: sx, title: t("Purchase Revenue") }, purchaseAmounts >= 2 ? (React.createElement(SitesAmountsList, { data: data })) : (React.createElement(Stack, { height: "100%", px: 2 },
|
|
16
32
|
React.createElement(Stack, { borderBottom: "1px solid", borderColor: "divider", height: "100%" }, purchaseAmounts === 1 ? (React.createElement(Typography, { component: "p", fontSize: 28, fontWeight: 700, variant: "h5" }, currencyFormat(Number.parseFloat(data[0].amount), data[0].currency))) : purchaseAmounts === 0 ? (React.createElement(Stack, { height: "100%" },
|
|
17
33
|
React.createElement(Typography, { color: "textSecondary", variant: "caption" }, t("No revenue data for current period")))) : null),
|
|
18
34
|
React.createElement(Typography, { color: "textSecondary", variant: "overline" }, t(`Over ${pluralizeGranularity(filteredAmount, filter.granularity)}`))))));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PurchaseAmountWidget.js","sourceRoot":"","sources":["../../../../../src/extensions/pos/contrib/PurchaseAmountWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"PurchaseAmountWidget.js","sourceRoot":"","sources":["../../../../../src/extensions/pos/contrib/PurchaseAmountWidget.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,EAAE,OAAO,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,UAAU,MAAM,gCAAgC,CAAC;AACxD,OAAO,EAAE,MAAM,EAAE,MAAM,8BAA8B,CAAC;AACtD,OAAO,EAAE,kBAAkB,EAAE,MAAM,0CAA0C,CAAC;AAC9E,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AACxD,OAAO,EAAE,OAAO,EAAE,MAAM,+BAA+B,CAAC;AAExD,OAAO,EAAE,oBAAoB,EAAsB,MAAM,0BAA0B,CAAC;A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Memo } from "react";
|
|
2
2
|
|
|
3
3
|
import { Stack, Typography } from "@mui/material";
|
|
4
4
|
|
|
5
5
|
import WidgetCard from "../../../components/WidgetCard";
|
|
6
|
+
import { useApi } from "../../../contexts/ApiContext";
|
|
6
7
|
import { useDashboardFilter } from "../../../contexts/DashboardFilterContext";
|
|
7
8
|
import { useI18n } from "../../../contexts/I18nContext";
|
|
9
|
+
import { useUser } from "../../../contexts/UserContext";
|
|
8
10
|
import { ContribComponent } from "../../../types";
|
|
9
11
|
import { pluralizeGranularity, PurchaseAmountItem } from "../../../types/dashboard";
|
|
12
|
+
import { hasPermission } from "../../../util/has_permission";
|
|
10
13
|
import SitesAmountsList from "../components/SitesAmountsList";
|
|
11
14
|
import { currencyFormat } from "../utils/amountToCurrencyString";
|
|
12
15
|
import { diffDatesByGranularityWithFilter } from "../utils/diffDatesByGranularity";
|
|
@@ -14,13 +17,30 @@ import { diffDatesByGranularityWithFilter } from "../utils/diffDatesByGranularit
|
|
|
14
17
|
const PurchaseAmountWidget: ContribComponent<PurchaseAmountItem[]> = ({ data, sx }) => {
|
|
15
18
|
const { t } = useI18n();
|
|
16
19
|
const { filter } = useDashboardFilter();
|
|
20
|
+
const api = useApi();
|
|
21
|
+
const { user } = useUser();
|
|
17
22
|
|
|
18
23
|
const purchaseAmounts = data.length;
|
|
19
24
|
const filteredAmount = diffDatesByGranularityWithFilter(filter);
|
|
25
|
+
const isFourColumn = useMemo(() => {
|
|
26
|
+
// Ugly check to see if the "Total Subscription Count" widget is present
|
|
27
|
+
if (
|
|
28
|
+
"subscription.stats:total" in api.operations &&
|
|
29
|
+
"dashboard:stats:subscription:total" in api.contrib
|
|
30
|
+
) {
|
|
31
|
+
const [{ component }] = Object.values(api.contrib["dashboard:stats:subscription:count"]);
|
|
32
|
+
|
|
33
|
+
if (component != null) {
|
|
34
|
+
return hasPermission(user, component.permission);
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
}, [api, user]);
|
|
20
40
|
|
|
21
41
|
return (
|
|
22
42
|
<WidgetCard
|
|
23
|
-
gridColumn={{
|
|
43
|
+
gridColumn={{ md: isFourColumn ? "span 3" : "span 4", sm: "span 1" }}
|
|
24
44
|
gridRow="span 1"
|
|
25
45
|
sx={sx}
|
|
26
46
|
title={t("Purchase Revenue")}
|