Skip to content

Commit

Permalink
close issue #121
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasdanillo committed Jul 17, 2021
1 parent 84b3248 commit 87e5fba
Show file tree
Hide file tree
Showing 5 changed files with 89 additions and 37 deletions.
4 changes: 2 additions & 2 deletions backend/src/controllers/ProfessionalController.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,11 @@ class ProfessionalController {

if(!user?.id) return response.status(400).json({ erro: 'Usuário não autenticado' });

const {name,email,password,crm_crp,speciality,association_code} = request.body;
const {name,nickname,email,password,crm_crp,speciality,association_code} = request.body;

const professionalService = new ProfessionalService();

await professionalService.update({name,crm_crp,speciality,email,password,association_code,id: user?.id})
await professionalService.update({name,nickname,crm_crp,speciality,email,password,association_code,id: user?.id})

return response.status(200).json({ message:"Profissional atualizado com sucesso!"});

Expand Down
8 changes: 5 additions & 3 deletions backend/src/services/ProfessionalService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,16 @@ import { UserService } from './UserService';

interface ProfessionalInterface {
name: string;
nickname?: string;
crm_crp: string;
speciality: string;
association_code?: string;
user_id: string;
}

interface UpdateClientInterface {
interface UpdateProfessionalInterface {
name?: string;
nickname?: string;
crm_crp?: string;
speciality?: string;
association_code?: string;
Expand Down Expand Up @@ -50,10 +52,10 @@ class ProfessionalService {

}

async update({ name, crm_crp, speciality, association_code, email, password, id }: UpdateClientInterface) {
async update({ name, nickname, crm_crp, speciality, association_code, email, password, id }: UpdateProfessionalInterface) {

const professional = await this.professionalRepository.findOne({ where: [{ id }], relations: ['user'] })
const professional_new_values = { name, crm_crp, speciality, association_code }
const professional_new_values = { name, nickname, crm_crp, speciality, association_code }

if (professional) {
await this.professionalRepository.save({
Expand Down
4 changes: 2 additions & 2 deletions frontend/src/components/Avatar/avatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const styles = StyleSheet.create({
height: PROFILE_PICTURE_DIMENSION,
borderRadius: PROFILE_PICTURE_DIMENSION / 2,
},
name: {
nickname: {
color: '#FCFCFF',
fontSize: 24,
fontWeight: 'bold',
Expand Down Expand Up @@ -83,7 +83,7 @@ const Avatar = (props: any) => {
</View> : <></>}
</View>
<View style={styles.textContainer}>
<Text style={styles.name}>{props.name}</Text>
<Text style={styles.nickname}>{props.nickname}</Text>
<Text style={styles.email}>{props.email}</Text>
</View >
</View >
Expand Down
103 changes: 77 additions & 26 deletions frontend/src/views/editProfile/index.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import {
View,
Text,
StyleSheet,
TouchableOpacity,
TextInput
TextInput,
ActivityIndicator
} from 'react-native';
import { Dimensions } from 'react-native';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { AxiosError, AxiosResponse } from 'axios';
import api from '../../services/api';

const SCREEN_WIDTH = Dimensions.get("window").width;
const iconColor = '#212325';
Expand All @@ -17,10 +20,40 @@ export default function EditProfile({ navigation, route }: any) {

const { user } = route.params;

const [nome, onChangeNome] = useState(user.isProfessional ? user.professional.name : user.client.name);
const [telefone, onChangeTelefone] = useState(user.isProfessional ? user.professional.phone : user.client.phone);
const [loading, setLoading] = useState(false);

//Todo usuário tem
const [name, onChangeNome] = useState(user.isProfessional ? user.professional.name : user.client.name);
const [nickname, onChangeNickname] = useState(user.isProfessional ? user.professional.nickname : user.client.nickname);
const [email, onChangeEmail] = useState(user.email);
const [endereco, onChangeEndereco] = useState("");

//Apenas cliente tem
const [telefone, onChangeTelefone] = useState(!user.isProfessional ? user.client.phone : "");

//Apenas profissional tem speciality crm_crp
const [speciality, onChangeSpeciality] = useState(user.isProfessional ? user.professional.speciality : "");
const [crm_crp, onChangeCrm_crp] = useState(user.isProfessional ? user.professional.crm_crp : "");

async function updateUserInformation() {
try {
setLoading(true);
const data = {
name: name,
nickname: nickname,
crm_crp: crm_crp,
speciality: speciality,
}
api.put('professionals', data)
.then((res: AxiosResponse) => navigation.goBack())
.catch((err: AxiosError) => console.log(err.message));

setLoading(false);
}
catch (error) {
console.log(error);
setLoading(false);
}
}

return (
<View style={styles.container}>
Expand All @@ -34,38 +67,56 @@ export default function EditProfile({ navigation, route }: any) {
<View style={styles.inputsContainer}>
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeNome}
value={nome}
placeholder='Nome'
onChangeText={onChangeEmail}
value={email}
placeholder='Email'
editable={false}
/>
</View>
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeTelefone}
value={telefone}
placeholder='Telefone'
keyboardType='numeric'
onChangeText={onChangeNome}
value={name}
placeholder='Nome'
/>
</View>
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeEmail}
value={email}
placeholder='Email'
editable={false}
onChangeText={onChangeNickname}
value={nickname}
placeholder='Apelido'
/>
</View>
{user.isProfessional ? <View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeEndereco}
value={endereco}
placeholder='Endereço'
/>
</View> : <></>}
<TouchableOpacity style={styles.buttonContainer}>
<Text style={styles.buttonText}>Salvar Alterações</Text>
{user.isProfessional ?
<View>
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeSpeciality}
value={speciality}
placeholder='Especialidade'
/>
</View>
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeCrm_crp}
value={crm_crp}
placeholder='CRM/CRP'
/>
</View>
</View>
:
<View style={styles.inputContainer}>
<TextInput style={styles.input}
onChangeText={onChangeTelefone}
value={telefone}
placeholder='Telefone'
keyboardType='numeric'
/>
</View>}
<TouchableOpacity style={styles.buttonContainer} onPress={() => updateUserInformation()} >
{loading ? <ActivityIndicator size={SCREEN_WIDTH * 0.1} color="#fad2d2" /> : <Text style={styles.buttonText}>Salvar Alterações</Text>}
</TouchableOpacity>
</View>
</View >
</View >
);
}
Expand Down
7 changes: 3 additions & 4 deletions frontend/src/views/profile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export default function Profile({ navigation }: any) {
const [loading, setLoading] = useState(true);

//Dados da tela e valores padrão]
const [user, setUser] = useState({ avatar: 3, email: 'julia_silva@mail.com', isProfessional: false, professional: { name: 'Lulu' }, client: { name: 'Lulu' } })
const [user, setUser] = useState({ avatar: 2, email: 'julia_silva@mail.com', isProfessional: true, professional: { name: 'Júlia Silva', nickname: 'Lulu', speciality: 'Psicologia', crm_crp: '123456' }, client: { name: 'Júlia Silva', nickname: 'Lulu', phone: '8632222222' } })

const toggleSwitch = () => setIsEnabled(previousState => !previousState);

Expand All @@ -42,8 +42,7 @@ export default function Profile({ navigation }: any) {
try {
setLoading(true);


const response = await api.get('users'); //Busca dados no back com o id do usuário recuperado do redux
const response = await api.get('/users'); //Busca dados no back com o id do usuário recuperado do redux
const responseUser = response.data.user;
setUser({ ...responseUser, ...{ isProfessional: (responseUser.type == 1) } });

Expand All @@ -68,7 +67,7 @@ export default function Profile({ navigation }: any) {
{
loading ? <ActivityIndicator size={80} color="#fad2d2" /> : <View style={styles.container}>
<View style={styles.avatarContainer}>
<Avatar profilePicture={user.avatar} name={user.isProfessional ? user.professional.name : user.client.name} email={user.email} isProfessional={user.isProfessional} />
<Avatar profilePicture={user.avatar} nickname={user.isProfessional ? user.professional.nickname : user.client.nickname} email={user.email} isProfessional={user.isProfessional} />
</View>
<View style={styles.settingsContainer}>
<View style={styles.accountSettingsContainer}>
Expand Down

0 comments on commit 87e5fba

Please sign in to comment.