forked from crowdbotics-apps/haileyshealthyhango-48467
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
97 lines (91 loc) · 2.94 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
import React, { useState, useEffect } from "react";
import { View, ScrollView, ActivityIndicator, Text, StyleSheet } from "react-native";
import { getUserById, slice } from "./store";
import { useSelector, useDispatch } from "react-redux";
import { styles, Color } from "./styles";
import PropTypes from "prop-types";
import { unwrapResult } from "@reduxjs/toolkit";
import { EditUser } from "./edit";
import ViewUser from "./view";
export const UserProfile = ({ route, textInputStyle = {}, buttonStyle = {}, buttonTextStyle = {}, avatarStyle = {}, editContainerStyle = {}, userInfoContainerStyle = {} }) => {
const [isEdit, setIsEdit] = useState(false);
// code below depends on the existence of any login module - update as needed.
const login = useSelector(state => {
return state?.login;
});
const userId = route?.params?.id || login?.user.id;
const user = useSelector(state => state.userProfile.users[userId]);
const api = useSelector(state => state.userProfile.api);
const dispatch = useDispatch();
useEffect(async () => {
if (userId) {
dispatch(getUserById(userId))
.then(unwrapResult)
.then(response => {
const edit = response.id === login?.user.id;
setIsEdit(edit);
})
.catch(e => console.log(e));
}
}, [userId]);
return (
<ScrollView style={styles.container} contentStyle={styles.content}>
{api.loading === "pending"
? (
<Loader color={Color.steel} />
)
: (
<View>
<View>{!user && <Text>No user to display information.</Text>}</View>
{user && (
<View>
{isEdit ? <EditUser user={user} textInputStyle={textInputStyle} buttonStyle={buttonStyle} buttonTextStyle={buttonTextStyle} avatarStyle={avatarStyle} editContainerStyle={editContainerStyle} /> : <ViewUser user={user} userInfoContainerStyle={userInfoContainerStyle} avatarStyle={avatarStyle} />}
</View>
)}
</View>
)}
</ScrollView>
);
};
UserProfile.propTypes = {
avatarStyle: PropTypes.object,
editContainerStyle: PropTypes.object,
userInfoContainerStyle: PropTypes.object,
textInputStyle: PropTypes.object,
buttonStyle: PropTypes.object,
buttonTextStyle: PropTypes.object
};
export default {
title: "userProfile",
navigator: UserProfile,
slice
};
const Loader = ({ color }) => {
return (
<View style={loaderStyles.container}>
<View style={loaderStyles.loaderContainer}>
<ActivityIndicator color={color} />
</View>
</View>
);
};
const loaderStyles = StyleSheet.create({
container: {
width: "100%",
height: "100%",
position: "absolute",
justifyContent: "center",
alignItems: "center",
zIndex: 9999
},
loaderContainer: {
width: 40,
height: 40,
borderRadius: 20,
justifyContent: "center",
alignItems: "center",
backgroundColor: "#F5F5F5",
shadowColor: "#000",
elevation: 3
}
});