Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat aldeed 5417 remove operator prefix #6

Merged
merged 16 commits into from
Oct 17, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
107 changes: 0 additions & 107 deletions client/modules/core/helpers/layout.js

This file was deleted.

96 changes: 3 additions & 93 deletions client/modules/core/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -349,20 +349,6 @@ export default {
return "";
},

/**
* @name getPrimaryShopSettings
* @method
* @memberof Core/Client
* @returns {Object} shop settings of the primary shop
*/
getPrimaryShopSettings() {
const settings = Packages.findOne({
name: "core",
shopId: this.getPrimaryShopId()
}) || {};
return settings.settings || {};
},

/**
* @name getCurrentShop
* @summary Get the proper current shop based on various checks. This mirrors the logic in
Expand Down Expand Up @@ -461,36 +447,6 @@ export default {
return this.getShopId() === this.getPrimaryShopId();
},

/**
* @name getShopName
* @method
* @memberof Core/Client
* @summary gets name of shop by provided shopId, or current active shop if shopId is not provided
* @param {String} providedShopId - shopId of shop to return name of
* @returns {String} - shop name
*/
getShopName(providedShopId) {
const shopId = providedShopId || this.getShopId();
const shop = Shops.findOne({
_id: shopId
});
return shop && shop.name;
},

/**
* @name getShopSettings
* @method
* @memberof Core/Client
* @returns {Object} shop settings
*/
getShopSettings() {
const settings = Packages.findOne({
name: "core",
shopId: this.shopId
}) || {};
return settings.settings || {};
},

getShopLanguage() {
const shopId = this.getShopId();
const shop = Shops.findOne({ _id: shopId });
Expand Down Expand Up @@ -529,46 +485,17 @@ export default {
return slug;
},

/**
* @name getPackageSettings
* @method
* @memberof Core/Client
* @param {String} name package name
* @returns {Object} package settings
*/
getPackageSettings(name) {
const shopId = this.getShopId();
const query = { name };

if (shopId) {
query.shopId = shopId;
}

return Packages.findOne(query);
},

/**
* @name getPackageSettingsWithOptions
* @method
* @memberof Core/Client
* @param {Object} options options to pass to query
* @returns {Object} package settings with options
*/
getPackageSettingsWithOptions(options) {
const query = options;
return Packages.findOne(query);
},

/**
* @name allowGuestCheckout
* @method
* @memberof Core/Client
* @returns {Boolean} is guest checkout allowed
*/
allowGuestCheckout() {
const settings = this.getShopSettings();
const pkg = Packages.findOne({ name: "core", shopId: this.getShopId() }) || {};
const shopSettings = pkg.settings || {};
// we can disable in admin, let's check.
return !!(settings.public && settings.public.allowGuestCheckout);
return !!(shopSettings.public && shopSettings.public.allowGuestCheckout);
},

/**
Expand Down Expand Up @@ -917,22 +844,5 @@ export default {
}
Logger.debug("getRegistryForCurrentRoute not found", template, provides);
return {};
},

/**
* @name getMarketplaceSettings
* @method
* @memberof Core/Client
* @summary finds the enabled `reaction-marketplace` package for the primary shop and returns the settings
* @returns {Object} The marketplace settings from the primary shop or undefined
*/
getMarketplaceSettings() {
const marketplaceSettings = Packages.findOne({
name: "reaction-marketplace",
shopId: this.getPrimaryShopId(), // the primary shop always owns the marketplace settings
enabled: true // only use the marketplace settings if marketplace is enabled
});

return marketplaceSettings && marketplaceSettings.settings;
}
};
32 changes: 4 additions & 28 deletions client/modules/core/subscriptions.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
import { Meteor } from "meteor/meteor";
import { Tracker } from "meteor/tracker";
import { SubsManager } from "meteor/meteorhacks:subs-manager";
import Reaction from "./main";
import { getUserId } from "./helpers/utils";

export const Subscriptions = {};

Expand All @@ -14,28 +10,8 @@ Subscriptions.Manager = new SubsManager();
* General Subscriptions
*/

Tracker.autorun(() => {
const userId = getUserId();
Subscriptions.Account = Subscriptions.Manager.subscribe("Accounts");
Subscriptions.UserProfile = Meteor.subscribe("UserProfile", userId);
});

// Primary shop subscription
Subscriptions.PrimaryShop = Subscriptions.Manager.subscribe("PrimaryShop");

// This Packages subscription is used for the Active shop's packages
Subscriptions.Packages = Subscriptions.Manager.subscribe("Packages");

Subscriptions.Groups = Subscriptions.Manager.subscribe("Groups");

Subscriptions.BrandAssets = Subscriptions.Manager.subscribe("BrandAssets");

