mozrest-sdk-react-dev 0.1.35 → 0.1.36

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.
Files changed (2) hide show
  1. package/mozrest-sdk.es.js +180 -149
  2. package/package.json +1 -1
package/mozrest-sdk.es.js CHANGED
@@ -89051,7 +89051,7 @@ const getCurrentRange = () => {
89051
89051
  };
89052
89052
  const getTodaysRange = () => {
89053
89053
  return {
89054
- from: subtractDate(void 0, 0, "day"),
89054
+ from: subtractDate(void 0, 7, "day"),
89055
89055
  till: subtractDate(void 0, 0, "day")
89056
89056
  };
89057
89057
  };
@@ -89216,7 +89216,7 @@ const formatComparedPeriod = (range4) => {
89216
89216
  return "";
89217
89217
  return `${formatDate(range4.from, dateFormat)} - ${formatDate(range4.till, dateFormat)}`;
89218
89218
  };
89219
- const Analytics$2 = ({ venueListingId }) => {
89219
+ const Analytics$3 = ({ venueListingId }) => {
89220
89220
  const { t: t2 } = useTranslation();
89221
89221
  const [filter, setFilters] = useState({
89222
89222
  range: getCurrentRange(),
@@ -89557,7 +89557,7 @@ const singleVenue$2 = async () => {
89557
89557
  }
89558
89558
  });
89559
89559
  };
89560
- const Analytics$1 = ({ venueListingId }) => {
89560
+ const Analytics$2 = ({ venueListingId }) => {
89561
89561
  const { t: t2 } = useTranslation();
89562
89562
  const [listingId, setListingId] = useState(venueListingId);
89563
89563
  const [formattedStats, setFormattedStats] = useState();
@@ -89665,134 +89665,6 @@ const Analytics$1 = ({ venueListingId }) => {
89665
89665
  data: formattedStats == null ? void 0 : formattedStats.actions
89666
89666
  }))));
89667
89667
  };
