How to use @shopgate/pwa-common - 10 common examples

To help you get started, we’ve selected a few @shopgate/pwa-common examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github shopgate / pwa / libraries / common / subscriptions / router.js View on Github external
location,
              state: routeState,
            },
          },
        }));

        return;
      }
    }

    // Check for a redirect and change location if one is found.
    let redirect = redirects.getRedirect(location);

    if (redirect) {
      if (typeof redirect === 'function' || redirect instanceof Promise) {
        const { pathname } = getCurrentRoute(state);
        LoadingProvider.setLoading(pathname);

        const pattern = router.findPattern(location.split('?')[0]);
        const { transform } = router.patterns[pattern] || {};
        const route = new Route({
          pathname: location,
          pattern,
          routeState,
          transform,
        });

        try {
          redirect = await redirect({
            ...params,
            action: {
              ...params.action,
github shopgate / pwa / libraries / ui-shared / Button / style.js View on Github external
const primary = (disabled, flat) => {
  if (!flat) {
    if (disabled) {
      // Regular disabled button style.
      return createButtonStyles(themeConfig.colors.shade4, themeConfig.colors.shade7);
    }

    // Regular enabled button style.
    return createButtonStyles(themeConfig.colors.accentContrast, themeConfig.colors.accent);
  }

  if (disabled) {
    // Flat disabled button style.
    return createButtonStyles(themeConfig.colors.shade4, null);
  }

  // Flat enabled button style.
  return createButtonStyles(themeConfig.colors.accent, null);
};
github shopgate / pwa / libraries / ui-shared / MessageBar / style.js View on Github external
import { css } from 'glamor';
// TODO: Remove the usage of themeConfig here
import { themeConfig } from '@shopgate/pwa-common/helpers/config';

const container = css({
  background: themeConfig.colors.background,
  display: 'flex',
  flexDirection: 'column',
  flexShrink: 0,
});

const messageBase = {
  padding: `${themeConfig.variables.gap.small}px ${themeConfig.variables.gap.big}px`,
  fontSize: '0.875rem',
  fontWeight: 500,
  ':not(:last-child)': {
    marginBottom: themeConfig.variables.gap.small * 0.5,
  },
};

const info = css(messageBase, {
  background: themeConfig.colors.accent,
github shopgate / pwa / themes / theme-gmd / components / Reviews / components / Header / components / AverageRating / index.jsx View on Github external
const AverageRating = ({ average, count, productId }) => {
  if (!productId) {
    return null;
  }

  return (
    
      
      
    
  );
};
github shopgate / pwa / themes / theme-gmd / components / ProductList / components / Item / index.jsx View on Github external
const Item = ({ display, product }) => (
  
    
      

        {/* IMAGE */}
        
        
          <img alt="{product.name}" src="{product.featuredImageUrl}">
        
        

        {/* DISCOUNT */}
github shopgate / pwa / libraries / ui-shared / Form / RadioGroup / components / Item / style.js View on Github external
const container = css({
  display: 'flex',
  marginLeft: -1, // Removes margin of svg.
}).toString();

const icon = css({
  width: 24,
  height: 24,
}).toString();

const label = css({
  flex: 1,
  fontSize: '1rem',
  lineHeight: 1.5,
  marginLeft: themeConfig.variables.gap.small,
  marginBottom: themeConfig.variables.gap.small,
}).toString();

const active = css({
  color: themeConfig.colors.primary,
}).toString();

export default {
  input,
  icon,
  container,
  label,
  active,
};
github shopgate / pwa / libraries / commerce / category / actions / fetchCategory.js View on Github external
const fetchCategory = categoryId => (dispatch, getState) => {
  const state = getState();
  const category = state.category.categoriesById[categoryId];

  if (!shouldFetchData(category)) {
    /**
     * Child categories are maybe missing.
     * So we need to check it (check happens inside fetchCategoryChildren).
     * This is the case if we got categories from getRootCategory
    */
    dispatch(fetchCategoryChildren(categoryId));
    return;
  }

  // No data at all. So we have the fetch the category with children included
  dispatch(requestCategory(categoryId));

  new PipelineRequest('shopgate.catalog.getCategory')
    .setInput({
      categoryId,
      includeChildren: true,
github shopgate / pwa / libraries / commerce / category / actions / fetchCategory.js View on Github external
const fetchCategory = categoryId => (dispatch, getState) => {
  const state = getState();
  const category = state.category.categoriesById[categoryId];

  if (!shouldFetchData(category)) {
    /**
     * Child categories are maybe missing.
     * So we need to check it (check happens inside fetchCategoryChildren).
     * This is the case if we got categories from getRootCategory
    */
    if (category.childrenCount) {
      dispatch(fetchCategoryChildren(categoryId));
    }

    return Promise.resolve(category);
  }

  // No data at all. So we have the fetch the category with children included
  dispatch(requestCategory(categoryId));

  return new PipelineRequest(pipelines.SHOPGATE_CATALOG_GET_CATEGORY)
github shopgate / pwa / libraries / commerce / search / actions / fetchSearchResults.js View on Github external
if (promise instanceof Promise) {
    promise.then((response) => {
      // Inspect the response object to determine, if it represents a search result, or an error.
      if (response && response.products && Array.isArray(response.products)) {
        // Dispatch the receive action when the response contains valid data.s
        dispatch(receiveSearchResults(searchPhrase, offset, response));
      } else {
        // If no valid data is delivered within the response the error action is dispatched.
        dispatch(errorSearchResults(searchPhrase, offset));
      }
    });
  }
};

/** @mixes {MutableFunction} */
export default mutable(fetchSearchResults);
github shopgate / pwa / themes / theme-ios11 / pages / More / components / Quicklinks / index.spec.jsx View on Github external
import React from 'react';
import { mount } from 'enzyme';
import { Provider } from 'react-redux';
import { createMockStore } from '@shopgate/pwa-common/store';
import { getMenuById } from '@shopgate/pwa-common/selectors/menu';
import Quicklinks from './index';

const store = createMockStore();

jest.mock('@shopgate/pwa-common/components/Link', () =&gt; {
  /* eslint-disable react/prop-types, require-jsdoc */
  const Link = ({ children }) =&gt; (
    <div>
      {children}
    </div>
  );

  /* eslint-enable react/prop-types, require-jsdoc */
  return Link;
});

let mockedQuicklinks;
jest.mock('@shopgate/pwa-common/selectors/menu', () =&gt; ({
  getMenuById: () =&gt; mockedQuicklinks,