ui-soxo-bootstrap-core 2.6.1-dev.23 → 2.6.1-dev.24

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.
@@ -1,4 +1,4 @@
1
- import { PostData, GetData, PutData, PatchData, DeleteData } from './../http/http.utils';
1
+ import { PostData, GetData, PutData, PatchData, DeleteData,UploadData } from './../http/http.utils';
2
2
 
3
3
  let headers = {};
4
4
 
@@ -124,32 +124,27 @@ export default class ApiUtils {
124
124
  });
125
125
  };
126
126
 
127
- static upload = ({ url, data }) => {
128
- return fetch(process.env.REACT_APP_endpoint + url, {
129
- // Your POST endpoint
130
- method: 'POST',
127
+ static upload = async ({ url, data, headers: customHeaders = {}, ...props }) => {
128
+ const dbPtr = localStorage.getItem('db_ptr');
129
+
130
+ console.log('nura upload called with:',dbPtr);
131
+ try {
132
+ return await UploadData({
133
+ url,
134
+ formBody: data, // FormData
135
+ settings,
131
136
  headers: {
132
- // 'App-Type': 313,
133
- // 'App-Version': '1.0.1',
134
- Authorization: 'Bearer ' + localStorage.access_token,
135
- // type:'multipart/formData'
136
- },
137
- // credentials: 'include',
138
- body: data,
139
- }).then(
140
- (result) => {
141
- return result.json();
142
- },
143
- (error) => {
144
- console.log(error);
145
- return error;
137
+ ...(settings.headers || {}),
138
+ ...(dbPtr ? { db_ptr: dbPtr } : {}),
139
+ ...customHeaders,
146
140
  },
147
- (progress) => {
148
- console.log(progress);
149
- return progress;
150
- }
151
- );
152
- };
141
+ ...props,
142
+ });
143
+ } catch (error) {
144
+ console.log('Upload Error:', error);
145
+ throw error;
146
+ }
147
+ };
153
148
 
154
149
  /**
155
150
  * Get Auth Status
@@ -76,18 +76,24 @@ export async function ApiCall({ url, formBody, method, settings, ...props }) {
76
76
  const path = window.location.pathname;
77
77
  const baseUrl = props.baseUrl || process.env.REACT_APP_endpoint;
78
78
 
79
+ // 1. Check if we are dealing with FormData (Upload)
80
+ const isFormData = formBody instanceof FormData;
81
+
79
82
  const payload = {
80
83
  method,
81
84
  headers: {
82
85
  ...settings.headers,
83
- ...headers,
84
86
  ...(props.headers || {}),
85
- ...(token ? { Authorization: `Bearer ${token}` } : {}),
86
- 'Content-Type': 'application/json',
87
+ Authorization: `Bearer ${token}`,
87
88
  },
88
- body: formBody ? JSON.stringify(formBody) : null,
89
+ // 2. If it's NOT FormData, stringify it. If it IS, pass it raw.
90
+ body: isFormData ? formBody : (formBody ? JSON.stringify(formBody) : null),
89
91
  };
90
92
 
93
+ // 3. Only add JSON Content-Type if it's NOT a FormData upload
94
+ if (!isFormData) {
95
+ payload.headers['Content-Type'] = 'application/json';
96
+ }
91
97
  // 🟡 Handles both normal and retried responses
92
98
  const handleResponse = async (res) => {
93
99
  if (props.responseType === 'blob') {
@@ -156,3 +162,17 @@ export async function ApiCall({ url, formBody, method, settings, ...props }) {
156
162
  throw err;
157
163
  }
158
164
  }
165
+
166
+ /**
167
+ * Method for uploading documents
168
+ * @public
169
+ */
170
+ export async function UploadData({ url, formBody, ...props }) {
171
+ return ApiCall({
172
+ url,
173
+ formBody,
174
+ method: 'POST',
175
+ returnResponse: true,
176
+ ...props,
177
+ });
178
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ui-soxo-bootstrap-core",
3
- "version": "2.6.1-dev.23",
3
+ "version": "2.6.1-dev.24",
4
4
  "description": "All the Core Components for you to start",
5
5
  "keywords": [
6
6
  "all in one"