@moamc/rn-cli 1.4.4 → 1.5.0
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
|
@@ -36,12 +36,58 @@ const generateInitialValues = (formFields = []) => {
|
|
|
36
36
|
return `\t\tloader: false,\n${fields}${additionalFields}`;
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
+
const { detectProjectStructure } = require('../utils/fileUtils');
|
|
40
|
+
|
|
39
41
|
const generateHookTemplate = (hookName, hasForm = false, formFields = [], eventName = null) => {
|
|
42
|
+
const { hasHeadersFolder } = detectProjectStructure();
|
|
43
|
+
const isDistributorStyle = !hasHeadersFolder;
|
|
44
|
+
|
|
40
45
|
if (hasForm) {
|
|
41
46
|
const hasDropdown = formFields.some(f => f.type === 'dropdown');
|
|
42
47
|
const hasDate = formFields.some(f => f.type === 'date');
|
|
43
48
|
|
|
44
|
-
|
|
49
|
+
if (isDistributorStyle) {
|
|
50
|
+
// Distributor app - use Formik
|
|
51
|
+
return `import { useFormik } from 'formik';
|
|
52
|
+
import { showToastNotification } from '../../../../helpers/common';${hasDate ? '\nimport moment from \'moment\';' : ''}
|
|
53
|
+
import { validate${hookName} } from '../validation';
|
|
54
|
+
|
|
55
|
+
export const use${hookName} = ({ navigation }) => {
|
|
56
|
+
\tconst formikState = useFormik({
|
|
57
|
+
\t\tinitialValues: {
|
|
58
|
+
${formFields.map(f => `\t\t\t${f.name}: '',`).join('\n')}
|
|
59
|
+
\t\t},
|
|
60
|
+
\t\tvalidate: validate${hookName},
|
|
61
|
+
\t\tonSubmit: async (values) => {
|
|
62
|
+
\t\t\ttry {
|
|
63
|
+
\t\t\t\t// Add your API call here
|
|
64
|
+
\t\t\t\tshowToastNotification('Success!');
|
|
65
|
+
\t\t\t} catch (error) {
|
|
66
|
+
\t\t\t\tshowToastNotification(error?.message || 'Something went wrong');
|
|
67
|
+
\t\t\t}
|
|
68
|
+
\t\t},
|
|
69
|
+
\t});
|
|
70
|
+
|
|
71
|
+
\tconst { values: formData, errors, touched, isSubmitting: loading, handleChange: formikHandleChange, handleSubmit } = formikState;
|
|
72
|
+
|
|
73
|
+
\tconst handleChange = (value, field) => {
|
|
74
|
+
\t\tformikState.setFieldValue(field, value);
|
|
75
|
+
\t\tformikState.setFieldTouched(field, true);
|
|
76
|
+
\t};
|
|
77
|
+
|
|
78
|
+
\treturn {
|
|
79
|
+
\t\tformData,
|
|
80
|
+
\t\terrors,
|
|
81
|
+
\t\ttouched,
|
|
82
|
+
\t\tloading,
|
|
83
|
+
\t\thandleChange,
|
|
84
|
+
\t\thandleSubmit,
|
|
85
|
+
\t};
|
|
86
|
+
};
|
|
87
|
+
`;
|
|
88
|
+
} else {
|
|
89
|
+
// Investor app - use useState with useCallback
|
|
90
|
+
return `import { useState, useCallback } from 'react';
|
|
45
91
|
import { showToastNotification } from '../../../../helpers/common';${hasDate ? '\nimport moment from \'moment\';' : ''}
|
|
46
92
|
import { validate${hookName} } from '../validation';
|
|
47
93
|
|
|
@@ -92,6 +138,7 @@ ${formFields.map(f => `\t\t${f.name}: '',`).join('\n')}
|
|
|
92
138
|
\t};
|
|
93
139
|
};
|
|
94
140
|
`;
|
|
141
|
+
}
|
|
95
142
|
}
|
|
96
143
|
|
|
97
144
|
return `import { useState, useEffect } from 'react';
|
|
@@ -118,7 +118,7 @@ const ${componentName} = ({ navigation }) => {
|
|
|
118
118
|
\t\t\t\t<Header redirect={() => navigation.goBack()} />
|
|
119
119
|
\t\t\t\t<ScrollView
|
|
120
120
|
\t\t\t\t\tshowsVerticalScrollIndicator={false}
|
|
121
|
-
\t\t\t\t\tcontentContainerStyle={
|
|
121
|
+
\t\t\t\t\tcontentContainerStyle={styles.scrollContent}
|
|
122
122
|
\t\t\t\t>
|
|
123
123
|
\t\t\t\t\t<Text style={styles.heading}>${screenName}</Text>
|
|
124
124
|
${generateFormFields(formFields)}
|
|
@@ -132,6 +132,9 @@ ${generateFormFields(formFields)}
|
|
|
132
132
|
};
|
|
133
133
|
|
|
134
134
|
const styles = StyleSheet.create({
|
|
135
|
+
\tscrollContent: {
|
|
136
|
+
\t\t...utilities.rowPadding24,
|
|
137
|
+
\t},
|
|
135
138
|
\theading: {
|
|
136
139
|
\t\t...fonts.fontWSSB18,
|
|
137
140
|
\t\tcolor: colorConstant.moBlack,
|
|
@@ -247,7 +250,7 @@ const ${componentName} = ({ navigation }) => {
|
|
|
247
250
|
\t\t\t\t<Header redirect={() => navigation.goBack()} />
|
|
248
251
|
\t\t\t\t<ScrollView
|
|
249
252
|
\t\t\t\t\tshowsVerticalScrollIndicator={false}
|
|
250
|
-
\t\t\t\t\tcontentContainerStyle={
|
|
253
|
+
\t\t\t\t\tcontentContainerStyle={styles.scrollContent}
|
|
251
254
|
\t\t\t\t>
|
|
252
255
|
\t\t\t\t\t<Text style={styles.heading}>${screenName}</Text>
|
|
253
256
|
\t\t\t\t\t{/* Add your content here */}
|
|
@@ -261,6 +264,9 @@ const ${componentName} = ({ navigation }) => {
|
|
|
261
264
|
};
|
|
262
265
|
|
|
263
266
|
const styles = StyleSheet.create({
|
|
267
|
+
\tscrollContent: {
|
|
268
|
+
\t\t...utilities.rowPadding24,
|
|
269
|
+
\t},
|
|
264
270
|
\theading: {
|
|
265
271
|
\t\t...fonts.fontWSSB18,
|
|
266
272
|
\t\tcolor: colorConstant.moBlack,
|