@eohjsc/react-native-smart-city 0.2.95 → 0.2.96
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +2 -2
- package/src/Images/Common/member.svg +4 -0
- package/src/Images/Common/owner.svg +3 -0
- package/src/commons/ActionGroup/NumberUpDownActionTemplate.js +5 -1
- package/src/commons/ActionGroup/OptionsDropdownActionTemplate.js +5 -1
- package/src/commons/ActionGroup/__test__/OptionsDropdownTemplate.test.js +2 -2
- package/src/commons/Connecting /__test__/Connecting.test.js +23 -0
- package/src/commons/Connecting /index.js +67 -0
- package/src/commons/Connecting /styles.js +28 -0
- package/src/commons/ConnectingProcess/index.js +3 -54
- package/src/commons/MenuActionMore/index.js +8 -1
- package/src/commons/Sharing/MemberList.js +5 -10
- package/src/commons/Sharing/RowMember.js +128 -38
- package/src/commons/Sharing/__test__/MemberList.test.js +3 -3
- package/src/commons/Sharing/__test__/RowMember.test.js +4 -4
- package/src/configs/API.js +10 -0
- package/src/configs/Constants.js +10 -0
- package/src/hooks/Common/useSensorsStatus.js +33 -23
- package/src/navigations/UnitStack.js +16 -0
- package/src/screens/AddNewGateway/PlugAndPlay/ConnectWifiWarning.js +12 -3
- package/src/screens/AddNewGateway/PlugAndPlay/FirstWarning.js +5 -1
- package/src/screens/AddNewGateway/PlugAndPlay/GatewayWifiList.js +9 -1
- package/src/screens/EditActionsList/Styles/indexStyles.js +1 -0
- package/src/screens/EmergencyContacts/EmergencyContactsList.js +1 -1
- package/src/screens/EmergencyContacts/EmergencyContactsSelectContacts.js +29 -11
- package/src/screens/EmergencyContacts/__test__/EmergencyContactList.test.js +1 -0
- package/src/screens/EmergencyContacts/__test__/EmergencyContactsSelectContacts.test.js +56 -0
- package/src/screens/EnterPassword/__test__/EnterPassword.test.js +124 -0
- package/src/screens/EnterPassword/index.js +84 -0
- package/src/screens/EnterPassword/styles.js +36 -0
- package/src/screens/Sharing/Components/ItemChangeRole.js +43 -0
- package/src/screens/Sharing/Components/SensorItem.js +7 -1
- package/src/screens/Sharing/Components/Styles/ItemChangeRoleStyles.js +35 -0
- package/src/screens/Sharing/Components/__test__/ItemChangeRole.test.js +37 -0
- package/src/screens/Sharing/Components/__test__/SensorItem.test.js +53 -0
- package/src/screens/Sharing/InfoMemberUnit.js +274 -0
- package/src/screens/Sharing/MemberList.js +50 -53
- package/src/screens/Sharing/SelectPermission.js +93 -12
- package/src/screens/Sharing/Styles/inforMemberUnitStyles.js +92 -0
- package/src/screens/Sharing/__test__/InfoMemberUnit.test.js +121 -0
- package/src/screens/Sharing/__test__/MemberList.test.js +9 -24
- package/src/screens/Sharing/__test__/SelectPermission.test.js +53 -0
- package/src/screens/Sharing/hooks/index.js +76 -32
- package/src/screens/Unit/Detail.js +12 -10
- package/src/screens/Unit/ManageUnit.js +5 -5
- package/src/screens/Unit/ManageUnitStyles.js +1 -0
- package/src/utils/I18n/translations/en.json +13 -1
- package/src/utils/I18n/translations/vi.json +11 -1
- package/src/utils/Route/index.js +2 -0
- package/src/utils/Utils.js +21 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import React, { memo } from 'react';
|
|
2
|
+
import { TouchableOpacity, View } from 'react-native';
|
|
3
|
+
import Text from '../../../commons/Text';
|
|
4
|
+
import { Colors } from '../../../configs';
|
|
5
|
+
|
|
6
|
+
import styles from './Styles/ItemChangeRoleStyles';
|
|
7
|
+
import { RadioCircle } from '../../../commons';
|
|
8
|
+
|
|
9
|
+
const ItemChangeRole = ({
|
|
10
|
+
isChecked,
|
|
11
|
+
onPress,
|
|
12
|
+
wrapStyle,
|
|
13
|
+
wrapCheckBoxStyle,
|
|
14
|
+
icon,
|
|
15
|
+
title = '',
|
|
16
|
+
message = '',
|
|
17
|
+
disabled = false,
|
|
18
|
+
}) => {
|
|
19
|
+
return (
|
|
20
|
+
<TouchableOpacity
|
|
21
|
+
style={[styles.wrapBtn, disabled && styles.wrapBtnDisable, wrapStyle]}
|
|
22
|
+
onPress={onPress}
|
|
23
|
+
disabled={disabled}
|
|
24
|
+
>
|
|
25
|
+
<View style={[styles.wrapView]}>
|
|
26
|
+
<View style={styles.icon}>{icon}</View>
|
|
27
|
+
<View style={styles.textContent}>
|
|
28
|
+
<Text type="H4" semibold>
|
|
29
|
+
{title}
|
|
30
|
+
</Text>
|
|
31
|
+
<Text type="Body" color={Colors.Gray7}>
|
|
32
|
+
{message}
|
|
33
|
+
</Text>
|
|
34
|
+
</View>
|
|
35
|
+
</View>
|
|
36
|
+
<View style={styles.radioCircle}>
|
|
37
|
+
<RadioCircle active={isChecked} />
|
|
38
|
+
</View>
|
|
39
|
+
</TouchableOpacity>
|
|
40
|
+
);
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
export default memo(ItemChangeRole);
|
|
@@ -6,6 +6,7 @@ import styles from './Styles/SensorItemStyles';
|
|
|
6
6
|
import FImage from '../../../commons/FImage';
|
|
7
7
|
import { TitleCheckBox } from '.';
|
|
8
8
|
import { CheckBoxCustom } from '.';
|
|
9
|
+
import { TESTID } from '../../../configs/Constants';
|
|
9
10
|
|
|
10
11
|
const SensorItem = ({
|
|
11
12
|
item = {},
|
|
@@ -101,7 +102,12 @@ const SensorItem = ({
|
|
|
101
102
|
/>
|
|
102
103
|
<View style={styles.wrapRight}>
|
|
103
104
|
<View style={styles.viewRight}>
|
|
104
|
-
<Text
|
|
105
|
+
<Text
|
|
106
|
+
numberOfLines={1}
|
|
107
|
+
style={styles.text}
|
|
108
|
+
onPress={onPressItem}
|
|
109
|
+
testID={TESTID.TEXT_SENSOR_ITEM}
|
|
110
|
+
>
|
|
105
111
|
{name}
|
|
106
112
|
</Text>
|
|
107
113
|
{dataConfig.length > 0 ? (
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { StyleSheet } from 'react-native';
|
|
2
|
+
import { Colors } from '../../../../configs';
|
|
3
|
+
const btnStyles = {
|
|
4
|
+
flexDirection: 'row',
|
|
5
|
+
justifyContent: 'space-between',
|
|
6
|
+
paddingHorizontal: 16,
|
|
7
|
+
alignItems: 'flex-start',
|
|
8
|
+
marginBottom: 16,
|
|
9
|
+
};
|
|
10
|
+
export default StyleSheet.create({
|
|
11
|
+
wrapBtn: {
|
|
12
|
+
...btnStyles,
|
|
13
|
+
},
|
|
14
|
+
wrapView: {
|
|
15
|
+
flex: 1,
|
|
16
|
+
flexDirection: 'row',
|
|
17
|
+
},
|
|
18
|
+
icon: {
|
|
19
|
+
paddingRight: 16,
|
|
20
|
+
paddingLeft: 8,
|
|
21
|
+
},
|
|
22
|
+
textContent: {
|
|
23
|
+
flex: 1,
|
|
24
|
+
paddingTop: 4,
|
|
25
|
+
paddingRight: 32,
|
|
26
|
+
},
|
|
27
|
+
radioCircle: {
|
|
28
|
+
paddingTop: 6,
|
|
29
|
+
paddingRight: 8,
|
|
30
|
+
},
|
|
31
|
+
wrapBtnDisable: {
|
|
32
|
+
...btnStyles,
|
|
33
|
+
backgroundColor: Colors.Gray11,
|
|
34
|
+
},
|
|
35
|
+
});
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import { SCProvider } from '../../../../context';
|
|
5
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
6
|
+
import ItemChangeRole from '../ItemChangeRole';
|
|
7
|
+
import { TouchableOpacity } from 'react-native';
|
|
8
|
+
|
|
9
|
+
jest.mock('react', () => {
|
|
10
|
+
return {
|
|
11
|
+
...jest.requireActual('react'),
|
|
12
|
+
memo: (x) => x,
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
const mockOnPress = jest.fn();
|
|
17
|
+
const wrapComponent = () => (
|
|
18
|
+
<SCProvider initState={mockSCStore({})}>
|
|
19
|
+
<ItemChangeRole onPress={mockOnPress} />
|
|
20
|
+
</SCProvider>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
describe('test ItemChangeRole', () => {
|
|
24
|
+
test('test ItemChangeRole', () => {
|
|
25
|
+
let tree;
|
|
26
|
+
act(() => {
|
|
27
|
+
tree = create(wrapComponent());
|
|
28
|
+
});
|
|
29
|
+
const instance = tree.root;
|
|
30
|
+
const touchableOpacity = instance.findAllByType(TouchableOpacity);
|
|
31
|
+
expect(touchableOpacity).toHaveLength(1);
|
|
32
|
+
act(() => {
|
|
33
|
+
touchableOpacity[0].props.onPress();
|
|
34
|
+
});
|
|
35
|
+
expect(mockOnPress).toHaveBeenCalled();
|
|
36
|
+
});
|
|
37
|
+
});
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import { create, act } from 'react-test-renderer';
|
|
3
|
+
|
|
4
|
+
import { SCProvider } from '../../../../context';
|
|
5
|
+
import { mockSCStore } from '../../../../context/mockStore';
|
|
6
|
+
import SensorItem from '../SensorItem';
|
|
7
|
+
import { Text } from 'react-native';
|
|
8
|
+
import { TESTID } from '../../../../configs/Constants';
|
|
9
|
+
|
|
10
|
+
jest.mock('react', () => {
|
|
11
|
+
return {
|
|
12
|
+
...jest.requireActual('react'),
|
|
13
|
+
memo: (x) => x,
|
|
14
|
+
};
|
|
15
|
+
});
|
|
16
|
+
|
|
17
|
+
const mockOnTickedSensor = jest.fn();
|
|
18
|
+
const mockOnTickedChild = jest.fn();
|
|
19
|
+
const wrapComponent = (item) => (
|
|
20
|
+
<SCProvider initState={mockSCStore({})}>
|
|
21
|
+
<SensorItem
|
|
22
|
+
item={item}
|
|
23
|
+
onTickedChild={mockOnTickedChild}
|
|
24
|
+
onTickedSensor={mockOnTickedSensor}
|
|
25
|
+
activeItemId={item.id}
|
|
26
|
+
/>
|
|
27
|
+
</SCProvider>
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
describe('test SensorItem', () => {
|
|
31
|
+
test('test SensorItem', () => {
|
|
32
|
+
const item = {
|
|
33
|
+
id: 1,
|
|
34
|
+
name: 'abc',
|
|
35
|
+
actions: [],
|
|
36
|
+
read_configs: [],
|
|
37
|
+
icon_kit: '',
|
|
38
|
+
isChecked: true,
|
|
39
|
+
};
|
|
40
|
+
let tree;
|
|
41
|
+
act(() => {
|
|
42
|
+
tree = create(wrapComponent(item));
|
|
43
|
+
});
|
|
44
|
+
const instance = tree.root;
|
|
45
|
+
const onPressText = instance.find(
|
|
46
|
+
(el) => el.type === Text && el.props.testID === TESTID.TEXT_SENSOR_ITEM
|
|
47
|
+
);
|
|
48
|
+
expect(onPressText).toBeDefined();
|
|
49
|
+
act(() => {
|
|
50
|
+
onPressText.props.onPress();
|
|
51
|
+
});
|
|
52
|
+
});
|
|
53
|
+
});
|
|
@@ -0,0 +1,274 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, memo, useMemo } from 'react';
|
|
2
|
+
import { View, ActivityIndicator, Image, TouchableOpacity } from 'react-native';
|
|
3
|
+
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
4
|
+
import { CircleView } from '../../commons/CircleView';
|
|
5
|
+
import Text from '../../commons/Text';
|
|
6
|
+
import { shortEmailName } from '../../utils/Utils';
|
|
7
|
+
import { Colors, Images, API } from '../../configs';
|
|
8
|
+
import { HeaderCustom } from '../../commons/Header';
|
|
9
|
+
import RowMemberInfo from '../GuestInfo/components/RowGuestInfo';
|
|
10
|
+
import { useIsOwnerOfUnit } from '../../hooks/Common';
|
|
11
|
+
import { axiosGet } from '../../utils/Apis/axios';
|
|
12
|
+
import { AlertAction } from '../../commons';
|
|
13
|
+
import { useStateAlertAction, useDataMember } from './hooks';
|
|
14
|
+
import ItemChangeRole from './Components/ItemChangeRole';
|
|
15
|
+
import MemberSvg from '../../Images/Common/member.svg';
|
|
16
|
+
import OwnerSvg from '../../Images/Common/owner.svg';
|
|
17
|
+
import styles from './Styles/inforMemberUnitStyles';
|
|
18
|
+
import { useNavigation, useIsFocused } from '@react-navigation/native';
|
|
19
|
+
import Routes from '../../utils/Route';
|
|
20
|
+
import { TESTID } from '../../configs/Constants';
|
|
21
|
+
|
|
22
|
+
const InfoMemberUnit = memo(({ route }) => {
|
|
23
|
+
const t = useTranslations();
|
|
24
|
+
const { member, unit } = route.params || {
|
|
25
|
+
member: {},
|
|
26
|
+
unit: {},
|
|
27
|
+
};
|
|
28
|
+
const { navigate } = useNavigation();
|
|
29
|
+
const [isLoading, setIsLoading] = useState(true);
|
|
30
|
+
const [memberInfo, setMemberInfo] = useState({});
|
|
31
|
+
const [itemSelected, setItemSelected] = useState({});
|
|
32
|
+
const isFocused = useIsFocused();
|
|
33
|
+
const {
|
|
34
|
+
stateAlertAction,
|
|
35
|
+
hideAlertAction,
|
|
36
|
+
onPressRemoveUser,
|
|
37
|
+
onPressChangeRole,
|
|
38
|
+
} = useStateAlertAction();
|
|
39
|
+
|
|
40
|
+
const { removeMember } = useDataMember(unit?.id);
|
|
41
|
+
const { isOwner } = useIsOwnerOfUnit(unit?.user_id);
|
|
42
|
+
|
|
43
|
+
const canRemoveMember = useMemo(
|
|
44
|
+
() => isOwner && memberInfo?.id !== unit?.user_id,
|
|
45
|
+
[isOwner, memberInfo?.id, unit?.user_id]
|
|
46
|
+
);
|
|
47
|
+
|
|
48
|
+
const isIdentityOwner = useMemo(
|
|
49
|
+
() => memberInfo?.identity === 'owner',
|
|
50
|
+
[memberInfo]
|
|
51
|
+
);
|
|
52
|
+
|
|
53
|
+
const handleRemoveOrChangeRole = useCallback(() => {
|
|
54
|
+
if (stateAlertAction?.member) {
|
|
55
|
+
if (stateAlertAction?.is_change) {
|
|
56
|
+
hideAlertAction();
|
|
57
|
+
if (itemSelected?.role?.is_owner) {
|
|
58
|
+
navigate(Routes.EnterPassword, {
|
|
59
|
+
dataParams: { unit_id: unit?.id, member },
|
|
60
|
+
type: 'infoMemberUnit',
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
} else {
|
|
64
|
+
removeMember(
|
|
65
|
+
stateAlertAction?.member?.share_id,
|
|
66
|
+
stateAlertAction?.member?.name
|
|
67
|
+
);
|
|
68
|
+
hideAlertAction();
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}, [
|
|
72
|
+
hideAlertAction,
|
|
73
|
+
itemSelected?.role?.is_owner,
|
|
74
|
+
member,
|
|
75
|
+
navigate,
|
|
76
|
+
removeMember,
|
|
77
|
+
stateAlertAction?.is_change,
|
|
78
|
+
stateAlertAction?.member,
|
|
79
|
+
unit?.id,
|
|
80
|
+
]);
|
|
81
|
+
|
|
82
|
+
const fetchMemberInfo = useCallback(async () => {
|
|
83
|
+
setIsLoading(true);
|
|
84
|
+
const { success, data } = await axiosGet(
|
|
85
|
+
API.SHARE.UNIT_MEMBER_INFO(unit?.id, member?.id)
|
|
86
|
+
);
|
|
87
|
+
if (success) {
|
|
88
|
+
setIsLoading(false);
|
|
89
|
+
setMemberInfo(data);
|
|
90
|
+
}
|
|
91
|
+
}, [member?.id, unit?.id]);
|
|
92
|
+
|
|
93
|
+
const firstWordsInName = useMemo(() => {
|
|
94
|
+
const wordTemp =
|
|
95
|
+
memberInfo?.name || shortEmailName(memberInfo?.email) || '';
|
|
96
|
+
return wordTemp?.charAt();
|
|
97
|
+
}, [memberInfo?.email, memberInfo?.name]);
|
|
98
|
+
|
|
99
|
+
const itemsRoleModal = useMemo(
|
|
100
|
+
() => [
|
|
101
|
+
{
|
|
102
|
+
id: 1,
|
|
103
|
+
icon: <OwnerSvg />,
|
|
104
|
+
title: t('owner'),
|
|
105
|
+
message: t('owner_share_content'),
|
|
106
|
+
role: { is_owner: true },
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
id: 2,
|
|
110
|
+
icon: <MemberSvg />,
|
|
111
|
+
title: t('member'),
|
|
112
|
+
message: t('member_share_content'),
|
|
113
|
+
role: { is_owner: false },
|
|
114
|
+
},
|
|
115
|
+
],
|
|
116
|
+
[t]
|
|
117
|
+
);
|
|
118
|
+
|
|
119
|
+
const ChangeRoleContent = useCallback(() => {
|
|
120
|
+
const onPressRole = (item) => () => {
|
|
121
|
+
setItemSelected(item);
|
|
122
|
+
};
|
|
123
|
+
if (stateAlertAction?.is_change) {
|
|
124
|
+
return itemsRoleModal?.map((item, index) => {
|
|
125
|
+
return (
|
|
126
|
+
<ItemChangeRole
|
|
127
|
+
key={index}
|
|
128
|
+
isChecked={itemSelected?.id === item?.id}
|
|
129
|
+
icon={item?.icon}
|
|
130
|
+
onPress={onPressRole(item)}
|
|
131
|
+
title={item?.title}
|
|
132
|
+
message={item?.message}
|
|
133
|
+
/>
|
|
134
|
+
);
|
|
135
|
+
});
|
|
136
|
+
}
|
|
137
|
+
return (
|
|
138
|
+
<Text style={styles.paddingLeft16}>{stateAlertAction?.message}</Text>
|
|
139
|
+
);
|
|
140
|
+
}, [
|
|
141
|
+
itemSelected?.id,
|
|
142
|
+
itemsRoleModal,
|
|
143
|
+
stateAlertAction?.is_change,
|
|
144
|
+
stateAlertAction?.message,
|
|
145
|
+
]);
|
|
146
|
+
const handleShareDevice = useCallback(() => {
|
|
147
|
+
if (isOwner && memberInfo?.identity === 'member') {
|
|
148
|
+
return navigate(Routes.AddMemberStack, {
|
|
149
|
+
screen: Routes.SharingSelectPermission,
|
|
150
|
+
params: {
|
|
151
|
+
unit: { id: unit?.id },
|
|
152
|
+
type: 'share_device',
|
|
153
|
+
member: memberInfo,
|
|
154
|
+
},
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
return <></>;
|
|
158
|
+
}, [isOwner, navigate, unit?.id, memberInfo]);
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (isIdentityOwner) {
|
|
162
|
+
setItemSelected(itemsRoleModal[0]);
|
|
163
|
+
} else {
|
|
164
|
+
setItemSelected(itemsRoleModal[1]);
|
|
165
|
+
}
|
|
166
|
+
}, [itemsRoleModal, isIdentityOwner]);
|
|
167
|
+
|
|
168
|
+
useEffect(() => {
|
|
169
|
+
!!isFocused && fetchMemberInfo();
|
|
170
|
+
}, [fetchMemberInfo, isFocused]);
|
|
171
|
+
|
|
172
|
+
return (
|
|
173
|
+
<>
|
|
174
|
+
<View style={styles.container}>
|
|
175
|
+
<HeaderCustom title={t('member_info')} isShowSeparator />
|
|
176
|
+
{isLoading ? (
|
|
177
|
+
<ActivityIndicator
|
|
178
|
+
size="large"
|
|
179
|
+
color={Colors.Primary}
|
|
180
|
+
style={styles.loading}
|
|
181
|
+
/>
|
|
182
|
+
) : (
|
|
183
|
+
<>
|
|
184
|
+
{!!memberInfo && (
|
|
185
|
+
<View style={styles.userWrap}>
|
|
186
|
+
{memberInfo?.avatar ? (
|
|
187
|
+
<Image
|
|
188
|
+
source={{ uri: memberInfo?.avatar }}
|
|
189
|
+
style={styles.avatar}
|
|
190
|
+
/>
|
|
191
|
+
) : (
|
|
192
|
+
<CircleView size={88} backgroundColor={Colors.Cyan2} center>
|
|
193
|
+
<Text type="H2" color={Colors.White}>
|
|
194
|
+
{firstWordsInName}
|
|
195
|
+
</Text>
|
|
196
|
+
</CircleView>
|
|
197
|
+
)}
|
|
198
|
+
<Text type="H3" bold style={styles.textName}>
|
|
199
|
+
{memberInfo?.name || shortEmailName(memberInfo?.email) || ''}
|
|
200
|
+
</Text>
|
|
201
|
+
</View>
|
|
202
|
+
)}
|
|
203
|
+
{memberInfo?.id && (
|
|
204
|
+
<RowMemberInfo
|
|
205
|
+
textLeft={t('eoh_account_id')}
|
|
206
|
+
textRight={memberInfo?.phone_number || memberInfo.id}
|
|
207
|
+
/>
|
|
208
|
+
)}
|
|
209
|
+
<RowMemberInfo
|
|
210
|
+
textLeft={t('identity')}
|
|
211
|
+
textRight={t(memberInfo?.identity)}
|
|
212
|
+
/>
|
|
213
|
+
{!isIdentityOwner && (
|
|
214
|
+
<RowMemberInfo
|
|
215
|
+
textLeft={t('share_devices')}
|
|
216
|
+
textRight={memberInfo?.shared_devices}
|
|
217
|
+
onPress={handleShareDevice}
|
|
218
|
+
/>
|
|
219
|
+
)}
|
|
220
|
+
{canRemoveMember && (
|
|
221
|
+
<>
|
|
222
|
+
<TouchableOpacity
|
|
223
|
+
onPress={onPressChangeRole}
|
|
224
|
+
style={styles.role}
|
|
225
|
+
>
|
|
226
|
+
<View style={styles.leftRole}>
|
|
227
|
+
<Text type="Body" color={Colors.Gray7}>
|
|
228
|
+
{t('role')}
|
|
229
|
+
</Text>
|
|
230
|
+
<Text type="H4" semibold>
|
|
231
|
+
{t(memberInfo?.identity)}
|
|
232
|
+
</Text>
|
|
233
|
+
</View>
|
|
234
|
+
<Image source={Images.arrowBack} style={styles.arrowRight} />
|
|
235
|
+
</TouchableOpacity>
|
|
236
|
+
<TouchableOpacity
|
|
237
|
+
style={styles.removeButton}
|
|
238
|
+
onPress={() => onPressRemoveUser(member)}
|
|
239
|
+
testID={TESTID.REMOVE_MEMBER}
|
|
240
|
+
>
|
|
241
|
+
<Text
|
|
242
|
+
type={'H4'}
|
|
243
|
+
semibold
|
|
244
|
+
color={Colors.Red}
|
|
245
|
+
style={styles.removeBorderBottom}
|
|
246
|
+
>
|
|
247
|
+
{t('remove_member')}
|
|
248
|
+
</Text>
|
|
249
|
+
</TouchableOpacity>
|
|
250
|
+
</>
|
|
251
|
+
)}
|
|
252
|
+
</>
|
|
253
|
+
)}
|
|
254
|
+
</View>
|
|
255
|
+
|
|
256
|
+
<AlertAction
|
|
257
|
+
visible={stateAlertAction.visible}
|
|
258
|
+
hideModal={hideAlertAction}
|
|
259
|
+
title={stateAlertAction.title}
|
|
260
|
+
leftButtonTitle={stateAlertAction.leftButton}
|
|
261
|
+
leftButtonClick={hideAlertAction}
|
|
262
|
+
rightButtonTitle={stateAlertAction.rightButton}
|
|
263
|
+
rightButtonClick={handleRemoveOrChangeRole}
|
|
264
|
+
rightButtonStyle={
|
|
265
|
+
!stateAlertAction?.is_change && styles.removeButtonStyle
|
|
266
|
+
}
|
|
267
|
+
>
|
|
268
|
+
<ChangeRoleContent />
|
|
269
|
+
</AlertAction>
|
|
270
|
+
</>
|
|
271
|
+
);
|
|
272
|
+
});
|
|
273
|
+
|
|
274
|
+
export default InfoMemberUnit;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
import React, { useCallback } from 'react';
|
|
1
|
+
import React, { useCallback, useEffect } from 'react';
|
|
2
2
|
import { IconOutline } from '@ant-design/icons-react-native';
|
|
3
|
-
import { useNavigation } from '@react-navigation/native';
|
|
3
|
+
import { useNavigation, useIsFocused } from '@react-navigation/native';
|
|
4
4
|
import { StyleSheet, TouchableOpacity, View } from 'react-native';
|
|
5
5
|
import { useTranslations } from '../../hooks/Common/useTranslations';
|
|
6
6
|
|
|
7
7
|
import { Colors } from '../../configs';
|
|
8
8
|
import Routes from '../../utils/Route';
|
|
9
|
-
import AlertAction from '../../commons/AlertAction';
|
|
10
9
|
import SharingMembers from '../../commons/Sharing/MemberList';
|
|
11
10
|
import WrapHeaderScrollable from '../../commons/Sharing/WrapHeaderScrollable';
|
|
12
11
|
import { useIsOwnerOfUnit } from '../../hooks/Common';
|
|
12
|
+
import AlertAction from '../../commons/AlertAction';
|
|
13
13
|
|
|
14
14
|
import { useDataMember, useStateAlertAction } from './hooks';
|
|
15
15
|
import { TESTID } from '../../configs/Constants';
|
|
@@ -18,41 +18,17 @@ import { useSCContextSelector } from '../../context';
|
|
|
18
18
|
const MemberList = ({ route }) => {
|
|
19
19
|
const t = useTranslations();
|
|
20
20
|
const { navigate } = useNavigation();
|
|
21
|
+
const isFocused = useIsFocused();
|
|
21
22
|
const account = useSCContextSelector((state) => state.auth.account);
|
|
22
23
|
const { unitId, unit } = route.params;
|
|
23
|
-
const {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
isRefresh,
|
|
29
|
-
onRefresh,
|
|
30
|
-
} = useDataMember(unitId);
|
|
31
|
-
const { isOwner } = useIsOwnerOfUnit(unit.user_id);
|
|
32
|
-
const {
|
|
33
|
-
stateAlertAction,
|
|
34
|
-
hideAlertAction,
|
|
35
|
-
onPressRemoveUser,
|
|
36
|
-
stateLeaveUnit,
|
|
37
|
-
} = useStateAlertAction();
|
|
24
|
+
const { dataMembers, isRefresh, onRefresh, leaveUnit } = useDataMember(
|
|
25
|
+
unitId,
|
|
26
|
+
unit?.user_id
|
|
27
|
+
);
|
|
28
|
+
const { isOwner } = useIsOwnerOfUnit(unit?.user_id);
|
|
38
29
|
|
|
39
|
-
const
|
|
40
|
-
|
|
41
|
-
removeMember(
|
|
42
|
-
stateAlertAction.member.share_id,
|
|
43
|
-
stateAlertAction.member.name
|
|
44
|
-
);
|
|
45
|
-
} else {
|
|
46
|
-
leaveUnit(unit.name);
|
|
47
|
-
}
|
|
48
|
-
hideAlertAction();
|
|
49
|
-
}, [
|
|
50
|
-
hideAlertAction,
|
|
51
|
-
leaveUnit,
|
|
52
|
-
removeMember,
|
|
53
|
-
stateAlertAction.member,
|
|
54
|
-
unit.name,
|
|
55
|
-
]);
|
|
30
|
+
const { stateAlertSharingMenu, hideStateAlertSharingMenu, stateLeaveUnit } =
|
|
31
|
+
useStateAlertAction();
|
|
56
32
|
|
|
57
33
|
const onPressRightHeader = useCallback(() => {
|
|
58
34
|
if (isOwner) {
|
|
@@ -63,7 +39,20 @@ const MemberList = ({ route }) => {
|
|
|
63
39
|
} else {
|
|
64
40
|
stateLeaveUnit(); //change state stateAlertAction
|
|
65
41
|
}
|
|
66
|
-
}, [isOwner,
|
|
42
|
+
}, [isOwner, navigate, stateLeaveUnit, unitId]);
|
|
43
|
+
|
|
44
|
+
const handleLeave = useCallback(() => {
|
|
45
|
+
if (!isOwner) {
|
|
46
|
+
leaveUnit(unit.name);
|
|
47
|
+
}
|
|
48
|
+
hideStateAlertSharingMenu();
|
|
49
|
+
}, [hideStateAlertSharingMenu, isOwner, leaveUnit, unit.name]);
|
|
50
|
+
|
|
51
|
+
useEffect(() => {
|
|
52
|
+
if (isFocused) {
|
|
53
|
+
onRefresh();
|
|
54
|
+
}
|
|
55
|
+
}, [isFocused, onRefresh]);
|
|
67
56
|
|
|
68
57
|
const rightHeader = (
|
|
69
58
|
<TouchableOpacity
|
|
@@ -81,29 +70,31 @@ const MemberList = ({ route }) => {
|
|
|
81
70
|
return (
|
|
82
71
|
<View style={styles.container}>
|
|
83
72
|
<WrapHeaderScrollable
|
|
84
|
-
title={t('
|
|
73
|
+
title={t('unit_member')}
|
|
85
74
|
rightComponent={rightHeader}
|
|
86
75
|
loading={isRefresh}
|
|
87
76
|
onRefresh={onRefresh}
|
|
77
|
+
headerAniStyle={styles.headerAniStyle}
|
|
78
|
+
styleScrollView={{ backgroundColor: Colors.White }}
|
|
88
79
|
>
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
)}
|
|
80
|
+
<SharingMembers
|
|
81
|
+
testID={TESTID.SHARING_MEMBER}
|
|
82
|
+
dataMember={dataMembers}
|
|
83
|
+
unit={unit}
|
|
84
|
+
ownerId={unit.user_id}
|
|
85
|
+
currentUserId={account.user.id}
|
|
86
|
+
/>
|
|
97
87
|
</WrapHeaderScrollable>
|
|
98
88
|
<AlertAction
|
|
99
|
-
visible={
|
|
100
|
-
hideModal={
|
|
101
|
-
title={
|
|
102
|
-
message={
|
|
103
|
-
leftButtonTitle={
|
|
104
|
-
leftButtonClick={
|
|
105
|
-
rightButtonTitle={
|
|
106
|
-
rightButtonClick={
|
|
89
|
+
visible={stateAlertSharingMenu.visible}
|
|
90
|
+
hideModal={hideStateAlertSharingMenu}
|
|
91
|
+
title={stateAlertSharingMenu.title}
|
|
92
|
+
message={stateAlertSharingMenu.message}
|
|
93
|
+
leftButtonTitle={stateAlertSharingMenu.leftButton}
|
|
94
|
+
leftButtonClick={hideStateAlertSharingMenu}
|
|
95
|
+
rightButtonTitle={stateAlertSharingMenu.rightButton}
|
|
96
|
+
rightButtonClick={handleLeave}
|
|
97
|
+
rightButtonStyle={styles.rightButtonStyle}
|
|
107
98
|
/>
|
|
108
99
|
</View>
|
|
109
100
|
);
|
|
@@ -122,4 +113,10 @@ const styles = StyleSheet.create({
|
|
|
122
113
|
justifyContent: 'center',
|
|
123
114
|
flex: 1,
|
|
124
115
|
},
|
|
116
|
+
headerAniStyle: {
|
|
117
|
+
borderBottomWidth: 0,
|
|
118
|
+
},
|
|
119
|
+
rightButtonStyle: {
|
|
120
|
+
color: Colors.Red,
|
|
121
|
+
},
|
|
125
122
|
});
|