@ammarkhalidfarooq/dashboard-package 0.6.82 → 0.6.84

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
@@ -714,7 +714,8 @@ var RenderChartCard = function RenderChartCard(_ref) {
714
714
  },
715
715
  children: [isPremium ? /*#__PURE__*/jsxs(Box, {
716
716
  sx: {
717
- textAlign: "left"
717
+ textAlign: "left",
718
+ marginBottom: "12px"
718
719
  },
719
720
  children: [/*#__PURE__*/jsx(Typography, {
720
721
  sx: {
@@ -767,7 +768,8 @@ var RenderChartCard = function RenderChartCard(_ref) {
767
768
  })]
768
769
  }) : /*#__PURE__*/jsxs(Box, {
769
770
  sx: {
770
- textAlign: "left"
771
+ textAlign: "left",
772
+ marginBottom: "12px"
771
773
  },
772
774
  children: [/*#__PURE__*/jsx(Typography, {
773
775
  variant: "subtitle2",
@@ -4003,7 +4005,9 @@ var NewOverview = function NewOverview(_ref) {
4003
4005
  apiLoading: apiLoading
4004
4006
  }), activeSection === "Paid" && /*#__PURE__*/jsx(PaidSection$2, {
4005
4007
  apiData: apiData,
4006
- apiLoading: apiLoading
4008
+ dateName: dateName,
4009
+ apiLoading: apiLoading,
4010
+ numberOfDays: numberOfDays
4007
4011
  }), activeSection === "Organic" && /*#__PURE__*/jsx(Box, {
4008
4012
  sx: {},
4009
4013
  children: /*#__PURE__*/jsx(OrganicSection$2, {
@@ -6251,36 +6255,39 @@ var TopCampaignsConvRateCard = function TopCampaignsConvRateCard(_ref7) {
6251
6255
  })]
6252
6256
  });
6253
6257
  };
6254
- var TopPerformingCampaignsCard = function TopPerformingCampaignsCard() {
6255
- var data = [{
6256
- id: "YO",
6257
- // avatarBg: "#c1cfde70",
6258
+ var getCampaignInitials$1 = function getCampaignInitials() {
6259
+ var name = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
6260
+ var words = name.trim().split(/\s+/).filter(Boolean);
6261
+ if (words.length >= 2) {
6262
+ return (words[0][0] + words[1][0]).toUpperCase();
6263
+ }
6264
+ return name.slice(0, 2).toUpperCase() || "—";
6265
+ };
6266
+ var TopPerformingCampaignsCard = function TopPerformingCampaignsCard(_ref8) {
6267
+ var _ref8$data = _ref8.data,
6268
+ dataProp = _ref8$data === void 0 ? null : _ref8$data;
6269
+ var fallbackData = [{
6258
6270
  name: "Yemen Orphans - Meta",
6259
6271
  spend: "$8,200",
6260
6272
  revenue: "$31,400",
6261
6273
  roas: "3.8x"
6262
6274
  }, {
6263
- id: "GF",
6264
- // avatarBg: "#c1cfdedb",
6265
6275
  name: "Gaza Food - Google",
6266
6276
  spend: "$7,400",
6267
6277
  revenue: "$25,200",
6268
6278
  roas: "3.4x"
6269
6279
  }, {
6270
- id: "PW",
6271
- // avatarBg: "#c1cfdedb",
6272
6280
  name: "Pakistan Wells - Meta",
6273
6281
  spend: "$5,800",
6274
6282
  revenue: "$18,600",
6275
6283
  roas: "3.2x"
6276
6284
  }, {
6277
- id: "R",
6278
- // avatarBg: "#c1cfdedb",
6279
6285
  name: "Ramadan - TikTok",
6280
6286
  spend: "$3,200",
6281
6287
  revenue: "$8,900",
6282
6288
  roas: "2.8x"
6283
6289
  }];
6290
+ var data = dataProp === null ? fallbackData : dataProp;
6284
6291
  return /*#__PURE__*/jsxs(CardWrapper, {
6285
6292
  title: "Top performing campaigns",
6286
6293
  subtitle: "Paid campaigns ranked by ROAS",
@@ -6325,7 +6332,14 @@ var TopPerformingCampaignsCard = function TopPerformingCampaignsCard() {
6325
6332
  },
6326
6333
  children: "ROAS"
6327
6334
  })]
6328
- }), data.map(function (item, index) {
6335
+ }), data.length === 0 ? /*#__PURE__*/jsx(Typography, {
6336
+ sx: {
6337
+ fontSize: "13px",
6338
+ color: "rgba(0, 0, 0, 0.4)",
6339
+ py: 2
6340
+ },
6341
+ children: "No campaign data for this period"
6342
+ }) : data.map(function (item, index) {
6329
6343
  return /*#__PURE__*/jsxs(Box, {
6330
6344
  sx: {
6331
6345
  display: "grid",
@@ -6354,7 +6368,7 @@ var TopPerformingCampaignsCard = function TopPerformingCampaignsCard() {
6354
6368
  fontSize: "10px",
6355
6369
  fontWeight: 700
6356
6370
  },
6357
- children: item.id
6371
+ children: item.id || getCampaignInitials$1(item.name)
6358
6372
  }), /*#__PURE__*/jsx(Typography, {
6359
6373
  sx: {
6360
6374
  fontSize: "13px",
@@ -6398,9 +6412,9 @@ var TopPerformingCampaignsCard = function TopPerformingCampaignsCard() {
6398
6412
  })]
6399
6413
  });
6400
6414
  };
6401
- var PaidDonorGeographyCard = function PaidDonorGeographyCard(_ref8) {
6402
- var sx = _ref8.sx,
6403
- donorGeographyData = _ref8.donorGeographyData;
6415
+ var PaidDonorGeographyCard = function PaidDonorGeographyCard(_ref9) {
6416
+ var sx = _ref9.sx,
6417
+ donorGeographyData = _ref9.donorGeographyData;
6404
6418
  var rawCountries = Array.isArray(donorGeographyData) ? donorGeographyData : (donorGeographyData === null || donorGeographyData === void 0 ? void 0 : donorGeographyData.countries) || [];
6405
6419
  var data = rawCountries.map(function (item) {
6406
6420
  return {
@@ -17976,87 +17990,341 @@ var OverallSection$1 = /*#__PURE__*/Object.freeze({
17976
17990
  default: OverallSection
17977
17991
  });
17978
17992
 
17993
+ var CHANNEL_STYLES = {
17994
+ "Meta Ads": {
17995
+ id: "M",
17996
+ avatarBg: "#4267B2",
17997
+ color: "#4267B2"
17998
+ },
17999
+ "Google Ads": {
18000
+ id: "G",
18001
+ avatarBg: "#4285F4",
18002
+ color: "#4285F4"
18003
+ },
18004
+ "TikTok Ads": {
18005
+ id: "T",
18006
+ avatarBg: "#000000",
18007
+ color: "#cd249dff"
18008
+ },
18009
+ YouTube: {
18010
+ id: "Y",
18011
+ avatarBg: "#FF0000",
18012
+ color: "#FF0000"
18013
+ },
18014
+ Snapchat: {
18015
+ id: "S",
18016
+ avatarBg: "#FFFC00",
18017
+ color: "#FFFC00"
18018
+ }
18019
+ };
18020
+ var formatGrowth$2 = function formatGrowth(value) {
18021
+ return "".concat(Number(value !== null && value !== void 0 ? value : 0).toFixed(2), "% vs pp");
18022
+ };
18023
+ var mapTimeSeries$2 = function mapTimeSeries(series) {
18024
+ if (!Array.isArray(series) || series.length === 0) {
18025
+ return {
18026
+ categories: [],
18027
+ data: []
18028
+ };
18029
+ }
18030
+ return {
18031
+ categories: series.map(function (item) {
18032
+ return item.date;
18033
+ }),
18034
+ data: series.map(function (item) {
18035
+ var _item$value;
18036
+ return (_item$value = item.value) !== null && _item$value !== void 0 ? _item$value : 0;
18037
+ })
18038
+ };
18039
+ };
18040
+ var getChannelStyle = function getChannelStyle() {
18041
+ var channel = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : "";
18042
+ return CHANNEL_STYLES[channel] || {
18043
+ id: channel.slice(0, 1).toUpperCase() || "?",
18044
+ avatarBg: "#F3F4F6",
18045
+ color: "#6366F1"
18046
+ };
18047
+ };
18048
+ var mapChannelTrend = function mapChannelTrend(trend) {
18049
+ var normalized = (trend || "stable").toLowerCase();
18050
+ if (normalized === "down" || normalized === "declining") {
18051
+ return {
18052
+ type: "trend",
18053
+ trendType: "down",
18054
+ trendLabel: "Declining"
18055
+ };
18056
+ }
18057
+ if (normalized === "up" || normalized === "improving") {
18058
+ return {
18059
+ type: "trend",
18060
+ trendType: "up",
18061
+ trendLabel: "Improving"
18062
+ };
18063
+ }
18064
+ return {
18065
+ type: "status",
18066
+ status: "Stable",
18067
+ statusBg: "#F3F4F6",
18068
+ statusColor: "#6B7280"
18069
+ };
18070
+ };
18071
+ var getRoasColor = function getRoasColor(roas) {
18072
+ return Number(roas !== null && roas !== void 0 ? roas : 0) >= 2.5 ? "#22C55E" : "#EF4444";
18073
+ };
17979
18074
  var PaidSection = function PaidSection(_ref) {
17980
- var _ref$apiLoading = _ref.apiLoading,
17981
- apiLoading = _ref$apiLoading === void 0 ? false : _ref$apiLoading;
18075
+ var _apiData$spendVsReven, _apiData$spendVsReven2, _selectedInfo$categor, _spendAllocation$subt, _spendAllocation$seri, _spendAllocation$labe, _spendAllocation$colo, _spendAllocation$cent, _spendAllocation$cent2, _spendAllocation$item;
18076
+ var _ref$apiData = _ref.apiData,
18077
+ apiData = _ref$apiData === void 0 ? {} : _ref$apiData;
18078
+ _ref.dateName;
18079
+ var _ref$apiLoading = _ref.apiLoading,
18080
+ apiLoading = _ref$apiLoading === void 0 ? false : _ref$apiLoading,
18081
+ _ref$numberOfDays = _ref.numberOfDays,
18082
+ numberOfDays = _ref$numberOfDays === void 0 ? 30 : _ref$numberOfDays;
17982
18083
  var _useState = useState("Total Spent"),
17983
18084
  _useState2 = _slicedToArray(_useState, 2),
17984
18085
  activeMetric = _useState2[0],
17985
18086
  setActiveMetric = _useState2[1];
17986
- if (apiLoading) {
17987
- return /*#__PURE__*/jsx(PaidSectionSkeleton, {});
17988
- }
17989
- var categories = ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
17990
- var metricInfo = {
17991
- "Total Spent": {
17992
- value: "$".concat(formatNumber(80313)),
17993
- subValue: "12% vs last month",
17994
- chartLabel: "Daily Spend",
17995
- data: [800, 950, 700, 1100, 900, 1200, 1300],
17996
- icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
17997
- money: true,
17998
- error: false,
17999
- warning: false
18000
- },
18001
- "Revinue Raised": {
18002
- value: "$".concat(formatNumber(240398)),
18003
- subValue: "12% vs last month",
18004
- chartLabel: "Daily Revenue",
18005
- data: [3200, 4100, 2800, 5600, 4200, 6100, 7500],
18006
- icon: /*#__PURE__*/jsx(PaidOutlined, {}),
18007
- money: true,
18008
- error: false,
18009
- warning: false
18010
- },
18011
- ROAS: {
18012
- value: "3.0",
18013
- subValue: "12% vs last month",
18014
- chartLabel: "ROAS Trend",
18015
- data: [2.5, 3.1, 2.8, 4.2, 3.8, 4.5, 5.2],
18016
- icon: /*#__PURE__*/jsx(TrendingUp, {}),
18017
- money: false,
18018
- error: false,
18019
- warning: false
18020
- },
18021
- "Cost per donor": {
18022
- value: "$".concat(formatNumber(373)),
18023
- subValue: "12% vs last month",
18024
- chartLabel: "CPA Trend",
18025
- data: [350, 380, 360, 410, 390, 370, 373],
18026
- icon: /*#__PURE__*/jsx(PersonOutlined, {}),
18027
- money: true,
18028
- error: false,
18029
- warning: false
18030
- },
18031
- "Conversion rate": {
18032
- value: "3.1%",
18033
- subValue: "12% vs last month",
18034
- chartLabel: "Conversion Rate",
18035
- data: [2.8, 3.0, 2.9, 3.4, 3.2, 3.1, 3.1],
18036
- icon: /*#__PURE__*/jsx(ConversionRateIcon, {}),
18037
- avatarSx: conversionRateAvatarSx,
18038
- money: false,
18039
- error: false,
18040
- warning: false
18041
- },
18042
- "Avg donation": {
18043
- value: "$".concat(formatNumber(130.58)),
18044
- subValue: "12% vs last month",
18045
- chartLabel: "Average Donation",
18046
- data: [120, 135, 125, 140, 130, 128, 130.58],
18047
- icon: /*#__PURE__*/jsx(AverageDonationIcon, {}),
18048
- avatarSx: avgDonationAvatarSx,
18049
- money: true,
18050
- error: false,
18051
- warning: false
18087
+ var overview = (apiData === null || apiData === void 0 ? void 0 : apiData.overview) || {};
18088
+ var growth = (overview === null || overview === void 0 ? void 0 : overview.growthPercentage) || {};
18089
+ var hasPaidOverview = Boolean(apiData === null || apiData === void 0 ? void 0 : apiData.overview);
18090
+ var spendSeries = mapTimeSeries$2(apiData === null || apiData === void 0 || (_apiData$spendVsReven = apiData.spendVsRevenue) === null || _apiData$spendVsReven === void 0 ? void 0 : _apiData$spendVsReven.spend);
18091
+ var revenueSeries = mapTimeSeries$2(apiData === null || apiData === void 0 || (_apiData$spendVsReven2 = apiData.spendVsRevenue) === null || _apiData$spendVsReven2 === void 0 ? void 0 : _apiData$spendVsReven2.revenue);
18092
+ var roasChartData = useMemo(function () {
18093
+ if (spendSeries.data.length === 0 || revenueSeries.data.length === 0) {
18094
+ return [];
18052
18095
  }
18096
+ var length = Math.min(spendSeries.data.length, revenueSeries.data.length);
18097
+ return Array.from({
18098
+ length: length
18099
+ }, function (_, index) {
18100
+ var _spendSeries$data$ind, _revenueSeries$data$i;
18101
+ var spend = (_spendSeries$data$ind = spendSeries.data[index]) !== null && _spendSeries$data$ind !== void 0 ? _spendSeries$data$ind : 0;
18102
+ var revenue = (_revenueSeries$data$i = revenueSeries.data[index]) !== null && _revenueSeries$data$i !== void 0 ? _revenueSeries$data$i : 0;
18103
+ return spend > 0 ? revenue / spend : 0;
18104
+ });
18105
+ }, [spendSeries.data, revenueSeries.data]);
18106
+ var fallbackCategories = spendSeries.categories.length ? spendSeries.categories : revenueSeries.categories.length ? revenueSeries.categories : ["Mon", "Tue", "Wed", "Thu", "Fri", "Sat", "Sun"];
18107
+ var flatSeries = function flatSeries(value) {
18108
+ return fallbackCategories.length > 0 ? fallbackCategories.map(function () {
18109
+ return Number(value !== null && value !== void 0 ? value : 0);
18110
+ }) : [Number(value !== null && value !== void 0 ? value : 0)];
18053
18111
  };
18112
+ var metricInfo = useMemo(function () {
18113
+ var _overview$totalSpent, _overview$totalRevenu, _overview$roas, _overview$roas2, _overview$costPerDono, _overview$costPerDono2, _overview$conversionR, _overview$conversionR2, _overview$averageDona, _overview$averageDona2;
18114
+ if (!hasPaidOverview) {
18115
+ return {
18116
+ "Total Spent": {
18117
+ value: "$".concat(formatNumber(80313)),
18118
+ subValue: "12% vs pp",
18119
+ data: [800, 950, 700, 1100, 900, 1200, 1300],
18120
+ categories: fallbackCategories,
18121
+ icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
18122
+ money: true,
18123
+ error: false,
18124
+ warning: false
18125
+ },
18126
+ "Revinue Raised": {
18127
+ value: "$".concat(formatNumber(240398)),
18128
+ subValue: "12% vs pp",
18129
+ data: [3200, 4100, 2800, 5600, 4200, 6100, 7500],
18130
+ categories: fallbackCategories,
18131
+ icon: /*#__PURE__*/jsx(PaidOutlined, {}),
18132
+ money: true,
18133
+ error: false,
18134
+ warning: false
18135
+ },
18136
+ ROAS: {
18137
+ value: "3.0x",
18138
+ subValue: "12% vs pp",
18139
+ data: [2.5, 3.1, 2.8, 4.2, 3.8, 4.5, 5.2],
18140
+ categories: fallbackCategories,
18141
+ icon: /*#__PURE__*/jsx(TrendingUp, {}),
18142
+ money: false,
18143
+ error: false,
18144
+ warning: false
18145
+ },
18146
+ "Cost per donor": {
18147
+ value: "$".concat(formatNumber(373)),
18148
+ subValue: "12% vs pp",
18149
+ data: [350, 380, 360, 410, 390, 370, 373],
18150
+ categories: fallbackCategories,
18151
+ icon: /*#__PURE__*/jsx(PersonOutlined, {}),
18152
+ money: true,
18153
+ error: false,
18154
+ warning: false
18155
+ },
18156
+ "Conversion rate": {
18157
+ value: "3.1%",
18158
+ subValue: "12% vs pp",
18159
+ data: [2.8, 3.0, 2.9, 3.4, 3.2, 3.1, 3.1],
18160
+ categories: fallbackCategories,
18161
+ icon: /*#__PURE__*/jsx(ConversionRateIcon, {}),
18162
+ avatarSx: conversionRateAvatarSx,
18163
+ money: false,
18164
+ error: false,
18165
+ warning: false
18166
+ },
18167
+ "Avg donation": {
18168
+ value: "$".concat(formatNumber(130.58)),
18169
+ subValue: "12% vs pp",
18170
+ data: [120, 135, 125, 140, 130, 128, 130.58],
18171
+ categories: fallbackCategories,
18172
+ icon: /*#__PURE__*/jsx(AverageDonationIcon, {}),
18173
+ avatarSx: avgDonationAvatarSx,
18174
+ money: true,
18175
+ error: false,
18176
+ warning: false
18177
+ }
18178
+ };
18179
+ }
18180
+ return {
18181
+ "Total Spent": {
18182
+ value: "$".concat(formatNumber((_overview$totalSpent = overview.totalSpent) !== null && _overview$totalSpent !== void 0 ? _overview$totalSpent : 0)),
18183
+ subValue: formatGrowth$2(growth.totalSpent),
18184
+ data: spendSeries.data,
18185
+ categories: spendSeries.categories,
18186
+ icon: /*#__PURE__*/jsx(IndeterminateCheckBoxOutlined, {}),
18187
+ money: true,
18188
+ error: false,
18189
+ warning: false
18190
+ },
18191
+ "Revinue Raised": {
18192
+ value: "$".concat(formatNumber((_overview$totalRevenu = overview.totalRevenue) !== null && _overview$totalRevenu !== void 0 ? _overview$totalRevenu : 0)),
18193
+ subValue: formatGrowth$2(growth.totalRevenue),
18194
+ data: revenueSeries.data,
18195
+ categories: revenueSeries.categories,
18196
+ icon: /*#__PURE__*/jsx(PaidOutlined, {}),
18197
+ money: true,
18198
+ error: false,
18199
+ warning: false
18200
+ },
18201
+ ROAS: {
18202
+ value: "".concat(Number((_overview$roas = overview.roas) !== null && _overview$roas !== void 0 ? _overview$roas : 0).toFixed(1), "x"),
18203
+ subValue: formatGrowth$2(growth.roas),
18204
+ data: roasChartData.length > 0 ? roasChartData : flatSeries((_overview$roas2 = overview.roas) !== null && _overview$roas2 !== void 0 ? _overview$roas2 : 0),
18205
+ categories: spendSeries.categories.length ? spendSeries.categories : fallbackCategories,
18206
+ icon: /*#__PURE__*/jsx(TrendingUp, {}),
18207
+ money: false,
18208
+ error: false,
18209
+ warning: false
18210
+ },
18211
+ "Cost per donor": {
18212
+ value: "$".concat(formatNumber((_overview$costPerDono = overview.costPerDonor) !== null && _overview$costPerDono !== void 0 ? _overview$costPerDono : 0)),
18213
+ subValue: formatGrowth$2(growth.costPerDonor),
18214
+ data: flatSeries((_overview$costPerDono2 = overview.costPerDonor) !== null && _overview$costPerDono2 !== void 0 ? _overview$costPerDono2 : 0),
18215
+ categories: fallbackCategories,
18216
+ icon: /*#__PURE__*/jsx(PersonOutlined, {}),
18217
+ money: true,
18218
+ error: false,
18219
+ warning: false
18220
+ },
18221
+ "Conversion rate": {
18222
+ value: "".concat(Number((_overview$conversionR = overview.conversionRate) !== null && _overview$conversionR !== void 0 ? _overview$conversionR : 0).toFixed(2), "%"),
18223
+ subValue: formatGrowth$2(growth.conversionRate),
18224
+ data: flatSeries((_overview$conversionR2 = overview.conversionRate) !== null && _overview$conversionR2 !== void 0 ? _overview$conversionR2 : 0),
18225
+ categories: fallbackCategories,
18226
+ icon: /*#__PURE__*/jsx(ConversionRateIcon, {}),
18227
+ avatarSx: conversionRateAvatarSx,
18228
+ money: false,
18229
+ error: false,
18230
+ warning: false
18231
+ },
18232
+ "Avg donation": {
18233
+ value: "$".concat(formatNumber((_overview$averageDona = overview.averageDonation) !== null && _overview$averageDona !== void 0 ? _overview$averageDona : 0)),
18234
+ subValue: formatGrowth$2(growth.averageDonation),
18235
+ data: flatSeries((_overview$averageDona2 = overview.averageDonation) !== null && _overview$averageDona2 !== void 0 ? _overview$averageDona2 : 0),
18236
+ categories: fallbackCategories,
18237
+ icon: /*#__PURE__*/jsx(AverageDonationIcon, {}),
18238
+ avatarSx: avgDonationAvatarSx,
18239
+ money: true,
18240
+ error: false,
18241
+ warning: false
18242
+ }
18243
+ };
18244
+ }, [fallbackCategories, growth, hasPaidOverview, overview, revenueSeries, roasChartData, spendSeries]);
18245
+ var channelRows = useMemo(function () {
18246
+ var channels = apiData === null || apiData === void 0 ? void 0 : apiData.channelPerformance;
18247
+ if (!hasPaidOverview) return null;
18248
+ if (!Array.isArray(channels) || channels.length === 0) return [];
18249
+ return channels.map(function (item) {
18250
+ var _item$roas, _item$spend, _item$revenue, _item$cpa;
18251
+ var style = getChannelStyle(item.channel);
18252
+ var roas = Number((_item$roas = item.roas) !== null && _item$roas !== void 0 ? _item$roas : 0);
18253
+ return _objectSpread2({
18254
+ id: style.id,
18255
+ avatarBg: style.avatarBg,
18256
+ name: item.channel,
18257
+ val1: "$".concat(formatNumber((_item$spend = item.spend) !== null && _item$spend !== void 0 ? _item$spend : 0)),
18258
+ val2: "$".concat(formatNumber((_item$revenue = item.revenue) !== null && _item$revenue !== void 0 ? _item$revenue : 0)),
18259
+ val3: "".concat(roas.toFixed(1), "x"),
18260
+ val4: "$".concat(formatNumber((_item$cpa = item.cpa) !== null && _item$cpa !== void 0 ? _item$cpa : 0)),
18261
+ highlightVal3: true,
18262
+ val3Color: getRoasColor(roas)
18263
+ }, mapChannelTrend(item.trend));
18264
+ });
18265
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.channelPerformance, hasPaidOverview]);
18266
+ var spendAllocation = useMemo(function () {
18267
+ var _allocation$totalSpen, _allocation$totalSpen2;
18268
+ var allocation = apiData === null || apiData === void 0 ? void 0 : apiData.spendAllocation;
18269
+ if (!hasPaidOverview) return null;
18270
+ if (!allocation || !Array.isArray(allocation.data) || allocation.data.length === 0) {
18271
+ return null;
18272
+ }
18273
+ var items = allocation.data.map(function (item) {
18274
+ var _item$percentage, _item$spend2, _item$percentage2;
18275
+ var style = getChannelStyle(item.channel);
18276
+ return {
18277
+ label: item.channel,
18278
+ val: "".concat(Number((_item$percentage = item.percentage) !== null && _item$percentage !== void 0 ? _item$percentage : 0).toFixed(1), "%"),
18279
+ color: style.color,
18280
+ spend: (_item$spend2 = item.spend) !== null && _item$spend2 !== void 0 ? _item$spend2 : 0,
18281
+ percentage: (_item$percentage2 = item.percentage) !== null && _item$percentage2 !== void 0 ? _item$percentage2 : 0
18282
+ };
18283
+ });
18284
+ return {
18285
+ series: items.map(function (item) {
18286
+ return item.percentage;
18287
+ }),
18288
+ labels: items.map(function (item) {
18289
+ return item.label;
18290
+ }),
18291
+ colors: items.map(function (item) {
18292
+ return item.color;
18293
+ }),
18294
+ centerLabel: "total spend",
18295
+ centerValue: "$".concat(formatNumber((_allocation$totalSpen = allocation.totalSpend) !== null && _allocation$totalSpen !== void 0 ? _allocation$totalSpen : 0)),
18296
+ subtitle: "Where $".concat(formatNumber((_allocation$totalSpen2 = allocation.totalSpend) !== null && _allocation$totalSpen2 !== void 0 ? _allocation$totalSpen2 : 0), " went"),
18297
+ items: items.map(function (_ref2) {
18298
+ var label = _ref2.label,
18299
+ val = _ref2.val,
18300
+ color = _ref2.color;
18301
+ return {
18302
+ label: label,
18303
+ val: val,
18304
+ color: color
18305
+ };
18306
+ })
18307
+ };
18308
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.spendAllocation, hasPaidOverview]);
18309
+ var topCampaignsData = useMemo(function () {
18310
+ var campaigns = apiData === null || apiData === void 0 ? void 0 : apiData.topCampaigns;
18311
+ if (!hasPaidOverview) return null;
18312
+ if (!Array.isArray(campaigns)) return null;
18313
+ if (campaigns.length === 0) return [];
18314
+ return campaigns.map(function (item) {
18315
+ var _item$spend3, _item$revenue2, _item$roas2;
18316
+ return {
18317
+ name: item.campaign || item.name || "Unknown",
18318
+ spend: "$".concat(formatNumber((_item$spend3 = item.spend) !== null && _item$spend3 !== void 0 ? _item$spend3 : 0)),
18319
+ revenue: "$".concat(formatNumber((_item$revenue2 = item.revenue) !== null && _item$revenue2 !== void 0 ? _item$revenue2 : 0)),
18320
+ roas: "".concat(Number((_item$roas2 = item.roas) !== null && _item$roas2 !== void 0 ? _item$roas2 : 0).toFixed(1), "x")
18321
+ };
18322
+ });
18323
+ }, [apiData === null || apiData === void 0 ? void 0 : apiData.topCampaigns, hasPaidOverview]);
18054
18324
  var renderCard = function renderCard(title) {
18055
- return /*#__PURE__*/jsx(MetricCard$1
18056
- // key={title}
18057
- , {
18325
+ return /*#__PURE__*/jsx(MetricCard$1, {
18058
18326
  title: title,
18059
- value: metricInfo[title].money ? metricInfo[title].value : metricInfo[title].value,
18327
+ value: metricInfo[title].value,
18060
18328
  caption: metricInfo[title].subValue,
18061
18329
  icon: metricInfo[title].icon,
18062
18330
  avatarSx: metricInfo[title].avatarSx,
@@ -18069,32 +18337,22 @@ var PaidSection = function PaidSection(_ref) {
18069
18337
  border: "2px solid #ef4444",
18070
18338
  bgcolor: "#fffafa"
18071
18339
  } : {}
18072
- })
18073
- // <DisplayCard
18074
- // key={title}
18075
- // title={title}
18076
- // value={metricInfo[title].value}
18077
- // subValue={metricInfo[title].subValue}
18078
- // icon={metricInfo[title].icon}
18079
- // onClick={() => setActiveMetric(title)}
18080
- // isActive={activeMetric === title}
18081
- // sx={{
18082
- // // border:
18083
- // // activeMetric === title
18084
- // // ? "2px solid rgb(99, 99, 230)"
18085
- // // : "2px solid #f0f0f0",
18086
- // }}
18087
- // />
18088
- ;
18340
+ });
18089
18341
  };
18090
- var selectedInfo = metricInfo[activeMetric];
18342
+ var selectedInfo = metricInfo[activeMetric] || metricInfo["Total Spent"];
18343
+ var chartCategories = ((_selectedInfo$categor = selectedInfo.categories) === null || _selectedInfo$categor === void 0 ? void 0 : _selectedInfo$categor.length) > 0 ? selectedInfo.categories : fallbackCategories;
18091
18344
  var mainChart = {
18092
18345
  label: activeMetric,
18093
18346
  value: selectedInfo.value,
18094
18347
  trend: selectedInfo.subValue,
18095
18348
  data: selectedInfo.data,
18096
- categories: categories
18349
+ categories: chartCategories,
18350
+ hideControls: true,
18351
+ isAmount: selectedInfo.money
18097
18352
  };
18353
+ if (apiLoading) {
18354
+ return /*#__PURE__*/jsx(PaidSectionSkeleton, {});
18355
+ }
18098
18356
  return /*#__PURE__*/jsxs(Fragment, {
18099
18357
  children: [/*#__PURE__*/jsx(Box, {
18100
18358
  sx: {
@@ -18121,7 +18379,9 @@ var PaidSection = function PaidSection(_ref) {
18121
18379
  md: 12,
18122
18380
  type: "area",
18123
18381
  isPrimary: true,
18124
- isPremium: true
18382
+ isPremium: true,
18383
+ numberOfDays: numberOfDays,
18384
+ metric: activeMetric === "Conversion rate" ? "Percent" : activeMetric === "ROAS" ? "ROAS" : selectedInfo.money ? "Revenue" : "Donors"
18125
18385
  })
18126
18386
  }), /*#__PURE__*/jsxs(Grid, {
18127
18387
  container: true,
@@ -18143,7 +18403,7 @@ var PaidSection = function PaidSection(_ref) {
18143
18403
  columns: ["channel", "spend", "revenue", "ROAS", "CPA", "trend"],
18144
18404
  gridTemplateColumns: "2.2fr 1fr 1fr 0.8fr 0.8fr 1.2fr",
18145
18405
  height: "100%",
18146
- rows: [{
18406
+ rows: channelRows !== null && channelRows !== void 0 ? channelRows : [{
18147
18407
  id: "M",
18148
18408
  avatarBg: "#4267B2",
18149
18409
  name: "Meta Ads",
@@ -18224,13 +18484,13 @@ var PaidSection = function PaidSection(_ref) {
18224
18484
  },
18225
18485
  children: /*#__PURE__*/jsx(DonorMixCard, {
18226
18486
  title: "Spend allocation",
18227
- subtitle: "Where $80.3K went this month",
18228
- series: [40.8, 35.1, 14.2, 6.6, 3.3],
18229
- labels: ["Meta Ads", "Google Ads", "TikTok", "YouTube", "Snapchat"],
18230
- colors: ["#4267B2", "#4285F4", "#cd249dff", "#FF0000", "#FFFC00"],
18231
- centerLabel: "total spend",
18232
- centerValue: "$80.3K",
18233
- items: [{
18487
+ subtitle: (_spendAllocation$subt = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.subtitle) !== null && _spendAllocation$subt !== void 0 ? _spendAllocation$subt : "Where $80.3K went this month",
18488
+ series: (_spendAllocation$seri = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.series) !== null && _spendAllocation$seri !== void 0 ? _spendAllocation$seri : [40.8, 35.1, 14.2, 6.6, 3.3],
18489
+ labels: (_spendAllocation$labe = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.labels) !== null && _spendAllocation$labe !== void 0 ? _spendAllocation$labe : ["Meta Ads", "Google Ads", "TikTok", "YouTube", "Snapchat"],
18490
+ colors: (_spendAllocation$colo = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.colors) !== null && _spendAllocation$colo !== void 0 ? _spendAllocation$colo : ["#4267B2", "#4285F4", "#cd249dff", "#FF0000", "#FFFC00"],
18491
+ centerLabel: (_spendAllocation$cent = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.centerLabel) !== null && _spendAllocation$cent !== void 0 ? _spendAllocation$cent : "total spend",
18492
+ centerValue: (_spendAllocation$cent2 = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.centerValue) !== null && _spendAllocation$cent2 !== void 0 ? _spendAllocation$cent2 : "$80.3K",
18493
+ items: (_spendAllocation$item = spendAllocation === null || spendAllocation === void 0 ? void 0 : spendAllocation.items) !== null && _spendAllocation$item !== void 0 ? _spendAllocation$item : [{
18234
18494
  label: "Meta Ads",
18235
18495
  val: "40.8%",
18236
18496
  color: "#4267B2"
@@ -18271,7 +18531,9 @@ var PaidSection = function PaidSection(_ref) {
18271
18531
  sx: {
18272
18532
  paddingTop: "0px !important"
18273
18533
  },
18274
- children: /*#__PURE__*/jsx(TopPerformingCampaignsCard, {})
18534
+ children: /*#__PURE__*/jsx(TopPerformingCampaignsCard, {
18535
+ data: topCampaignsData
18536
+ })
18275
18537
  }), /*#__PURE__*/jsx(Grid, {
18276
18538
  item: true,
18277
18539
  xs: 12,
@@ -18283,7 +18545,9 @@ var PaidSection = function PaidSection(_ref) {
18283
18545
  md: "0px"
18284
18546
  }
18285
18547
  },
18286
- children: /*#__PURE__*/jsx(PaidDonorGeographyCard, {})
18548
+ children: /*#__PURE__*/jsx(PaidDonorGeographyCard, {
18549
+ donorGeographyData: apiData === null || apiData === void 0 ? void 0 : apiData.donorGeography
18550
+ })
18287
18551
  })]
18288
18552
  })]
18289
18553
  });