89668
- const formatData$2 = (dataToFormat) => {
89669
- const compare2 = groupByDate(dataToFormat.compare);
89670
- const inPeriod = groupByDate(dataToFormat.data);
89671
- return {
89672
- reviews: formatReviews(inPeriod, compare2),
89673
- treatment: formatTreatment(inPeriod, compare2),
89674
- replyTime: formatAvgReplyTime(inPeriod, compare2),
89675
- average: formatAvgChart(inPeriod, compare2),
89676
- chart: formatChart(inPeriod)
89677
- };
89678
- };
89679
- const sumReviews = (data2) => data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => acc + positive2 + negative2 + neutral2, 0);
89680
- const fixed = (value2) => {
89681
- return Number(value2.toFixed(2)) || 0;
89682
- };
89683
- const getPercentageDiff = (inPeriod, compare2) => {
89684
- if (compare2 === 0) {
89685
- return 0;
89686
- }
89687
- return fixed((inPeriod - compare2) * 100 / compare2);
89688
- };
89689
- const formatReviews = (inPeriod, compare2) => {
89690
- const totalInPeriod = sumReviews(inPeriod);
89691
- const totalCompare = sumReviews(compare2);
89692
- return {
89693
- value: totalInPeriod,
89694
- comparison: getPercentageDiff(totalInPeriod, totalCompare)
89695
- };
89696
- };
89697
- const sumTreatment = (data2) => data2.reduce((acc, { treatment }) => acc + treatment, 0);
89698
- const getPercentage = (part, total) => {
89699
- return fixed(part * 100 / total);
89700
- };
89701
- const formatTreatment = (inPeriod, compare2) => {
89702
- const totalTreatmentInPeriod = sumTreatment(inPeriod);
89703
- const totalTreatmentCompare = sumTreatment(compare2);
89704
- const totalReviewsInPeriod = sumReviews(inPeriod);
89705
- return {
89706
- value: {
89707
- value: getPercentage(totalTreatmentInPeriod, totalReviewsInPeriod),
89708
- units: "%"
89709
- },
89710
- comparison: getPercentageDiff(totalTreatmentInPeriod, totalTreatmentCompare)
89711
- };
89712
- };
89713
- const getAvgReplyTime = (data2) => {
89714
- if (data2.length === 0) {
89715
- return 0;
89716
- }
89717
- const totalTreatment = data2.reduce((acc, { treatment }) => acc + treatment, 0);
89718
- if (totalTreatment === 0) {
89719
- return 0;
89720
- }
89721
- const totalReplyTime = data2.reduce((acc, { avgReplyTime, treatment }) => acc + avgReplyTime * treatment, 0);
89722
- return Math.round(totalReplyTime / totalTreatment);
89723
- };
89724
- const formatAvgReplyTime = (inPeriod, compare2) => {
89725
- const inPeriodReplyTime = getAvgReplyTime(inPeriod);
89726
- const compareReplyTime = getAvgReplyTime(compare2);
89727
- return {
89728
- value: humanizeMinutes(inPeriodReplyTime),
89729
- comparison: getPercentageDiff(inPeriodReplyTime, compareReplyTime)
89730
- };
89731
- };
89732
- const getAvg = (data2) => {
89733
- const total = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => acc + positive2 + negative2 + neutral2, 0);
89734
- const rating = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2, avg }) => acc + avg * (positive2 + negative2 + neutral2), 0);
89735
- return fixed(rating / total);
89736
- };
89737
- const circleChart = (data2) => {
89738
- const value2 = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => ({
89739
- positive: positive2 + acc.positive,
89740
- negative: negative2 + acc.negative,
89741
- neutral: neutral2 + acc.neutral
89742
- }), { positive: 0, negative: 0, neutral: 0 });
89743
- return [
89744
- { name: instance.t("SATISFIED"), value: value2.positive },
89745
- { name: instance.t("DISSATISFIED"), value: value2.negative },
89746
- { name: instance.t("NEUTRAL"), value: value2.neutral }
89747
- ];
89748
- };
89749
- const formatAvgChart = (inPeriod, compare2) => {
89750
- return {
89751
- inPeriod: {
89752
- avg: getAvg(inPeriod),
89753
- chart: circleChart(inPeriod)
89754
- },
89755
- compare: {
89756
- avg: getAvg(compare2),
89757
- chart: circleChart(compare2)
89758
- }
89759
- };
89760
- };
89761
- const formatChart = (inPeriod) => inPeriod.map((item2) => ({
89762
- ...item2,
89763
- date: dateFromString(item2.date)
89764
- }));
89765
- const groupByDate = (data2) => {
89766
- const grouped = groupBy(data2, "date");
89767
- return Object.values(grouped).map((items) => {
89768
- const { total, ...rest } = items.reduce((acc, item2) => {
89769
- const total2 = item2.positive + item2.negative + item2.neutral;
89770
- return {
89771
- ...item2,
89772
- positive: acc.positive + item2.positive,
89773
- negative: acc.negative + item2.negative,
89774
- neutral: acc.neutral + item2.neutral,
89775
- treatment: acc.treatment + item2.treatment,
89776
- avg: acc.avg + total2 * item2.avg,
89777
- avgReplyTime: acc.avgReplyTime + item2.treatment * item2.avgReplyTime,
89778
- total: acc.total + total2
89779
- };
89780
- }, {
89781
- positive: 0,
89782
- negative: 0,
89783
- neutral: 0,
89784
- treatment: 0,
89785
- avg: 0,
89786
- avgReplyTime: 0,
89787
- total: 0
89788
- });
89789
- return {
89790
- ...rest,
89791
- avg: fixed(rest.avg / total),
89792
- avgReplyTime: rest.treatment > 0 ? fixed(rest.avgReplyTime / rest.treatment) : 0
89793
- };
89794
- });
89795
- };
89796
89668
  const formatStats = (stat) => {
89797
89669
  var _a2;
89798
89670
  let sum = 0;
@@ -89876,7 +89748,7 @@ const singleVenue$1 = async () => {
89876
89748
  }
89877
89749
  });
89878
89750
  };
