datastake-daf 0.6.573 → 0.6.574

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,200 @@
1
+ import React, { useState, useEffect, useCallback } from "react";
2
+ import { Form, Input, Select } from "antd";
3
+ import BorderedButton from "../Button/BorderedButton/index.jsx";
4
+
5
+ function AuthForm ({
6
+ steps,
7
+ fields,
8
+ onSubmit,
9
+ initialValues = {},
10
+ submitText = "Submit",
11
+ form,
12
+ errors,
13
+ t = (key) => key,
14
+ executeRecaptcha = () => {},
15
+ }){
16
+ const [formInstance] = Form.useForm(form);
17
+ const [currentStep, setCurrentStep] = useState(0);
18
+ const [allFormValues, setAllFormValues] = useState(initialValues);
19
+ const [formErrors, setFormErrors] = useState(null);
20
+
21
+ console.log({errors})
22
+
23
+ const isMultiStep = !!steps;
24
+ const currentFields = isMultiStep ? steps?.[currentStep]?.fields : fields || [];
25
+
26
+ useEffect(() => {
27
+ if (isMultiStep && Object.keys(allFormValues).length > 0) {
28
+ formInstance.setFieldsValue(allFormValues);
29
+ }
30
+ }, [currentStep, allFormValues, formInstance, isMultiStep]);
31
+
32
+ const handleReCaptchaVerify = useCallback(async () => {
33
+ if (!executeRecaptcha) {
34
+ console.log('Execute recaptcha not yet available');
35
+ return;
36
+ }
37
+
38
+ const token = await executeRecaptcha('submit');
39
+ return token;
40
+ }, [executeRecaptcha]);
41
+
42
+ const next = async () => {
43
+ try {
44
+ await formInstance.validateFields(
45
+ currentFields.map((f) => f.name)
46
+ );
47
+ // Save current step values before moving to next step
48
+ const currentValues = formInstance.getFieldsValue();
49
+ setAllFormValues((prev) => ({ ...prev, ...currentValues }));
50
+ setCurrentStep((prev) => prev + 1);
51
+ } catch (err) {
52
+ console.error("Please fix the validation errors before continuing.");
53
+ }
54
+ };
55
+
56
+ const prev = () => setCurrentStep((prev) => prev - 1);
57
+
58
+ const handleSubmit = async (values) => {
59
+ try {
60
+ await formInstance.validateFields();
61
+
62
+ const token = await handleReCaptchaVerify();
63
+ if (!token) {
64
+ console.error('reCAPTCHA verification failed');
65
+ return;
66
+ }
67
+
68
+ setFormErrors(null);
69
+
70
+ if (!isMultiStep) return onSubmit?.(values);
71
+
72
+ if (currentStep < steps?.length - 1) return next();
73
+
74
+ const finalValues = { ...allFormValues, ...values };
75
+ onSubmit?.(finalValues);
76
+ } catch (err) {
77
+ console.error("Validation failed:", err);
78
+ }
79
+ };
80
+
81
+ const checkRequiredFieldsFilled = (changedValues, allValues) => {
82
+ const requiredFields = currentFields.filter(f => f.required).map(f => f.name);
83
+ return requiredFields.every(fieldName => {
84
+ const value = allValues[fieldName];
85
+ return value !== undefined && value !== null && value !== '';
86
+ });
87
+ };
88
+
89
+ useEffect(() => {
90
+ setFormErrors(errors);
91
+ }, [errors]);
92
+
93
+ const renderErrors = (err, t) => {
94
+ document.querySelectorAll('.ant-form-item')
95
+ .forEach(input => input.classList.add('ant-form-item-has-error'))
96
+ return Object.keys(err).map(key => {
97
+ return err[key].map(error =>
98
+ <div
99
+ key={error}
100
+ className="ant-form-item-explain errors-cont"
101
+ style={{ color: '#ff4d4f' }}>
102
+ {t(error)}
103
+ </div>
104
+ )
105
+ });
106
+ }
107
+
108
+ const renderField = (field) => {
109
+ let inputNode = null;
110
+ switch (field.type) {
111
+ case "input":
112
+ case "email":
113
+ case "number":
114
+ inputNode = <Input type={field.type} placeholder={field.placeholder} {...field.props} />;
115
+ break;
116
+ case "password":
117
+ inputNode = <Input.Password placeholder={field.placeholder} {...field.props} />;
118
+ break;
119
+ case "textarea":
120
+ inputNode = <Input.TextArea placeholder={field.placeholder} {...field.props} />;
121
+ break;
122
+ case "select":
123
+ inputNode = (
124
+ <Select placeholder={field.placeholder} {...field.props}>
125
+ {field.options?.map((opt) => (
126
+ <Select.Option key={opt.value} value={opt.value}>
127
+ {opt.label}
128
+ </Select.Option>
129
+ ))}
130
+ </Select>
131
+ );
132
+ break;
133
+ case "custom":
134
+ inputNode = field.component;
135
+ break;
136
+ default:
137
+ inputNode = <Input placeholder={field.placeholder} {...field.props} />;
138
+ }
139
+
140
+ return (
141
+ <Form.Item key={field.name} name={field.name} label={field.label} rules={field.rules} style={{ marginBottom: 0 }}>
142
+ {inputNode}
143
+ </Form.Item>
144
+ );
145
+ };
146
+
147
+ return (
148
+ <>
149
+ <Form
150
+ form={formInstance}
151
+ layout="vertical"
152
+ initialValues={initialValues}
153
+ onFinish={handleSubmit}
154
+ >
155
+ {currentFields.map(renderField)}
156
+
157
+
158
+ {formErrors ? (
159
+ renderErrors(formErrors, t)
160
+ ) : null}
161
+
162
+ {isMultiStep && currentStep > 0 ? (
163
+ <div className="flex flex-column gap-2" style={{ width: '100%' }}>
164
+ <Form.Item noStyle shouldUpdate>
165
+ {(form) => {
166
+ const isLastStep = currentStep === steps?.length - 1;
167
+ const allFieldsFilled = checkRequiredFieldsFilled({}, form.getFieldsValue());
168
+
169
+ return (
170
+ <div className="buttons" style={{ marginTop: 0}}>
171
+ <BorderedButton
172
+ type="primary"
173
+ htmlType="submit"
174
+ disabled={isLastStep && !allFieldsFilled}
175
+ block className="normal-br"
176
+ >
177
+ {isLastStep ? submitText : t("Next")}
178
+ </BorderedButton>
179
+ </div>
180
+ );
181
+ }}
182
+ </Form.Item>
183
+ <div className="buttons" style={{ marginTop: 0}}>
184
+ <BorderedButton onClick={prev} block className="normal-br">
185
+ {t("Back")}
186
+ </BorderedButton>
187
+ </div>
188
+ </div>
189
+ ) : (
190
+ <div className="buttons" style={{ marginTop: 0}}>
191
+ <BorderedButton type="primary" htmlType="submit" block className="normal-br">
192
+ {isMultiStep ? t("Next") : submitText}
193
+ </BorderedButton>
194
+ </div>
195
+ )}
196
+ </Form>
197
+ </>
198
+ );
199
+ }
200
+ export default AuthForm;
@@ -117,7 +117,9 @@ export default function SidenavMenu({
117
117
  }, [filteredItems]);
