avada-feature-request
Version:
Feature Request component library for React applications
1,197 lines (1,170 loc) • 607 kB
JavaScript
'use strict';
var jsxRuntime = require('react/jsx-runtime');
var React = require('react');
var polaris = require('@shopify/polaris');
var polarisIcons = require('@shopify/polaris-icons');
var reactRouterDom = require('react-router-dom');
var firestore$1 = require('firebase/firestore');
var app = require('firebase/app');
function styleInject(css, ref) {
if ( ref === void 0 ) ref = {};
var insertAt = ref.insertAt;
if (!css || typeof document === 'undefined') { return; }
var head = document.head || document.getElementsByTagName('head')[0];
var style = document.createElement('style');
style.type = 'text/css';
if (insertAt === 'top') {
if (head.firstChild) {
head.insertBefore(style, head.firstChild);
} else {
head.appendChild(style);
}
} else {
head.appendChild(style);
}
if (style.styleSheet) {
style.styleSheet.cssText = css;
} else {
style.appendChild(document.createTextNode(css));
}
}
var css_248z$3 = ".Polaris-Page-Header--mediumTitle:not(.Polaris-Page-Header--noBreadcrumbs) .Polaris-Page-Header__Row{display:flex}.Avada-CardFeatureReq-Main{margin:0 0 15px}.Avada-CardFeatureReq-Main:hover .swiper-button-next,.Avada-CardFeatureReq-Main:hover .swiper-button-prev{display:flex}.Avada-CardFeatureReq-Main .Polaris-LegacyCard__Section:hover{background-color:#f7f7f7}@media(max-width:1024px){.Avada-CardFeatureReq-Slider{max-height:250px}}@media(min-width:1280px){.Avada-CardFeatureReq-Slider{max-height:260px}}.Avada-CardFeatureReq-Slider{max-height:300px}.Avada-CardFeatureReq-Slider .Avada-FeatureReq-Body__Title{-webkit-line-clamp:1;-webkit-box-orient:vertical;display:-webkit-box;line-height:1.6em;min-height:10px;overflow:hidden;text-overflow:ellipsis}.Avada-CardFeatureReq-Slider .Avada-FeatureReq-Body__Descripstion{-webkit-line-clamp:3;-webkit-box-orient:vertical;display:-webkit-box;line-height:1.6em;max-height:4.8em;min-height:4.8em;overflow:hidden;text-overflow:ellipsis}.Avada-FeatureReq-CardHover:hover{cursor:pointer}.Avada-FeatureReq-Card .Avada-FeatureReq-Header{display:flex;justify-content:space-between}.Avada-FeatureReq-Card .Avada-FeatureReq-Header .Avada-Feature-Header__Info{display:flex;gap:9px;justify-content:space-between}.Avada-FeatureReq-Card .Avada-FeatureReq-Header .Avada-Feature-Header__Info .Avada-Feature-Header__Title .Polaris-Text--bold,.Avada-FeatureReq-Card .Avada-FeatureReq-Header .Avada-Feature-Header__Info .Avada-Feature-Header__Title p{align-items:center;display:flex}.Avada-FeatureReq-Card .Avada-FeatureReq-Header .Avada-Feature-Header__Info .Avada-FeatureReq-Avatar{display:flex;height:40px;overflow:hidden;width:40px}.Avada-FeatureReq-Card .Avada-FeatureReq-Header .Avada-Feature-Header__Info .Avada-FeatureReq-Avatar img{border-radius:26px;height:100%;width:100%}.Avada-FeatureReq-Card .Avada-FeatureReq-Body{margin:10px 0}.Avada-FeatureReq-Card .Avada-FeatureReq-Body__Title{color:#303030;font-size:22px;font-weight:600;margin-bottom:8px}.Avada-FeatureReq-Card .Avada-FeatureReq-Body__Descripstion{color:#303030;font-size:13px;font-weight:500}.Avada-FeatureReq-Card .Avada-FeatureReq-ActionItem{align-items:center;display:flex;justify-content:space-between}.Avada-FeatureReq-Card .Avada-FeatureReq-Action{display:flex;gap:10px}.Avada-FeatureReq-Card .Avada-FeatureReq-Action .Polaris-Tag.Polaris-Tag--clickable{background-color:#f7f7f7}.Avada-FeatureReq-Card .Avada-FeatureReq-Action .Polaris-LegacyStack{padding:3px 5px}.Avada-FeatureReq-Card .Avada-FeatureReq-ActionComment .Polaris-Tag.Polaris-Tag--clickable{background-color:transparent}.Avada-FeatureReq-Card .Avada-FeatureReq-ActionComment .Polaris-LegacyStack{padding-left:0}.Avada-FeatureReqTrending{margin-bottom:15px}.Avada-FeatureReqTrending .Avada-Feature-Header__Info{height:45px}.Avada-FeatureReqTrending .Polaris-LegacyCard__Section{padding:var(--p-space-400) var(--p-space-400)}.Avada-FeatureReqTrending .Polaris-LegacyCard__Section:hover{background-color:#f7f7f7}.Avada-Comment-Main{border:1px solid #eaeaea}.Avada-Comment-Main .Polaris-TextField__Backdrop{background-color:transparent;border:none}.Avada-Comment-Main .Polaris-TextField__Backdrop:after{box-shadow:none}.Avada-Comment-Main .Polaris-TextField__Backdrop{background-color:transparent!important;outline:none!important}.Avada-Comment-Main .Polaris-Text--medium{font-size:13px!important;font-weight:500!important}.Avada-CreateFeatureReq-Select .Polaris-Select__Input:hover{cursor:pointer}.Avada-FeatureReq-Link{color:#007bff;text-decoration:none;transition:color .3s ease-in-out,-webkit-text-decoration .3s ease-in-out;transition:color .3s ease-in-out,text-decoration .3s ease-in-out;transition:color .3s ease-in-out,text-decoration .3s ease-in-out,-webkit-text-decoration .3s ease-in-out}.Avada-FeatureReq-Link:hover{color:#0056b3;text-decoration:underline}.Avada-Badge{align-items:center;border-radius:.7rem;cursor:default;display:inline-flex;font-family:-apple-system,BlinkMacSystemFont,Segoe UI,Roboto,Oxygen,Ubuntu,Cantarell,sans-serif;font-weight:600;gap:.25rem;justify-content:center;letter-spacing:.02em;position:relative;text-decoration:none;-webkit-user-select:none;-moz-user-select:none;user-select:none;vertical-align:baseline;white-space:nowrap}.Avada-Badge--size-small{border-radius:.7rem;font-size:.6875rem;font-weight:500;line-height:1;min-height:1.375rem;padding:.25rem .5rem}.Avada-Badge--size-medium{border-radius:.7rem;font-size:.75rem;line-height:1.125;min-height:1.75rem;padding:.375rem .75rem}.Avada-Badge--size-large{border-radius:.7rem;font-size:.875rem;line-height:1.25;min-height:2.25rem;padding:.5rem 1rem}.Avada-Badge--tone-info{background-color:#e3f2fd;color:#1565c0}.Avada-Badge--tone-success{background-color:#e8f5e8;color:#2e7d32}.Avada-Badge--tone-warning{background-color:#fff8e1;color:#f57c00}.Avada-Badge--tone-critical{background-color:#ffebee;color:#c62828}.Avada-Badge--tone-attention{background-color:#fffde7;color:#f9a825}.Avada-Badge--tone-new{background-color:#f3e5f5;color:#7b1fa2;position:relative}.Avada-Badge--tone-new:after{animation:sparkle 2s ease-in-out infinite;content:\"✨\";font-size:.75em;position:absolute;right:-.25rem;top:-.25rem;z-index:2}.Avada-Badge--tone-read-only{background-color:#f5f5f5;color:#616161}.Avada-Badge--tone-enabled{background-color:#e8f5e8;color:#2e7d32}.Avada-Badge--progress-complete,.Avada-Badge--progress-incomplete,.Avada-Badge--progress-partially-complete{padding-left:1.25rem;position:relative}.Avada-Badge__Pip{border-radius:50%;box-shadow:0 0 0 2px hsla(0,0%,100%,.8);height:.5rem;left:.5rem;position:absolute;top:50%;transform:translateY(-50%);width:.5rem}.Avada-Badge--progress-incomplete .Avada-Badge__Pip{background-color:#bdbdbd;opacity:.6}.Avada-Badge--progress-partially-complete .Avada-Badge__Pip{animation:pulse 2s ease-in-out infinite;background-color:#ff9800}.Avada-Badge--progress-complete .Avada-Badge__Pip{background-color:#4caf50}.Avada-Badge__Progress{border-radius:inherit;display:block;height:100%;width:100%}.Avada-Badge--progress-incomplete .Avada-Badge__Progress{background-color:transparent}.Avada-Badge--progress-partially-complete .Avada-Badge__Progress{background:linear-gradient(90deg,#ff9800,#ff9800 50%,transparent 0)}.Avada-Badge--progress-complete .Avada-Badge__Progress{background-color:#4caf50}.Avada-Badge__Icon{align-items:center;display:flex;flex-shrink:0;justify-content:center;z-index:1}.Avada-Badge__Icon svg{fill:currentColor;height:1em;width:1em}.Avada-Badge--size-small .Avada-Badge__Icon svg{height:.75rem;width:.75rem}.Avada-Badge--size-medium .Avada-Badge__Icon svg{height:.875rem;width:.875rem}.Avada-Badge--size-large .Avada-Badge__Icon svg{height:1rem;width:1rem}.Avada-Badge__Text{display:inline-block;font-weight:inherit;line-height:inherit;text-align:center;text-shadow:0 .5px 1px hsla(0,0%,100%,.8);z-index:1}.Avada-Badge__Text p{font-weight:500}@keyframes sparkle{0%,to{opacity:1;transform:scale(1) rotate(0deg)}50%{opacity:.7;transform:scale(1.2) rotate(180deg)}}@keyframes pulse{0%,to{opacity:1;transform:translateY(-50%) scale(1)}50%{opacity:.8;transform:translateY(-50%) scale(1.1)}}";
styleInject(css_248z$3);
var FeatureRequestContext = /*#__PURE__*/React.createContext(undefined);
var FeatureRequestProvider = function FeatureRequestProvider(_a) {
var appDomain = _a.appDomain,
prefix = _a.prefix,
activeShop = _a.activeShop,
_b = _a.typeRequest,
typeRequest = _b === void 0 ? ["new-feature", "bug-report", "improvement"] : _b,
_c = _a.isEmbeddedAppEnv,
isEmbeddedAppEnv = _c === void 0 ? false : _c,
fetchAuthenticatedApi = _a.fetchAuthenticatedApi,
onShopInfoUpdate = _a.onShopInfoUpdate,
firebaseConfig = _a.firebaseConfig,
children = _a.children;
var contextValue = {
appDomain: appDomain,
shopInfo: activeShop,
typeRequest: typeRequest,
isEmbeddedAppEnv: isEmbeddedAppEnv,
fetchAuthenticatedApi: fetchAuthenticatedApi,
onShopInfoUpdate: onShopInfoUpdate,
firebaseConfig: firebaseConfig,
prefix: prefix
};
if (!contextValue.appDomain) throw new Error("appDomain is required");
if (!contextValue.shopInfo) throw new Error("activeShop is required");
if (!contextValue.fetchAuthenticatedApi) throw new Error("fetch is required");
return jsxRuntime.jsx(FeatureRequestContext.Provider, {
value: contextValue,
children: children
});
};
/******************************************************************************
Copyright (c) Microsoft Corporation.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
***************************************************************************** */
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
var __assign$1 = function() {
__assign$1 = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign$1.apply(this, arguments);
};
function __awaiter(thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __spreadArray(to, from, pack) {
if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
if (ar || !(i in from)) {
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
ar[i] = from[i];
}
}
return to.concat(ar || Array.prototype.slice.call(from));
}
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
var e = new Error(message);
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
};
var CustomBadge = function CustomBadge(_a) {
var children = _a.children,
Icon = _a.icon,
_b = _a.tone,
tone = _b === void 0 ? "info" : _b,
_c = _a.size,
size = _c === void 0 ? "medium" : _c,
progress = _a.progress,
_d = _a.className,
className = _d === void 0 ? "" : _d;
var getToneClasses = function getToneClasses(tone) {
switch (tone) {
case "critical":
return "Avada-Badge--tone-critical";
case "warning":
return "Avada-Badge--tone-warning";
case "attention":
return "Avada-Badge--tone-attention";
case "success":
return "Avada-Badge--tone-success";
case "new":
return "Avada-Badge--tone-new";
case "read-only":
return "Avada-Badge--tone-read-only";
case "enabled":
return "Avada-Badge--tone-enabled";
case "info":
default:
return "Avada-Badge--tone-info";
}
};
var getSizeClasses = function getSizeClasses(size) {
switch (size) {
case "small":
return "Avada-Badge--size-small";
case "large":
return "Avada-Badge--size-large";
case "medium":
default:
return "Avada-Badge--size-medium";
}
};
var getProgressClasses = function getProgressClasses(progress) {
if (!progress) return "";
switch (progress) {
case "incomplete":
return "Avada-Badge--progress-incomplete";
case "partially-complete":
return "Avada-Badge--progress-partially-complete";
case "complete":
return "Avada-Badge--progress-complete";
default:
return "";
}
};
var badgeClasses = ["Avada-Badge", getToneClasses(tone), getSizeClasses(size), getProgressClasses(progress), className].filter(Boolean).join(" ");
var renderProgressPip = function renderProgressPip() {
if (!progress) return null;
return jsxRuntime.jsx("span", {
className: "Avada-Badge__Pip",
children: jsxRuntime.jsx("span", {
className: "Avada-Badge__Progress"
})
});
};
var renderIcon = function renderIcon() {
if (!Icon) return null;
return jsxRuntime.jsx("span", {
className: "Avada-Badge__Icon",
children: jsxRuntime.jsx(Icon, {})
});
};
var renderContent = function renderContent() {
if (!children) return null;
return jsxRuntime.jsx("span", {
className: "Avada-Badge__Text",
children: children
});
};
return jsxRuntime.jsxs("span", {
className: badgeClasses,
children: [renderProgressPip(), renderIcon(), renderContent()]
});
};
var tabsFeatureReq = [{
id: "all",
content: "All",
value: 0
}, {
id: "new-feature",
content: "New feature",
value: 1
}, {
id: "improvement",
content: "Improvement",
value: 2
}, {
id: "bug-report",
content: "Bug report",
value: 3
}, {
id: "submitted",
content: "Submitted",
value: 4
}];
var convertUrlsToLinks = function convertUrlsToLinks(text) {
var urlPattern = /(https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*))/gi;
return text.replace(urlPattern, function (url) {
return "<a href=\"".concat(url, "\" target=\"_blank\" rel=\"noopener noreferrer\" class=\"Avada-FeatureReq-Link\">").concat(url, "</a>");
});
};
var optionsFeatureReq = [{
label: "New feature",
value: "new-feature"
}, {
label: "Bug report",
value: "bug-report"
}, {
label: "Improvement",
value: "improvement"
}, {
label: "Speed up",
value: "speed-up"
}];
var defaultFeatureReqQuery = {
sort: "Most recent",
status: "all",
limit: 10,
lastDoc: null
};
var statusType = ["Doing", "Considering", "Completed"];
var STATUS_ORDER_BY_SUPPORT_REQUEST = {
Doing: 1,
Considering: 2,
Completed: 3
};
function StatusFeatureReqUI(_a) {
var status = _a.status;
switch (status) {
case "Considering":
return jsxRuntime.jsx("p", {
style: {
color: "#616161",
fontStyle: "italic"
},
children: status
});
case "Doing":
return jsxRuntime.jsx("p", {
style: {
color: "#0094D5",
fontStyle: "italic"
},
children: status
});
case "Completed":
return jsxRuntime.jsx("p", {
style: {
color: "#29845A",
fontStyle: "italic"
},
children: status
});
default:
return jsxRuntime.jsx("p", {
style: {
color: "#616161",
fontStyle: "italic"
},
children: status
});
}
}
function FeatureTypeUI(_a) {
var type = _a.type;
var getBadgeProps = function getBadgeProps(type) {
switch (type) {
case "new-feature":
return {
icon: polarisIcons.StarIcon,
tone: "success"
};
case "bug-report":
return {
icon: polarisIcons.BugIcon,
tone: "critical"
};
case "speed-up":
return {
icon: polarisIcons.CodeIcon,
tone: "attention"
};
default:
return {
icon: polarisIcons.CodeIcon,
tone: "info"
};
}
};
var _b = getBadgeProps(type),
icon = _b.icon,
tone = _b.tone;
var formatType = function formatType(type) {
return type.replace(/^([a-z])|-(\w)/g, function (_, first, afterDash) {
return first ? first.toUpperCase() : " " + afterDash.toLowerCase();
});
};
return jsxRuntime.jsx(CustomBadge, {
icon: icon,
tone: tone,
children: jsxRuntime.jsx("p", {
style: {
whiteSpace: "nowrap",
overflow: "hidden",
textOverflow: "ellipsis",
margin: 0
},
children: formatType(type)
})
});
}
var GMAIL_EXCLUDE_ROLE_FEATURE_REQ = ["truongnn@avadagroup.com", "tranggt@avadagroup.com"];
jsxRuntime.jsx("svg", {
width: "5",
height: "6",
viewBox: "0 0 5 6",
fill: "none",
xmlns: "http://www.w3.org/2000/svg",
children: jsxRuntime.jsx("circle", {
cx: "2.5",
cy: "3",
r: "2.5",
fill: "#CCCCCC"
})
});
var FREE = "free";
var STORE_ONBOARD = "STORE_ONBOARD";
var STORE_REVIEW = "STORE_REVIEW";
var STORE_OLD = "STORE_OLD";
var STORE_GROWING = "STORE_GROWING";
var STORE_POTENTIAL = "STORE_POTENTIAL";
var STORE_TEST = "STORE_TEST";
var STORE_NOT_POTENTIAL = "STORE_NOT_POTENTIAL";
var STORE_PRO = "STORE_PRO";
/**
*
* @param countMonthCreateShop
* @param country
* @param shopifyPlan
* @param plan
* @returns {string}
*/
var checkTypeShopGH = function checkTypeShopGH(_ref) {
var _ref$countMonthCreate = _ref.countMonthCreateShop,
countMonthCreateShop = _ref$countMonthCreate === void 0 ? 3 : _ref$countMonthCreate,
_ref$country = _ref.country,
country = _ref$country === void 0 ? "US" : _ref$country,
_ref$shopifyPlan = _ref.shopifyPlan,
shopifyPlan = _ref$shopifyPlan === void 0 ? "" : _ref$shopifyPlan,
_ref$plan = _ref.plan,
plan = _ref$plan === void 0 ? "free" : _ref$plan;
var isShopTest = isShopifyTest({
shopifyPlan: shopifyPlan
});
if (isShopTest) return STORE_TEST;
if (countMonthCreateShop < 3) {
return STORE_ONBOARD;
}
if (plan !== FREE) return STORE_PRO;
if (storeNotPotential.includes(country)) {
return STORE_NOT_POTENTIAL;
}
if (storeReview.includes(country)) {
return STORE_REVIEW;
}
if (countMonthCreateShop > 3 && countMonthCreateShop < 6 && !storeNotPotential.includes(country)) {
return STORE_POTENTIAL;
}
if (countMonthCreateShop <= 12) {
return STORE_GROWING;
}
return STORE_OLD;
};
var storeReview = ["BR", "DZ", "MA", "PK", "PT", "PL"];
var storeNotPotential = ["IN", "PK"];
var isShopifyTest = function isShopifyTest(_ref2) {
var shopifyPlan = _ref2.shopifyPlan;
return ["trial", "affiliate", "partner_test", "staff", "staff_business"].includes(shopifyPlan);
};
function _typeof(o) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) {
return typeof o;
} : function (o) {
return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
}, _typeof(o);
}
// Mock formatDateFields function
var formatDateFields = function formatDateFields(data) {
if (!data) return data;
// Convert Firebase timestamps to Date objects
var formatted = __assign$1({}, data);
if (data.createdAt && typeof data.createdAt.toDate === "function") {
formatted.createdAt = data.createdAt.toDate();
}
if (data.updatedAt && typeof data.updatedAt.toDate === "function") {
formatted.updatedAt = data.updatedAt.toDate();
}
return formatted;
};
var LiveVoteFeatureReq = /** @class */function () {
function LiveVoteFeatureReq(props) {
this.initialize(props);
}
LiveVoteFeatureReq.prototype.initialize = function (_a) {
var db = _a.db,
shop = _a.shop;
this.featureReqRef = firestore$1.collection(db, "featureReq");
this.commentFeatureReqRef = firestore$1.collection(db, "commentFeatureReq");
this.support = firestore$1.collection(db, "support");
this.db = db;
this.shopId = shop === null || shop === void 0 ? void 0 : shop.id;
this.shop = shop;
this.data = [];
this.activeSubscriptions = new Set();
};
LiveVoteFeatureReq.prototype.subscribeToDocumentCounts = function (callback, dataQuery) {
return __awaiter(this, void 0, void 0, function () {
var docRef, unsubscribe_1;
var _this = this;
var _a;
return __generator(this, function (_b) {
try {
if (!(dataQuery === null || dataQuery === void 0 ? void 0 : dataQuery.id)) return [2 /*return*/];
docRef = (dataQuery === null || dataQuery === void 0 ? void 0 : dataQuery.featureType) ? firestore$1.doc(this.featureReqRef, dataQuery.id) : firestore$1.doc(this.commentFeatureReqRef, dataQuery.id);
unsubscribe_1 = firestore$1.onSnapshot(docRef, function (docSnap) {
if (docSnap.exists()) {
var docData_1 = formatDateFields(docSnap.data());
if (dataQuery === null || dataQuery === void 0 ? void 0 : dataQuery.featureType) {
callback(function (prevState) {
return __assign$1(__assign$1({}, prevState), {
commentCount: docData_1.commentCount || 0,
voteCount: docData_1.voteCount || 0,
likedUserIds: docData_1.likedUserIds || []
});
});
} else if (dataQuery === null || dataQuery === void 0 ? void 0 : dataQuery.replies) {
callback(function (prevState) {
return __assign$1(__assign$1({}, prevState), {
voteCount: docData_1.voteCount || 0,
likedUserIds: docData_1.likedUserIds || []
});
});
} else {
callback(function (prevState) {
return __assign$1(__assign$1({}, prevState), {
commentCount: docData_1.repliesCount || 0,
voteCount: docData_1.voteCount || 0,
likedUserIds: docData_1.likedUserIds || []
});
});
}
}
});
(_a = this.activeSubscriptions) === null || _a === void 0 ? void 0 : _a.add(unsubscribe_1);
return [2 /*return*/, function () {
var _a;
unsubscribe_1();
(_a = _this.activeSubscriptions) === null || _a === void 0 ? void 0 : _a["delete"](unsubscribe_1);
}];
} catch (error) {
console.error("Error getting document:", error);
}
return [2 /*return*/];
});
});
};
LiveVoteFeatureReq.prototype.toggleVote = function (_a) {
return __awaiter(this, arguments, void 0, function (_b) {
var docToUpdate, docSnap, docData, likedUserIds, hasLiked, voteChange, updateAction, error_1;
var targetId = _b.targetId,
shopId = _b.shopId,
byFeatureReq = _b.byFeatureReq;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 5,, 6]);
docToUpdate = byFeatureReq ? firestore$1.doc(this.featureReqRef, targetId) : firestore$1.doc(this.commentFeatureReqRef, targetId);
return [4 /*yield*/, firestore$1.getDoc(docToUpdate)];
case 1:
docSnap = _c.sent();
if (!docSnap.exists()) return [3 /*break*/, 3];
docData = docSnap.data();
likedUserIds = docData.likedUserIds || [];
hasLiked = likedUserIds.includes(shopId);
voteChange = hasLiked ? -1 : 1;
updateAction = hasLiked ? firestore$1.arrayRemove(shopId) : firestore$1.arrayUnion(shopId);
return [4 /*yield*/, firestore$1.updateDoc(docToUpdate, {
voteCount: firestore$1.increment(voteChange),
likedUserIds: updateAction
})];
case 2:
_c.sent();
return [3 /*break*/, 4];
case 3:
console.error("Document does not exist:", targetId);
_c.label = 4;
case 4:
return [3 /*break*/, 6];
case 5:
error_1 = _c.sent();
console.error("Error voting like:", error_1);
return [3 /*break*/, 6];
case 6:
return [2 /*return*/];
}
});
});
};
LiveVoteFeatureReq.prototype.subscribeToComments = function (parentId, callback) {
return __awaiter(this, void 0, void 0, function () {
var docRef, unsubscribe_2;
var _this = this;
return __generator(this, function (_a) {
try {
if (!parentId) {
if (typeof callback === "function") callback([]);
return [2 /*return*/];
}
docRef = firestore$1.query(this.commentFeatureReqRef, firestore$1.where("parentId", "==", parentId), firestore$1.orderBy("createdAt", "asc"));
unsubscribe_2 = firestore$1.onSnapshot(docRef, function (snapshot) {
if (typeof callback !== "function") return;
var data = snapshot.docs.map(function (doc) {
var docData = doc.data();
if (docData.createdAt && docData.createdAt.toDate) {
docData.createdAt = docData.createdAt.toDate().toISOString();
}
return __assign$1({
id: doc.id
}, docData);
});
callback(data);
});
this.activeSubscriptions.add(unsubscribe_2);
return [2 /*return*/, function () {
unsubscribe_2();
_this.activeSubscriptions["delete"](unsubscribe_2);
}];
} catch (error) {
console.error("subscribeToComments", error);
if (typeof callback === "function") callback([]);
}
return [2 /*return*/];
});
});
};
LiveVoteFeatureReq.prototype.cleanup = function () {
this.activeSubscriptions.forEach(function (unsubscribe) {
if (typeof unsubscribe === "function") unsubscribe();
});
this.activeSubscriptions.clear();
};
LiveVoteFeatureReq.prototype.subscribeTrendingRequests = function (callback, limitCount) {
var _this = this;
if (limitCount === void 0) {
limitCount = 10;
}
try {
var queryRef = firestore$1.query(this.featureReqRef, firestore$1.orderBy("createdAt", "desc"));
var unsubscribe_3 = firestore$1.onSnapshot(queryRef, function (snapshot) {
if (typeof callback !== "function") return;
if (!snapshot.empty) {
var now_1 = new Date();
var data = snapshot.docs.map(function (doc) {
var threadData = __assign$1(__assign$1({}, formatDateFields(doc.data())), {
id: doc.id
});
// Calculate trending score based on votes, comments and recency
var createdAt = new Date(threadData.createdAt);
var daysSincePosted = Math.max((now_1.getTime() - createdAt.getTime()) / (1000 * 60 * 60 * 24), 1);
var score = (threadData.voteCount * 1 + threadData.commentCount * 2) / daysSincePosted;
return __assign$1(__assign$1({}, threadData), {
score: score
});
}).sort(function (a, b) {
return (b.score || 0) - (a.score || 0);
}).slice(0, limitCount);
callback({
data: data
});
} else {
callback({
data: []
});
}
});
this.activeSubscriptions.add(unsubscribe_3);
return function () {
unsubscribe_3();
_this.activeSubscriptions["delete"](unsubscribe_3);
};
} catch (error) {
console.error("Error getting trending feature requests:", error);
if (typeof callback === "function") callback({
data: []
});
return function () {};
}
};
LiveVoteFeatureReq.prototype.subscribeFeatureRequests = function (callback, queryParams) {
var _this = this;
var _a;
if (queryParams === void 0) {
queryParams = defaultFeatureReqQuery;
}
try {
var queryRef = firestore$1.query(this.featureReqRef);
if (["new-feature", "improvement", "bug-report"].includes(queryParams.status)) {
queryRef = firestore$1.query(queryRef, firestore$1.where("featureType", "==", queryParams.status));
}
if (queryParams.status === "submitted") {
queryRef = firestore$1.query(queryRef, firestore$1.where("shopId", "==", this.shopId));
}
if (queryParams.status === "speed-up") {
queryRef = firestore$1.query(queryRef, firestore$1.where("featureType", "==", "speed-up"), firestore$1.where("status", "in", ["Doing", "Considering"]));
}
if (queryParams.sort === "Most recent") {
queryRef = firestore$1.query(queryRef, firestore$1.orderBy("createdAt", "desc"));
} else if (queryParams.sort === "Top Voted") {
queryRef = firestore$1.query(queryRef, firestore$1.orderBy("voteCount", "desc"));
}
queryRef = firestore$1.query(queryRef, firestore$1.limit(parseInt(((_a = queryParams.limit) === null || _a === void 0 ? void 0 : _a.toString()) || "0")));
if (queryParams.lastDoc) {
queryRef = firestore$1.query(queryRef, firestore$1.startAfter(queryParams.lastDoc));
}
var unsubscribe_4 = firestore$1.onSnapshot(queryRef, function (snapshot) {
if (typeof callback !== "function") return;
if (!snapshot.empty) {
var lastVisible = snapshot.docs[snapshot.docs.length - 1];
var data = snapshot.docs.map(function (doc) {
return __assign$1(__assign$1({}, formatDateFields(doc.data())), {
id: doc.id
});
});
if (queryParams.status === "speed-up") {
data.sort(function (a, b) {
return STATUS_ORDER_BY_SUPPORT_REQUEST[a.status] - STATUS_ORDER_BY_SUPPORT_REQUEST[b.status];
});
return callback({
data: data,
lastDoc: lastVisible
});
}
callback({
data: data,
lastDoc: lastVisible
});
} else {
callback({
data: [],
lastDoc: null
});
}
}, function (error) {
console.error("Error in snapshot listener:", error);
callback({
data: [],
lastDoc: null
});
});
this.activeSubscriptions.add(unsubscribe_4);
return function () {
unsubscribe_4();
_this.activeSubscriptions["delete"](unsubscribe_4);
};
} catch (error) {
console.error("Error getting feature requests:", error);
if (typeof callback === "function") callback({
data: [],
lastDoc: null
});
return function () {};
}
};
LiveVoteFeatureReq.prototype.subscribeFeatureRequest = function (id, callback) {
var _this = this;
try {
if (!id) return function () {};
if (id.trim() === "") {
console.warn("Invalid or empty ID passed to subscribeFeatureRequest:", id);
if (typeof callback === "function") callback({});
return function () {};
}
var docRef = firestore$1.doc(this.featureReqRef, id);
var unsubscribe_5 = firestore$1.onSnapshot(docRef, function (docSnapshot) {
if (typeof callback !== "function") return;
if (docSnapshot.exists()) {
var data = __assign$1(__assign$1({}, formatDateFields(docSnapshot.data())), {
id: docSnapshot.id
});
callback(data);
} else {
console.log("Feature request with ID ".concat(id, " not found"));
callback({});
}
});
this.activeSubscriptions.add(unsubscribe_5);
return function () {
unsubscribe_5();
_this.activeSubscriptions["delete"](unsubscribe_5);
};
} catch (error) {
console.error("Error getting feature request by ID:", error);
if (typeof callback === "function") callback({});
return function () {};
}
};
LiveVoteFeatureReq.prototype.removeFeatureRequest = function (id) {
return __awaiter(this, void 0, void 0, function () {
var batch_1, getDocsByField_1, parentComments, replies, error_2;
var _this = this;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 4,, 5]);
if (!id) throw new Error("ID is required to delete feature request");
batch_1 = firestore$1.writeBatch(this.db);
getDocsByField_1 = function getDocsByField_1(collectionRef, field, value) {
return __awaiter(_this, void 0, void 0, function () {
var q, snapshot;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
q = firestore$1.query(collectionRef, firestore$1.where(field, "==", value));
return [4 /*yield*/, firestore$1.getDocs(q)];
case 1:
snapshot = _a.sent();
return [2 /*return*/, snapshot.docs];
}
});
});
};
return [4 /*yield*/, getDocsByField_1(this.commentFeatureReqRef, "parentId", id)];
case 1:
parentComments = _a.sent();
return [4 /*yield*/, Promise.all(parentComments.map(function (comment) {
return getDocsByField_1(_this.commentFeatureReqRef, "parentId", comment.id);
})).then(function (results) {
return results.flat();
})];
case 2:
replies = _a.sent();
// Delete everything in batch
__spreadArray(__spreadArray([firestore$1.doc(this.featureReqRef, id)], parentComments.map(function (doc) {
return doc.ref;
}), true), replies.map(function (doc) {
return doc.ref;
}), true).forEach(function (ref) {
return batch_1["delete"](ref);
});
return [4 /*yield*/, batch_1.commit()];
case 3:
_a.sent();
return [3 /*break*/, 5];
case 4:
error_2 = _a.sent();
console.error("Error deleting feature request and related data:", error_2);
throw error_2;
case 5:
return [2 /*return*/];
}
});
});
};
LiveVoteFeatureReq.prototype.updateFeatureRequest = function (id, updateData) {
return __awaiter(this, void 0, void 0, function () {
var featureReqDocRef, error_3;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 2,, 3]);
if (!id) throw new Error("ID is required to update feature request");
if (!updateData || _typeof(updateData) !== "object") throw new Error("Update data must be an object");
featureReqDocRef = firestore$1.doc(this.featureReqRef, id);
return [4 /*yield*/, firestore$1.updateDoc(featureReqDocRef, updateData)];
case 1:
_a.sent();
return [2 /*return*/, {
success: true,
message: "Feature request updated successfully"
}];
case 2:
error_3 = _a.sent();
console.error("Error updating feature request:", error_3);
throw error_3;
case 3:
return [2 /*return*/];
}
});
});
};
LiveVoteFeatureReq.prototype.removeComment = function (commentId, shopId) {
return __awaiter(this, void 0, void 0, function () {
var commentDocRef, commentSnapshot, commentData, batch_2, parentId, repliesSnapshot, error_4;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
_a.trys.push([0, 6,, 7]);
if (!commentId || !shopId) return [2 /*return*/];
commentDocRef = firestore$1.doc(this.commentFeatureReqRef, commentId);
return [4 /*yield*/, firestore$1.getDoc(commentDocRef)];
case 1:
commentSnapshot = _a.sent();
if (!commentSnapshot.exists()) return [2 /*return*/];
commentData = formatDateFields(commentSnapshot.data());
if (commentData.shopId !== shopId) return [2 /*return*/];
batch_2 = firestore$1.writeBatch(this.db);
parentId = commentData.parentId;
if (!commentData.replies) return [3 /*break*/, 2];
batch_2.update(firestore$1.doc(this.commentFeatureReqRef, parentId), {
repliesCount: firestore$1.increment(-1)
});
batch_2["delete"](commentDocRef);
return [3 /*break*/, 4];
case 2:
return [4 /*yield*/, firestore$1.getDocs(firestore$1.query(this.commentFeatureReqRef, firestore$1.where("parentId", "==", commentId)))];
case 3:
repliesSnapshot = _a.sent();
repliesSnapshot.docs.forEach(function (doc) {
return batch_2["delete"](doc.ref);
});
batch_2.update(firestore$1.doc(this.featureReqRef, parentId), {
commentCount: firestore$1.increment(-1)
});
batch_2["delete"](commentDocRef);
_a.label = 4;
case 4:
return [4 /*yield*/, batch_2.commit()];
case 5:
_a.sent();
return [3 /*break*/, 7];
case 6:
error_4 = _a.sent();
console.error("Error deleting comment:", error_4);
return [3 /*break*/, 7];
case 7:
return [2 /*return*/];
}
});
});
};
LiveVoteFeatureReq.prototype.subscribeSupport = function (shopId, callback) {
var _this = this;
try {
if (!shopId) return function () {};
var queryRef = firestore$1.query(this.support, firestore$1.where("shopId", "==", shopId));
var unsubscribe_6 = firestore$1.onSnapshot(queryRef, function (snapshot) {
if (typeof callback !== "function") return;
if (!snapshot.empty) {
var docSnapshot = snapshot.docs[0];
var data = __assign$1(__assign$1({}, formatDateFields(docSnapshot.data())), {
id: docSnapshot.id
});
callback(data);
} else {
callback({});
}
});
this.activeSubscriptions.add(unsubscribe_6);
return function () {
unsubscribe_6();
_this.activeSubscriptions["delete"](unsubscribe_6);
};
} catch (error) {
console.error("Error getting support document by shopId:", error);
if (typeof callback === "function") {
callback({});
}
return function () {};
}
};
return LiveVoteFeatureReq;
}();
var defaultConfig = {
apiKey: "AIzaSyDEXUMfw7e2UQJTMPMG2fX4DPwvTaHJq5Y",
authDomain: "avad-seo-staging.firebaseapp.com",
databaseURL: "https://avad-seo-staging.firebaseio.com",
projectId: "avad-seo-staging",
storageBucket: "avad-seo-staging.appspot.com",
messagingSenderId: "1071354174065",
appId: "1:1071354174065:web:968c5ac7883159ea3d99d0",
measurementId: "G-KJJP018Q9E"
};
var firebaseApp;
var firestore;
var initializeFirebase = function initializeFirebase(config) {
if (config === void 0) {
config = defaultConfig;
}
firebaseApp = app.initializeApp(config);
firestore = firestore$1.getFirestore(firebaseApp);
return {
app: firebaseApp,
db: firestore
};
};
var _a = initializeFirebase(),
db = _a.db;
var openModal = function openModal() {
try {
$crisp.push(["do", "chat:open"]);
} catch (e) {
console.log("Cannot send open crisp modal");
}
};
var useFeatureRequest = function useFeatureRequest() {
var context = React.useContext(FeatureRequestContext);
if (context === undefined) throw new Error("error useFeatureRequest");
if (!(context === null || context === void 0 ? void 0 : context.shopInfo)) throw new Error("error shopInfo");
var liveVote = React.useMemo(function () {
return new LiveVoteFeatureReq({
db: db,
shop: context.shopInfo
});
}, [context]);
var _a = React.useState([]),
data = _a[0],
setData = _a[1];
var _b = React.useState(true),
loading = _b[0],
setLoading = _b[1];
var _c = React.useState([]),
dataFeatureTrending = _c[0],
setDataFeatureTrending = _c[1];
var _d = React.useState({
data: [],
lastDoc: null
}),
featureRequests = _d[0],
setFeatureRequests = _d[1];
var _e = React.useState(defaultFeatureReqQuery),
queryParams = _e[0],
setQueryParams = _e[1];
var _f = React.useState(false),
loadingMore = _f[0],
setLoadingMore = _f[1];
var _g = React.useState(false),
loadingComment = _g[0],
setLoadingComment = _g[1];
var _h = React.useState({
requestFeature: 0
}),
dataShopSupport = _h[0],
setDataShopSupport = _h[1];
var shopInfo = context.shopInfo;
var checkRuleSubmit = React.useMemo(function () {
if (GMAIL_EXCLUDE_ROLE_FEATURE_REQ.includes(shopInfo.email)) return true;
return ![STORE_ONBOARD, STORE_TEST, STORE_REVIEW].includes(checkTypeShopGH(shopInfo));
}, [shopInfo]);
var updateQuery = React.useCallback(function (newParams) {
setQueryParams(function (prev) {
return __assign$1(__assign$1(__assign$1({}, prev), newParams), {
lastDoc: newParams.sort || newParams.status ? null : newParams.lastDoc
});
});
}, []);
React.useEffect(function () {
var unsubscribe;
var initTrendingFeatures = function initTrendingFeatures() {
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
try {
unsubscribe = liveVote.subscribeTrendingRequests(function (result) {
setDataFeatureTrending(result.data);
});
} catch (error) {
console.error("Error fetching trending features:", error);
}
return [2 /*return*/];
});
});
};
initTrendingFeatures()["catch"](console.error);
return function () {
if (unsubscribe) unsubscribe();
};
}, [liveVote]);
React.useEffect(function () {
var unsubscribe;
var initFeatureRequests = function initFeatureRequests() {
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
try {
if (!queryParams.lastDoc) {
setLoading(true);
}
unsubscribe = liveVote.subscribeFeatureRequests(function (result) {
setFeatureRequests(function (prev) {
return {
data: queryParams.lastDoc ? __spreadArray(__spreadArray([], prev.data, true), result.data, true) : result.data,
lastDoc: result.lastDoc
};
});
setLoading(false);
setLoadingMore(false);
}, queryParams);
} catch (error) {
console.error("Error fetching feature requests:", error);
setLoading(false);
setLoadingMore(false);
}
return [2 /*return*/];
});
});
};
initFeatureRequests()["catch"](console.error);
return function () {
if (unsubscribe) unsubscribe();
};
}, [liveVote, queryParams]);
var loadMore = React.useCallback(function () {
return __awaiter(void 0, void 0, void 0, function () {
return __generator(this, function (_a) {
if (!featureRequests.lastDoc || loadingMore) return [2 /*return*/];
try {
setLoadingMore(true);
setQueryParams(function (prev) {
return __assign$1(__assign$1({}, prev), {
lastDoc: featureRequests.lastDoc
});
});
} catch (e) {
console.error(e);
} finally {
setLoadingMore(false);
}
return [2 /*return*/];
});
});
}, [featureRequests.lastDoc, loadingMore]);
var subscribeToDocumentCounts = React.useCallback(function (dataQuery) {
return __awaiter(void 0, void 0, void 0, function () {
var error_1;
return __generator(this, function (_a) {
switch (_a.label) {
case 0:
setLoading(true);
_a.label = 1;
case 1:
_a.trys.push([1, 3,, 4]);
return [4 /*yield*/, liveVote.subscribeToDocumentCounts(setData, dataQuery)];
case 2:
_a.sent();
setLoading(false);
return [3 /*break*/, 4];
case 3:
error_1 = _a.sent();
setLoading(false);
console.error("Error fetching feature requests:", error_1);
return [3 /*break*/, 4];
case 4:
return [2 /*return*/];
}
});
});
}, [liveVote]);
var handleComment = function handleComment(_a) {
return __awaiter(void 0, [_a], void 0, function (_b) {
var processedContent;
var parentId = _b.parentId,
replies = _b.replies,
value = _b.value;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
setLoadingComment(true);
_c.label = 1;
case 1:
_c.trys.push([1,, 3, 4]);
processedContent = convertUrlsToLinks(value.replace(/\n/g, "<br>"));
return [4 /*yield*/, context.fetchAuthenticatedApi("/featureReqComment", {
method: "POST",
body: {
content: processedContent,
parentId: parentId,
shopId: shopInfo.shopId,
replies: replies,
shopOwner: shopInfo.shopOwner,
isTeamAvada: !context.isEmbeddedAppEnv
}
})];
case 2:
_c.sent();
return [3 /*break*/, 4];
case 3:
setLoadingComment(false);
openModal();
return [7 /*endfinally*/];
case 4:
return [2 /*return*/];
}
});
});
};
var handleVoteLike = React.useCallback(function (_a) {
return __awaiter(void 0, [_a], void 0, function (_b) {
var error_2;
var targetId = _b.targetId,
shopId = _b.shopId,
byFeatureReq = _b.byFeatureReq;
return __generator(this, function (_c) {
switch (_c.label) {
case 0:
_c.trys.push([0, 2,, 3]);
return [4 /*yield*/, liveVote.toggleVote({
targetId: targetId,
shopId: shopId,
byFeatureReq: byFeatureReq
})];
case 1:
_c.sent();
return [3 /*break*/, 3];
case 2:
error_2 = _c.sent();
console.error("Error handleVoteLike:", error_2);
return [3 /*break*/, 3];
case 3:
return [2 /*return*/];
}
});
});
}, [liveVote]);
var checkUserLiked = React.useCallback(function (item, userId) {
if (!item || !userId) return false;
return item.likedUs