89879
- const Analytics = ({ venueListingId }) => {
89751
+ const Analytics$1 = ({ venueListingId }) => {
89880
89752
  const { t: t2 } = useTranslation();
89881
89753
  const [filter, setFilters] = useState({
89882
89754
  range: getTodaysRange(),
@@ -89884,11 +89756,7 @@ const Analytics = ({ venueListingId }) => {
89884
89756
  platform: "",
89885
89757
  compareType: "period"
89886
89758
  });
89887
- const { data: data2, isLoading, error: error3 } = useFetch(GetReviewAnalytics, {
89888
- cacheId: `reviews-analytics-${venueListingId}`,
89889
- params: filter
89890
- }, { formatData: formatData$2 });
89891
- const comparedPeriod = formatComparedPeriod(filter.compare);
89759
+ formatComparedPeriod(filter.compare);
89892
89760
  const [listingId, setListingId] = useState(venueListingId);
89893
89761
  const [formattedStats, setFormattedStats] = useState();
89894
89762
  const [notAuthorized, setNotAuthorized] = useState(false);
@@ -89902,17 +89770,17 @@ const Analytics = ({ venueListingId }) => {
89902
89770
  findBy: "venueId",
89903
89771
  range: getTodaysRange()
89904
89772
  });
89905
- const { data: dataListingAnalytics, isLoading: isLoadingListingAnalytics } = useFetch(GetListingAnalytics, {
89773
+ const { data: data2, isLoading: isLoadingListingAnalytics, error: error3 } = useFetch(GetListingAnalytics, {
89906
89774
  cacheId: `listing-analytics-${listingId}`,
89907
89775
  params: filterAnalytics,
89908
89776
  id: listingId
89909
89777
  });
89910
89778
  useEffect(() => {
89911
- if (dataListingAnalytics && !(dataListingAnalytics == null ? void 0 : dataListingAnalytics.error)) {
89912
- if (dataListingAnalytics && (dataListingAnalytics == null ? void 0 : dataListingAnalytics.BUSINESS_IMPRESSIONS_DESKTOP_SEARCH.error)) {
89779
+ if (data2 && !(data2 == null ? void 0 : data2.error)) {
89780
+ if (data2 && (data2 == null ? void 0 : data2.BUSINESS_IMPRESSIONS_DESKTOP_SEARCH.error)) {
89913
89781
  setNotAuthorized(true);
89914
89782
  } else {
89915
- setFormattedStats(formatDataAnalytics(dataListingAnalytics));
89783
+ setFormattedStats(formatDataAnalytics(data2));
89916
89784
  }
89917
89785
  }
89918
89786
  }, [data2]);
@@ -89925,7 +89793,12 @@ const Analytics = ({ venueListingId }) => {
89925
89793
  src: Loader,
89926
89794
  className: styles$7.loader,
89927
89795
  alt: "Loading"
89928
- }), "Loading listing analytics"))), !isLoadingListingAnalytics && formattedStats && !(dataListingAnalytics == null ? void 0 : dataListingAnalytics.error) && !notAuthorized && /* @__PURE__ */ React__default.createElement(Row$1, {
89796
+ }), "Loading listing analytics"))), !isLoadingListingAnalytics && formattedStats && !(data2 == null ? void 0 : data2.error) && !notAuthorized && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Row$1, {
89797
+ gutter: [28, 28],
89798
+ style: { marginBottom: 10, textAlign: "right" }
89799
+ }, /* @__PURE__ */ React__default.createElement(Col$1, {
89800
+ lg: 24
89801
+ }, "Last 7 days analytics")), /* @__PURE__ */ React__default.createElement(Row$1, {
89929
89802
  gutter: [28, 28],
89930
89803
  style: { marginBottom: 28 }
89931
89804
  }, /* @__PURE__ */ React__default.createElement(Col$1, {
@@ -89982,7 +89855,164 @@ const Analytics = ({ venueListingId }) => {
89982
89855
  tooltip: t2("DIRECTIONREQUES")
89983
89856
  }
89984
89857
  ]
89985
- })))), isLoading && /* @__PURE__ */ React__default.createElement(SkeletonPage, null), !isLoading && /* @__PURE__ */ React__default.createElement(Row$1, {
89858
+ })))))));
89859
+ };
89860
+ const formatData$2 = (dataToFormat) => {
89861
+ const compare2 = groupByDate(dataToFormat.compare);
89862
+ const inPeriod = groupByDate(dataToFormat.data);
89863
+ return {
89864
+ reviews: formatReviews(inPeriod, compare2),
89865
+ treatment: formatTreatment(inPeriod, compare2),
89866
+ replyTime: formatAvgReplyTime(inPeriod, compare2),
89867
+ average: formatAvgChart(inPeriod, compare2),
89868
+ chart: formatChart(inPeriod)
89869
+ };
89870
+ };
89871
+ const sumReviews = (data2) => data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => acc + positive2 + negative2 + neutral2, 0);
89872
+ const fixed = (value2) => {
89873
+ return Number(value2.toFixed(2)) || 0;
89874
+ };
89875
+ const getPercentageDiff = (inPeriod, compare2) => {
89876
+ if (compare2 === 0) {
89877
+ return 0;
89878
+ }
89879
+ return fixed((inPeriod - compare2) * 100 / compare2);
89880
+ };
89881
+ const formatReviews = (inPeriod, compare2) => {
89882
+ const totalInPeriod = sumReviews(inPeriod);
89883
+ const totalCompare = sumReviews(compare2);
89884
+ return {
89885
+ value: totalInPeriod,
89886
+ comparison: getPercentageDiff(totalInPeriod, totalCompare)
89887
+ };
89888
+ };
89889
+ const sumTreatment = (data2) => data2.reduce((acc, { treatment }) => acc + treatment, 0);
89890
+ const getPercentage = (part, total) => {
89891
+ return fixed(part * 100 / total);
89892
+ };
89893
+ const formatTreatment = (inPeriod, compare2) => {
89894
+ const totalTreatmentInPeriod = sumTreatment(inPeriod);
89895
+ const totalTreatmentCompare = sumTreatment(compare2);
89896
+ const totalReviewsInPeriod = sumReviews(inPeriod);
89897
+ return {
89898
+ value: {
89899
+ value: getPercentage(totalTreatmentInPeriod, totalReviewsInPeriod),
89900
+ units: "%"
89901
+ },
89902
+ comparison: getPercentageDiff(totalTreatmentInPeriod, totalTreatmentCompare)
89903
+ };
89904
+ };
89905
+ const getAvgReplyTime = (data2) => {
89906
+ if (data2.length === 0) {
89907
+ return 0;
89908
+ }
89909
+ const totalTreatment = data2.reduce((acc, { treatment }) => acc + treatment, 0);
89910
+ if (totalTreatment === 0) {
89911
+ return 0;
89912
+ }
89913
+ const totalReplyTime = data2.reduce((acc, { avgReplyTime, treatment }) => acc + avgReplyTime * treatment, 0);
89914
+ return Math.round(totalReplyTime / totalTreatment);
89915
+ };
89916
+ const formatAvgReplyTime = (inPeriod, compare2) => {
89917
+ const inPeriodReplyTime = getAvgReplyTime(inPeriod);
89918
+ const compareReplyTime = getAvgReplyTime(compare2);
89919
+ return {
89920
+ value: humanizeMinutes(inPeriodReplyTime),
89921
+ comparison: getPercentageDiff(inPeriodReplyTime, compareReplyTime)
89922
+ };
89923
+ };
89924
+ const getAvg = (data2) => {
89925
+ const total = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => acc + positive2 + negative2 + neutral2, 0);
89926
+ const rating = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2, avg }) => acc + avg * (positive2 + negative2 + neutral2), 0);
89927
+ return fixed(rating / total);
89928
+ };
89929
+ const circleChart = (data2) => {
89930
+ const value2 = data2.reduce((acc, { positive: positive2, negative: negative2, neutral: neutral2 }) => ({
89931
+ positive: positive2 + acc.positive,
89932
+ negative: negative2 + acc.negative,
89933
+ neutral: neutral2 + acc.neutral
89934
+ }), { positive: 0, negative: 0, neutral: 0 });
89935
+ return [
89936
+ { name: instance.t("SATISFIED"), value: value2.positive },
89937
+ { name: instance.t("DISSATISFIED"), value: value2.negative },
89938
+ { name: instance.t("NEUTRAL"), value: value2.neutral }
89939
+ ];
89940
+ };
89941
+ const formatAvgChart = (inPeriod, compare2) => {
89942
+ return {
89943
+ inPeriod: {
89944
+ avg: getAvg(inPeriod),
89945
+ chart: circleChart(inPeriod)
89946
+ },
89947
+ compare: {
89948
+ avg: getAvg(compare2),
89949
+ chart: circleChart(compare2)
89950
+ }
89951
+ };
89952
+ };
89953
+ const formatChart = (inPeriod) => inPeriod.map((item2) => ({
89954
+ ...item2,
89955
+ date: dateFromString(item2.date)
89956
+ }));
89957
+ const groupByDate = (data2) => {
89958
+ const grouped = groupBy(data2, "date");
89959
+ return Object.values(grouped).map((items) => {
89960
+ const { total, ...rest } = items.reduce((acc, item2) => {
89961
+ const total2 = item2.positive + item2.negative + item2.neutral;
89962
+ return {
89963
+ ...item2,
89964
+ positive: acc.positive + item2.positive,
89965
+ negative: acc.negative + item2.negative,
89966
+ neutral: acc.neutral + item2.neutral,
89967
+ treatment: acc.treatment + item2.treatment,
89968
+ avg: acc.avg + total2 * item2.avg,
89969
+ avgReplyTime: acc.avgReplyTime + item2.treatment * item2.avgReplyTime,
89970
+ total: acc.total + total2
89971
+ };
89972
+ }, {
89973
+ positive: 0,
89974
+ negative: 0,
89975
+ neutral: 0,
89976
+ treatment: 0,
89977
+ avg: 0,
89978
+ avgReplyTime: 0,
89979
+ total: 0
89980
+ });
89981
+ return {
89982
+ ...rest,
89983
+ avg: fixed(rest.avg / total),
89984
+ avgReplyTime: rest.treatment > 0 ? fixed(rest.avgReplyTime / rest.treatment) : 0
89985
+ };
89986
+ });
89987
+ };
89988
+ const Analytics = ({ venueListingId }) => {
89989
+ const { t: t2 } = useTranslation();
89990
+ const [filter, setFilters] = useState({
89991
+ range: getTodaysRange(),
89992
+ compare: getCompareRange(getTodaysRange(), "period"),
89993
+ platform: "",
89994
+ compareType: "period"
89995
+ });
89996
+ const { data: data2, isLoading, error: error3 } = useFetch(GetReviewAnalytics, {
89997
+ cacheId: `reviews-analytics-${venueListingId}`,
89998
+ params: filter
89999
+ }, { formatData: formatData$2 });
90000
+ const comparedPeriod = formatComparedPeriod(filter.compare);
90001
+ useState({
90002
+ findBy: "venueId",
90003
+ range: getTodaysRange()
90004
+ });
90005
+ if (error3) {
90006
+ return /* @__PURE__ */ React__default.createElement(Error$1, {
90007
+ error: error3
90008
+ });
90009
+ }
90010
+ return /* @__PURE__ */ React__default.createElement(LayoutPage$1, null, /* @__PURE__ */ React__default.createElement("div", null, isLoading && /* @__PURE__ */ React__default.createElement(SkeletonPage, null), !isLoading && /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Row$1, {
90011
+ gutter: [28, 28],
90012
+ style: { marginBottom: 10, textAlign: "right" }
90013
+ }, /* @__PURE__ */ React__default.createElement(Col$1, {
90014
+ lg: 24
90015
+ }, "Last 7 days analytics")), /* @__PURE__ */ React__default.createElement(Row$1, {
89986
90016
  gutter: [28, 28]
89987
90017
  }, /* @__PURE__ */ React__default.createElement(Col$1, {
89988
90018
  xs: 24,
@@ -90019,7 +90049,7 @@ const Analytics = ({ venueListingId }) => {
90019
90049
  icon: Clock$1,
90020
90050
  color: "red"
90021
90051
  })
90022
- })))));
90052
+ }))))));
90023
90053
  };