Tracker.autorun(() => {
// Reload Packages sub if shopId changes
// We have a persistent subscription to the primary shop's packages,
// so don't refresh sub if we're updating to primaryShopId sub
const shopId = Reaction.getShopId();
if (shopId && shopId !== Reaction.getPrimaryShopId()) {
Subscriptions.Packages = Subscriptions.Manager.subscribe("Packages", shopId);
}
});
Subscriptions.Groups = Subscriptions.Manager.subscribe("Groups");
Subscriptions.MyAccount = Subscriptions.Manager.subscribe("MyAccount");
Subscriptions.PrimaryShop = Subscriptions.Manager.subscribe("PrimaryShop");
Subscriptions.UserProfile = Subscriptions.Manager.subscribe("UserProfile");
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class ProfileImageWithData extends Component {
open={Boolean(menuAnchorEl)}
onClose={() => setMenuAnchorEl(null)}
>
<Link to={"/operator/profile"}>
<Link to={"/profile"}>
<MenuItem>{i18next.t("admin.userAccountDropdown.profileLabel")}</MenuItem>
</Link>
<MenuItem onClick={() => Meteor.logout()}>{i18next.t("accountsUI.signOut")}</MenuItem>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ ShopLogoWithData.propTypes = {
};

ShopLogoWithData.defaultProps = {
linkTo: "/operator",
linkTo: "/",
shouldShowShopName: false,
size: 60
};
Expand Down
10 changes: 6 additions & 4 deletions imports/client/ui/components/Sidebar/Sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import withStyles from "@material-ui/core/styles/withStyles";
import SettingsIcon from "mdi-material-ui/Settings";
import CloseIcon from "mdi-material-ui/Close";
import { Translation } from "/imports/plugins/core/ui/client/components";
import useIsAppLoading from "/imports/client/ui/hooks/useIsAppLoading.js";
import useCurrentShopId from "../../hooks/useCurrentShopId";
import ShopLogoWithData from "../ShopLogoWithData";

Expand Down Expand Up @@ -107,6 +108,7 @@ function Sidebar(props) {
routes
} = props;

const [isAppLoading] = useIsAppLoading();
const [currentShopId] = useCurrentShopId();

const primaryRoutes = routes.filter(({ isNavigationLink, isSetting }) => isNavigationLink && !isSetting).sort(routeSort);
Expand All @@ -133,14 +135,14 @@ function Sidebar(props) {
}

let list;
if (currentShopId) {
if (!isAppLoading && currentShopId) {
list = (
<List disablePadding>
{primaryRoutes.map((route) => (
<NavLink
activeClassName={!isSettingsOpen ? activeClassName : null}
className={classes.link}
to={`/operator${route.path}`}
to={route.path}
key={route.path}
onClick={() => {
setIsSettingsOpen(false);
Expand Down Expand Up @@ -170,7 +172,7 @@ function Sidebar(props) {
const [firstRoute] = settingRoutes;

if (firstRoute) {
history.push(`/operator${firstRoute.path}`);
history.push(firstRoute.path);
}
}
setIsSettingsOpen(!isSettingsOpen);
Expand All @@ -192,7 +194,7 @@ function Sidebar(props) {
<NavLink
activeClassName={activeClassName}
className={classes.link}
to={`/operator${route.path}`}
to={route.path}
key={route.path}
onClick={onDrawerClose}
>
Expand Down
2 changes: 1 addition & 1 deletion imports/client/ui/hooks/useAuth.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export default function useAuth() {
setLoggedIn(!!Reaction.getUserId());

// Attempt to check if we are still loading this data
setLoading((hasDashboardAccessForAnyShop !== true && hasDashboardAccessForAnyShop !== false) || !shop);
setLoading((hasDashboardAccessForAnyShop !== true && hasDashboardAccessForAnyShop !== false));

if (!hasStorefrontHomeUrl && !isLoading) {
Logger.warn("Missing storefront home URL. Please set this from the shop settings panel so that customer users can be redirected to your storefront.");
Expand Down
20 changes: 20 additions & 0 deletions imports/client/ui/hooks/useCurrentInternalShopId.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { useState, useEffect } from "react";
import { Tracker } from "meteor/tracker";
import { Reaction } from "/client/api";

/**
* React Hook that gets the globally current shop ID
* @return {Array} [currentShopId]
*/
export default function useCurrentInternalShopId() {
const [currentShopId, setCurrentShopId] = useState(null);

useEffect(() => {
Tracker.autorun(() => {
const shop = Reaction.getCurrentShop();
setCurrentShopId((shop && shop._id) || null);
});
});

return [currentShopId];
}
Loading