├── .gitignore ├── LICENSE ├── README.md ├── SFCC-RN-Components ├── .babelrc ├── .eslintrc ├── .flowconfig ├── .gitignore ├── .watchmanconfig ├── App.js ├── App.test.js ├── README.md ├── app.json ├── assets │ └── images │ │ ├── hamburger_collapsed.png │ │ ├── hamburger_expanded.png │ │ ├── missing_img.png │ │ ├── parchment_logo.png │ │ ├── profile_icon.png │ │ ├── school.png │ │ ├── search_icon.png │ │ └── user_icon.png ├── package-lock.json ├── package.json ├── src │ ├── actionTypes.js │ ├── components │ │ ├── Home │ │ │ ├── Home.js │ │ │ ├── HomeContainer.js │ │ │ └── actions.js │ │ ├── ImageCarousel │ │ │ └── ThumbnailImage.js │ │ ├── Layout │ │ │ └── SectionCard.js │ │ ├── Navbar │ │ │ ├── Navbar.js │ │ │ └── NavbarContainer.js │ │ ├── SFCC │ │ │ ├── Category │ │ │ │ └── ProductCategoryTree │ │ │ │ │ ├── MenuCategory.js │ │ │ │ │ ├── ProductCategoryTree.js │ │ │ │ │ └── actions.js │ │ │ └── Product │ │ │ │ ├── InfoTile │ │ │ │ ├── InfoTile.js │ │ │ │ ├── InfoTileContainer.js │ │ │ │ └── actions.js │ │ │ │ └── ListView │ │ │ │ ├── ListView.js │ │ │ │ ├── ListViewContainer.js │ │ │ │ └── actions.js │ │ └── UserAccount │ │ │ ├── UserAccount.js │ │ │ ├── UserAccountContainer.js │ │ │ └── actions.js │ ├── config │ │ ├── apiConfig.js │ │ └── appConfig.js │ ├── configureStore.js │ ├── lib │ │ ├── OCAPIService │ │ │ ├── Authorize │ │ │ │ ├── AuthorizeService.js │ │ │ │ └── __tests__ │ │ │ │ │ └── AuthTokenTests.js │ │ │ ├── OCAPICallInfo.js │ │ │ ├── OCAPIService.js │ │ │ ├── __mocks__ │ │ │ │ └── CategoryMock.js │ │ │ └── __tests__ │ │ │ │ ├── CategoryTests.js │ │ │ │ └── ProductTests.js │ │ ├── documents │ │ │ ├── Basket.js │ │ │ ├── BundledProduct.js │ │ │ ├── Category.js │ │ │ ├── CategoryResult.js │ │ │ ├── Image.js │ │ │ ├── ImageGroup.js │ │ │ ├── Inventory.js │ │ │ ├── Option.js │ │ │ ├── Product.js │ │ │ ├── ProductLink.js │ │ │ ├── ProductPromotion.js │ │ │ ├── ProductRef.js │ │ │ ├── ProductSearchHit.js │ │ │ ├── ProductSearchResult.js │ │ │ ├── ProductType.js │ │ │ ├── Recommendation.js │ │ │ ├── Variant.js │ │ │ ├── VariationAttribute.js │ │ │ └── VariationGroup.js │ │ └── utilityHelpers │ │ │ ├── URLHelper.js │ │ │ └── __tests__ │ │ │ └── utilityHelperTests.js │ ├── menuItems.js │ ├── models │ │ └── UserProfile.js │ ├── reducers │ │ ├── UserAccountReducer.js │ │ ├── __tests__ │ │ │ └── categoryTreeReducerTests.js │ │ ├── categoryTreeReducer.js │ │ ├── homeReducer.js │ │ ├── infoTileReducer.js │ │ ├── productSearchReducer.js │ │ └── rootReducer.js │ ├── services │ │ └── deviceStorage │ │ │ ├── DeviceStorageService.js │ │ │ └── __tests__ │ │ │ └── DeviceStorageServiceTests.js │ └── styles │ │ └── globalStyles.js └── yarn.lock ├── package-lock.json ├── package.json └── yarn.lock /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/* 2 | node_modules/** 3 | .idea/** 4 | .DS_Store 5 | **/*.code-workspace -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Galen Goforth 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # sfcc-react 2 | sfcc-react is a React Native mobile application that uses Sales Force Commerce Cloud or SFCC (formerly Demandware) and their Open Commerce API (OCAPI) to read and write to an SFCC instance. 3 | 4 | The app uses the Redux framework for global state management and redux-thunk for handling ASYNC action creation methods in order to make calls to OCAPI. This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 5 | 6 | ## Setup and Run 7 | To run this app you need to setup a connection to your SFCC sandbox instance. This can be done by changing the settings in the appConfig.js file: SFCC-RN-Components/src/config/appConfig.js. There are 2 main exports from this file that define the current compile time settings for the app. 8 | 9 | ### apiConfig 10 | The apiConfig object literal that is exported from the appConfig.js configuration file contains the information needed for your app to make calls to your SFCC instance using OCAPI. All of the OCAPI config is contained in a property of the apiConfig export simply named 'OCAPI'. There are several properties to this object property that allow for different setups: 11 | - environment : An attribute with string properties for each type of instance setup (i.e.: production, staging, qa, development). Each of these environment attributes has a string property denoting if the app is to use live API calls to the SFCC instance for that environment setup, or if it should use mock API calls instead. 12 | - resources : This is where you define the resource calls that you will be accessing from the Open Commerce API, and the different types of parameters that will be accepted and/or required to make a specific API call for a resource. 13 | - baseEndpoints : Contains attributes for each type of environment which point to the corresponding URL for making OCAPI calls. 14 | - clientIDs: This attribute must be setup with a valid SFCC user ID that has been configured for OCAPI use. See the SFCC documentation for information on how to setup a user account for OCAPI access. Like the baseEndpoints, and environment attributes, this setup object also has attributes for describing the URL for each individual SFCC instance type. 15 | 16 | ## Disclaimer 17 | The repo is still in the setup phase and there is still a large amout of work left to do. Check back soon to see more. 18 | 19 | Author: Galen Goforth -- galengoforth@gmail.com 20 | -------------------------------------------------------------------------------- /SFCC-RN-Components/.babelrc: -------------------------------------------------------------------------------- 1 | { 2 | "presets": ["babel-preset-expo"], 3 | "env": { 4 | "development": { 5 | "plugins": ["transform-react-jsx-source"] 6 | } 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /SFCC-RN-Components/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "root": true, 3 | 4 | "parser": "babel-eslint", 5 | 6 | "env": { 7 | "es6": true, 8 | "jest": true 9 | }, 10 | 11 | "plugins": [ 12 | "eslint-comments", 13 | "flowtype", 14 | "prettier", 15 | "react", 16 | "react-native", 17 | "jest" 18 | ], 19 | 20 | "globals": { 21 | "__DEV__": true, 22 | "__dirname": false, 23 | "__fbBatchedBridgeConfig": false, 24 | "alert": false, 25 | "cancelAnimationFrame": false, 26 | "cancelIdleCallback": false, 27 | "clearImmediate": true, 28 | "clearInterval": false, 29 | "clearTimeout": false, 30 | "console": false, 31 | "document": false, 32 | "escape": false, 33 | "Event": false, 34 | "EventTarget": false, 35 | "exports": false, 36 | "fetch": false, 37 | "FormData": false, 38 | "global": false, 39 | "jest": false, 40 | "Map": true, 41 | "module": false, 42 | "navigator": false, 43 | "process": false, 44 | "Promise": true, 45 | "requestAnimationFrame": true, 46 | "requestIdleCallback": true, 47 | "require": false, 48 | "Set": true, 49 | "setImmediate": true, 50 | "setInterval": false, 51 | "setTimeout": false, 52 | "window": false, 53 | "XMLHttpRequest": false, 54 | "pit": false 55 | }, 56 | 57 | "rules": { 58 | "comma-dangle": [2, { 59 | "arrays": "ignore", 60 | "objects": "ignore", 61 | "imports": "ignore", 62 | "exports": "ignore", 63 | "functions": "never" 64 | }], 65 | 66 | "no-cond-assign": 1, 67 | "no-console": 0, 68 | "no-const-assign": 2, 69 | "no-constant-condition": 0, 70 | "no-control-regex": 1, 71 | "no-debugger": 1, 72 | "no-dupe-keys": 2, 73 | "no-empty": 0, 74 | "no-ex-assign": 1, 75 | "no-extra-boolean-cast": 1, 76 | "no-extra-parens": 0, 77 | "no-extra-semi": 1, 78 | "no-func-assign": 1, 79 | "no-inner-declarations": 0, 80 | "no-invalid-regexp": 1, 81 | "no-negated-in-lhs": 1, 82 | "no-obj-calls": 1, 83 | "no-regex-spaces": 1, 84 | "no-reserved-keys": 0, 85 | "no-sparse-arrays": 1, 86 | "no-unreachable": 2, 87 | "use-isnan": 1, 88 | "valid-jsdoc": 0, 89 | "valid-typeof": 1, 90 | 91 | "block-scoped-var": 0, 92 | "complexity": 0, 93 | "consistent-return": 0, 94 | "curly": 1, 95 | "default-case": 0, 96 | "dot-notation": 1, 97 | "eqeqeq": [1, "allow-null"], 98 | "guard-for-in": 0, 99 | "no-alert": 1, 100 | "no-caller": 1, 101 | "no-div-regex": 1, 102 | "no-else-return": 0, 103 | "no-eq-null": 0, 104 | "no-eval": 2, 105 | "no-extend-native": 1, 106 | "no-extra-bind": 1, 107 | "no-fallthrough": 1, 108 | "no-floating-decimal": 1, 109 | "no-implied-eval": 1, 110 | "no-labels": 1, 111 | "no-iterator": 1, 112 | "no-lone-blocks": 1, 113 | "no-loop-func": 0, 114 | "no-multi-str": 0, 115 | "no-native-reassign": 0, 116 | "no-new": 1, 117 | "no-new-func": 2, 118 | "no-new-wrappers": 1, 119 | "no-octal": 1, 120 | "no-octal-escape": 1, 121 | "no-proto": 1, 122 | "no-redeclare": 0, 123 | "no-return-assign": 1, 124 | "no-script-url": 1, 125 | "no-self-compare": 1, 126 | "no-sequences": 1, 127 | "no-unused-expressions": 0, 128 | "no-void": 1, 129 | "no-warning-comments": 0, 130 | "no-with": 1, 131 | "radix": 1, 132 | "semi-spacing": 1, 133 | "vars-on-top": 0, 134 | "wrap-iife": 0, 135 | "yoda": 1, 136 | 137 | "no-catch-shadow": 1, 138 | "no-delete-var": 1, 139 | "no-label-var": 1, 140 | "no-shadow": 1, 141 | "no-shadow-restricted-names": 1, 142 | "no-undef": 2, 143 | "no-undefined": 0, 144 | "no-undef-init": 1, 145 | "no-unused-vars": [1, { "vars": "all", "args": "none" }], 146 | "no-use-before-define": 0, 147 | 148 | "handle-callback-err": 1, 149 | "no-mixed-requires": 1, 150 | "no-new-require": 1, 151 | "no-path-concat": 1, 152 | "no-process-exit": 0, 153 | "no-restricted-modules": 1, 154 | "no-sync": 0, 155 | 156 | "eslint-comments/no-aggregating-enable": 1, 157 | "eslint-comments/no-unlimited-disable": 1, 158 | "eslint-comments/no-unused-disable": 1, 159 | "eslint-comments/no-unused-enable": 1, 160 | 161 | "flowtype/define-flow-type": 1, 162 | "flowtype/use-flow-type": 1, 163 | 164 | "prettier/prettier": [2, "fb", "@format"], 165 | 166 | "key-spacing": 0, 167 | "keyword-spacing": 1, 168 | "jsx-quotes": [1, "prefer-double"], 169 | "comma-spacing": 0, 170 | "no-multi-spaces": 0, 171 | "brace-style": 0, 172 | "camelcase": 0, 173 | "consistent-this": 1, 174 | "eol-last": 1, 175 | "func-names": 0, 176 | "func-style": 0, 177 | "new-cap": 0, 178 | "new-parens": 1, 179 | "no-nested-ternary": 0, 180 | "no-array-constructor": 1, 181 | "no-empty-character-class": 1, 182 | "no-lonely-if": 0, 183 | "no-new-object": 1, 184 | "no-spaced-func": 1, 185 | "no-ternary": 0, 186 | "no-trailing-spaces": 1, 187 | "no-underscore-dangle": 0, 188 | "no-mixed-spaces-and-tabs": 1, 189 | "quotes": [1, "single", "avoid-escape"], 190 | "quote-props": 0, 191 | "semi": 1, 192 | "sort-vars": 0, 193 | "space-in-brackets": 0, 194 | "space-in-parens": 0, 195 | "space-infix-ops": 1, 196 | "space-unary-ops": [1, { "words": true, "nonwords": false }], 197 | "max-nested-callbacks": 0, 198 | "one-var": 0, 199 | "wrap-regex": 0, 200 | 201 | "max-depth": 0, 202 | "max-len": 0, 203 | "max-params": 0, 204 | "max-statements": 0, 205 | "no-bitwise": 1, 206 | "no-plusplus": 0, 207 | 208 | "react/display-name": 0, 209 | "react/jsx-boolean-value": 0, 210 | "react/jsx-no-comment-textnodes": 1, 211 | "react/jsx-no-duplicate-props": 2, 212 | "react/jsx-no-undef": 2, 213 | "react/jsx-sort-props": 0, 214 | "react/jsx-uses-react": 1, 215 | "react/jsx-uses-vars": 1, 216 | "react/no-did-mount-set-state": 1, 217 | "react/no-did-update-set-state": 1, 218 | "react/no-multi-comp": 0, 219 | "react/no-string-refs": 1, 220 | "react/no-unknown-property": 0, 221 | "react/prop-types": 0, 222 | "react/react-in-jsx-scope": 1, 223 | "react/self-closing-comp": 1, 224 | "react/wrap-multilines": 0, 225 | 226 | "react-native/no-inline-styles": 1, 227 | 228 | "jest/no-disabled-tests": 1, 229 | "jest/no-focused-tests": 1, 230 | "jest/no-identical-title": 1, 231 | "jest/valid-expect": 1 232 | }, 233 | 234 | "overrides": [ 235 | { 236 | "files": [ 237 | "Libraries/**/*.js", 238 | "RNTester/**/*.js", 239 | "jest/**/*.js" 240 | ], 241 | "rules": { 242 | 243 | "comma-dangle": 0 244 | } 245 | }, 246 | { 247 | "files": [ 248 | "local-cli/**/*.js" 249 | ], 250 | "rules": { 251 | 252 | "comma-dangle": 0, 253 | "lint/extra-arrow-initializer": 0, 254 | "no-alert": 0, 255 | "no-console-disallow": 0 256 | }, 257 | "env": { 258 | "node": true 259 | } 260 | } 261 | ] 262 | } 263 | -------------------------------------------------------------------------------- /SFCC-RN-Components/.flowconfig: -------------------------------------------------------------------------------- 1 | [ignore] 2 | ; We fork some components by platform 3 | .*/*[.]android.js 4 | 5 | ; Ignore templates for 'react-native init' 6 | /node_modules/react-native/local-cli/templates/.* 7 | 8 | ; Ignore RN jest 9 | /node_modules/react-native/jest/.* 10 | 11 | ; Ignore RNTester 12 | /node_modules/react-native/RNTester/.* 13 | 14 | ; Ignore the website subdir 15 | /node_modules/react-native/website/.* 16 | 17 | ; Ignore the Dangerfile 18 | /node_modules/react-native/danger/dangerfile.js 19 | 20 | ; Ignore Fbemitter 21 | /node_modules/fbemitter/.* 22 | 23 | ; Ignore "BUCK" generated dirs 24 | /node_modules/react-native/\.buckd/ 25 | 26 | ; Ignore unexpected extra "@providesModule" 27 | .*/node_modules/.*/node_modules/fbjs/.* 28 | 29 | ; Ignore polyfills 30 | /node_modules/react-native/Libraries/polyfills/.* 31 | 32 | ; Ignore various node_modules 33 | /node_modules/react-native-gesture-handler/.* 34 | /node_modules/expo/.* 35 | /node_modules/react-navigation/.* 36 | /node_modules/xdl/.* 37 | /node_modules/reqwest/.* 38 | /node_modules/metro-bundler/.* 39 | 40 | [include] 41 | 42 | [libs] 43 | node_modules/react-native/Libraries/react-native/react-native-interface.js 44 | node_modules/react-native/flow/ 45 | node_modules/expo/flow/ 46 | 47 | [options] 48 | emoji=true 49 | 50 | module.system=haste 51 | 52 | module.file_ext=.js 53 | module.file_ext=.jsx 54 | module.file_ext=.json 55 | module.file_ext=.ios.js 56 | 57 | munge_underscores=true 58 | 59 | module.name_mapper='^[./a-zA-Z0-9$_-]+\.\(bmp\|gif\|jpg\|jpeg\|png\|psd\|svg\|webp\|m4v\|mov\|mp4\|mpeg\|mpg\|webm\|aac\|aiff\|caf\|m4a\|mp3\|wav\|html\|pdf\)$' -> 'RelativeImageStub' 60 | 61 | suppress_type=$FlowIssue 62 | suppress_type=$FlowFixMe 63 | suppress_type=$FlowFixMeProps 64 | suppress_type=$FlowFixMeState 65 | suppress_type=$FixMe 66 | 67 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixMe\\($\\|[^(]\\|(\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\) 68 | suppress_comment=\\(.\\|\n\\)*\\$FlowIssue\\((\\(>=0\\.\\(5[0-6]\\|[1-4][0-9]\\|[0-9]\\).[0-9]\\)? *\\(site=[a-z,_]*react_native_oss[a-z,_]*\\)?)\\)?:? #[0-9]+ 69 | suppress_comment=\\(.\\|\n\\)*\\$FlowFixedInNextDeploy 70 | suppress_comment=\\(.\\|\n\\)*\\$FlowExpectedError 71 | 72 | unsafe.enable_getters_and_setters=true 73 | 74 | [version] 75 | ^0.56.0 76 | -------------------------------------------------------------------------------- /SFCC-RN-Components/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/ignore-files/ for more about ignoring files. 2 | 3 | # expo 4 | .expo/ 5 | 6 | # dependencies 7 | /node_modules 8 | 9 | # misc 10 | .env.local 11 | .env.development.local 12 | .env.test.local 13 | .env.production.local 14 | 15 | npm-debug.log* 16 | yarn-debug.log* 17 | yarn-error.log* 18 | -------------------------------------------------------------------------------- /SFCC-RN-Components/.watchmanconfig: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /SFCC-RN-Components/App.js: -------------------------------------------------------------------------------- 1 | /** 2 | * Sample React Native App 3 | * https://github.com/facebook/react-native 4 | * @flow 5 | */ 6 | 7 | import configureStore from './src/configureStore'; 8 | import React, {Component} from 'react'; 9 | import {Router, Scene, ActionConst, Actions} from 'react-native-router-flux'; 10 | import {Provider, connect} from 'react-redux'; 11 | import HomeContainer from './src/components/Home/HomeContainer'; 12 | import InfoTileContainer from './src/components/SFCC/Product/InfoTile/InfoTileContainer'; 13 | import NavbarContainer from './src/components/Navbar/NavbarContainer'; 14 | import UserAccountContainer from './src/components/UserAccount/UserAccountContainer'; 15 | 16 | const RouterWithRedux = connect()(Router); 17 | const store = configureStore(); 18 | 19 | const Scenes = Actions.create( 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | ); 30 | 31 | export default class App extends Component { 32 | render() { 33 | return ( 34 | 35 | 36 | 37 | 38 | ); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /SFCC-RN-Components/App.test.js: -------------------------------------------------------------------------------- 1 | import React from 'react'; 2 | import App from './App'; 3 | 4 | import renderer from 'react-test-renderer'; 5 | 6 | it('renders without crashing', () => { 7 | const rendered = renderer.create().toJSON(); 8 | expect(rendered).toBeTruthy(); 9 | }); 10 | -------------------------------------------------------------------------------- /SFCC-RN-Components/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React Native App](https://github.com/react-community/create-react-native-app). 2 | 3 | Below you'll find information about performing common tasks. The most recent version of this guide is available [here](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/README.md). 4 | 5 | ## Table of Contents 6 | 7 | * [Updating to New Releases](#updating-to-new-releases) 8 | * [Available Scripts](#available-scripts) 9 | * [npm start](#npm-start) 10 | * [npm test](#npm-test) 11 | * [npm run ios](#npm-run-ios) 12 | * [npm run android](#npm-run-android) 13 | * [npm run eject](#npm-run-eject) 14 | * [Writing and Running Tests](#writing-and-running-tests) 15 | * [Environment Variables](#environment-variables) 16 | * [Configuring Packager IP Address](#configuring-packager-ip-address) 17 | * [Adding Flow](#adding-flow) 18 | * [Customizing App Display Name and Icon](#customizing-app-display-name-and-icon) 19 | * [Sharing and Deployment](#sharing-and-deployment) 20 | * [Publishing to Expo's React Native Community](#publishing-to-expos-react-native-community) 21 | * [Building an Expo "standalone" app](#building-an-expo-standalone-app) 22 | * [Ejecting from Create React Native App](#ejecting-from-create-react-native-app) 23 | * [Build Dependencies (Xcode & Android Studio)](#build-dependencies-xcode-android-studio) 24 | * [Should I Use ExpoKit?](#should-i-use-expokit) 25 | * [Troubleshooting](#troubleshooting) 26 | * [Networking](#networking) 27 | * [iOS Simulator won't open](#ios-simulator-wont-open) 28 | * [QR Code does not scan](#qr-code-does-not-scan) 29 | 30 | ## Updating to New Releases 31 | 32 | You should only need to update the global installation of `create-react-native-app` very rarely, ideally never. 33 | 34 | Updating the `react-native-scripts` dependency of your app should be as simple as bumping the version number in `package.json` and reinstalling your project's dependencies. 35 | 36 | Upgrading to a new version of React Native requires updating the `react-native`, `react`, and `expo` package versions, and setting the correct `sdkVersion` in `app.json`. See the [versioning guide](https://github.com/react-community/create-react-native-app/blob/master/VERSIONS.md) for up-to-date information about package version compatibility. 37 | 38 | ## Available Scripts 39 | 40 | If Yarn was installed when the project was initialized, then dependencies will have been installed via Yarn, and you should probably use it to run these commands as well. Unlike dependency installation, command running syntax is identical for Yarn and NPM at the time of this writing. 41 | 42 | ### `npm start` 43 | 44 | Runs your app in development mode. 45 | 46 | Open it in the [Expo app](https://expo.io) on your phone to view it. It will reload if you save edits to your files, and you will see build errors and logs in the terminal. 47 | 48 | Sometimes you may need to reset or clear the React Native packager's cache. To do so, you can pass the `--reset-cache` flag to the start script: 49 | 50 | ``` 51 | npm start -- --reset-cache 52 | # or 53 | yarn start -- --reset-cache 54 | ``` 55 | 56 | #### `npm test` 57 | 58 | Runs the [jest](https://github.com/facebook/jest) test runner on your tests. 59 | 60 | #### `npm run ios` 61 | 62 | Like `npm start`, but also attempts to open your app in the iOS Simulator if you're on a Mac and have it installed. 63 | 64 | #### `npm run android` 65 | 66 | Like `npm start`, but also attempts to open your app on a connected Android device or emulator. Requires an installation of Android build tools (see [React Native docs](https://facebook.github.io/react-native/docs/getting-started.html) for detailed setup). We also recommend installing Genymotion as your Android emulator. Once you've finished setting up the native build environment, there are two options for making the right copy of `adb` available to Create React Native App: 67 | 68 | ##### Using Android Studio's `adb` 69 | 70 | 1. Make sure that you can run adb from your terminal. 71 | 2. Open Genymotion and navigate to `Settings -> ADB`. Select “Use custom Android SDK tools” and update with your [Android SDK directory](https://stackoverflow.com/questions/25176594/android-sdk-location). 72 | 73 | ##### Using Genymotion's `adb` 74 | 75 | 1. Find Genymotion’s copy of adb. On macOS for example, this is normally `/Applications/Genymotion.app/Contents/MacOS/tools/`. 76 | 2. Add the Genymotion tools directory to your path (instructions for [Mac](http://osxdaily.com/2014/08/14/add-new-path-to-path-command-line/), [Linux](http://www.computerhope.com/issues/ch001647.htm), and [Windows](https://www.howtogeek.com/118594/how-to-edit-your-system-path-for-easy-command-line-access/)). 77 | 3. Make sure that you can run adb from your terminal. 78 | 79 | #### `npm run eject` 80 | 81 | This will start the process of "ejecting" from Create React Native App's build scripts. You'll be asked a couple of questions about how you'd like to build your project. 82 | 83 | **Warning:** Running eject is a permanent action (aside from whatever version control system you use). An ejected app will require you to have an [Xcode and/or Android Studio environment](https://facebook.github.io/react-native/docs/getting-started.html) set up. 84 | 85 | ## Customizing App Display Name and Icon 86 | 87 | You can edit `app.json` to include [configuration keys](https://docs.expo.io/versions/latest/guides/configuration.html) under the `expo` key. 88 | 89 | To change your app's display name, set the `expo.name` key in `app.json` to an appropriate string. 90 | 91 | To set an app icon, set the `expo.icon` key in `app.json` to be either a local path or a URL. It's recommended that you use a 512x512 png file with transparency. 92 | 93 | ## Writing and Running Tests 94 | 95 | This project is set up to use [jest](https://facebook.github.io/jest/) for tests. You can configure whatever testing strategy you like, but jest works out of the box. Create test files in directories called `__tests__` or with the `.test` extension to have the files loaded by jest. See the [the template project](https://github.com/react-community/create-react-native-app/blob/master/react-native-scripts/template/App.test.js) for an example test. The [jest documentation](https://facebook.github.io/jest/docs/en/getting-started.html) is also a wonderful resource, as is the [React Native testing tutorial](https://facebook.github.io/jest/docs/en/tutorial-react-native.html). 96 | 97 | ## Environment Variables 98 | 99 | You can configure some of Create React Native App's behavior using environment variables. 100 | 101 | ### Configuring Packager IP Address 102 | 103 | When starting your project, you'll see something like this for your project URL: 104 | 105 | ``` 106 | exp://192.168.0.2:19000 107 | ``` 108 | 109 | The "manifest" at that URL tells the Expo app how to retrieve and load your app's JavaScript bundle, so even if you load it in the app via a URL like `exp://localhost:19000`, the Expo client app will still try to retrieve your app at the IP address that the start script provides. 110 | 111 | In some cases, this is less than ideal. This might be the case if you need to run your project inside of a virtual machine and you have to access the packager via a different IP address than the one which prints by default. In order to override the IP address or hostname that is detected by Create React Native App, you can specify your own hostname via the `REACT_NATIVE_PACKAGER_HOSTNAME` environment variable: 112 | 113 | Mac and Linux: 114 | 115 | ``` 116 | REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' npm start 117 | ``` 118 | 119 | Windows: 120 | ``` 121 | set REACT_NATIVE_PACKAGER_HOSTNAME='my-custom-ip-address-or-hostname' 122 | npm start 123 | ``` 124 | 125 | The above example would cause the development server to listen on `exp://my-custom-ip-address-or-hostname:19000`. 126 | 127 | ## Adding Flow 128 | 129 | Flow is a static type checker that helps you write code with fewer bugs. Check out this [introduction to using static types in JavaScript](https://medium.com/@preethikasireddy/why-use-static-types-in-javascript-part-1-8382da1e0adb) if you are new to this concept. 130 | 131 | React Native works with [Flow](http://flowtype.org/) out of the box, as long as your Flow version matches the one used in the version of React Native. 132 | 133 | To add a local dependency to the correct Flow version to a Create React Native App project, follow these steps: 134 | 135 | 1. Find the Flow `[version]` at the bottom of the included [.flowconfig](.flowconfig) 136 | 2. Run `npm install --save-dev flow-bin@x.y.z` (or `yarn add --dev flow-bin@x.y.z`), where `x.y.z` is the .flowconfig version number. 137 | 3. Add `"flow": "flow"` to the `scripts` section of your `package.json`. 138 | 4. Add `// @flow` to any files you want to type check (for example, to `App.js`). 139 | 140 | Now you can run `npm run flow` (or `yarn flow`) to check the files for type errors. 141 | You can optionally use a [plugin for your IDE or editor](https://flow.org/en/docs/editors/) for a better integrated experience. 142 | 143 | To learn more about Flow, check out [its documentation](https://flow.org/). 144 | 145 | ## Sharing and Deployment 146 | 147 | Create React Native App does a lot of work to make app setup and development simple and straightforward, but it's very difficult to do the same for deploying to Apple's App Store or Google's Play Store without relying on a hosted service. 148 | 149 | ### Publishing to Expo's React Native Community 150 | 151 | Expo provides free hosting for the JS-only apps created by CRNA, allowing you to share your app through the Expo client app. This requires registration for an Expo account. 152 | 153 | Install the `exp` command-line tool, and run the publish command: 154 | 155 | ``` 156 | $ npm i -g exp 157 | $ exp publish 158 | ``` 159 | 160 | ### Building an Expo "standalone" app 161 | 162 | You can also use a service like [Expo's standalone builds](https://docs.expo.io/versions/latest/guides/building-standalone-apps.html) if you want to get an IPA/APK for distribution without having to build the native code yourself. 163 | 164 | ### Ejecting from Create React Native App 165 | 166 | If you want to build and deploy your app yourself, you'll need to eject from CRNA and use Xcode and Android Studio. 167 | 168 | This is usually as simple as running `npm run eject` in your project, which will walk you through the process. Make sure to install `react-native-cli` and follow the [native code getting started guide for React Native](https://facebook.github.io/react-native/docs/getting-started.html). 169 | 170 | #### Should I Use ExpoKit? 171 | 172 | If you have made use of Expo APIs while working on your project, then those API calls will stop working if you eject to a regular React Native project. If you want to continue using those APIs, you can eject to "React Native + ExpoKit" which will still allow you to build your own native code and continue using the Expo APIs. See the [ejecting guide](https://github.com/react-community/create-react-native-app/blob/master/EJECTING.md) for more details about this option. 173 | 174 | ## Troubleshooting 175 | 176 | ### Networking 177 | 178 | If you're unable to load your app on your phone due to a network timeout or a refused connection, a good first step is to verify that your phone and computer are on the same network and that they can reach each other. Create React Native App needs access to ports 19000 and 19001 so ensure that your network and firewall settings allow access from your device to your computer on both of these ports. 179 | 180 | Try opening a web browser on your phone and opening the URL that the packager script prints, replacing `exp://` with `http://`. So, for example, if underneath the QR code in your terminal you see: 181 | 182 | ``` 183 | exp://192.168.0.1:19000 184 | ``` 185 | 186 | Try opening Safari or Chrome on your phone and loading 187 | 188 | ``` 189 | http://192.168.0.1:19000 190 | ``` 191 | 192 | and 193 | 194 | ``` 195 | http://192.168.0.1:19001 196 | ``` 197 | 198 | If this works, but you're still unable to load your app by scanning the QR code, please open an issue on the [Create React Native App repository](https://github.com/react-community/create-react-native-app) with details about these steps and any other error messages you may have received. 199 | 200 | If you're not able to load the `http` URL in your phone's web browser, try using the tethering/mobile hotspot feature on your phone (beware of data usage, though), connecting your computer to that WiFi network, and restarting the packager. 201 | 202 | ### iOS Simulator won't open 203 | 204 | If you're on a Mac, there are a few errors that users sometimes see when attempting to `npm run ios`: 205 | 206 | * "non-zero exit code: 107" 207 | * "You may need to install Xcode" but it is already installed 208 | * and others 209 | 210 | There are a few steps you may want to take to troubleshoot these kinds of errors: 211 | 212 | 1. Make sure Xcode is installed and open it to accept the license agreement if it prompts you. You can install it from the Mac App Store. 213 | 2. Open Xcode's Preferences, the Locations tab, and make sure that the `Command Line Tools` menu option is set to something. Sometimes when the CLI tools are first installed by Homebrew this option is left blank, which can prevent Apple utilities from finding the simulator. Make sure to re-run `npm/yarn run ios` after doing so. 214 | 3. If that doesn't work, open the Simulator, and under the app menu select `Reset Contents and Settings...`. After that has finished, quit the Simulator, and re-run `npm/yarn run ios`. 215 | 216 | ### QR Code does not scan 217 | 218 | If you're not able to scan the QR code, make sure your phone's camera is focusing correctly, and also make sure that the contrast on the two colors in your terminal is high enough. For example, WebStorm's default themes may [not have enough contrast](https://github.com/react-community/create-react-native-app/issues/49) for terminal QR codes to be scannable with the system barcode scanners that the Expo app uses. 219 | 220 | If this causes problems for you, you may want to try changing your terminal's color theme to have more contrast, or running Create React Native App from a different terminal. You can also manually enter the URL printed by the packager script in the Expo app's search bar to load it manually. 221 | -------------------------------------------------------------------------------- /SFCC-RN-Components/app.json: -------------------------------------------------------------------------------- 1 | { 2 | "expo": { 3 | "sdkVersion": "23.0.0" 4 | } 5 | } 6 | -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/hamburger_collapsed.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/hamburger_collapsed.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/hamburger_expanded.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/hamburger_expanded.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/missing_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/missing_img.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/parchment_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/parchment_logo.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/profile_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/profile_icon.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/school.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/school.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/search_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/search_icon.png -------------------------------------------------------------------------------- /SFCC-RN-Components/assets/images/user_icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ghgofort/sfcc-react/d6272fff56f2510a802235b2b437fffc8d531647/SFCC-RN-Components/assets/images/user_icon.png -------------------------------------------------------------------------------- /SFCC-RN-Components/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "sfcc-rn-components", 3 | "version": "0.1.0", 4 | "private": true, 5 | "devDependencies": { 6 | "babel-eslint": "^8.2.2", 7 | "babel-plugin-jest-hoist": "^23.0.1", 8 | "eslint": "^4.19.1", 9 | "eslint-plugin-react": "^7.7.0", 10 | "eslint-plugin-react-native": "^3.2.1", 11 | "expect": "^22.0.3", 12 | "glob": "*", 13 | "jest-cli": "^22.4.3", 14 | "jest-environment-node": "^22.4.3", 15 | "jest-expo": "23.0.0", 16 | "react-native-scripts": "^1.11.1", 17 | "react-test-renderer": "16.0.0", 18 | "redux-mock-store": "^1.3.0", 19 | "redux-testkit": "^1.0.6" 20 | }, 21 | "main": "./node_modules/react-native-scripts/build/bin/crna-entry.js", 22 | "scripts": { 23 | "start": "react-native-scripts start", 24 | "eject": "react-native-scripts eject", 25 | "android": "react-native-scripts android", 26 | "ios": "react-native-scripts ios", 27 | "test": "node_modules/jest/bin/jest.js", 28 | "test:watch": "node node_modules/jest/bin/jest.js --watch" 29 | }, 30 | "jest": { 31 | "preset": "jest-expo", 32 | "testEnvironment": "node", 33 | "transformIgnorePatterns": [ 34 | "node_modules/(?!react-native|expo|react-navigation|native-base-shoutem-theme|@shoutem/theme|@shoutem/animation|@shoutem/ui|tcomb-form-native|mobx-react|react-native-router-flux)" 35 | ] 36 | }, 37 | "dependencies": { 38 | "babel-core": "^6.0.0", 39 | "expo": "^23.0.4", 40 | "react": "16.0.0", 41 | "react-native": "0.50.3", 42 | "react-native-router-flux": "^4.0.0-beta.28", 43 | "react-redux": "^5.0.6", 44 | "redux": "^3.7.2", 45 | "redux-logger": "^3.0.6", 46 | "redux-promise": "^0.5.3", 47 | "redux-thunk": "^2.2.0" 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/actionTypes.js: -------------------------------------------------------------------------------- 1 | /** 2 | * actionTypes.js 3 | * Define action types for non-navigation actions that need to be emitted 4 | * in order to update the state of the application. 5 | */ 6 | 7 | /******** OTHER ACTION TYPES **********/ 8 | export const SCENE_TRANSITION = 'sceneTransition'; 9 | 10 | /******** ACTION CONSTANTS FOR THE USER'S PROFILE **********/ 11 | export const UPDATE_PROFILE = 'UPDATE_PROFILE'; 12 | 13 | export const REQUEST_LOAD_PROFILE = 'REQUEST_LOAD_PROFILE'; 14 | export const RECEIVED_LOAD_PROFILE = 'RECEIVED_LOAD_PROFILE'; 15 | export const FAILED_LOAD_PROFILE = 'FAILED_LOAD_PROFILE'; 16 | 17 | export const REQUEST_SAVE_PROFILE = 'REQUEST_SAVE_PROFILE'; 18 | export const RECEIVED_SAVE_PROFILE = 'RECEIVED_SAVE_PROFILE'; 19 | export const FAILED_SAVE_PROFILE = 'FAILED_SAVE_PROFILE'; 20 | 21 | /******** ACTION CONSTANTS FOR PRODUCT REQUESTS **********/ 22 | export const REQUEST_RESOURCE_PRODUCT_BY_ID = 'REQUEST_RESOURCE_PRODUCT_BY_ID'; 23 | export const RECEIVED_RESOURCE_PRODUCT_BY_ID = 'RECEIVED_RESOURCE_PRODUCT_BY_ID'; 24 | export const FAILED_RESOURCE_PRODUCT_BY_ID = 'FAILED_RESOURCE_PRODUCT_BY_ID'; 25 | 26 | // Product Images 27 | export const REQUEST_RESOURCE_PRODUCT_IMAGES = 'REQUEST_RESOURCE_PRODUCT_IMAGES'; 28 | export const RECEIVED_RESOURCE_PRODUCT_IMAGES = 'RECEIVED_RESOURCE_PRODUCT_IMAGES'; 29 | export const FAILED_RESOURCE_PRODUCT_IMAGES = 'FAILED_RESOURCE_PRODUCT_IMAGES'; 30 | 31 | // Product Search 32 | export const REQUEST_RESOURCE_PRODUCT_SEARCH = 'REQUEST_RESOURCE_PRODUCT_SEARCH'; 33 | export const RECEIVED_RESOURCE_PRODUCT_SEARCH = 'RECEIVED_RESOURCE_PRODUCT_SEARCH'; 34 | export const FAILED_RESOURCE_PRODUCT_SEARCH = 'FAILED_RESOURCE_PRODUCT_SEARCH'; 35 | 36 | /******** ACTION CONSTANTS FOR Category REQUESTS **********/ 37 | export const REQUEST_RESOURCE_CATEGORY_BY_ID = 'REQUEST_RESOURCE_CATEGORY_BY_ID'; 38 | export const RECEIVED_RESOURCE_CATEGORY_BY_ID = 'RECEIVED_RESOURCE_CATEGORY_BY_ID'; 39 | export const FAILED_RESOURCE_CATEGORY_BY_ID = 'FAILED_RESOURCE_CATEGORY_BY_ID'; 40 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Home/Home.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file Home.jsx 3 | * @author Galen Goforth -- galengoforth@gmail.com 4 | * @desc A home page example that utilizes the SFCC React Native API and 5 | * the included set of components to show SFCC Business Manager 6 | * created content sections. 7 | */ 8 | 9 | import React, {Component} from 'react'; 10 | import { View, Text, StyleSheet, Dimensions } from 'react-native'; 11 | import {connect} from 'react-redux'; 12 | import {Actions} from 'react-native-router-flux'; 13 | import Routes from '../../menuItems'; 14 | import NavbarContainer from '../Navbar/NavbarContainer'; 15 | import InfoTileContainer from '../SFCC/Product/InfoTile/InfoTileContainer'; 16 | import InfoTile from '../SFCC/Product/InfoTile/InfoTile'; 17 | 18 | const screenSize = Dimensions.get('window'); 19 | 20 | 21 | class Home extends Component { 22 | constructor(props) { 23 | super(props); 24 | const screenSize = Dimensions.get('window'); 25 | 26 | this.state = { 27 | width: screenSize.width, 28 | height: screenSize.height, 29 | routes: Routes 30 | }; 31 | } 32 | 33 | componentWillReceiveProps(nextProps) { 34 | this.setState((prevState, nextProps) => { 35 | // Recieve props from other components. 36 | }); 37 | } 38 | 39 | render() { 40 | return ( 41 | 47 | 48 | 49 | 50 | 51 | ); 52 | } 53 | } 54 | 55 | const homeStyles = StyleSheet.create({ 56 | mainView: { 57 | flexDirection: 'column', 58 | backgroundColor: '#cccccc' 59 | } 60 | }); 61 | 62 | export default connect(({routes}) => ({routes}))(Home); 63 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Home/HomeContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * home/index.js 3 | * Container for the CollegeTools component. 4 | */ 5 | import {connect } from 'react-redux'; 6 | import { bindActionCreators } from 'redux'; 7 | import Home from './Home'; 8 | import * as actions from './actions'; 9 | import {getHome} from '../../reducers/rootReducer'; 10 | 11 | const mapStateToProps = state => { 12 | return { 13 | user: 'mario' 14 | }; 15 | }; 16 | 17 | const mapDispatchToProps = (dispatch) => { 18 | return { 19 | actions: bindActionCreators(actions, dispatch) 20 | }; 21 | }; 22 | 23 | const HomeContainer = connect(mapStateToProps, mapDispatchToProps)(Home); 24 | 25 | export default HomeContainer; 26 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Home/actions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * home/actions.js 3 | * Action creation methods for actions that occur in the Home scene of the app. 4 | */ 5 | 6 | import * as actionTypes from '../../actionTypes'; 7 | import {getLogin} from '../../reducers/rootReducer'; 8 | import {Actions} from 'react-native-router-flux'; 9 | 10 | // Action creators 11 | export const home = () => { 12 | return {type: actionTypes.SCENE_TRANSITION}; 13 | }; 14 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/ImageCarousel/ThumbnailImage.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ThumbnailImage.js 3 | * A Stateless function component that holds a thumnail image. 4 | */ 5 | 6 | import React, { Component } from 'react'; 7 | import { View, Image, TouchableHighlight, StyleSheet } from 'react-native'; 8 | import PropTypes from 'prop-types'; 9 | 10 | const ThumbnailImage = (props) => { 11 | const imgSrc = props.src ? 12 | props.src : require('../../../assets/images/missing_img.png'); 13 | const imgStyle = !props.imgStyle ? tiStyles.imgStyle : props.imgStyle; 14 | const viewStyle = !props.viewStyle ? tiStyles.viewStyle : props.viewStyle; 15 | 16 | 17 | return ( 18 | 19 | 20 | 23 | 24 | 25 | ); 26 | }; 27 | 28 | /** 29 | * Default styles if not passed in as props. 30 | */ 31 | const tiStyles = StyleSheet.create({ 32 | imgStyle: { 33 | width: 55, 34 | height: 75, 35 | alignSelf: 'stretch' 36 | }, 37 | viewStyle: { 38 | width: 65, 39 | height: 75, 40 | alignItems: 'stretch', 41 | padding: 5 42 | } 43 | }); 44 | 45 | ThumbnailImage.propTypes = { 46 | thumbnailSelected: PropTypes.func.isRequired, 47 | src: PropTypes.object, 48 | imgStyle: PropTypes.any, 49 | viewStyle: PropTypes.any 50 | }; 51 | 52 | export default ThumbnailImage = ThumbnailImage; 53 | 54 | 55 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Layout/SectionCard.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /* 4 | * SectionCard.js 5 | * A Layout component for seperation of sections within a scene. 6 | */ 7 | 8 | import React from 'react'; 9 | import { 10 | View, 11 | StyleSheet, 12 | } from 'react-native'; 13 | 14 | const SectionCard = (props) => { 15 | return ( 16 | 17 | {props.children} 18 | 19 | ); 20 | }; 21 | 22 | const styles = StyleSheet.create({ 23 | containerStyle: { 24 | padding: 5, 25 | backgroundColor: '#fff', 26 | justifyContent: 'center', 27 | position: 'relative', 28 | marginTop: 10, 29 | marginBottom: 0, 30 | margin: 10, 31 | borderRadius: 5, 32 | } 33 | }); 34 | 35 | export default SectionCard; 36 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Navbar/Navbar.js: -------------------------------------------------------------------------------- 1 | 'use strict'; 2 | 3 | /** 4 | * @file Navbar.js 5 | * @fileoverview - A Navbar component to hold the top navbar that will be included globaly 6 | * for all scenes in the app. 7 | */ 8 | 9 | import React, {Component} from 'react'; 10 | import { 11 | Easing, 12 | View, 13 | Text, 14 | StyleSheet, 15 | Image, 16 | TouchableHighlight, 17 | Dimensions, 18 | Animated 19 | } from 'react-native'; 20 | 21 | import { Actions } from 'react-native-router-flux'; 22 | import { updateProfile } from '../UserAccount/actions'; 23 | //import LeftButton from './leftbutton' 24 | import { dispatch, connect } from 'react-redux'; 25 | import { appConfig } from '../../config/appConfig'; 26 | import { navbarStyles, colors } from '../../styles/globalStyles'; 27 | 28 | /** 29 | * @class 30 | * @description - A Hamburger style menu that allows for rendering of custom 31 | * menu items as child components. 32 | */ 33 | class Navbar extends Component { 34 | constructor(props) { 35 | super(props); 36 | this.props = props; 37 | 38 | /* Class property to disable buttons when animation is taking place. */ 39 | this.isAnimating = false; 40 | 41 | const screenSize = Dimensions.get('window'); 42 | const edge = screenSize.width - (screenSize.width * appConfig.sidebar.marginRight); 43 | 44 | this.state = { 45 | animator: new Animated.Value(-1 * edge), 46 | isOpen: false, 47 | width: screenSize.width, 48 | height: screenSize.height, 49 | edge: edge, 50 | topMenuHeight: 46, 51 | toggleTime: appConfig.sidebar.toggleTime, 52 | menuItems: props.menuItems, 53 | pageTitle: props.pageTitle 54 | }; 55 | } 56 | 57 | /** 58 | * @function componentDidMount - React lifecycle method that is executed when 59 | * this component is first rendered to the dom. 60 | */ 61 | componentDidMount() { 62 | this.props.categoryActions.getCategory(); 63 | } 64 | 65 | /** 66 | * @function componentWillReceiveProps - React lifecycle method used to pass 67 | * in data from the application state. 68 | * @param {object} nextProps - The updated props object that is passed in from 69 | * the component's container. 70 | */ 71 | componentWillReceiveProps(nextProps) { 72 | this.setState((prevState, nextProps) => ({ 73 | ...prevState, 74 | menuItems: nextProps.menuItems, 75 | pateTitle: nextProps.pageTitle 76 | })); 77 | } 78 | 79 | /** 80 | * @function _toggleSidebar 81 | * Toggle the sidebar menu. 82 | */ 83 | _toggleSidebar() { 84 | if (!this.isAnimating) { 85 | this.setState((prevState, props) => ({ 86 | isOpen: !prevState.isOpen 87 | })); 88 | 89 | /* Disable the hamburger button */ 90 | this.isAnimating = true; 91 | this._animateSidebar(() => { 92 | this.forceUpdate(); 93 | }); 94 | } 95 | } 96 | 97 | /** 98 | * @function _menuItemSelect - Used to call an action creation method assigned 99 | * to handle a click action on a menu item. 100 | * @param {object} item - An action creation method to call when the 101 | * associated menu item is selcted. 102 | */ 103 | _menuItemSelect(item) { 104 | Actions[item.id].apply(); 105 | } 106 | 107 | /** 108 | * @function _animateSidebar - Animate the toggle of the sidebar menu. 109 | * @param {function callback() {}} 110 | */ 111 | _animateSidebar(callback) { 112 | /* Set the current value for the open/close animation */ 113 | const animateValue = this.state.isOpen 114 | ? 0 115 | : (-1 * this.state.edge); 116 | this.state.animator.setValue(animateValue); 117 | 118 | /* Set the value we want to animate to */ 119 | const newX = !this.state.isOpen 120 | ? 0 121 | : (-1 * this.state.edge); 122 | 123 | const animateConfig = { 124 | toValue: newX, 125 | duration: this.state.toggleTime, 126 | easing: Easing.linear 127 | }; 128 | 129 | // Animate the opening and closing of the menu, and set the state to reflect the changes. 130 | Animated.timing(this.state.animator, { 131 | ...animateConfig 132 | },).start(() => { 133 | /* Enable the hamburger button. */ 134 | this.isAnimating = false; 135 | }); 136 | } 137 | 138 | /** 139 | * @function _handleLayoutChange - Event handler method to adjust rendering of 140 | * the navbar component when the screen orientation of the host device is 141 | * changed between landscape and portrait. 142 | * @param {Event} event - The Event object that is created when the action 143 | * occurs. 144 | */ 145 | _handleLayoutChange(event) { 146 | const layout = event.nativeEvent.layout; 147 | this.setState({ 148 | height: layout.height, 149 | width: layout.width, 150 | edge: layout.width - (layout.width * appConfig.sidebar.marginRight) 151 | }); 152 | } 153 | 154 | /** 155 | * @function _getSidebarOverlay - Creates an overlay for holding all of the controls 156 | * that live in the sidebar control. 157 | * @return {React.Component} 158 | */ 159 | _getSidebarOverlay() { 160 | const menuWidth = this.state.isOpen 161 | ? this.state.edge 162 | : 0; 163 | 164 | const mySidebar = this.state.menuItems.map((item) => { 165 | if (!item.renderProps) { 166 | return ( 167 | { 169 | this._toggleSidebar(); 170 | this._menuItemSelect(item); 171 | }}> 172 | 173 | 174 | 175 | {item.title} 176 | 177 | 178 | 179 | 180 | ); 181 | } else { 182 | return item.renderProps(); 183 | } 184 | }); 185 | 186 | return ( 187 | 199 | {mySidebar} 200 | 201 | ); 202 | } 203 | 204 | /** 205 | * @function _updateProfile - Calls the action creator method to navigate to 206 | * the user profile editor. 207 | */ 208 | _updateProfile() { 209 | Actions['userAccount'].apply(); 210 | } 211 | 212 | /** 213 | * @function render - Renders the custom function when a layout change is needed. 214 | * @return {React.Component} 215 | */ 216 | render() { 217 | return ( 218 | 219 | 222 | 223 | 228 | 229 | 232 | 233 | {this.props.pageTitle} 234 | 235 | 236 | 239 | 240 | 241 | 242 | 243 | 244 | {this._getSidebarOverlay()} 245 | 246 | 252 | {this.props.children} 253 | 254 | 255 | ); 256 | } 257 | } 258 | 259 | export default connect(({routes}) => ({routes}))(Navbar); 260 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/Navbar/NavbarContainer.js: -------------------------------------------------------------------------------- 1 | /** 2 | * NavbarContainer.js 3 | * Container component for handling lifecycle events for the component lifecycle, 4 | * and connecting the component to the application state. 5 | */ 6 | import React, { Component } from 'react'; 7 | import { connect } from 'react-redux'; 8 | import { bindActionCreators } from 'redux'; 9 | import * as categoryActions from '../SFCC/Category/ProductCategoryTree/actions'; 10 | import * as actionCreators from '../UserAccount/actions'; 11 | import Navbar from './Navbar'; 12 | import MenuCategory from '../SFCC/Category/ProductCategoryTree/MenuCategory'; 13 | import { getProfile, getCategoryTree } from '../../reducers/rootReducer'; 14 | 15 | const mapDispatchToProps = (dispatch) => { 16 | return { 17 | actions: bindActionCreators(actionCreators, dispatch), 18 | categoryActions: bindActionCreators(categoryActions, dispatch) 19 | }; 20 | }; 21 | 22 | const mapStateToProps = (state) => { 23 | let menuItems = [{id: 'home', title: 'yesir'}]; 24 | const catTree = getCategoryTree(state).categories; 25 | 26 | // If categories were returned from the API call, then add these to the 27 | // menuItems array. 28 | if (catTree && catTree.length) { 29 | catTree.forEach(cat => { 30 | menuItems.push({ 31 | renderProps: () => ( 32 | 37 | ) 38 | }); 39 | }); 40 | } 41 | 42 | return { 43 | menuItems: menuItems, 44 | pageTitle: 'hello' 45 | }; 46 | }; 47 | 48 | const NavbarContainer = connect(mapStateToProps, mapDispatchToProps)(Navbar); 49 | 50 | export default NavbarContainer; 51 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/SFCC/Category/ProductCategoryTree/MenuCategory.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file MenuCategory.js 3 | */ 4 | 5 | import React, { Component } from 'react'; 6 | import { 7 | Animated, 8 | Text, 9 | View, 10 | TouchableHighlight, 11 | StyleSheet 12 | } from 'react-native'; 13 | import { navbarStyles, colors } from '../../../../styles/globalStyles'; 14 | import * as actions from './actions'; 15 | 16 | /** 17 | * Stateless functional component for rendering individual catagories in the 18 | * app hamburger menu (Navbar component). 19 | * @param {Object} props 20 | */ 21 | const MenuCategory = (props) => { 22 | const childMenuLevel = props.menuLevel + 1; 23 | const children = props.category && 24 | props.category.categories && 25 | props.category.categories.length ? 26 | props.category.categories.map((childCategory) => ( 27 | 32 | )) : 33 | [()]; 34 | 35 | 36 | this.onSelect = (ID) => { 37 | console.log(ID); 38 | /** 39 | * @todo --> Navigate to the product list page for the selected category. 40 | */ 41 | }; 42 | 43 | return ( 44 | 45 | { 46 | this.onSelect(props.category.ID); 47 | } 48 | }> 49 | 50 | 51 | {props.category.name} 52 | 53 | 54 | 55 | 56 | {children} 57 | 58 | 59 | ); 60 | }; 61 | 62 | export default MenuCategory = MenuCategory; 63 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/SFCC/Category/ProductCategoryTree/ProductCategoryTree.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ProductCategoryTree.js 3 | * @fileoverview - The ProductCategoryTree file is a React Native component used 4 | * as part of the Navbar component, but could be adopted for use in other 5 | * places in the app if needed. 6 | */ 7 | 8 | import React, { Component } from 'react'; 9 | import { View, Text, } from 'react-native'; 10 | import PropTypes from 'prop-types'; 11 | import { MenuCategory } from "./MenuCategory"; 12 | 13 | /** 14 | * @class 15 | * @description - Renders SFCC product categories as an expandable tree 16 | * type component for use in the main navigation menu. 17 | */ 18 | export default class ProductCategoryTree extends Component { 19 | constructor(props) { 20 | super(props); 21 | this.props = props; 22 | 23 | this.state = { 24 | catagories: props.catagories || [] 25 | }; 26 | }; 27 | 28 | /** 29 | * @function _renderCategory - Render a single category. 30 | */ 31 | _renderCategory() { 32 | 33 | } 34 | 35 | /** 36 | * @function _renderCategories - Renders each category in the component state 37 | * as an item in the Category tree. Loops through each top level category, 38 | * and then recursivly calls renderCategory to fill in all of the child 39 | * catagories. 40 | */ 41 | _renderCatagories() { 42 | const cats = this.state.catagories; 43 | 44 | } 45 | 46 | render() { 47 | const cats = this._renderCatagories(); 48 | 49 | return ( 50 | 51 | 52 | 53 | ); 54 | } 55 | } 56 | 57 | ProductCategoryTree.propTypes = { 58 | catagories: PropTypes.array 59 | }; 60 | 61 | 62 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/SFCC/Category/ProductCategoryTree/actions.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ProductCategoryTree/actions.js 3 | * @fileoverview Provides redux action creation methods for propogating events 4 | * that need to modify the scope at a global level. 5 | */ 6 | 7 | import ReduxThunk from 'redux-thunk'; 8 | import { Actions } from 'react-native-router-flux'; 9 | import Category from '../../../../lib/documents/Category'; 10 | import OCAPIService from '../../../../lib/OCAPIService/OCAPIService'; 11 | import { 12 | REQUEST_RESOURCE_CATEGORY_BY_ID, 13 | RECEIVED_RESOURCE_CATEGORY_BY_ID, 14 | FAILED_RESOURCE_CATEGORY_BY_ID 15 | } from '../../../../actionTypes'; 16 | 17 | /* ========================================================================== * 18 | * Synchronous Action Creators 19 | * ========================================================================== */ 20 | 21 | export const requestCategory = (categoryID, levels) => { 22 | return { 23 | type: REQUEST_RESOURCE_CATEGORY_BY_ID, 24 | categoryID: categoryID, 25 | levels: levels 26 | }; 27 | }; 28 | 29 | export const recievedCategory = (category) => { 30 | return { 31 | type: RECEIVED_RESOURCE_CATEGORY_BY_ID, 32 | category: category 33 | }; 34 | }; 35 | 36 | export const failedCategory = (categoryID, levels, error) => { 37 | return { 38 | type: FAILED_RESOURCE_CATEGORY_BY_ID, 39 | categoryID: categoryID, 40 | levels: levels, 41 | error: error 42 | }; 43 | }; 44 | 45 | /* ========================================================================== * 46 | * Async Action Creators 47 | * ========================================================================== */ 48 | 49 | /** 50 | * 51 | * @param {String|String[]} [categoryID=root] - The Category ID attribute or an array of Category IDs. 52 | * @param {number} [levels=2] - The depth of child categories to be retrieved. 53 | */ 54 | export const getCategory = (categoryID = 'root', levels = 2) => { 55 | return (dispatch) => { 56 | // Dispatch the Redux action to identify that an OCAPI request was made. 57 | dispatch(requestCategory(categoryID, levels)); 58 | const svc = new OCAPIService(); 59 | const callSetup = svc.setupCall('categories', 'get', { 60 | categoryID: categoryID, levels: levels }); 61 | 62 | if (!callSetup.error) { 63 | svc.makeCall(callSetup) 64 | .then(response => { 65 | if (response.status >= 200 && response.status < 300 && response.ok) { 66 | return response.json(); 67 | } else { 68 | return { 69 | error: true, 70 | errMsg: 'ERROR at Category/ProductCategoryTree/actions.js in ' + 71 | 'ASYNC action creator: requestCategory' 72 | } 73 | } 74 | }).then(result => { 75 | if (!result.error) { 76 | dispatch(recievedCategory(new Category(result))); 77 | } else { 78 | console.log(result.errMsg); 79 | dispatch(failedCategory(categoryID, levels, result.error)); 80 | } 81 | }, 82 | 83 | // Handle error conditions. 84 | err => dispatch(failedCategory(categoryID, levels, err)) 85 | ); 86 | 87 | } else { 88 | console.log('Call Setup Error:'); 89 | console.log(callSetup.errMsg); 90 | dispatch(failedCategory(categoryID, levels)); 91 | } 92 | }; 93 | }; 94 | -------------------------------------------------------------------------------- /SFCC-RN-Components/src/components/SFCC/Product/InfoTile/InfoTile.js: -------------------------------------------------------------------------------- 1 | /** 2 | * @file InfoTile.js 3 | * @fileoverview An InfoTile instance is a visual componenet that represnts a 4 | * product from a SFCC instance. 5 | */ 6 | 7 | import React, { Component } from "react"; 8 | import { 9 | View, 10 | Text, 11 | Button, 12 | StyleSheet, 13 | Image, 14 | Dimensions, 15 | FlatList 16 | } from "react-native"; 17 | import Routes from "../../../../menuItems"; 18 | import { connect } from "react-redux"; 19 | import ThumbnailImage from "../../../ImageCarousel/ThumbnailImage"; 20 | 21 | /** 22 | * @class 23 | * @name InfoTile 24 | * @desc - React Native component that displays basic product information from 25 | * a SFCC instance. 26 | */ 27 | class InfoTile extends Component { 28 | constructor(props) { 29 | super(props); 30 | const screenSize = Dimensions.get("window"); 31 | this.props = props; 32 | this.height = props.height ? props.height : screenSize.height - 46; 33 | this.width = props.width ? props.width : screenSize.width; 34 | this.state = { 35 | product: { 36 | id: "test", 37 | imageGroups: [ 38 | { 39 | images: [] 40 | } 41 | ] 42 | }, 43 | imgURL: "", 44 | imageIndex: 0 45 | }; 46 | } 47 | 48 | /** 49 | * Redux component lifecycle method used for passing in props to the component. 50 | * @param {Object} nextProps - The key/value pairs from the root reducer that 51 | * make up the applicaitons next state. 52 | */ 53 | componentWillReceiveProps(nextProps) { 54 | this.setState((prevState, nextProps) => ({ 55 | ...prevState, 56 | product: nextProps.infoTile.product, 57 | imgURL: nextProps.infoTile.imageURL 58 | })); 59 | } 60 | 61 | /************************************************* 62 | * Private instance functions. 63 | *************************************************/ 64 | 65 | /** 66 | * Event handler for the pressing of the button to get a product for showing. 67 | * 68 | * __NOTE:__ This is a method for application setup only and should be 69 | * removed once there are calls capable of getting product ID's 70 | * back to populate the parameters of this call in the future. 71 | */ 72 | _buttonPressed() { 73 | this.props.actions.requestImagesForProduct("1016786"); 74 | } 75 | 76 | /** 77 | * Sets the source of the main product image, or a _missing_ badge to show 78 | * that the photo that is supposed to be displayed could not be found. 79 | * @return {string|object} 80 | */ 81 | _setImageSrc() { 82 | if (this.state.imgURL && this.state.imgURL !== "") { 83 | return { uri: this.state.imgURL }; 84 | } else { 85 | return require("../../../../../assets/images/missing_img.png"); 86 | } 87 | } 88 | 89 | /** 90 | * @desc - Event handler for the touch/click of a product thumbnail image. 91 | * @param {Image} item - The Image class isntance that is bound to the 92 | * thumbnail that was selected. 93 | */ 94 | _thumbnailsSelected(item) { 95 | this.setState(prevState => ({ 96 | ...prevState, 97 | imgURL: item.disBaseLink 98 | })); 99 | } 100 | 101 | /** 102 | * @desc - Returns an array of ThumbnailImage stateless components for the current 103 | * ImageGroup images, or an empty View component if there are not any ImageGroups 104 | * in the current component state's 'product' property. 105 | * @return {ThumbnailImage[]|View} 106 | */ 107 | _getThumbnails() { 108 | const thumbs = 109 | this.state.product.imageGroups.length && 110 | this.state.product.imageGroups[this.state.imageIndex].images.length ? ( 111 | item.disBaseLink} 114 | horizontal={true} 115 | renderItem={({ item }) => ( 116 | this._thumbnailsSelected(item)} 120 | viewStyle={itStyles.productThumbView} 121 | imgStyle={itStyles.productThumbImg} 122 | /> 123 | )} 124 | /> 125 | ) : ( 126 | 127 | ); 128 | 129 | return thumbs; 130 | } 131 | 132 | render() { 133 | const srcObj = this._setImageSrc(); 134 | const thumbnails = this._getThumbnails(); 135 | 136 | return ( 137 | 146 | 147 |