From 64d4fe2dd9effcb5dd69cf44b6e3c4976782c573 Mon Sep 17 00:00:00 2001 From: Bu Kinoshita Date: Wed, 24 Jan 2018 21:31:45 -0200 Subject: [PATCH] signup with api --- .gitignore | 4 +++ package.json | 13 +++++++ renderer/components/settings/identity.js | 4 +-- renderer/pages/settings.js | 18 +++++++--- renderer/pages/signup.js | 46 ++++++++++++++++-------- yarn.lock | 10 ++++++ 6 files changed, 75 insertions(+), 20 deletions(-) diff --git a/.gitignore b/.gitignore index cbdf022..9e34613 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,7 @@ package-lock.json # Certificates Certificates.p12 + +## .files +.env +.env.production diff --git a/package.json b/package.json index c1c5869..5ee4879 100644 --- a/package.json +++ b/package.json @@ -33,6 +33,8 @@ "dependencies": { "app-root-path": "^2.0.1", "axios": "^0.17.1", + "babel-plugin-inline-dotenv": "^1.1.2", + "babel-plugin-transform-inline-environment-variables": "^0.2.0", "classnames": "^2.2.5", "electron-is-dev": "^0.3.0", "electron-next": "^3.1.3", @@ -82,5 +84,16 @@ "prettier --semi false --single-quote --write", "git add" ] + }, + "babel": { + "presets": ["next/babel"], + "env": { + "development": { + "plugins": ["inline-dotenv"] + }, + "production": { + "plugins": ["transform-inline-environment-variables"] + } + } } } diff --git a/renderer/components/settings/identity.js b/renderer/components/settings/identity.js index d4d37c9..47f0d16 100644 --- a/renderer/components/settings/identity.js +++ b/renderer/components/settings/identity.js @@ -50,8 +50,8 @@ const Identity = ({ username, email }) => { display: flex; flex-direction: column; justify-content: center; - height: calc(580px - 215px); - max-height: calc(580px - 215px); + height: calc(580px - 246px); + max-height: calc(580px - 246px); } .avatar { diff --git a/renderer/pages/settings.js b/renderer/pages/settings.js index 017b1a5..f5da04f 100644 --- a/renderer/pages/settings.js +++ b/renderer/pages/settings.js @@ -30,7 +30,12 @@ class Settings extends Component { this.onSelectChange = this.onSelectChange.bind(this) this.selectTab = this.selectTab.bind(this) - this.state = { defaultOption: 'Today', tabSelected: 'Identity' } + this.state = { + defaultOption: 'Today', + tabSelected: 'Identity', + email: '', + username: '' + } } componentDidMount() { @@ -39,7 +44,12 @@ class Settings extends Component { const { createOn } = user const tabSelected = tab ? tab : 'Identity' - this.setState({ defaultOption: createOn, tabSelected }) + this.setState({ + defaultOption: createOn, + tabSelected, + email: user.email, + username: user.username + }) } componentWillReceiveProps({ url: { query: { tab } } }) { @@ -82,7 +92,7 @@ class Settings extends Component { render() { let content - const { tabSelected, defaultOption } = this.state + const { tabSelected, defaultOption, username, email } = this.state const list = [ { name: 'Identity', href: '/settings?tab=Identity' }, { name: 'Account', href: '/settings?tab=Account' }, @@ -92,7 +102,7 @@ class Settings extends Component { switch (tabSelected) { case 'Identity': - content = + content = break case 'Account': diff --git a/renderer/pages/signup.js b/renderer/pages/signup.js index 17103f5..d2cc503 100644 --- a/renderer/pages/signup.js +++ b/renderer/pages/signup.js @@ -3,6 +3,7 @@ // Packages import { Component } from 'react' import Link from 'next/link' +import Router from 'next/router' // Layouts import Page from './../layouts/page' @@ -15,6 +16,8 @@ import ButtonLink from './../ui/button-link' // Services import api from './../services/api' +import { setCookie } from './../services/cookies' +import { getUser, updateUser } from './../services/local-storage' // Theme import { colors, typography } from './../theme' @@ -28,7 +31,7 @@ class Signup extends Component { this.state = { email: '', - username: '', + name: '', password: '' } } @@ -42,16 +45,31 @@ class Signup extends Component { onSignup(e) { e.preventDefault() - const { email, username, password } = this.state + const { email, name, password } = this.state api .post('/signup', { email, - username, + name, password }) .then(res => { - console.log(res) + if (res.token) { + const { email, name, username, subscription } = res.user + const { user } = getUser() + + setCookie(res.token) + + user.token = res.token + user.email = email + user.name = name + user.username = username + user.subscription = subscription + + updateUser(user) + + return Router.push('/home?tab=Today') + } }) .catch(err => { console.log(err) @@ -59,7 +77,7 @@ class Signup extends Component { } render() { - const { email, username, password } = this.state + const { email, name, password } = this.state return ( @@ -75,6 +93,15 @@ class Signup extends Component {
+ + - -