@bindu-dashing/dam-solution-v2 5.8.202 → 5.8.203

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.
@@ -152,66 +152,105 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
152
152
  fetchClientData();
153
153
  }, [isEditMode, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.brandId, existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain, api, form]);
154
154
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
155
- var _a, _b, _c, _d, _e, _f, _g, _h, _j;
155
+ var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
156
156
  try {
157
- // Use teamsApiDetails from clientData if available (from API response), otherwise use props
158
- const teamsApiDetailsFromData = get(clientData, "teamsApiDetails", {});
159
- const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
160
- const finalUsername = teamsApiDetailsFromData.username || username;
161
- const finalPassword = teamsApiDetailsFromData.password || password;
162
- // Convert adminTeams to strings for API (API expects strings like ["547"] not numbers like [547])
163
- const adminTeamsAsStrings = Array.isArray(data.adminTeams)
164
- ? data.adminTeams.map((team) => String(team))
165
- : [];
166
- const values = Object.assign(Object.assign({}, data), { adminTeams: adminTeamsAsStrings, showFilePreview: (_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false, accessKey: appType == "reactJs"
167
- ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
168
- : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
169
- ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SECRET_KEY
170
- : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
171
- ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
172
- : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
173
- teamsApi: finalTeamsApi,
174
- username: finalUsername,
175
- password: finalPassword,
176
- }, damLocationDetails: damLocationType === "external"
177
- ? {
178
- bucket: (_b = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _b === void 0 ? void 0 : _b.bucket,
179
- locationType: "EXTERNAL",
180
- rootPath: (_c = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _c === void 0 ? void 0 : _c.rootPath,
181
- accessKeyId: (_d = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _d === void 0 ? void 0 : _d.accessKeyId,
182
- secretAccessKey: (_e = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _e === void 0 ? void 0 : _e.secretAccessKey,
183
- url: (_f = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _f === void 0 ? void 0 : _f.url,
184
- region: (_g = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _g === void 0 ? void 0 : _g.region,
185
- }
186
- : {
187
- locationType: "INTERNAL",
188
- rootPath: (_h = data === null || data === void 0 ? void 0 : data.damLocationDetails) === null || _h === void 0 ? void 0 : _h.rootPath,
189
- } });
190
157
  setLoading(true);
191
158
  let response;
192
159
  const baseUrl = getBaseUrl(appType);
193
160
  if (isEditMode && brandIdForUpdate && authToken) {
194
- // Update existing client: PUT to /brands/{brandId}
195
- const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, values, {
161
+ // Edit mode: send only changed fields via PUT
162
+ const adminTeamsAsStrings = Array.isArray(data.adminTeams)
163
+ ? data.adminTeams.map((team) => String(team))
164
+ : [];
165
+ const existingAdminTeams = (get(clientData, "adminTeams", []) || []).map((t) => String(t));
166
+ const arraysEqual = (a, b) => {
167
+ const sa = [...a].sort();
168
+ const sb = [...b].sort();
169
+ return sa.length === sb.length && sa.every((v, i) => v === sb[i]);
170
+ };
171
+ const accessTypesChanged = JSON.stringify([...(data.accessTypes || [])].sort()) !==
172
+ JSON.stringify([...(get(clientData, "accessTypes", []) || [])].sort());
173
+ const payload = {};
174
+ if (data.name !== get(clientData, "name"))
175
+ payload.name = data.name;
176
+ if (accessTypesChanged)
177
+ payload.accessTypes = data.accessTypes || [];
178
+ if (!arraysEqual(adminTeamsAsStrings, existingAdminTeams))
179
+ payload.adminTeams = adminTeamsAsStrings;
180
+ if (((_a = data.showFilePreview) !== null && _a !== void 0 ? _a : false) !== get(clientData, "showFilePreview", false))
181
+ payload.showFilePreview = (_b = data.showFilePreview) !== null && _b !== void 0 ? _b : false;
182
+ if (Object.keys(payload).length === 0) {
183
+ setLoading(false);
184
+ showNotification("No changes to save", NotificationStatus.INFO);
185
+ return;
186
+ }
187
+ const putResponse = yield axios.put(`${baseUrl}/brands/${brandIdForUpdate}`, payload, {
196
188
  headers: {
197
- 'Authorization': `Bearer ${authToken}`,
198
- 'Content-Type': 'application/json',
199
- 'accept': 'application/json, text/plain, */*'
200
- }
189
+ Authorization: `Bearer ${authToken}`,
190
+ "Content-Type": "application/json",
191
+ accept: "application/json, text/plain, */*",
192
+ },
201
193
  });
202
194
  // Extract data from axios response (API returns { data: {...} } or { data: { data: {...} } })
203
195
  response = get(putResponse, "data.data", get(putResponse, "data", putResponse));
204
196
  }
205
197
  else {
206
- // Create new client: POST to /brands/sub-brand
198
+ // Create new client: POST to /brands/sub-brand (full payload required)
199
+ const teamsApiDetailsFromData = clientData ? get(clientData, "teamsApiDetails", {}) : {};
200
+ const finalTeamsApi = teamsApiDetailsFromData.teamsApi || teamsApi;
201
+ const finalUsername = teamsApiDetailsFromData.username || username;
202
+ const finalPassword = teamsApiDetailsFromData.password || password;
203
+ const adminTeamsAsStrings = Array.isArray(data.adminTeams)
204
+ ? data.adminTeams.map((team) => String(team))
205
+ : [];
206
+ const formDamLocation = data === null || data === void 0 ? void 0 : data.damLocationDetails;
207
+ const damLocationDetails = damLocationType === "external"
208
+ ? {
209
+ bucket: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.bucket,
210
+ locationType: "EXTERNAL",
211
+ rootPath: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.rootPath,
212
+ accessKeyId: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.accessKeyId,
213
+ secretAccessKey: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.secretAccessKey,
214
+ url: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.url,
215
+ region: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.region,
216
+ }
217
+ : {
218
+ locationType: "INTERNAL",
219
+ rootPath: formDamLocation === null || formDamLocation === void 0 ? void 0 : formDamLocation.rootPath,
220
+ };
221
+ const values = Object.assign(Object.assign({}, data), { adminTeams: adminTeamsAsStrings, showFilePreview: (_c = data.showFilePreview) !== null && _c !== void 0 ? _c : false, accessKey: appType == "reactJs"
222
+ ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY
223
+ : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_ACCESS_KEY, secretKey: appType == "reactJs"
224
+ ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SECRET_KEY
225
+ : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SECRET_KEY, parentSubdomain: appType == "reactJs"
226
+ ? process.env.REACT_APP_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN
227
+ : process.env.NEXT_PUBLIC_MIXDRIVE_CLIENT_PARENT_SUBDOMAIN, teamsApiDetails: {
228
+ teamsApi: finalTeamsApi,
229
+ username: finalUsername,
230
+ password: finalPassword,
231
+ }, damLocationDetails });
207
232
  response = yield api.post(CREATE_SUB_BRAND, values);
208
233
  }
209
234
  setLoading(false);
210
- showNotification((_j = response === null || response === void 0 ? void 0 : response.message) !== null && _j !== void 0 ? _j : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
211
- toggleShow();
235
+ showNotification((_d = response === null || response === void 0 ? void 0 : response.message) !== null && _d !== void 0 ? _d : (get(response, "message") || CREATE_SUCCESS), NotificationStatus.SUCCESS);
236
+ // Call onSuccess before closing drawer so parent can show its toast (e.g. d1-admin, ThemePage)
237
+ // Parent expects accessKey, secretKey, subdomain - always provide when in edit mode
212
238
  if (onSuccess) {
213
- onSuccess(response === null || response === void 0 ? void 0 : response.data);
239
+ const successData = isEditMode
240
+ ? Object.assign(Object.assign(Object.assign({}, response === null || response === void 0 ? void 0 : response.data), response), { accessKey: (_f = (_e = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.accessKey) !== null && _e !== void 0 ? _e : get(response, "accessKey")) !== null && _f !== void 0 ? _f : get(clientData, "accessKey"), secretKey: (_h = (_g = existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.secretKey) !== null && _g !== void 0 ? _g : get(response, "secretKey")) !== null && _h !== void 0 ? _h : get(clientData, "secretKey"), subdomain: (_l = (_k = (_j = data === null || data === void 0 ? void 0 : data.subdomain) !== null && _j !== void 0 ? _j : existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) !== null && _k !== void 0 ? _k : get(response, "subdomain")) !== null && _l !== void 0 ? _l : get(clientData, "subdomain") }) : (_m = response === null || response === void 0 ? void 0 : response.data) !== null && _m !== void 0 ? _m : response;
241
+ // Guard: parent (e.g. ThemePage.onCreateDamClient) accesses data.accessKey - never pass undefined
242
+ const safeData = successData && typeof successData === "object"
243
+ ? successData
244
+ : isEditMode && existingClientData
245
+ ? {
246
+ accessKey: existingClientData.accessKey,
247
+ secretKey: existingClientData.secretKey,
248
+ subdomain: existingClientData.subdomain,
249
+ }
250
+ : {};
251
+ onSuccess(safeData);
214
252
  }
253
+ toggleShow();
215
254
  }
216
255
  catch (error) {
217
256
  setLoading(false);
@@ -300,7 +339,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
300
339
  required: true,
301
340
  message: "Team Ids is required",
302
341
  },
303
- ], children: _jsx(Select, { showSearch: true, mode: "multiple", placeholder: "Team Ids", options: filteredTeams, optionFilterProp: "key" }) }), _jsxs(Form.Item, { label: "DAM Location Details", name: "damLocationDetails", children: [_jsx(Form.Item, { label: "Type", name: ["damLocationDetails", "type"], rules: [
342
+ ], children: _jsx(Select, { showSearch: true, mode: "multiple", placeholder: "Team Ids", options: filteredTeams, optionFilterProp: "key" }) }), !isEditMode && (_jsxs(Form.Item, { label: "DAM Location Details", name: "damLocationDetails", children: [_jsx(Form.Item, { label: "Type", name: ["damLocationDetails", "type"], rules: [
304
343
  {
305
344
  required: true,
306
345
  message: "Type is required",
@@ -337,11 +376,33 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
337
376
  required: damLocationType === "external",
338
377
  message: "Region is required",
339
378
  },
340
- ], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" }) })] }))] }), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
379
+ ], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" }) })] }))] })), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
341
380
  {
342
381
  required: true,
343
382
  message: "Subdomain is required",
344
383
  },
345
- ], children: _jsx(Input, { placeholder: "Subdomain" }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview Editor" }) }), _jsx(Form.Item, { children: _jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, children: "Submit" }) })] })) }));
384
+ ], children: _jsx(Input, { placeholder: "Subdomain", disabled: isEditMode }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview Editor" }) }), _jsx(Form.Item, { shouldUpdate: true, style: { marginBottom: 0 }, children: () => {
385
+ var _a, _b, _c, _d, _e, _f, _g, _h;
386
+ const values = form.getFieldsValue(true);
387
+ const hasName = !!((_a = values === null || values === void 0 ? void 0 : values.name) === null || _a === void 0 ? void 0 : _a.trim());
388
+ const hasAccessTypes = Array.isArray(values === null || values === void 0 ? void 0 : values.accessTypes) && values.accessTypes.length > 0;
389
+ const hasAdminTeams = Array.isArray(values === null || values === void 0 ? void 0 : values.adminTeams) && values.adminTeams.length > 0;
390
+ const hasSubdomain = !!((_b = values === null || values === void 0 ? void 0 : values.subdomain) === null || _b === void 0 ? void 0 : _b.trim());
391
+ const baseValid = hasName && hasAccessTypes && hasAdminTeams && hasSubdomain;
392
+ let damLocationValid = true;
393
+ if (!isEditMode) {
394
+ const dl = (values === null || values === void 0 ? void 0 : values.damLocationDetails) || {};
395
+ damLocationValid = !!((dl === null || dl === void 0 ? void 0 : dl.type) && ((_c = dl === null || dl === void 0 ? void 0 : dl.rootPath) === null || _c === void 0 ? void 0 : _c.trim()));
396
+ if (damLocationValid && damLocationType === "external") {
397
+ damLocationValid = !!(((_d = dl === null || dl === void 0 ? void 0 : dl.bucket) === null || _d === void 0 ? void 0 : _d.trim()) &&
398
+ ((_e = dl === null || dl === void 0 ? void 0 : dl.accessKeyId) === null || _e === void 0 ? void 0 : _e.trim()) &&
399
+ ((_f = dl === null || dl === void 0 ? void 0 : dl.secretAccessKey) === null || _f === void 0 ? void 0 : _f.trim()) &&
400
+ ((_g = dl === null || dl === void 0 ? void 0 : dl.url) === null || _g === void 0 ? void 0 : _g.trim()) &&
401
+ ((_h = dl === null || dl === void 0 ? void 0 : dl.region) === null || _h === void 0 ? void 0 : _h.trim()));
402
+ }
403
+ }
404
+ const isFormValid = baseValid && damLocationValid;
405
+ return (_jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, disabled: !isFormValid, children: "Submit" }));
406
+ } })] })) }));
346
407
  };
347
408
  export default CreateClientForm;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bindu-dashing/dam-solution-v2",
3
- "version": "5.8.202",
3
+ "version": "5.8.203",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",