-
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.
Merge pull request #1 from w-arantes/feature-auth-SignIn/SignOut
Feature sign in / sign out with fixes
- Loading branch information
Showing
15 changed files
with
312 additions
and
26 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
import React from 'react'; | ||
import { useSelector } from 'react-redux'; | ||
import { Link } from 'react-router-dom'; | ||
|
||
import Notifications from '~/components/Notifications'; | ||
|
@@ -7,11 +8,13 @@ import logo from '~/assets/logo-purple.svg'; | |
import { Container, Content, Profile } from './styles'; | ||
|
||
export default function Header() { | ||
const profile = useSelector(state => state.user.profile); | ||
|
||
return ( | ||
<Container> | ||
<Content> | ||
<nav> | ||
<img src={logo} alt="Gobarber" /> | ||
<img src={logo} alt="GoBarber" /> | ||
<Link to="/dashboard">DASHBOARD</Link> | ||
</nav> | ||
|
||
|
@@ -20,11 +23,14 @@ export default function Header() { | |
|
||
<Profile> | ||
<div> | ||
<strong>Wellington Arantes</strong> | ||
<Link to="/profile">Meu Perfil</Link> | ||
<strong>{profile.name}</strong> | ||
<Link to="/profile">Meu perfil</Link> | ||
</div> | ||
<img | ||
src="https://api.adorable.io/avatars/50/[email protected]" | ||
src={ | ||
(profile.avatar && profile.avatar.url) || | ||
`https://api.adorable.io/avatars/50/[email protected]` | ||
} | ||
alt="Wellington Arantes" | ||
/> | ||
</Profile> | ||
|
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
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
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,59 @@ | ||
import React, { useState, useRef, useEffect } from 'react'; | ||
import { useField } from '@rocketseat/unform'; | ||
import api from '~/services/api'; | ||
|
||
import { Container } from './styles'; | ||
|
||
export default function AvatarInput() { | ||
const { defaultValue, registerField } = useField('avatar'); | ||
|
||
const [file, setFile] = useState(defaultValue && defaultValue.id); | ||
const [preview, setPreview] = useState(defaultValue && defaultValue.url); | ||
|
||
const ref = useRef(); | ||
|
||
useEffect(() => { | ||
if (ref.current) { | ||
registerField({ | ||
name: 'avatar_id', | ||
ref: ref.current, | ||
path: 'dataset.file', | ||
}); | ||
} | ||
}, [ref, registerField]); | ||
|
||
async function handleChange(e) { | ||
const data = new FormData(); | ||
|
||
data.append('file', e.target.files[0]); | ||
|
||
const response = await api.post('files', data); | ||
|
||
const { id, url } = response.data; | ||
|
||
setFile(id); | ||
setPreview(url); | ||
} | ||
|
||
return ( | ||
<Container> | ||
<label htmlFor="avatar"> | ||
<img | ||
src={ | ||
preview || 'https://api.adorable.io/avatars/50/[email protected]' | ||
} | ||
alt="" | ||
/> | ||
|
||
<input | ||
type="file" | ||
id="avatar" | ||
accept="image/*" | ||
data-file={file} | ||
onChange={handleChange} | ||
ref={ref} | ||
/> | ||
</label> | ||
</Container> | ||
); | ||
} |
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,26 @@ | ||
import styled from 'styled-components'; | ||
|
||
export const Container = styled.div` | ||
align-self: center; | ||
margin-bottom: 30px; | ||
label { | ||
cursor: pointer; | ||
&:hover { | ||
opacity: 0.7; | ||
} | ||
img { | ||
height: 120px; | ||
width: 120px; | ||
border-radius: 50%; | ||
border: 3px solid rgba(255, 255, 255, 0.3); | ||
background: #eee; | ||
} | ||
input { | ||
display: none; | ||
} | ||
} | ||
`; |
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 |
---|---|---|
@@ -1,7 +1,53 @@ | ||
import React from 'react'; | ||
import { useDispatch, useSelector } from 'react-redux'; | ||
import { Form, Input } from '@rocketseat/unform'; | ||
|
||
// import { Container } from './styles'; | ||
import { logOut } from '~/store/modules/auth/actions'; | ||
import { updateProfileRequest } from '~/store/modules/user/actions'; | ||
|
||
import AvatarInput from './AvatarInput'; | ||
|
||
import { Container } from './styles'; | ||
|
||
export default function Profile() { | ||
return <div />; | ||
const dispatch = useDispatch(); | ||
const profile = useSelector(state => state.user.profile); | ||
|
||
function handleSubmit(data) { | ||
dispatch(updateProfileRequest(data)); | ||
} | ||
|
||
function handlelogOut() { | ||
dispatch(logOut()); | ||
} | ||
|
||
return ( | ||
<Container> | ||
<Form initialData={profile} onSubmit={handleSubmit}> | ||
<AvatarInput name="avatar_id" /> | ||
<Input name="name" placeholder="Nome completo" /> | ||
<Input name="email" placeholder="Seu endereço de e-mail" /> | ||
|
||
<hr /> | ||
|
||
<Input | ||
type="password" | ||
name="oldPassword" | ||
placeholder="Sua senha atual" | ||
/> | ||
<Input type="password" name="password" placeholder="Nova senha" /> | ||
<Input | ||
type="password" | ||
name="confirmPassword" | ||
placeholder="Confirmação de senha" | ||
/> | ||
|
||
<button type="submit">Atualizar perfil</button> | ||
</Form> | ||
|
||
<button type="submit" onClick={handlelogOut}> | ||
Sair do GoBarber | ||
</button> | ||
</Container> | ||
); | ||
} |
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,87 @@ | ||
import styled from 'styled-components'; | ||
import { darken } from 'polished'; | ||
|
||
export const Container = styled.div` | ||
max-width: 600px; | ||
margin: 50px auto; | ||
form { | ||
display: flex; | ||
flex-direction: column; | ||
margin-top: 30px; | ||
input { | ||
background: rgba(0, 0, 0, 0.1); | ||
border: 0; | ||
border-radius: 4px; | ||
height: 44px; | ||
padding: 0 15px; | ||
color: #fff; | ||
margin: 0 0 10px; | ||
&::placeholder { | ||
color: rgba(255, 255, 255, 0.7); | ||
} | ||
} | ||
span { | ||
color: #fb6f91; | ||
align-self: flex-start; | ||
margin: 0 0 10px; | ||
font-weight: bold; | ||
} | ||
hr { | ||
border: 0; | ||
height: 1px; | ||
background: rgba(255, 255, 255, 0.2); | ||
margin: 10px 0 20px; | ||
} | ||
button { | ||
margin: 5px 0 0; | ||
height: 44px; | ||
background: #3b9eff; | ||
font-weight: bold; | ||
color: #fff; | ||
border: 0; | ||
border-radius: 4px; | ||
font-size: 16px; | ||
transition: background 0.2s; | ||
&:hover { | ||
background: ${darken(0.03, '#3b9eff')}; | ||
} | ||
} | ||
a { | ||
color: #fff; | ||
margin-top: 15px; | ||
font-size: 16px; | ||
opacity: 0.8; | ||
&:hover { | ||
opacity: 1; | ||
} | ||
} | ||
} | ||
> button { | ||
width: 100%; | ||
margin: 10px 0 0; | ||
height: 44px; | ||
background: #fb6f91; | ||
font-weight: bold; | ||
color: #fff; | ||
border: 0; | ||
border-radius: 4px; | ||
font-size: 16px; | ||
transition: background 0.2s; | ||
&:hover { | ||
background: ${darken(0.08, '#fb6f91')}; | ||
} | ||
} | ||
`; | ||
|
||
// export const Input = styled.div``; |
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
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
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
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,19 @@ | ||
export function updateProfileRequest(data) { | ||
return { | ||
type: '@user/UPDATE_PROFILE_REQUEST', | ||
payload: { data }, | ||
}; | ||
} | ||
|
||
export function updateProfileSuccess(profile) { | ||
return { | ||
type: '@user/UPDATE_PROFILE_SUCCESS', | ||
payload: { profile }, | ||
}; | ||
} | ||
|
||
export function updateProfileFailure() { | ||
return { | ||
type: '@user/UPDATE_PROFILE_FAILURE', | ||
}; | ||
} |
Oops, something went wrong.