-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
70 changed files
with
2,342 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files. | ||
|
||
# dependencies | ||
/node_modules | ||
/.pnp | ||
.pnp.js | ||
|
||
# testing | ||
/coverage | ||
|
||
# production | ||
/build | ||
|
||
# misc | ||
.DS_Store | ||
.env.local | ||
.env.development.local | ||
.env.test.local | ||
.env.production.local | ||
|
||
npm-debug.log* | ||
yarn-debug.log* | ||
yarn-error.log* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,117 @@ | ||
# react-context-lesson | ||
We are going to replace our local state management from redux to the new context API. This repository is our application before we introduced sagas to handle our asynchronous code, which is a good starting point to make the appropriate changes! | ||
|
||
# How to fork and clone | ||
|
||
One quick note about cloning this project. If you wish to make commits and push the code up after cloning this repo, you should fork the project first. In order to own your own copy of this repository, you have to fork it so you get your own copy on your own profile! | ||
|
||
You can see the fork button in the top right corner of every GitHub project; click it and a copy of the project will be added to your GitHub profile under the same name as the original project. | ||
|
||
![alt text](https://i.ibb.co/1YN7SJ6/Screen-Shot-2019-07-01-at-2-02-40-AM.png "image to fork button") | ||
|
||
After forking the project, simply clone it the way you would from the new forked project in your own GitHub repository and you can commit and push to it freely! | ||
|
||
|
||
# After you fork and clone: | ||
|
||
## Install dependencies | ||
|
||
In your terminal after you clone your project down, remember to run either `yarn` or `npm install` to build all the dependencies in the project. | ||
|
||
## Set your firebase config | ||
|
||
Remember to replace the `config` variable in your `firebase.utils.js` with your own config object from the firebase dashboard! Navigate to the project settings and scroll down to the config code. Copy the object in the code and replace the variable in your cloned code. | ||
|
||
![alt text](https://i.ibb.co/6ywMkBf/Screen-Shot-2019-07-01-at-11-35-02-AM.png "image to firebase config") | ||
|
||
|
||
## Set your stripe publishable key | ||
|
||
Set the `publishableKey` variable in the `stripe-button.component.jsx` with your own publishable key from the stripe dashboard. | ||
|
||
![alt text](https://i.ibb.co/djQTmVF/Screen-Shot-2019-07-01-at-2-18-50-AM.png "image to publishable key") | ||
|
||
## Things to set before you deploy | ||
|
||
You will also need to connect your existing Heroku app to this new forked and cloned repo, or you have to create a new Heroku app and push to it. A quick refresher on how to do either of these: | ||
|
||
## Set to an existing Heroku app | ||
|
||
To set to an existing Heroku app you already have deployed, you need to know the name of the app you want to deploy to. To see a list of all the apps you currently have on Heroku: | ||
|
||
``` | ||
heroku apps | ||
``` | ||
|
||
Copy the name of the app you want to connect the project to, then run: | ||
|
||
``` | ||
heroku git:remote -a <PASTE_YOUR_APP_NAME_HERE> | ||
``` | ||
|
||
And now you'll have your repo connected to the heroku app under the git remote name `heroku`. | ||
|
||
Then skip to the bottom of this article to see what to do next! | ||
|
||
|
||
## To create a new Heroku app | ||
|
||
Create a new Heroku project by typing in your terminal: | ||
|
||
``` | ||
heroku create | ||
``` | ||
|
||
This will create a new Heroku project for you. Then run: | ||
|
||
``` | ||
git remote -v | ||
``` | ||
|
||
You should see heroku `https://git.heroku.com/<RANDOMLY_GENERATED_NAME_OF_YOUR_APP>` in the list. This means you have successfully connected your project to the newly created Heroku app under the git remote of `heroku`. | ||
|
||
|
||
## Deploying to Heroku | ||
|
||
Add the `mars/create-react-app-buildpack` to your heroku project by typing: | ||
|
||
``` | ||
heroku buildpacks:set mars/create-react-app-buildpack | ||
``` | ||
|
||
You can then deploy to heroku by running: | ||
|
||
``` | ||
git push heroku master | ||
``` | ||
|
||
You will see this warning message if you are pushing to an existing app: | ||
|
||
``` | ||
! [rejected] master -> master (fetch first) | ||
error: failed to push some refs to 'https://git.heroku.com/hasura-crwn-clothing.git' | ||
hint: Updates were rejected because the remote contains work that you do | ||
hint: not have locally. This is usually caused by another repository pushing | ||
hint: to the same ref. You may want to first integrate the remote changes | ||
hint: (e.g., 'git pull ...') before pushing again. | ||
hint: See the 'Note about fast-forwards' in 'git push --help' for details. | ||
``` | ||
|
||
This is because we are pushing to an existing app that was deploying an entirely different repository from what we have now. Simply run: | ||
|
||
``` | ||
git push heroku master --force | ||
``` | ||
|
||
This will overwrite the existing Heroku app with our new code. | ||
|
||
|
||
## Open our Heroku project | ||
|
||
After heroku finishes building our project, we can simply run: | ||
|
||
``` | ||
heroku open | ||
``` | ||
|
||
This will open up our browser and take us to our newly deployed Heroku project! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"name": "crwn-clothing", | ||
"version": "0.1.0", | ||
"proxy": "http://localhost:5000", | ||
"private": true, | ||
"dependencies": { | ||
"firebase": "6.0.2", | ||
"node-sass": "4.12.0", | ||
"react": "^16.8.6", | ||
"react-dom": "^16.8.6", | ||
"react-redux": "7.0.3", | ||
"react-router-dom": "5.0.0", | ||
"react-stripe-checkout": "2.6.3", | ||
"redux": "4.0.1", | ||
"redux-logger": "3.0.6", | ||
"redux-persist": "5.10.0", | ||
"reselect": "4.0.0" | ||
}, | ||
"devDependencies": { | ||
"react-scripts": "3.0.0" | ||
}, | ||
"resolutions": { | ||
"babel-jest": "24.7.1" | ||
}, | ||
"scripts": { | ||
"start": "react-scripts start", | ||
"build": "react-scripts build", | ||
"test": "react-scripts test", | ||
"eject": "react-scripts eject" | ||
}, | ||
"eslintConfig": { | ||
"extends": "react-app" | ||
}, | ||
"browserslist": { | ||
"production": [ | ||
">0.2%", | ||
"not dead", | ||
"not op_mini all" | ||
], | ||
"development": [ | ||
"last 1 chrome version", | ||
"last 1 firefox version", | ||
"last 1 safari version" | ||
] | ||
} | ||
} |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" /> | ||
<meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
<meta name="theme-color" content="#000000" /> | ||
<!-- | ||
manifest.json provides metadata used when your web app is installed on a | ||
user's mobile device or desktop. See https://developers.google.com/web/fundamentals/web-app-manifest/ | ||
--> | ||
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" /> | ||
<link | ||
href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300" | ||
rel="stylesheet" | ||
/> | ||
<!-- | ||
Notice the use of %PUBLIC_URL% in the tags above. | ||
It will be replaced with the URL of the `public` folder during the build. | ||
Only files inside the `public` folder can be referenced from the HTML. | ||
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will | ||
work correctly both with client-side routing and a non-root public URL. | ||
Learn how to configure a non-root public URL by running `npm run build`. | ||
--> | ||
<title>CRWN Clothing</title> | ||
</head> | ||
<body> | ||
<noscript>You need to enable JavaScript to run this app.</noscript> | ||
<div id="root"></div> | ||
<!-- | ||
This HTML file is a template. | ||
If you open it directly in the browser, you will see an empty page. | ||
You can add webfonts, meta tags, or analytics to this file. | ||
The build step will place the bundled scripts into the <body> tag. | ||
To begin the development, run `npm start` or `yarn start`. | ||
To create a production bundle, use `npm run build` or `yarn build`. | ||
--> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"short_name": "React App", | ||
"name": "Create React App Sample", | ||
"icons": [ | ||
{ | ||
"src": "favicon.ico", | ||
"sizes": "64x64 32x32 24x24 16x16", | ||
"type": "image/x-icon" | ||
} | ||
], | ||
"start_url": ".", | ||
"display": "standalone", | ||
"theme_color": "#000000", | ||
"background_color": "#ffffff" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
body { | ||
font-family: 'Open Sans Condensed'; | ||
padding: 20px 40px; | ||
} | ||
|
||
a { | ||
text-decoration: none; | ||
color: black; | ||
} | ||
|
||
* { | ||
box-sizing: border-box; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
import React from 'react'; | ||
import { Switch, Route, Redirect } from 'react-router-dom'; | ||
import { connect } from 'react-redux'; | ||
import { createStructuredSelector } from 'reselect'; | ||
|
||
import './App.css'; | ||
|
||
import HomePage from './pages/homepage/homepage.component'; | ||
import ShopPage from './pages/shop/shop.component'; | ||
import SignInAndSignUpPage from './pages/sign-in-and-sign-up/sign-in-and-sign-up.component'; | ||
import CheckoutPage from './pages/checkout/checkout.component'; | ||
|
||
import Header from './components/header/header.component'; | ||
|
||
import { auth, createUserProfileDocument } from './firebase/firebase.utils'; | ||
|
||
import { setCurrentUser } from './redux/user/user.actions'; | ||
import { selectCurrentUser } from './redux/user/user.selectors'; | ||
|
||
class App extends React.Component { | ||
unsubscribeFromAuth = null; | ||
|
||
componentDidMount() { | ||
const { setCurrentUser } = this.props; | ||
|
||
this.unsubscribeFromAuth = auth.onAuthStateChanged(async userAuth => { | ||
if (userAuth) { | ||
const userRef = await createUserProfileDocument(userAuth); | ||
|
||
userRef.onSnapshot(snapShot => { | ||
setCurrentUser({ | ||
id: snapShot.id, | ||
...snapShot.data() | ||
}); | ||
}); | ||
} | ||
|
||
setCurrentUser(userAuth); | ||
}); | ||
} | ||
|
||
componentWillUnmount() { | ||
this.unsubscribeFromAuth(); | ||
} | ||
|
||
render() { | ||
return ( | ||
<div> | ||
<Header /> | ||
<Switch> | ||
<Route exact path='/' component={HomePage} /> | ||
<Route path='/shop' component={ShopPage} /> | ||
<Route exact path='/checkout' component={CheckoutPage} /> | ||
<Route | ||
exact | ||
path='/signin' | ||
render={() => | ||
this.props.currentUser ? ( | ||
<Redirect to='/' /> | ||
) : ( | ||
<SignInAndSignUpPage /> | ||
) | ||
} | ||
/> | ||
</Switch> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
const mapStateToProps = createStructuredSelector({ | ||
currentUser: selectCurrentUser | ||
}); | ||
|
||
const mapDispatchToProps = dispatch => ({ | ||
setCurrentUser: user => dispatch(setCurrentUser(user)) | ||
}); | ||
|
||
export default connect( | ||
mapStateToProps, | ||
mapDispatchToProps | ||
)(App); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import React from 'react'; | ||
import ReactDOM from 'react-dom'; | ||
import App from './App'; | ||
|
||
it('renders without crashing', () => { | ||
const div = document.createElement('div'); | ||
ReactDOM.render(<App />, div); | ||
ReactDOM.unmountComponentAtNode(div); | ||
}); |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.