@ammarkhalidfarooq/dashboard-package 0.6.82 → 0.6.83

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