ordering-ui-react-native 0.21.83 → 0.21.84

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.21.83",
3
+ "version": "0.21.84",
4
4
  "description": "Reusable components made in react native",
5
5
  "main": "src/index.tsx",
6
6
  "author": "ordering.inc",
@@ -43,6 +43,7 @@ import { NewOrderNotification } from './src/components/NewOrderNotification';
43
43
  import { DriverSchedule } from './src/components/DriverSchedule';
44
44
  import { ScheduleBlocked } from './src/components/ScheduleBlocked';
45
45
  import { OrderDetailsLogistic } from './src/components/OrderDetailsLogistic'
46
+ import { Sessions } from './src/components/Sessions';
46
47
  //OComponents
47
48
  import {
48
49
  OText,
@@ -106,6 +107,7 @@ export {
106
107
  ReviewCustomer,
107
108
  SafeAreaContainerLayout,
108
109
  SearchBar,
110
+ Sessions,
109
111
  SignupForm,
110
112
  StoresList,
111
113
  UserFormDetailsUI,
@@ -0,0 +1,187 @@
1
+ import React, { useState } from 'react'
2
+ import { View, TouchableOpacity, Platform, StyleSheet } from 'react-native'
3
+ import { useLanguage, useSession, useUtils, Sessions as SessionsController } from 'ordering-components/native'
4
+ import { SessionsParams } from '../../types'
5
+ import { OAlert } from '../../../../../src/components/shared'
6
+ import { OButton, OIcon, OText } from '../shared'
7
+ import { useTheme } from 'styled-components/native'
8
+ import { Fade, Placeholder, PlaceholderLine } from 'rn-placeholder'
9
+ import AntIcon from 'react-native-vector-icons/AntDesign'
10
+
11
+ import {
12
+ SessionsWrapper,
13
+ SessionItem,
14
+ DurationWrapper,
15
+ Container
16
+ } from './styles'
17
+
18
+ export const SessionsUI = (props: SessionsParams) => {
19
+ const {
20
+ navigation,
21
+ sessionsList,
22
+ actionState,
23
+ handleDeleteSession,
24
+ handleDeleteAllSessions
25
+ } = props
26
+
27
+ const [, t] = useLanguage()
28
+ const [{ user }] = useSession()
29
+ const [{ parseDate }] = useUtils()
30
+ const theme = useTheme()
31
+ const [confirm, setConfirm] = useState<any>({ open: false, content: null, handleOnAccept: null, id: null, title: null })
32
+ const goToBack = () => navigation?.canGoBack() && navigation.goBack()
33
+
34
+ const onDeleteSession = (session: any) => {
35
+ setConfirm({
36
+ open: true,
37
+ title: t('WEB_APPNAME', 'Ordering'),
38
+ content: [t('QUESTION_DELETE_SESSION', 'Are you sure to delete this session?')],
39
+ handleOnAccept: () => {
40
+ handleDeleteSession(session)
41
+ setConfirm({ ...confirm, open: false })
42
+ }
43
+ })
44
+ }
45
+
46
+ const onDeleteAllSessions = (isOldUser: any, deleteCurrent: any) => {
47
+ setConfirm({
48
+ open: true,
49
+ title: t('WEB_APPNAME', 'Ordering'),
50
+ content:
51
+ isOldUser
52
+ ? [t('QUESTION_ENABLE_ALL_SESSIONS', 'Are you sure to enable all sessions?')]
53
+ : deleteCurrent
54
+ ? [t('QUESTION_DELETE_ALL_SESSIONS', 'Are you sure that you want to delete all sessions?')]
55
+ : [t('QUESTION_DELETE_ALL_SESSIONS_EXCEPT_CURRENT', 'Are you sure that you want to delete all sessions except current?')],
56
+ handleOnAccept: () => {
57
+ handleDeleteAllSessions(deleteCurrent)
58
+ setConfirm({ ...confirm, open: false })
59
+ }
60
+ })
61
+ }
62
+
63
+ const styles = StyleSheet.create({
64
+ titleGroups: {
65
+ alignItems: 'center',
66
+ flexDirection: 'row',
67
+ minHeight: 33,
68
+ },
69
+ btnBackArrow: {
70
+ borderWidth: 0,
71
+ width: 32,
72
+ height: 32,
73
+ tintColor: theme.colors.textGray,
74
+ backgroundColor: theme.colors.clear,
75
+ borderColor: theme.colors.clear,
76
+ shadowColor: theme.colors.clear,
77
+ paddingLeft: 0,
78
+ paddingRight: 0,
79
+ marginTop: Platform.OS === 'ios' ? 30 : 10
80
+ },
81
+ innerPadding: {
82
+ paddingLeft: 10,
83
+ paddingRight: 10
84
+ }
85
+ });
86
+
87
+ return (
88
+ <Container
89
+ pdng={Platform.OS === 'ios' ? '10px' : '8px'}
90
+ style={styles.innerPadding}
91
+ >
92
+ <View style={styles.titleGroups}>
93
+ <TouchableOpacity onPress={() => goToBack()} style={styles.btnBackArrow}>
94
+ <OIcon src={theme.images.general.arrow_left} color={theme.colors.textGray} />
95
+ </TouchableOpacity>
96
+ </View>
97
+ <OText size={24} style={{ paddingTop: 12 }}>
98
+ {t('SESSIONS', 'Sessions')}
99
+ </OText>
100
+ {user?.session_strategy === 'jwt_session' ? (
101
+ <>
102
+ {sessionsList.loading ? (
103
+ [...Array(5).keys()].map(i => (
104
+ <SessionItem key={i}>
105
+ <Placeholder Animation={Fade}>
106
+ <View style={{ flexDirection: 'row', alignItems: 'center' }}>
107
+ <View style={{ flex: 1 }}>
108
+ <PlaceholderLine width={40} />
109
+ <PlaceholderLine width={40} />
110
+ </View>
111
+ <PlaceholderLine width={5} />
112
+ </View>
113
+ </Placeholder>
114
+ </SessionItem>
115
+ ))
116
+ ) : (
117
+ sessionsList.sessions.length > 0 ? (
118
+ <SessionsWrapper>
119
+ {sessionsList.sessions.map((session: any) => (
120
+ <SessionItem key={session.id}>
121
+ <DurationWrapper>
122
+ <OText>{parseDate(session.created_at)}</OText>
123
+ <OText>{parseDate(session.valid_thru)}</OText>
124
+ </DurationWrapper>
125
+ {session.current && (
126
+ <OText mLeft={15} style={{ flex: 1 }}>({t('CURRENT', 'Current')})</OText>
127
+ )}
128
+ <TouchableOpacity
129
+ onPress={() => onDeleteSession(session)}
130
+ >
131
+ <AntIcon name='close' size={16} color={theme.colors.red} />
132
+ </TouchableOpacity>
133
+ </SessionItem>
134
+ ))}
135
+ <OButton
136
+ text={t('DELETE_ALL_SESSIONS', 'Delete all sessions')}
137
+ isDisabled={actionState.loading}
138
+ textStyle={{ color: theme.colors.white, fontSize: 14 }}
139
+ onClick={() => onDeleteAllSessions(false, true)}
140
+ style={{ borderRadius: 7.6, marginTop: 30 }}
141
+ />
142
+ <OButton
143
+ text={t('DELETE_ALL_SESSIONS_EXCEPT_CURRENT', 'Delete all sessions except current')}
144
+ isDisabled={actionState.loading}
145
+ textStyle={{ color: theme.colors.white, fontSize: 14 }}
146
+ onClick={() => onDeleteAllSessions(false, false)}
147
+ style={{ borderRadius: 7.6, marginTop: 20 }}
148
+ />
149
+ </SessionsWrapper>
150
+ ) : (
151
+ <OText>{t('YOU_DONT_HAVE_ANY_SESSIONS', 'You don\'t have any sessions')}</OText>
152
+ )
153
+ )}
154
+ </>
155
+ ) : (
156
+ <View>
157
+ <OText>
158
+ {t('YOU_DONT_HAVE_ENABLED_THE_SESSIONS', 'You don\'t have enabled the sessions, please active them to have a better control of your sessions.')}
159
+ </OText>
160
+ <OButton
161
+ text={t('ACTIVE_SESSIONS', 'Active sessions')}
162
+ isDisabled={actionState.loading}
163
+ textStyle={{ color: theme.colors.white, fontSize: 14 }}
164
+ onClick={() => onDeleteAllSessions(true, false)}
165
+ style={{ borderRadius: 7.6, marginTop: 20 }}
166
+ />
167
+ </View>
168
+ )}
169
+ <OAlert
170
+ open={confirm.open}
171
+ title={confirm.title}
172
+ content={confirm.content}
173
+ onAccept={confirm.handleOnAccept}
174
+ onCancel={() => setConfirm({ ...confirm, open: false, title: null })}
175
+ onClose={() => setConfirm({ ...confirm, open: false, title: null })}
176
+ />
177
+ </Container>
178
+ )
179
+ }
180
+
181
+ export const Sessions = (props: SessionsParams) => {
182
+ const sessionsProps = {
183
+ ...props,
184
+ UIComponent: SessionsUI
185
+ }
186
+ return <SessionsController {...sessionsProps} />
187
+ }
@@ -0,0 +1,20 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const SessionsWrapper = styled.View`
4
+ `
5
+ export const SessionItem = styled.View`
6
+ flex-direction: row;
7
+ align-items: center;
8
+ justify-content: space-between;
9
+ padding-vertical: 15px;
10
+ border-bottom-color: ${(props: any) => props.theme.colors.lightGray};
11
+ border-bottom-width: 1px;
12
+ `
13
+ export const DurationWrapper = styled.View`
14
+ /* flex-direction: row; */
15
+ `
16
+
17
+ export const Container = styled.View`
18
+ padding-top: ${(props: any) => props.pdng};
19
+ margin-bottom: 50px;
20
+ `
@@ -47,7 +47,8 @@ const ProfileUI = (props: ProfileParams) => {
47
47
  cleanFormState,
48
48
  handleToggleAvalaibleStatusDriver,
49
49
  isAlsea,
50
- isHideDriverStatus
50
+ isHideDriverStatus,
51
+ navigation
51
52
  } = props;
52
53
 
53
54
  const [{ user, sessionLoading }] = useSession();
@@ -509,6 +510,17 @@ const ProfileUI = (props: ProfileParams) => {
509
510
  marginTop: 10
510
511
  }} />
511
512
  </Pressable>
513
+ <Pressable style={{ marginBottom: 10 }} onPress={() => navigation.navigate('Sessions')}>
514
+ <View style={{ flexDirection: 'row', justifyContent: 'space-between' }}>
515
+ <OText size={16}>{t('SESSIONS', 'Sessions')}</OText>
516
+ <AntDesignIcon size={18} name='right' />
517
+ </View>
518
+ <View style={{
519
+ borderBottomColor: theme.colors.tabBar,
520
+ borderBottomWidth: 1,
521
+ marginTop: 10
522
+ }} />
523
+ </Pressable>
512
524
  <Actions>
513
525
  <LanguageSelector />
514
526
 
@@ -629,3 +629,11 @@ export interface OrderDetailsLogisticParams {
629
629
  orderAssingId: number,
630
630
  order: any
631
631
  }
632
+
633
+ export interface SessionsParams {
634
+ navigation: any,
635
+ sessionsList: any,
636
+ actionState: any,
637
+ handleDeleteSession: any,
638
+ handleDeleteAllSessions: any
639
+ }