90024
90054
  const WorkingPage = () => {
90025
90055
  return /* @__PURE__ */ React__default.createElement(React__default.Fragment, null, /* @__PURE__ */ React__default.createElement(Heading, null, "Work in progress"), /* @__PURE__ */ React__default.createElement("iframe", {
@@ -91174,12 +91204,12 @@ function App({
91174
91204
  element: /* @__PURE__ */ React__default.createElement(Permissions, null)
91175
91205
  }), /* @__PURE__ */ React__default.createElement(Route, {
91176
91206
  path: "/analytics/listing",
91177
- element: /* @__PURE__ */ React__default.createElement(Analytics$1, {
91207
+ element: /* @__PURE__ */ React__default.createElement(Analytics$2, {
91178
91208
  venueListingId
91179
91209
  })
91180
91210
  }), /* @__PURE__ */ React__default.createElement(Route, {
91181
91211
  path: "/analytics/review",
91182
- element: /* @__PURE__ */ React__default.createElement(Analytics$2, {
91212
+ element: /* @__PURE__ */ React__default.createElement(Analytics$3, {
91183
91213
  venueListingId
91184
91214
  })
91185
91215
  }), /* @__PURE__ */ React__default.createElement(Route, {
@@ -91194,9 +91224,10 @@ const pages = {
91194
91224
  Roles: App$1,
91195
91225
  Notifications,
91196
91226
  ReplyTemplates,
91197
- ReviewAnalytics: Analytics$2,
91198
- ListingAnalytics: Analytics$1,
91199
- DashboardAnalytics: Analytics,
91227
+ ReviewAnalytics: Analytics$3,
91228
+ ListingAnalytics: Analytics$2,
91229
+ DashboardListingAnalytics: Analytics$1,
91230
+ DashboardReviewAnalytics: Analytics,
91200
91231
  Users: App$2,
91201
91232
  ProfileManagement,
91202
91233
  App
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mozrest-sdk-react-dev",
3
- "version": "0.1.35",
3
+ "version": "0.1.36",
4
4
  "main": "mozrest-sdk.es.js",
5
5
  "keywords": ["mozrest"],
6
6
  "author": {