118
118
  const [openKeys, setOpenKeys] = useState([]);
119
119
 
120
- const renderSubMenu = (item, i) => ({
120
+ console.log({filteredItems})
121
+
122
+ const renderSubMenu = (item, i) => (console.log({item}),{
121
123
  key: i,
122
124
  disabled: item.isDisabled,
123
125
  onTitleClick: () => {
@@ -233,6 +235,7 @@ export default function SidenavMenu({
233
235
  }, [selectedKeys]);
234
236
 
235
237
  const renderMenu = (items) => (
238
+ console.log({items}),
236
239
  <Menu
237
240
  theme="dark"
238
241
  mode={menuMode}
@@ -16,9 +16,8 @@ class ChannelsService extends BaseService {
16
16
  }
17
17
 
18
18
  return this.apiGet({
19
- url: `/api/channels`,
19
+ url: `/store/channels`,
20
20
  params,
21
- isStore: true,
22
21
  headers: token ? {
23
22
  Authorization: `Bearer ${token}`,
24
23
  } : undefined,
package/src/index.js CHANGED
@@ -87,6 +87,7 @@ export { Sections as EditFormSections } from "./@daf/core/components/EditForm/se
87
87
  export { default as ViewFormNavigation } from "./@daf/core/components/ViewForm/navigation.jsx";
88
88
  export { default as PhoneInput } from "./@daf/core/components/Inputs/PhoneInput/index.js";
89
89
  export { AjaxSelectMain as AjaxSelect } from "./@daf/core/components/EditForm/components/ajaxSelect.js";
90
+ export { default as AuthForm } from "./@daf/core/components/AuthForm/index.jsx";
90
91
 
91
92
  // Progress Bar
92
93
  export { default as ProgressBar } from "./@daf/core/components/ProgressBar/index.jsx";
package/src/layouts.js CHANGED
@@ -1,3 +1 @@
1
- export { default as AppLayout } from './@daf/layouts/AppLayout/index.jsx';
2
- export { default as AuthLayout } from './@daf/layouts/AuthLayout/index.jsx';
3
- export { default as AuthNavbar } from './@daf/layouts/AuthLayout/components/NavbarComponent.jsx';
1
+ export { default as AppLayout } from './@daf/layouts/AppLayout/index.jsx';