@ammarkhalidfarooq/dashboard-package 0.5.38 → 0.5.39

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.
package/dist/index.es.js CHANGED
@@ -109,7 +109,10 @@ function _iterableToArrayLimit(r, l) {
109
109
  f = true,
110
110
  o = false;
111
111
  try {
112
- if (i = (t = t.call(r)).next, 0 === l) ; else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
112
+ if (i = (t = t.call(r)).next, 0 === l) {
113
+ if (Object(t) !== t) return;
114
+ f = !1;
115
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
113
116
  } catch (r) {
114
117
  o = true, n = r;
115
118
  } finally {
@@ -3266,8 +3269,9 @@ var GeographyCard = function GeographyCard(_ref4) {
3266
3269
  })
3267
3270
  });
3268
3271
  };
3269
- var TopCampaignsRaisedCard = function TopCampaignsRaisedCard() {
3270
- var data = [{
3272
+ var TopCampaignsRaisedCard = function TopCampaignsRaisedCard(_ref5) {
3273
+ var dataProp = _ref5.data;
3274
+ var data = dataProp !== null && dataProp !== void 0 ? dataProp : [{
3271
3275
  id: "RK",
3272
3276
  name: "Ramadan kickoff",
3273
3277
  value: "$14,200"
@@ -3313,7 +3317,15 @@ var TopCampaignsRaisedCard = function TopCampaignsRaisedCard() {
3313
3317
  },
3314
3318
  children: "Raised"
3315
3319
  })]
3316
- }), data.map(function (item, index) {
3320
+ }), data.length === 0 ? /*#__PURE__*/jsx(Typography, {
3321
+ sx: {
3322
+ fontSize: "13px",
3323
+ color: "rgba(0, 0, 0, 0.45)",
3324
+ py: 2,
3325
+ textAlign: "left"
3326
+ },
3327
+ children: "No campaign data for this period."
3328
+ }) : data.map(function (item, index) {
3317
3329
  return /*#__PURE__*/jsxs(Box, {
3318
3330
  sx: {
3319
3331
  display: "flex",
@@ -3363,8 +3375,9 @@ var TopCampaignsRaisedCard = function TopCampaignsRaisedCard() {
3363
3375
  })]
3364
3376
  });
3365
3377
  };
3366
- var TopCampaignsCTRCard = function TopCampaignsCTRCard() {
3367
- var data = [{
3378
+ var TopCampaignsCTRCard = function TopCampaignsCTRCard(_ref6) {
3379
+ var dataProp = _ref6.data;
3380
+ var data = dataProp !== null && dataProp !== void 0 ? dataProp : [{
3368
3381
  id: "RK",
3369
3382
  name: "Ramadan kickoff",
3370
3383
  value: "12.4%"
@@ -3410,7 +3423,15 @@ var TopCampaignsCTRCard = function TopCampaignsCTRCard() {
3410
3423
  },
3411
3424
  children: "CTR"
3412
3425
  })]
3413
- }), data.map(function (item, index) {
3426
+ }), data.length === 0 ? /*#__PURE__*/jsx(Typography, {
3427
+ sx: {
3428
+ fontSize: "13px",
3429
+ color: "rgba(0, 0, 0, 0.45)",
3430
+ py: 2,
3431
+ textAlign: "left"
3432
+ },
3433
+ children: "No campaign data for this period."
3434
+ }) : data.map(function (item, index) {
3414
3435
  return /*#__PURE__*/jsxs(Box, {
3415
3436
  sx: {
3416
3437
  display: "flex",
@@ -3460,8 +3481,9 @@ var TopCampaignsCTRCard = function TopCampaignsCTRCard() {
3460
3481
  })]
3461
3482
  });
3462
3483
  };
3463
- var TopCampaignsConvRateCard = function TopCampaignsConvRateCard() {
3464
- var data = [{
3484
+ var TopCampaignsConvRateCard = function TopCampaignsConvRateCard(_ref7) {
3485
+ var dataProp = _ref7.data;
3486
+ var data = dataProp !== null && dataProp !== void 0 ? dataProp : [{
3465
3487
  id: "YO",
3466
3488
  name: "Yemen orphans drive",
3467
3489
  value: "5.2%"
@@ -3507,7 +3529,15 @@ var TopCampaignsConvRateCard = function TopCampaignsConvRateCard() {
3507
3529
  },
3508
3530
  children: "Conv. rate"
3509
3531
  })]
3510
- }), data.map(function (item, index) {
3532
+ }), data.length === 0 ? /*#__PURE__*/jsx(Typography, {
3533
+ sx: {
3534
+ fontSize: "13px",
3535
+ color: "rgba(0, 0, 0, 0.45)",
3536
+ py: 2,
3537
+ textAlign: "left"
3538
+ },
3539
+ children: "No campaign data for this period."
3540
+ }) : data.map(function (item, index) {
3511
3541
  return /*#__PURE__*/jsxs(Box, {
3512
3542
  sx: {
3513
3543
  display: "flex",
@@ -3704,9 +3734,9 @@ var TopPerformingCampaignsCard = function TopPerformingCampaignsCard() {
3704
3734
  })]
3705
3735
  });
3706
3736
  };
3707
- var PaidDonorGeographyCard = function PaidDonorGeographyCard(_ref5) {
3708
- var sx = _ref5.sx,
3709
- donorGeographyData = _ref5.donorGeographyData;
3737
+ var PaidDonorGeographyCard = function PaidDonorGeographyCard(_ref8) {
3738
+ var sx = _ref8.sx,
3739
+ donorGeographyData = _ref8.donorGeographyData;
3710
3740
  var rawCountries = Array.isArray(donorGeographyData) ? donorGeographyData : (donorGeographyData === null || donorGeographyData === void 0 ? void 0 : donorGeographyData.countries) || [];
3711
3741
  var data = rawCountries.map(function (item) {
3712
3742
  return {
@@ -4946,7 +4976,10 @@ var NewOverview = function NewOverview(_ref) {
4946
4976
  })
4947
4977
  }), activeSection === "Email" && /*#__PURE__*/jsx(Box, {
4948
4978
  sx: {},
4949
- children: /*#__PURE__*/jsx(EmailSection$2, {})
4979
+ children: /*#__PURE__*/jsx(EmailSection$2, {
4980
+ apiData: apiData,
4981
+ dateName: dateName
4982
+ })
4950
4983
  })]
4951
4984
  }), showExportLayout && /*#__PURE__*/jsx("div", {
4952
4985
  "aria-hidden": "true",
@@ -15318,10 +15351,10 @@ var PaidSection$1 = /*#__PURE__*/Object.freeze({
15318
15351
  default: PaidSection
15319
15352
  });
15320
15353
 
15321
- var formatGrowth = function formatGrowth(value, dateName) {
15354
+ var formatGrowth$1 = function formatGrowth(value, dateName) {
15322
15355
  return "".concat(Number(value !== null && value !== void 0 ? value : 0).toFixed(2), "% vs ").concat(dateName || "previous period");
15323
15356
  };
15324
- var mapTimeSeries = function mapTimeSeries(series) {
15357
+ var mapTimeSeries$1 = function mapTimeSeries(series) {
15325
15358
  if (!Array.isArray(series) || series.length === 0) {
15326
15359
  return {
15327
15360
  categories: [],
@@ -15351,14 +15384,14 @@ var OrganicSection = function OrganicSection(_ref) {
15351
15384
  var overview = (apiData === null || apiData === void 0 ? void 0 : apiData.overview) || {};
15352
15385
  var growth = (overview === null || overview === void 0 ? void 0 : overview.growthPercentage) || {};
15353
15386
  var hasOrganicOverview = Boolean(apiData === null || apiData === void 0 ? void 0 : apiData.overview);
15354
- var organicUsersSeries = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.organicUsers);
15355
- var donationsSeries = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.totalDonations);
15356
- var conversionSeries = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.conversionRate);
15357
- var revenueSeries = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.totalRevenue);
15358
- var avgDonationSeries = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.avgDonations);
15387
+ var organicUsersSeries = mapTimeSeries$1(apiData === null || apiData === void 0 ? void 0 : apiData.organicUsers);
15388
+ var donationsSeries = mapTimeSeries$1(apiData === null || apiData === void 0 ? void 0 : apiData.totalDonations);
15389
+ var conversionSeries = mapTimeSeries$1(apiData === null || apiData === void 0 ? void 0 : apiData.conversionRate);
15390
+ var revenueSeries = mapTimeSeries$1(apiData === null || apiData === void 0 ? void 0 : apiData.totalRevenue);
15391
+ var avgDonationSeries = mapTimeSeries$1(apiData === null || apiData === void 0 ? void 0 : apiData.avgDonations);
15359
15392
  var fallbackCategories = organicUsersSeries.categories.length ? organicUsersSeries.categories : ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
15360
15393
  var growthCaption = function growthCaption(key) {
15361
- return formatGrowth(growth[key], dateName);
15394
+ return formatGrowth$1(growth[key], dateName);
15362
15395
  };
15363
15396
  var metricInfo = useMemo(function () {
15364
15397
  var _overview$totalRevenu2, _overview$overallAVGD2, _overview$organicUser, _apiData$topOrganicKe, _overview$totalDonati, _overview$conversionR, _overview$totalRevenu3, _overview$overallAVGD3;
@@ -15713,13 +15746,42 @@ var OrganicSection$1 = /*#__PURE__*/Object.freeze({
15713
15746
  default: OrganicSection
15714
15747
  });
15715
15748
 
15749
+ var formatCategoryLabel = function formatCategoryLabel(val) {
15750
+ if (!val || typeof val !== "string") return val;
15751
+ var ddMmYyyy = val.match(/^(\d{2})-(\d{2})-(\d{4})$/);
15752
+ if (ddMmYyyy) {
15753
+ var _ddMmYyyy = _slicedToArray(ddMmYyyy, 4),
15754
+ day = _ddMmYyyy[1],
15755
+ month = _ddMmYyyy[2],
15756
+ year = _ddMmYyyy[3];
15757
+ var _date = new Date(Number(year), Number(month) - 1, Number(day));
15758
+ if (!Number.isNaN(_date.getTime())) {
15759
+ return _date.toLocaleDateString("en-US", {
15760
+ month: "short",
15761
+ day: "numeric"
15762
+ });
15763
+ }
15764
+ }
15765
+ var date = new Date(val);
15766
+ if (!Number.isNaN(date.getTime())) {
15767
+ return date.toLocaleDateString("en-US", {
15768
+ month: "short",
15769
+ day: "numeric"
15770
+ });
15771
+ }
15772
+ return val;
15773
+ };
15716
15774
  var EmailTrendCard = function EmailTrendCard(_ref) {
15717
15775
  var title = _ref.title,
15718
15776
  subtitle = _ref.subtitle,
15719
15777
  value = _ref.value,
15720
15778
  trend = _ref.trend,
15721
- series = _ref.series,
15779
+ _ref$series = _ref.series,
15780
+ series = _ref$series === void 0 ? [] : _ref$series,
15781
+ trendData = _ref.trendData,
15782
+ trendSeries = _ref.trendSeries,
15722
15783
  colors = _ref.colors,
15784
+ categoriesProp = _ref.categories,
15723
15785
  _ref$yAxisMax = _ref.yAxisMax,
15724
15786
  yAxisMax = _ref$yAxisMax === void 0 ? 60 : _ref$yAxisMax,
15725
15787
  _ref$yAxisTickAmount = _ref.yAxisTickAmount,
@@ -15728,6 +15790,47 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15728
15790
  yAxisFormatter = _ref$yAxisFormatter === void 0 ? function (val) {
15729
15791
  return "".concat(val, "%");
15730
15792
  } : _ref$yAxisFormatter;
15793
+ var categories = useMemo(function () {
15794
+ var _trendSeries$;
15795
+ if (Array.isArray(trendSeries) && ((_trendSeries$ = trendSeries[0]) === null || _trendSeries$ === void 0 || (_trendSeries$ = _trendSeries$.data) === null || _trendSeries$ === void 0 ? void 0 : _trendSeries$.length) > 0) {
15796
+ return trendSeries[0].data.map(function (item) {
15797
+ return item.date;
15798
+ });
15799
+ }
15800
+ if (Array.isArray(trendData) && trendData.length > 0) {
15801
+ return trendData.map(function (item) {
15802
+ return item.date;
15803
+ });
15804
+ }
15805
+ return categoriesProp !== null && categoriesProp !== void 0 ? categoriesProp : [];
15806
+ }, [trendData, trendSeries, categoriesProp]);
15807
+ var chartSeries = useMemo(function () {
15808
+ if (Array.isArray(trendSeries) && trendSeries.length > 0) {
15809
+ return trendSeries.map(function (item) {
15810
+ var _item$data;
15811
+ return {
15812
+ name: item.name,
15813
+ data: ((_item$data = item.data) !== null && _item$data !== void 0 ? _item$data : []).map(function (point) {
15814
+ var _point$value;
15815
+ return (_point$value = point.value) !== null && _point$value !== void 0 ? _point$value : 0;
15816
+ }),
15817
+ dashed: item.dashed
15818
+ };
15819
+ });
15820
+ }
15821
+ if (Array.isArray(trendData) && trendData.length > 0) {
15822
+ var _series$0$name, _series$, _series$2;
15823
+ return [{
15824
+ name: (_series$0$name = (_series$ = series[0]) === null || _series$ === void 0 ? void 0 : _series$.name) !== null && _series$0$name !== void 0 ? _series$0$name : "Value",
15825
+ data: trendData.map(function (item) {
15826
+ var _item$value;
15827
+ return (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : 0;
15828
+ }),
15829
+ dashed: (_series$2 = series[0]) === null || _series$2 === void 0 ? void 0 : _series$2.dashed
15830
+ }];
15831
+ }
15832
+ return series;
15833
+ }, [trendData, trendSeries, series]);
15731
15834
  var chartOptions = {
15732
15835
  chart: {
15733
15836
  type: "area",
@@ -15742,7 +15845,7 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15742
15845
  stroke: {
15743
15846
  curve: "smooth",
15744
15847
  width: 2,
15745
- dashArray: series.map(function (s) {
15848
+ dashArray: chartSeries.map(function (s) {
15746
15849
  return s.dashed ? 5 : 0;
15747
15850
  })
15748
15851
  },
@@ -15757,14 +15860,18 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15757
15860
  },
15758
15861
  colors: colors,
15759
15862
  xaxis: {
15760
- categories: ["Apr 5", "Apr 12", "Apr 19", "Apr 26", "May 4"],
15863
+ categories: categories,
15864
+ tickAmount: 5,
15761
15865
  labels: {
15762
15866
  show: true,
15867
+ rotate: 0,
15868
+ hideOverlappingLabels: true,
15763
15869
  style: {
15764
- colors: 'rgba(0, 0, 0, 0.3)',
15765
- fontSize: '10px'
15870
+ colors: "rgba(0, 0, 0, 0.3)",
15871
+ fontSize: "10px"
15766
15872
  },
15767
- offsetY: -5
15873
+ offsetY: -5,
15874
+ formatter: formatCategoryLabel
15768
15875
  },
15769
15876
  axisBorder: {
15770
15877
  show: false
@@ -15772,7 +15879,7 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15772
15879
  axisTicks: {
15773
15880
  show: false
15774
15881
  },
15775
- position: 'bottom'
15882
+ position: "bottom"
15776
15883
  },
15777
15884
  yaxis: {
15778
15885
  max: yAxisMax,
@@ -15780,8 +15887,8 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15780
15887
  labels: {
15781
15888
  show: true,
15782
15889
  style: {
15783
- colors: 'rgba(0, 0, 0, 0.3)',
15784
- fontSize: '10px'
15890
+ colors: "rgba(0, 0, 0, 0.3)",
15891
+ fontSize: "10px"
15785
15892
  },
15786
15893
  formatter: yAxisFormatter
15787
15894
  }
@@ -15810,11 +15917,11 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15810
15917
  enabled: false
15811
15918
  },
15812
15919
  legend: {
15813
- show: series.length > 1,
15814
- position: 'bottom',
15815
- horizontalAlign: 'left',
15816
- fontSize: '11px',
15817
- fontFamily: 'Inter, sans-serif',
15920
+ show: chartSeries.length > 1,
15921
+ position: "bottom",
15922
+ horizontalAlign: "left",
15923
+ fontSize: "11px",
15924
+ fontFamily: "Inter, sans-serif",
15818
15925
  offsetY: -5,
15819
15926
  markers: {
15820
15927
  width: 8,
@@ -15827,7 +15934,13 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15827
15934
  }
15828
15935
  },
15829
15936
  tooltip: {
15830
- theme: 'light'
15937
+ theme: "light",
15938
+ x: {
15939
+ formatter: function formatter(_, _ref2) {
15940
+ var dataPointIndex = _ref2.dataPointIndex;
15941
+ return formatCategoryLabel(categories[dataPointIndex]);
15942
+ }
15943
+ }
15831
15944
  }
15832
15945
  };
15833
15946
  return /*#__PURE__*/jsxs(Card, {
@@ -15844,7 +15957,7 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15844
15957
  children: [/*#__PURE__*/jsxs(Box, {
15845
15958
  sx: {
15846
15959
  mb: 1,
15847
- textAlign: 'left'
15960
+ textAlign: "left"
15848
15961
  },
15849
15962
  children: [/*#__PURE__*/jsx(Typography, {
15850
15963
  sx: {
@@ -15890,7 +16003,7 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15890
16003
  },
15891
16004
  children: [/*#__PURE__*/jsx("span", {
15892
16005
  style: {
15893
- fontSize: '10px'
16006
+ fontSize: "10px"
15894
16007
  },
15895
16008
  children: "\u25B2"
15896
16009
  }), " ", trend]
@@ -15904,7 +16017,7 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15904
16017
  },
15905
16018
  children: /*#__PURE__*/jsx(ReactApexChart, {
15906
16019
  options: chartOptions,
15907
- series: series,
16020
+ series: chartSeries,
15908
16021
  type: "area",
15909
16022
  height: "100%"
15910
16023
  })
@@ -15912,109 +16025,282 @@ var EmailTrendCard = function EmailTrendCard(_ref) {
15912
16025
  });
15913
16026
  };
15914
16027
 
15915
- var EmailSection = function EmailSection() {
16028
+ var formatGrowth = function formatGrowth(value, dateName) {
16029
+ return "".concat(Number(value !== null && value !== void 0 ? value : 0).toFixed(2), "% vs ").concat(dateName || "previous period");
16030
+ };
16031
+ var mapTimeSeries = function mapTimeSeries(series) {
16032
+ if (!Array.isArray(series) || series.length === 0) {
16033
+ return {
16034
+ categories: [],
16035
+ data: []
16036
+ };
16037
+ }
16038
+ return {
16039
+ categories: series.map(function (item) {
16040
+ return item.date;
16041
+ }),
16042
+ data: series.map(function (item) {
16043
+ var _item$value;
16044
+ return (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : 0;
16045
+ })
16046
+ };
16047
+ };
16048
+ var getCampaignInitials = function getCampaignInitials() {
16049
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
16050
+ var words = name.trim().split(/\s+/).filter(Boolean);
16051
+ if (words.length >= 2) {
16052
+ return (words[0][0] + words[1][0]).toUpperCase();
16053
+ }
16054
+ return name.slice(0, 2).toUpperCase() || "—";
16055
+ };
16056
+ var computeYAxisMax = function computeYAxisMax(values) {
16057
+ var defaultMax = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 10;
16058
+ var max = Math.max.apply(Math, _toConsumableArray(values.length ? values : [0]).concat([0]));
16059
+ return max === 0 ? defaultMax : Math.ceil(max * 1.2);
16060
+ };
16061
+ var formatTrendBadge = function formatTrendBadge(value) {
16062
+ var isPercentage = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
16063
+ var num = Number(value !== null && value !== void 0 ? value : 0);
16064
+ if (isPercentage) {
16065
+ return "".concat(num >= 0 ? "+" : "").concat(num.toFixed(1), "pp");
16066
+ }
16067
+ return "".concat(num >= 0 ? "+" : "").concat(num.toFixed(1), "%");
16068
+ };
16069
+ var EmailSection = function EmailSection(_ref) {
16070
+ var _deliverability$openR2, _deliverability$total2, _deliverability$bounc2;
16071
+ var _ref$apiData = _ref.apiData,
16072
+ apiData = _ref$apiData === void 0 ? {} : _ref$apiData,
16073
+ _ref$dateName = _ref.dateName,
16074
+ dateName = _ref$dateName === void 0 ? "Last Period" : _ref$dateName;
15916
16075
  var _useState = useState("Total raised"),
15917
16076
  _useState2 = _slicedToArray(_useState, 2),
15918
16077
  activeMetric = _useState2[0],
15919
16078
  setActiveMetric = _useState2[1];
15920
- var metricInfo = {
15921
- "Total raised": {
15922
- value: "$".concat(formatNumber(48920)),
15923
- subValue: "12% vs last month",
15924
- icon: /*#__PURE__*/jsx(PaidOutlined, {}),
15925
- data: [3200, 4100, 2800, 5600, 4200, 6100, 7500],
15926
- money: true,
15927
- error: false,
15928
- warning: false
15929
- },
15930
- Donations: {
15931
- value: "62",
15932
- subValue: "12% vs last month",
15933
- icon: /*#__PURE__*/jsx(FavoriteOutlined, {}),
15934
- data: [4, 8, 5, 12, 10, 11, 12],
15935
- money: false,
15936
- error: false,
15937
- warning: false
15938
- },
15939
- "Conversion rate": {
15940
- value: "3.2%",
15941
- subValue: "12% vs last month",
15942
- icon: /*#__PURE__*/jsx(Adjust, {}),
15943
- data: [2.8, 3.1, 2.9, 3.4, 3.2, 3.1, 3.2],
15944
- money: false,
15945
- error: false,
15946
- warning: false
15947
- },
15948
- CTR: {
15949
- value: "8.1%",
15950
- subValue: "12% vs last month",
15951
- icon: /*#__PURE__*/jsx(NotInterested, {}),
15952
- data: [7.2, 8.4, 7.8, 8.9, 8.1, 8.0, 8.1],
15953
- money: false,
15954
- error: false,
15955
- warning: false
15956
- },
15957
- "Revenue per email": {
15958
- value: "$".concat(formatNumber(2.45)),
15959
- subValue: "12% vs last month",
15960
- icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
15961
- data: [2.1, 2.5, 2.3, 2.8, 2.4, 2.4, 2.45],
15962
- money: true,
15963
- error: false,
15964
- warning: false
15965
- },
15966
- "Open rate": {
15967
- value: "42.3%",
15968
- subValue: "12% vs last month",
15969
- icon: /*#__PURE__*/jsx(Email, {}),
15970
- data: [38, 44, 40, 46, 42, 41, 42.3],
15971
- money: false,
15972
- error: false,
15973
- warning: false
15974
- },
15975
- Clicks: {
15976
- value: "1,612",
15977
- subValue: "12% vs last month",
15978
- icon: /*#__PURE__*/jsx(NearMe, {}),
15979
- data: [210, 240, 220, 280, 250, 245, 245],
15980
- money: false,
15981
- error: false,
15982
- warning: false
15983
- },
15984
- "Unique Clicks": {
15985
- value: "".concat(formatNumber(1148)),
15986
- subValue: "12% vs last month",
15987
- icon: /*#__PURE__*/jsx(NearMe, {}),
15988
- data: [150, 180, 160, 210, 190, 185, 185],
15989
- money: false,
15990
- error: false,
15991
- warning: false
15992
- },
15993
- "Bounce rate": {
15994
- value: "1.8%",
15995
- subValue: "12% vs last month",
15996
- icon: /*#__PURE__*/jsx(HighlightOff, {}),
15997
- data: [2.1, 1.9, 1.8, 1.7, 1.8, 1.8, 1.8],
15998
- money: false,
15999
- error: false,
16000
- warning: false
16001
- },
16002
- "Revenue per Click": {
16003
- value: "$".concat(formatNumber(30.35)),
16004
- subValue: "12% vs last month",
16005
- icon: /*#__PURE__*/jsx(HighlightOff, {}),
16006
- data: [28, 32, 29, 34, 30, 30, 30.35],
16007
- money: true,
16008
- error: false,
16009
- warning: false
16010
- }
16079
+ var overview = (apiData === null || apiData === void 0 ? void 0 : apiData.overview) || {};
16080
+ var overviewGrowth = (overview === null || overview === void 0 ? void 0 : overview.growthPercentage) || {};
16081
+ var deliverability = (apiData === null || apiData === void 0 ? void 0 : apiData.deliverability) || {};
16082
+ var deliverabilityGrowth = (deliverability === null || deliverability === void 0 ? void 0 : deliverability.growthPercentage) || {};
16083
+ var hasEmailOverview = Boolean(apiData === null || apiData === void 0 ? void 0 : apiData.overview);
16084
+ var openRateTrend = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.openRateTrend);
16085
+ var totalClicksTrend = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.totalClicksTrend);
16086
+ var uniqueClicksTrend = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.uniqueClicksTrend);
16087
+ var bounceRateTrend = mapTimeSeries(apiData === null || apiData === void 0 ? void 0 : apiData.bounceRateTrend);
16088
+ var growthCaption = function growthCaption(key) {
16089
+ var source = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : overviewGrowth;
16090
+ return formatGrowth(source[key], dateName);
16011
16091
  };
16092
+ var metricInfo = useMemo(function () {
16093
+ var _overview$totalRevenu, _overview$totalDonati, _overview$conversionR, _overview$ctr, _overview$revenuePerE, _deliverability$openR, _deliverability$total, _deliverability$uniqu, _deliverability$bounc, _deliverability$reven;
16094
+ if (!hasEmailOverview) {
16095
+ return {
16096
+ "Total raised": {
16097
+ value: "$".concat(formatNumber(48920)),
16098
+ subValue: "12% vs last month",
16099
+ icon: /*#__PURE__*/jsx(PaidOutlined, {}),
16100
+ money: true,
16101
+ error: false,
16102
+ warning: false
16103
+ },
16104
+ Donations: {
16105
+ value: "62",
16106
+ subValue: "12% vs last month",
16107
+ icon: /*#__PURE__*/jsx(FavoriteOutlined, {}),
16108
+ money: false,
16109
+ error: false,
16110
+ warning: false
16111
+ },
16112
+ "Conversion rate": {
16113
+ value: "3.2%",
16114
+ subValue: "12% vs last month",
16115
+ icon: /*#__PURE__*/jsx(Adjust, {}),
16116
+ money: false,
16117
+ error: false,
16118
+ warning: false
16119
+ },
16120
+ CTR: {
16121
+ value: "8.1%",
16122
+ subValue: "12% vs last month",
16123
+ icon: /*#__PURE__*/jsx(NotInterested, {}),
16124
+ money: false,
16125
+ error: false,
16126
+ warning: false
16127
+ },
16128
+ "Revenue per email": {
16129
+ value: "$".concat(formatNumber(2.45)),
16130
+ subValue: "12% vs last month",
16131
+ icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
16132
+ money: true,
16133
+ error: false,
16134
+ warning: false
16135
+ },
16136
+ "Open rate": {
16137
+ value: "42.3%",
16138
+ subValue: "12% vs last month",
16139
+ icon: /*#__PURE__*/jsx(Email, {}),
16140
+ money: false,
16141
+ error: false,
16142
+ warning: false
16143
+ },
16144
+ Clicks: {
16145
+ value: "1,612",
16146
+ subValue: "12% vs last month",
16147
+ icon: /*#__PURE__*/jsx(NearMe, {}),
16148
+ money: false,
16149
+ error: false,
16150
+ warning: false
16151
+ },
16152
+ "Unique Clicks": {
16153
+ value: formatNumber(1148),
16154
+ subValue: "12% vs last month",
16155
+ icon: /*#__PURE__*/jsx(NearMe, {}),
16156
+ money: false,
16157
+ error: false,
16158
+ warning: false
16159
+ },
16160
+ "Bounce rate": {
16161
+ value: "1.8%",
16162
+ subValue: "12% vs last month",
16163
+ icon: /*#__PURE__*/jsx(HighlightOff, {}),
16164
+ money: false,
16165
+ error: false,
16166
+ warning: false
16167
+ },
16168
+ "Revenue per Click": {
16169
+ value: "$".concat(formatNumber(30.35)),
16170
+ subValue: "12% vs last month",
16171
+ icon: /*#__PURE__*/jsx(HighlightOff, {}),
16172
+ money: true,
16173
+ error: false,
16174
+ warning: false
16175
+ }
16176
+ };
16177
+ }
16178
+ return {
16179
+ "Total raised": {
16180
+ value: "$".concat(formatNumber((_overview$totalRevenu = overview.totalRevenue) !== null && _overview$totalRevenu !== void 0 ? _overview$totalRevenu : 0)),
16181
+ subValue: growthCaption("totalRevenue"),
16182
+ icon: /*#__PURE__*/jsx(PaidOutlined, {}),
16183
+ money: true,
16184
+ error: false,
16185
+ warning: false
16186
+ },
16187
+ Donations: {
16188
+ value: formatNumber((_overview$totalDonati = overview.totalDonations) !== null && _overview$totalDonati !== void 0 ? _overview$totalDonati : 0),
16189
+ subValue: growthCaption("totalDonations"),
16190
+ icon: /*#__PURE__*/jsx(FavoriteOutlined, {}),
16191
+ money: false,
16192
+ error: false,
16193
+ warning: false
16194
+ },
16195
+ "Conversion rate": {
16196
+ value: "".concat(Number((_overview$conversionR = overview.conversionRate) !== null && _overview$conversionR !== void 0 ? _overview$conversionR : 0).toFixed(2), "%"),
16197
+ subValue: growthCaption("conversionRate"),
16198
+ icon: /*#__PURE__*/jsx(Adjust, {}),
16199
+ money: false,
16200
+ error: false,
16201
+ warning: false
16202
+ },
16203
+ CTR: {
16204
+ value: "".concat(Number((_overview$ctr = overview.ctr) !== null && _overview$ctr !== void 0 ? _overview$ctr : 0).toFixed(2), "%"),
16205
+ subValue: growthCaption("ctr"),
16206
+ icon: /*#__PURE__*/jsx(NotInterested, {}),
16207
+ money: false,
16208
+ error: false,
16209
+ warning: false
16210
+ },
16211
+ "Revenue per email": {
16212
+ value: "$".concat(formatNumber((_overview$revenuePerE = overview.revenuePerEmail) !== null && _overview$revenuePerE !== void 0 ? _overview$revenuePerE : 0)),
16213
+ subValue: growthCaption("revenuePerEmail"),
16214
+ icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
16215
+ money: true,
16216
+ error: false,
16217
+ warning: false
16218
+ },
16219
+ "Open rate": {
16220
+ value: "".concat(Number((_deliverability$openR = deliverability.openRate) !== null && _deliverability$openR !== void 0 ? _deliverability$openR : 0).toFixed(2), "%"),
16221
+ subValue: growthCaption("openRate", deliverabilityGrowth),
16222
+ icon: /*#__PURE__*/jsx(Email, {}),
16223
+ money: false,
16224
+ error: false,
16225
+ warning: false
16226
+ },
16227
+ Clicks: {
16228
+ value: formatNumber((_deliverability$total = deliverability.totalClicks) !== null && _deliverability$total !== void 0 ? _deliverability$total : 0),
16229
+ subValue: growthCaption("totalClicks", deliverabilityGrowth),
16230
+ icon: /*#__PURE__*/jsx(NearMe, {}),
16231
+ money: false,
16232
+ error: false,
16233
+ warning: false
16234
+ },
16235
+ "Unique Clicks": {
16236
+ value: formatNumber((_deliverability$uniqu = deliverability.uniqueClicks) !== null && _deliverability$uniqu !== void 0 ? _deliverability$uniqu : 0),
16237
+ subValue: growthCaption("uniqueClicks", deliverabilityGrowth),
16238
+ icon: /*#__PURE__*/jsx(NearMe, {}),
16239
+ money: false,
16240
+ error: false,
16241
+ warning: false
16242
+ },
16243
+ "Bounce rate": {
16244
+ value: "".concat(Number((_deliverability$bounc = deliverability.bounceRate) !== null && _deliverability$bounc !== void 0 ? _deliverability$bounc : 0).toFixed(2), "%"),
16245
+ subValue: growthCaption("bounceRate", deliverabilityGrowth),
16246
+ icon: /*#__PURE__*/jsx(HighlightOff, {}),
16247
+ money: false,
16248
+ error: false,
16249
+ warning: false
16250
+ },
16251
+ "Revenue per Click": {
16252
+ value: "$".concat(formatNumber((_deliverability$reven = deliverability.revenuePerClick) !== null && _deliverability$reven !== void 0 ? _deliverability$reven : 0)),
16253
+ subValue: growthCaption("revenuePerClick", deliverabilityGrowth),
16254
+ icon: /*#__PURE__*/jsx(HighlightOff, {}),
16255
+ money: true,
16256
+ error: false,
16257
+ warning: false
16258
+ }
16259
+ };
16260
+ }, [deliverability, deliverabilityGrowth, hasEmailOverview, overview, overviewGrowth, dateName]);
16261
+ var campaignsRaisedData = useMemo(function () {
16262
+ var campaigns = apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByRaised;
16263
+ if (!hasEmailOverview) return null;
16264
+ if (!Array.isArray(campaigns) || campaigns.length === 0) return [];
16265
+ return campaigns.map(function (item) {
16266
+ var _item$value2;
16267
+ return {
16268
+ id: getCampaignInitials(item.campaignName),
16269
+ name: item.campaignName || "Unknown",
16270
+ value: "$".concat(formatNumber((_item$value2 = item.value) !== null && _item$value2 !== void 0 ? _item$value2 : 0))
16271
+ };
16272
+ });
16273
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByRaised, hasEmailOverview]);
16274
+ var campaignsCtrData = useMemo(function () {
16275
+ var campaigns = apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByCtr;
16276
+ if (!hasEmailOverview) return null;
16277
+ if (!Array.isArray(campaigns) || campaigns.length === 0) return [];
16278
+ return campaigns.map(function (item) {
16279
+ var _item$value3;
16280
+ return {
16281
+ id: getCampaignInitials(item.campaignName),
16282
+ name: item.campaignName || "Unknown",
16283
+ value: "".concat(Number((_item$value3 = item.value) !== null && _item$value3 !== void 0 ? _item$value3 : 0).toFixed(2), "%")
16284
+ };
16285
+ });
16286
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByCtr, hasEmailOverview]);
16287
+ var campaignsConversionData = useMemo(function () {
16288
+ var campaigns = apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByConversion;
16289
+ if (!hasEmailOverview) return null;
16290
+ if (!Array.isArray(campaigns) || campaigns.length === 0) return [];
16291
+ return campaigns.map(function (item) {
16292
+ var _item$value4;
16293
+ return {
16294
+ id: getCampaignInitials(item.campaignName),
16295
+ name: item.campaignName || "Unknown",
16296
+ value: "".concat(Number((_item$value4 = item.value) !== null && _item$value4 !== void 0 ? _item$value4 : 0).toFixed(2), "%")
16297
+ };
16298
+ });
16299
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.topCampaignsByConversion, hasEmailOverview]);
16012
16300
  var renderCard = function renderCard(title) {
16013
- return /*#__PURE__*/jsx(MetricCard
16014
- // key={title}
16015
- , {
16301
+ return /*#__PURE__*/jsx(MetricCard, {
16016
16302
  title: title,
16017
- value: metricInfo[title].money ? metricInfo[title].value : metricInfo[title].value,
16303
+ value: metricInfo[title].value,
16018
16304
  caption: metricInfo[title].subValue,
16019
16305
  icon: metricInfo[title].icon,
16020
16306
  error: metricInfo[title].error,
@@ -16026,19 +16312,7 @@ var EmailSection = function EmailSection() {
16026
16312
  border: "2px solid #ef4444",
16027
16313
  bgcolor: "#fffafa"
16028
16314
  } : {}
16029
- })
16030
- // <DisplayCard
16031
- // key={title}
16032
- // title={title}
16033
- // value={metricInfo[title].value}
16034
- // subValue={metricInfo[title].subValue}
16035
- // icon={metricInfo[title].icon}
16036
- // // onClick={() => setActiveMetric(title)}
16037
- // // isActive={activeMetric === title}
16038
- // sx={{
16039
- // }}
16040
- // />
16041
- ;
16315
+ });
16042
16316
  };
16043
16317
  return /*#__PURE__*/jsxs(Fragment, {
16044
16318
  children: [/*#__PURE__*/jsx(Box, {
@@ -16070,14 +16344,16 @@ var EmailSection = function EmailSection() {
16070
16344
  children: /*#__PURE__*/jsx(EmailTrendCard, {
16071
16345
  title: "Open rate trend",
16072
16346
  subtitle: "Daily \xB7 30 days",
16073
- value: "42.3%",
16074
- trend: "2.1pp",
16347
+ value: hasEmailOverview ? "".concat(Number((_deliverability$openR2 = deliverability.openRate) !== null && _deliverability$openR2 !== void 0 ? _deliverability$openR2 : 0).toFixed(2), "%") : "42.3%",
16348
+ trend: hasEmailOverview ? formatTrendBadge(deliverabilityGrowth.openRate, true) : "2.1pp",
16349
+ trendData: hasEmailOverview ? apiData === null || apiData === void 0 ? void 0 : apiData.openRateTrend : undefined,
16075
16350
  series: [{
16076
- name: 'Open Rate',
16351
+ name: "Open Rate",
16077
16352
  data: [38, 42, 41, 43, 42.3]
16078
16353
  }],
16079
- colors: ['rgb(99, 99, 230)'],
16080
- yAxisMax: 53,
16354
+ categories: ["Apr 5", "Apr 12", "Apr 19", "Apr 26", "May 4"],
16355
+ colors: ["rgb(99, 99, 230)"],
16356
+ yAxisMax: computeYAxisMax(openRateTrend.data, 5),
16081
16357
  yAxisTickAmount: 3
16082
16358
  })
16083
16359
  }), /*#__PURE__*/jsx(Grid, {
@@ -16095,18 +16371,27 @@ var EmailSection = function EmailSection() {
16095
16371
  children: /*#__PURE__*/jsx(EmailTrendCard, {
16096
16372
  title: "Clicks trend",
16097
16373
  subtitle: "Total + unique \xB7 30 days",
16098
- value: "1,612",
16099
- trend: "14%",
16374
+ value: hasEmailOverview ? formatNumber((_deliverability$total2 = deliverability.totalClicks) !== null && _deliverability$total2 !== void 0 ? _deliverability$total2 : 0) : "1,612",
16375
+ trend: hasEmailOverview ? formatTrendBadge(deliverabilityGrowth.totalClicks) : "14%",
16376
+ trendSeries: hasEmailOverview ? [{
16377
+ name: "Total clicks",
16378
+ data: apiData === null || apiData === void 0 ? void 0 : apiData.totalClicksTrend
16379
+ }, {
16380
+ name: "Unique clicks",
16381
+ data: apiData === null || apiData === void 0 ? void 0 : apiData.uniqueClicksTrend,
16382
+ dashed: true
16383
+ }] : undefined,
16100
16384
  series: [{
16101
- name: 'Total clicks',
16385
+ name: "Total clicks",
16102
16386
  data: [56, 112, 80, 150, 112]
16103
16387
  }, {
16104
- name: 'Unique clicks',
16388
+ name: "Unique clicks",
16105
16389
  data: [30, 70, 45, 100, 75],
16106
16390
  dashed: true
16107
16391
  }],
16108
- colors: ['#10B981', '#10B981'],
16109
- yAxisMax: 168,
16392
+ categories: ["Apr 5", "Apr 12", "Apr 19", "Apr 26", "May 4"],
16393
+ colors: ["#10B981", "#10B981"],
16394
+ yAxisMax: computeYAxisMax([].concat(_toConsumableArray(totalClicksTrend.data), _toConsumableArray(uniqueClicksTrend.data)), 10),
16110
16395
  yAxisTickAmount: 3,
16111
16396
  yAxisFormatter: function yAxisFormatter(val) {
16112
16397
  return val;
@@ -16127,14 +16412,16 @@ var EmailSection = function EmailSection() {
16127
16412
  children: /*#__PURE__*/jsx(EmailTrendCard, {
16128
16413
  title: "Bounce rate trend",
16129
16414
  subtitle: "Daily \xB7 lower is better",
16130
- value: "1.8%",
16131
- trend: "0.3pp",
16415
+ value: hasEmailOverview ? "".concat(Number((_deliverability$bounc2 = deliverability.bounceRate) !== null && _deliverability$bounc2 !== void 0 ? _deliverability$bounc2 : 0).toFixed(2), "%") : "1.8%",
16416
+ trend: hasEmailOverview ? formatTrendBadge(deliverabilityGrowth.bounceRate, true) : "0.3pp",
16417
+ trendData: hasEmailOverview ? apiData === null || apiData === void 0 ? void 0 : apiData.bounceRateTrend : undefined,
16132
16418
  series: [{
16133
- name: 'Bounce Rate',
16419
+ name: "Bounce Rate",
16134
16420
  data: [2.2, 1.9, 2.0, 1.7, 1.8]
16135
16421
  }],
16136
- colors: ['#f2994a'],
16137
- yAxisMax: 2.5,
16422
+ categories: ["Apr 5", "Apr 12", "Apr 19", "Apr 26", "May 4"],
16423
+ colors: ["#f2994a"],
16424
+ yAxisMax: computeYAxisMax(bounceRateTrend.data, 2.5),
16138
16425
  yAxisTickAmount: 3
16139
16426
  })
16140
16427
  })]
@@ -16151,7 +16438,9 @@ var EmailSection = function EmailSection() {
16151
16438
  sx: {
16152
16439
  paddingTop: "0px !important"
16153
16440
  },
16154
- children: /*#__PURE__*/jsx(TopCampaignsRaisedCard, {})
16441
+ children: /*#__PURE__*/jsx(TopCampaignsRaisedCard, {
16442
+ data: campaignsRaisedData
16443
+ })
16155
16444
  }), /*#__PURE__*/jsx(Grid, {
16156
16445
  item: true,
16157
16446
  xs: 12,
@@ -16164,7 +16453,9 @@ var EmailSection = function EmailSection() {
16164
16453
  md: "0px"
16165
16454
  }
16166
16455
  },
16167
- children: /*#__PURE__*/jsx(TopCampaignsCTRCard, {})
16456
+ children: /*#__PURE__*/jsx(TopCampaignsCTRCard, {
16457
+ data: campaignsCtrData
16458
+ })
16168
16459
  }), /*#__PURE__*/jsx(Grid, {
16169
16460
  item: true,
16170
16461
  xs: 12,
@@ -16177,7 +16468,9 @@ var EmailSection = function EmailSection() {
16177
16468
  md: "0px"
16178
16469
  }
16179
16470
  },
16180
- children: /*#__PURE__*/jsx(TopCampaignsConvRateCard, {})
16471
+ children: /*#__PURE__*/jsx(TopCampaignsConvRateCard, {
16472
+ data: campaignsConversionData
16473
+ })
16181
16474
  })]
16182
16475
  })]
16183
16476
  });