-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (53 loc) · 1.66 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
import React, { useState, useEffect } from "react"
import { View, ScrollView, ActivityIndicator, Text } from "react-native"
import { getUserById, slice } from "./store"
import { useSelector, useDispatch } from "react-redux"
import { styles, Color } from "./styles"
import { unwrapResult } from "@reduxjs/toolkit"
import { EditUser } from "./edit"
import ViewUser from "./view"
export const UserProfile = ({ route }) => {
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" ? (
<View>
<ActivityIndicator color={Color.steel} />
</View>
) : (
<View>
<View>{!user && <Text>No user to display information.</Text>}</View>
{user && (
<View>
{isEdit ? <EditUser user={user} /> : <ViewUser user={user} />}
</View>
)}
</View>
)}
</ScrollView>
)
}
export default {
title: "userProfile",
navigator: UserProfile,
slice
}