ordering-ui-react-native 0.17.72 → 0.17.73

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.
@@ -0,0 +1,178 @@
1
+ import React, { useEffect } from 'react'
2
+ import {
3
+ useLanguage, useUtils, RedeemGiftCard as RedeemGiftCardController
4
+ } from 'ordering-components/native'
5
+ import { useForm, Controller } from 'react-hook-form'
6
+ import { StyleSheet, View, Alert } from 'react-native';
7
+ import { useTheme } from 'styled-components/native';
8
+ import { OText, OButton, OInput } from '../../shared';
9
+
10
+ import {
11
+ Container,
12
+ FormController
13
+ } from './styles'
14
+
15
+ const RedeemGiftCardUI = (props: any) => {
16
+ const {
17
+ actionState,
18
+ redeemedGiftCard,
19
+ handleApply,
20
+ onClose,
21
+ setRedeemedGiftCard
22
+ } = props
23
+
24
+ const theme = useTheme()
25
+ const [, t] = useLanguage()
26
+ const { handleSubmit, control, errors } = useForm()
27
+ const [{ parsePrice }] = useUtils()
28
+
29
+ const style = StyleSheet.create({
30
+ btnStyle: {
31
+ borderRadius: 7.6,
32
+ height: 44,
33
+ marginTop: 20
34
+ },
35
+ inputStyle: {
36
+ borderWidth: 1,
37
+ borderColor: theme.colors.border,
38
+ borderRadius: 7.6,
39
+ },
40
+ })
41
+
42
+ const onSubmit = (values) => {
43
+ handleApply(values)
44
+ }
45
+
46
+ useEffect(() => {
47
+ if (Object.keys(errors).length > 0) {
48
+ const list = Object.values(errors)
49
+ let stringError = ''
50
+ list.map((item: any, i: number) => {
51
+ stringError += (i + 1) === list.length ? `- ${item.message}` : `- ${item.message}\n`
52
+ })
53
+ Alert.alert(
54
+ t('ERROR', 'Error'),
55
+ stringError,
56
+ [
57
+ { text: t('OK', 'oK'), onPress: () => {} }
58
+ ]
59
+ )
60
+ }
61
+ }, [errors])
62
+
63
+ useEffect(() => {
64
+ if (!actionState.error) return
65
+ let stringError = ''
66
+ if (typeof actionState.error === 'string') {
67
+ stringError = actionState.error
68
+ } else {
69
+ actionState.error.map(item => {
70
+ stringError += `- ${item}\n`
71
+ })
72
+ }
73
+ Alert.alert(
74
+ t('ERROR', 'Error'),
75
+ stringError,
76
+ [
77
+ { text: t('OK', 'oK'), onPress: () => {} }
78
+ ]
79
+ )
80
+ }, [actionState.error])
81
+
82
+ return (
83
+ <Container>
84
+ {!redeemedGiftCard ? (
85
+ <View>
86
+ <OText color={theme.colors.textNormal} weight='bold' size={20} mBottom={40}>{t('REDEEM_GIFT_CARD', 'Redeem a gift card')}</OText>
87
+ <FormController>
88
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('GIFT_CARD_CODE', 'Gift card code')}</OText>
89
+ <Controller
90
+ control={control}
91
+ render={({ onChange, value }: any) => (
92
+ <OInput
93
+ placeholder='0000 0000'
94
+ value={value}
95
+ onChange={(val: any) => onChange(val)}
96
+ autoCapitalize='none'
97
+ autoCorrect={false}
98
+ blurOnSubmit={false}
99
+ style={style.inputStyle}
100
+ />
101
+ )}
102
+ name='code'
103
+ rules={{
104
+ required: t('VALIDATION_ERROR_REQUIRED', 'Code is required').replace('_attribute_', t('CODE', 'Code'))
105
+ }}
106
+ defaultValue=""
107
+ />
108
+ </FormController>
109
+ <FormController>
110
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('PASSWORD', 'Password')}</OText>
111
+ <Controller
112
+ control={control}
113
+ render={({ onChange, value }: any) => (
114
+ <OInput
115
+ isSecured
116
+ placeholder={t('PASSWORD', 'Password')}
117
+ value={value}
118
+ onChange={(val: any) => onChange(val)}
119
+ autoCapitalize='none'
120
+ autoCompleteType='password'
121
+ autoCorrect={false}
122
+ blurOnSubmit={false}
123
+ style={style.inputStyle}
124
+ />
125
+ )}
126
+ name='password'
127
+ rules={{
128
+ required: t('VALIDATION_ERROR_REQUIRED', 'Password is required').replace('_attribute_', t('PASSWORD', 'Password'))
129
+ }}
130
+ defaultValue=""
131
+ />
132
+ </FormController>
133
+ <OButton
134
+ onClick={handleSubmit(onSubmit)}
135
+ text={actionState?.loading ? t('LOADING', 'Loading') : t('APPLY_TO_YOUR_BALANCE', 'Apply to your balance')}
136
+ bgColor={theme.colors.primary}
137
+ borderColor={theme.colors.primary}
138
+ textStyle={{ color: 'white', fontSize: 13 }}
139
+ imgRightSrc={null}
140
+ style={style.btnStyle}
141
+ isDisabled={actionState.loading}
142
+ />
143
+ </View>
144
+ ) : (
145
+ <>
146
+ <OText color={theme.colors.textNormal} weight='bold' size={20} mBottom={40}>{t('GIFT_CARD', 'Gift card')}</OText>
147
+ <View>
148
+ <OText color={theme.colors.textNormal} size={14} mBottom={6}>{t('TYPE', 'Type')}: {redeemedGiftCard?.type}</OText>
149
+ <OText color={theme.colors.textNormal} size={14} mBottom={6}>{t('AMOUNT', 'Amount')}: {parsePrice(redeemedGiftCard?.amount)}</OText>
150
+ <OText color={theme.colors.textNormal} size={14} mBottom={6}>{t('FROM', 'From')}: {redeemedGiftCard?.receiver?.name} {redeemedGiftCard?.receiver?.lastname}</OText>
151
+ <OText color={theme.colors.textNormal} size={14} mBottom={6}>{t('TITLE', 'Title')}: {redeemedGiftCard?.title}</OText>
152
+ <OText color={theme.colors.textNormal} size={14} mBottom={6}>{t('MESSAGES', 'Messages')}: {redeemedGiftCard?.message}</OText>
153
+ <OButton
154
+ onClick={() => {
155
+ setRedeemedGiftCard(null)
156
+ onClose()
157
+ }}
158
+ text={t('OK', 'Ok')}
159
+ bgColor={theme.colors.primary}
160
+ borderColor={theme.colors.primary}
161
+ textStyle={{ color: 'white', fontSize: 13 }}
162
+ imgRightSrc={null}
163
+ style={style.btnStyle}
164
+ />
165
+ </View>
166
+ </>
167
+ )}
168
+ </Container>
169
+ )
170
+ }
171
+
172
+ export const RedeemGiftCard = (props: any) => {
173
+ const redeemGiftCardProps = {
174
+ ...props,
175
+ UIComponent: RedeemGiftCardUI
176
+ }
177
+ return <RedeemGiftCardController {...redeemGiftCardProps} />
178
+ }
@@ -0,0 +1,8 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const Container = styled.View`
4
+ padding-horizontal: 40px;
5
+ `
6
+ export const FormController = styled.View`
7
+ margin-bottom: 25px;
8
+ `
@@ -0,0 +1,165 @@
1
+ import React, { useEffect } from 'react'
2
+ import { StyleSheet, Platform, Alert } from 'react-native';
3
+ import { useLanguage, SendGiftCard as SendGiftCardController } from 'ordering-components/native';
4
+ import { useTheme } from 'styled-components/native';
5
+ import { OText, OButton, OInput } from '../../shared';
6
+ import { useForm, Controller } from 'react-hook-form'
7
+
8
+ import {
9
+ Container,
10
+ FormController
11
+ } from './styles'
12
+
13
+
14
+ const SendGiftCardUI = (props: any) => {
15
+ const {
16
+ actionState,
17
+ handleSendGiftCard
18
+ } = props
19
+
20
+ const theme = useTheme()
21
+ const [, t] = useLanguage()
22
+
23
+ const { handleSubmit, control, errors } = useForm()
24
+
25
+ const style = StyleSheet.create({
26
+ btnStyle: {
27
+ borderRadius: 7.6,
28
+ height: 44,
29
+ marginTop: 20
30
+ },
31
+ inputStyle: {
32
+ borderWidth: 1,
33
+ borderColor: theme.colors.border,
34
+ borderRadius: 7.6,
35
+ },
36
+ })
37
+
38
+ const onSubmit = (values) => {
39
+ handleSendGiftCard(values)
40
+ }
41
+
42
+ useEffect(() => {
43
+ if (Object.keys(errors).length > 0) {
44
+ const list = Object.values(errors)
45
+ let stringError = ''
46
+ list.map((item: any, i: number) => {
47
+ stringError += (i + 1) === list.length ? `- ${item.message}` : `- ${item.message}\n`
48
+ })
49
+ Alert.alert(
50
+ t('ERROR', 'Error'),
51
+ stringError,
52
+ [
53
+ { text: t('OK', 'oK'), onPress: () => {} }
54
+ ]
55
+ )
56
+ }
57
+ }, [errors])
58
+
59
+ return (
60
+ <Container>
61
+ <OText color={theme.colors.textNormal} size={20} mBottom={10} style={{ fontWeight: Platform.OS == 'ios' ? '600' : 'bold' }}>{t('GIFT_CARD_DETAILS', 'Gift Card details')}</OText>
62
+ <FormController>
63
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('TO', 'To')}</OText>
64
+ <Controller
65
+ control={control}
66
+ render={({ onChange, value }: any) => (
67
+ <OInput
68
+ placeholder={t('ENTER_AN_EMAIL', 'Enter an email')}
69
+ value={value}
70
+ onChange={(val: any) => onChange(val)}
71
+ autoCompleteType='email'
72
+ autoCapitalize='none'
73
+ autoCorrect={false}
74
+ type='email-address'
75
+ blurOnSubmit={false}
76
+ style={style.inputStyle}
77
+ />
78
+ )}
79
+ name='email'
80
+ rules={{
81
+ required: t('VALIDATION_ERROR_REQUIRED', 'To email is required').replace('_attribute_', t('EMAIL', 'EMail'))
82
+ }}
83
+ defaultValue=""
84
+ />
85
+ </FormController>
86
+ <FormController>
87
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('FROM', 'From')}</OText>
88
+ <Controller
89
+ control={control}
90
+ render={({ onChange, value }: any) => (
91
+ <OInput
92
+ placeholder={t('WRITE_YOUR_NAME', 'Write your name')}
93
+ value={value}
94
+ onChange={(val: any) => onChange(val)}
95
+ autoCapitalize='none'
96
+ autoCorrect={false}
97
+ blurOnSubmit={false}
98
+ style={style.inputStyle}
99
+ />
100
+ )}
101
+ name='user_name'
102
+ defaultValue=""
103
+ />
104
+ </FormController>
105
+ <FormController>
106
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('TITLE', 'Title')}</OText>
107
+ <Controller
108
+ control={control}
109
+ render={({ onChange, value }: any) => (
110
+ <OInput
111
+ placeholder={t('TITLE', 'Title')}
112
+ value={value}
113
+ onChange={(val: any) => onChange(val)}
114
+ autoCapitalize='none'
115
+ autoCorrect={false}
116
+ blurOnSubmit={false}
117
+ style={style.inputStyle}
118
+ />
119
+ )}
120
+ name='title'
121
+ defaultValue=""
122
+ />
123
+ </FormController>
124
+ <FormController>
125
+ <OText color={theme.colors.textNormal} size={14} mBottom={10}>{t('MESSAGES', 'Messages')}</OText>
126
+ <Controller
127
+ control={control}
128
+ render={({ onChange, value }: any) => (
129
+ <OInput
130
+ multiline
131
+ placeholder={t('TYPE_YOUR_MESSAGE_HERE', 'Type your message here')}
132
+ value={value}
133
+ onChange={(val: any) => onChange(val)}
134
+ autoCapitalize='none'
135
+ autoCorrect={false}
136
+ blurOnSubmit={false}
137
+ style={{ ...style.inputStyle, height: 100, alignItems: 'flex-start', }}
138
+ />
139
+ )}
140
+ name='message'
141
+ defaultValue=""
142
+ />
143
+ </FormController>
144
+ <OButton
145
+ onClick={handleSubmit(onSubmit)}
146
+ text={actionState?.loading ? t('LOADING', 'Loading') : t('SEND_GIFT_CARD', 'Send gift card')}
147
+ bgColor={theme.colors.primary}
148
+ borderColor={theme.colors.primary}
149
+ textStyle={{ color: 'white', fontSize: 13 }}
150
+ imgRightSrc={null}
151
+ style={style.btnStyle}
152
+ isDisabled={actionState.loading}
153
+ />
154
+ </Container>
155
+ )
156
+ }
157
+
158
+ export const SendGiftCard = (props: any) => {
159
+ const sendGiftCardProps = {
160
+ ...props,
161
+ showToastMsg: true,
162
+ UIComponent: SendGiftCardUI
163
+ }
164
+ return <SendGiftCardController {...sendGiftCardProps} />
165
+ }
@@ -0,0 +1,9 @@
1
+ import styled from 'styled-components/native'
2
+
3
+ export const Container = styled.View`
4
+ padding-horizontal: 40px;
5
+ margin-bottom: 30px;
6
+ `
7
+ export const FormController = styled.View`
8
+ margin-bottom: 25px;
9
+ `