ordering-ui-react-native 0.16.2 → 0.16.3

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 CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ordering-ui-react-native",
3
- "version": "0.16.2",
3
+ "version": "0.16.3",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -1,5 +1,6 @@
1
- import React from 'react';
1
+ import React, { useEffect, useState } from 'react';
2
2
  import {
3
+ UserFormDetails as UserProfileController,
3
4
  useSession,
4
5
  useLanguage,
5
6
  } from 'ordering-components/native';
@@ -13,6 +14,7 @@ import MaterialCommunityIcons from 'react-native-vector-icons/MaterialCommunityI
13
14
  import Ionicons from 'react-native-vector-icons/Ionicons'
14
15
 
15
16
  import {
17
+ OAlert,
16
18
  OIcon,
17
19
  OText
18
20
  } from '../shared';
@@ -20,18 +22,24 @@ import {
20
22
  Container,
21
23
  Names,
22
24
  UserInfoContainer,
23
- LanguageContainer
25
+ LanguageContainer,
26
+ RemoveAccountContainer
24
27
  } from './styles';
25
28
 
26
- export const UserProfileForm = (props: ProfileParams) => {
29
+ export const UserProfileFormUI = (props: ProfileParams) => {
27
30
  const {
28
- navigation
31
+ navigation,
32
+ handleRemoveAccount,
33
+ removeAccountState
29
34
  } = props;
30
35
 
31
36
  const theme = useTheme();
32
- const [{ user }] = useSession();
37
+ const [{ user }, { logout }] = useSession();
33
38
  const [, t] = useLanguage();
34
39
 
40
+ const isAdmin = user?.level === 0
41
+ const [confirm, setConfirm] = useState<any>({ open: false, content: null, handleOnAccept: null, id: null, title: null })
42
+
35
43
  const styles = StyleSheet.create({
36
44
  linkStyle: {
37
45
  color: theme.colors.primary,
@@ -44,6 +52,9 @@ export const UserProfileForm = (props: ProfileParams) => {
44
52
  },
45
53
  iconStyle: {
46
54
  fontSize: 24
55
+ },
56
+ removeAccount: {
57
+ flexDirection: 'row'
47
58
  }
48
59
  });
49
60
 
@@ -78,13 +89,31 @@ export const UserProfileForm = (props: ProfileParams) => {
78
89
  },
79
90
  chevronUp: {
80
91
  display: 'none'
81
- }
92
+ },
82
93
  })
83
94
 
84
95
  const onRedirect = (route: string, params?: any) => {
85
96
  navigation.navigate(route, params)
86
97
  }
87
98
 
99
+ const onRemoveAccount = () => {
100
+ setConfirm({
101
+ open: true,
102
+ content: [t('QUESTION_REMOVE_ACCOUNT', 'Are you sure that you want to remove your account?')],
103
+ title: t('ACCOUNT_ALERT', 'Account alert'),
104
+ handleOnAccept: () => {
105
+ setConfirm({ ...confirm, open: false })
106
+ handleRemoveAccount && handleRemoveAccount(user?.id)
107
+ }
108
+ })
109
+ }
110
+
111
+ useEffect(() => {
112
+ if (removeAccountState?.result === 'OK') {
113
+ logout()
114
+ }
115
+ }, [removeAccountState])
116
+
88
117
  return (
89
118
  <Container>
90
119
  <View>
@@ -134,7 +163,35 @@ export const UserProfileForm = (props: ProfileParams) => {
134
163
  <LanguageSelector pickerStyle={_pickerStyle} />
135
164
  </LanguageContainer>
136
165
  <LogoutButton />
166
+ <RemoveAccountContainer>
167
+ <TouchableOpacity
168
+ disabled={isAdmin}
169
+ style={styles.removeAccount}
170
+ onPress={() => onRemoveAccount()}
171
+ activeOpacity={0.7}
172
+ >
173
+ <OIcon src={theme.images.general.user} width={20} color={theme.colors.black} style={{ marginEnd: 14 }} />
174
+ <OText size={14} weight={'400'} style={{ opacity: isAdmin ? 0.5 : 1, top: 1 }} color={theme.colors.red}>{t('REMOVE_ACCOUNT', 'Remove account')}</OText>
175
+ </TouchableOpacity>
176
+ </RemoveAccountContainer>
137
177
  </View>
178
+ <OAlert
179
+ open={confirm.open}
180
+ title={confirm.title}
181
+ content={confirm.content}
182
+ onAccept={confirm.handleOnAccept}
183
+ onCancel={() => setConfirm({ ...confirm, open: false, title: null })}
184
+ onClose={() => setConfirm({ ...confirm, open: false, title: null })}
185
+ />
138
186
  </Container>
139
187
  );
140
188
  };
189
+
190
+ export const UserProfileForm = (props: any) => {
191
+ const profileProps = {
192
+ ...props,
193
+ UIComponent: UserProfileFormUI,
194
+ useSessionUser: true
195
+ };
196
+ return <UserProfileController {...profileProps} />;
197
+ };
@@ -35,3 +35,11 @@ export const LanguageContainer = styled.View`
35
35
  align-items: center;
36
36
  margin-bottom: 10px;
37
37
  `
38
+
39
+ export const RemoveAccountContainer = styled.View`
40
+ flex-direction: row;
41
+ justify-content: flex-start;
42
+ align-items: center;
43
+ margin-bottom: 10px;
44
+ margin-top: 15px;
45
+ `
@@ -31,6 +31,8 @@ export interface ProfileParams {
31
31
  validationFields?: any;
32
32
  showField?: any;
33
33
  isRequiredField?: any;
34
+ handleRemoveAccount?: any,
35
+ removeAccountState?: any
34
36
  }
35
37
 
36
38
  export interface AddressListParams {