Skip to content

Commit

Permalink
implementando as issues #120, #122 e #123
Browse files Browse the repository at this point in the history
  • Loading branch information
basilioarth committed Jul 17, 2021
1 parent 4dab3af commit 7d25977
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 5 deletions.
7 changes: 7 additions & 0 deletions frontend/src/store/reducers/user/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,11 @@ export function clearUser() {
return {
type: '@user/CLEAR_USER'
};
}

export function updateUser(user: any) {
return {
type: '@user/UPDATE_USER',
payload: { user },
};
}
7 changes: 7 additions & 0 deletions frontend/src/store/reducers/user/reducer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
const INITIAL_STATE = {
name: "",
nickname: "",
speciality: "",
crm_crp: "",
email: "",
phone: "",
type: null
Expand All @@ -18,6 +21,10 @@ const user = (state = INITIAL_STATE, action: any) => {
return {
...state, ...INITIAL_STATE
}
case `${baseAction}UPDATE_USER`:
return {
...state, ...action.payload.user
}
default:
return state;
}
Expand Down
2 changes: 1 addition & 1 deletion frontend/src/views/ClientList/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const ClientList = (props: any) => {
setLoading(true);

if(searchQuery === "") {
const response = await api.get(`professionals/clients`, {headers: {authorization: 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6IjEiLCJpYXQiOjE2MjY1MzEyNTR9.EORwoXB5Xvt77nRLhSVL5S67d_FP_n_uMROyFJaMa4A'}});
const response = await api.get(`professionals/clients`);
setClients(response.data.clients);

} else {
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/views/authentication/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ const Authentication = () => {
dispatch(setToken({ accessToken: res.data.userInformations.accessToken }));
dispatch(setUser({
name: res.data.userInformations.name,
nickname: res.data.userInformations.nickname,
speciality: res.data.userInformations.speciality,
crm_crp: res.data.userInformations.crm_crp,
email: res.data.userInformations.email,
phone: res.data.userInformations.phone,
type: res.data.userInformations.type
Expand Down
20 changes: 16 additions & 4 deletions frontend/src/views/editProfile/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import {
import { Dimensions } from 'react-native';
import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityIcons';
import { AxiosError, AxiosResponse } from 'axios';
import { useDispatch } from 'react-redux';
import { updateUser } from '../../store/actions';
import api from '../../services/api';

const SCREEN_WIDTH = Dimensions.get("window").width;
Expand All @@ -28,11 +30,13 @@ export default function EditProfile({ navigation, route }: any) {
const [email, onChangeEmail] = useState(user.email);

//Apenas cliente tem
const [telefone, onChangeTelefone] = useState(!user.isProfessional ? user.client.phone : "");
const [telefone, onChangeTelefone] = useState(!(user.type === 1) ? user.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 : "");
const [speciality, onChangeSpeciality] = useState(user.type === 1 ? user.speciality : "");
const [crm_crp, onChangeCrm_crp] = useState(user.type === 1 ? user.crm_crp : "");

const dispatch = useDispatch();

async function updateUserInformation() {
try {
Expand All @@ -44,7 +48,15 @@ export default function EditProfile({ navigation, route }: any) {
speciality: speciality,
}
api.put('professionals', data)
.then((res: AxiosResponse) => navigation.goBack())
.then((res: AxiosResponse) => {
dispatch(updateUser({
name: data.name,
nickname: data.nickname,
speciality: data.speciality,
crm_crp: data.crm_crp,
}));
navigation.goBack()
})
.catch((err: AxiosError) => console.log(err.message));

setLoading(false);
Expand Down

0 comments on commit 7d25977

Please sign in to comment.