@bindu-dashing/dam-solution-v2 5.8.153 → 5.8.154

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.
@@ -26,6 +26,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
26
26
  const [fetchingClientData, setFetchingClientData] = useState(false);
27
27
  const [damLocationType, setDamLocationType] = useState("external");
28
28
  const [filteredTeams, setFilteredTeams] = useState([]);
29
+ const [clientData, setClientData] = useState(null);
29
30
  const api = useMemo(() => createApiClient(damConfig), [damConfig]);
30
31
  const [form] = Form.useForm();
31
32
  const isEditMode = !!existingClientData;
@@ -40,33 +41,25 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
40
41
  setFetchingClientData(true);
41
42
  try {
42
43
  const response = yield api.get(`${FETCH_BRAND_USING_SUBDOMAIN}?subdomain=${existingClientData.subdomain}`);
43
- const clientData = get(response, "data.data", {});
44
+ // API response structure: { status: true, code: 200, data: { _id, name, adminTeams, subdomain, ... } }
45
+ const fetchedData = get(response, "data.data", {});
46
+ console.log("Fetched client data:", fetchedData);
47
+ // Store client data in state
48
+ setClientData(fetchedData);
44
49
  // Populate form with existing client data
45
- if (clientData) {
46
- form.setFieldsValue({
47
- name: get(clientData, "name", ""),
48
- subdomain: get(clientData, "subdomain", existingClientData.subdomain),
49
- accessTypes: get(clientData, "accessTypes", []),
50
- adminTeams: get(clientData, "adminTeams", []),
51
- showFilePreview: get(clientData, "showFilePreview", false),
52
- damLocationDetails: {
53
- type: get(clientData, "damLocationDetails.locationType") === "EXTERNAL" ? "external" : "internal",
54
- bucket: get(clientData, "damLocationDetails.bucket", ""),
55
- rootPath: get(clientData, "damLocationDetails.rootPath", ""),
56
- accessKeyId: get(clientData, "damLocationDetails.accessKeyId", ""),
57
- secretAccessKey: get(clientData, "damLocationDetails.secretAccessKey", ""),
58
- url: get(clientData, "damLocationDetails.url", ""),
59
- region: get(clientData, "damLocationDetails.region", ""),
60
- },
61
- });
62
- // Set DAM location type
63
- const locationType = get(clientData, "damLocationDetails.locationType");
50
+ if (fetchedData && Object.keys(fetchedData).length > 0) {
51
+ const damLocationDetails = get(fetchedData, "damLocationDetails", {});
52
+ const locationType = get(damLocationDetails, "locationType", "");
53
+ // Set DAM location type state first
64
54
  if (locationType === "EXTERNAL") {
65
55
  setDamLocationType("external");
66
56
  }
67
- else {
57
+ else if (locationType === "INTERNAL") {
68
58
  setDamLocationType("internal");
69
59
  }
60
+ else {
61
+ setDamLocationType("external"); // default
62
+ }
70
63
  }
71
64
  }
72
65
  catch (error) {
@@ -85,7 +78,7 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
85
78
  }
86
79
  });
87
80
  fetchClientData();
88
- }, [isEditMode, existingClientData, api, form]);
81
+ }, [isEditMode, existingClientData, api, form, filteredTeams]);
89
82
  const onFinish = (data) => __awaiter(void 0, void 0, void 0, function* () {
90
83
  var _a, _b, _c, _d, _e, _f, _g, _h;
91
84
  try {
@@ -127,6 +120,37 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
127
120
  showNotification(get(error, "message", SOMETHING_WENT_WRONG), NotificationStatus.ERROR);
128
121
  }
129
122
  });
123
+ // Populate form when client data and teams are ready
124
+ useEffect(() => {
125
+ if (clientData && Object.keys(clientData).length > 0) {
126
+ const damLocationDetails = get(clientData, "damLocationDetails", {});
127
+ const locationType = get(damLocationDetails, "locationType", "");
128
+ // Convert adminTeams to numbers if they're strings, to match Select component values
129
+ const adminTeamsData = get(clientData, "adminTeams", []);
130
+ const adminTeamsFormatted = Array.isArray(adminTeamsData)
131
+ ? adminTeamsData.map((team) => {
132
+ const teamNum = typeof team === "string" ? Number(team) : team;
133
+ return teamNum;
134
+ })
135
+ : [];
136
+ form.setFieldsValue({
137
+ name: get(clientData, "name", ""),
138
+ subdomain: get(clientData, "subdomain", (existingClientData === null || existingClientData === void 0 ? void 0 : existingClientData.subdomain) || ""),
139
+ accessTypes: get(clientData, "accessTypes", []),
140
+ adminTeams: adminTeamsFormatted,
141
+ showFilePreview: get(clientData, "showFilePreview", false),
142
+ damLocationDetails: {
143
+ type: locationType === "EXTERNAL" ? "external" : locationType === "INTERNAL" ? "internal" : "external",
144
+ bucket: get(damLocationDetails, "bucket", ""),
145
+ rootPath: get(damLocationDetails, "rootPath", ""),
146
+ accessKeyId: get(damLocationDetails, "accessKeyId", ""),
147
+ secretAccessKey: get(damLocationDetails, "secretAccessKey", ""),
148
+ url: get(damLocationDetails, "url", ""),
149
+ region: get(damLocationDetails, "region", ""),
150
+ },
151
+ });
152
+ }
153
+ }, [clientData, filteredTeams, form, existingClientData]);
130
154
  useEffect(() => {
131
155
  if (teamsApi && username && password) {
132
156
  fetchTeams();
@@ -153,6 +177,9 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
153
177
  console.log("Error while fetching external teams", err);
154
178
  }
155
179
  });
180
+ // Debug: Log edit mode and location type
181
+ const shouldShowExternalFields = damLocationType === "external" || isEditMode;
182
+ console.log("CreateClientForm - isEditMode:", isEditMode, "damLocationType:", damLocationType, "shouldShowExternalFields:", shouldShowExternalFields, "existingClientData:", existingClientData);
156
183
  return (_jsx(Drawer, { open: true, title: isEditMode ? "Edit Client" : "Create Client", onClose: toggleShow, width: 500, maskClosable: false, children: fetchingClientData ? (_jsx("div", { style: { textAlign: "center", padding: "20px" }, children: _jsx(Typography.Text, { children: "Loading client data..." }) })) : (_jsxs(Form, { layout: "vertical", form: form, onFinish: onFinish, children: [_jsx(Form.Item, { label: "Name", name: "name", rules: [
157
184
  {
158
185
  required: true,
@@ -175,41 +202,41 @@ const CreateClientForm = ({ teamsApi, username, password, toggleShow, onSuccess,
175
202
  },
176
203
  ], children: _jsx(Select, { options: DAM_LOCATION_TYPES, onChange: (e) => {
177
204
  onChangeDamLocationType(e);
178
- }, placeholder: "Type" }) }), damLocationType === "external" && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
205
+ }, placeholder: "Type" }) }), shouldShowExternalFields && (_jsxs(_Fragment, { children: [_jsx(Form.Item, { label: "Bucket", name: ["damLocationDetails", "bucket"], rules: [
179
206
  {
180
- required: true,
207
+ required: damLocationType === "external",
181
208
  message: "Bucket is required",
182
209
  },
183
- ], children: _jsx(Input, { placeholder: "Bucket" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
210
+ ], children: _jsx(Input, { placeholder: "Bucket", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Root Path", name: ["damLocationDetails", "rootPath"], rules: [
184
211
  {
185
- required: true,
212
+ required: damLocationType === "external",
186
213
  message: "Root path is required",
187
214
  },
188
- ], children: _jsx(Input, { placeholder: "Root path" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
215
+ ], children: _jsx(Input, { placeholder: "Root path", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Access Key", name: ["damLocationDetails", "accessKeyId"], rules: [
189
216
  {
190
- required: true,
217
+ required: damLocationType === "external",
191
218
  message: "Access key is required",
192
219
  },
193
- ], children: _jsx(Input, { placeholder: "Access Key" }) }), _jsx(Form.Item, { label: "Secret Access Key", name: ["damLocationDetails", "secretAccessKey"], rules: [
220
+ ], children: _jsx(Input, { placeholder: "Access Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Secret Access Key", name: ["damLocationDetails", "secretAccessKey"], rules: [
194
221
  {
195
- required: true,
222
+ required: damLocationType === "external",
196
223
  message: "Secret Access Key is required",
197
224
  },
198
- ], children: _jsx(Input, { placeholder: "Secret Key" }) }), _jsx(Form.Item, { label: "Url", name: ["damLocationDetails", "url"], rules: [
225
+ ], children: _jsx(Input, { placeholder: "Secret Key", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Url", name: ["damLocationDetails", "url"], rules: [
199
226
  {
200
- required: true,
227
+ required: damLocationType === "external",
201
228
  message: "Url is required",
202
229
  },
203
- ], children: _jsx(Input, { placeholder: "Url" }) }), _jsx(Form.Item, { label: "Region", name: ["damLocationDetails", "region"], rules: [
230
+ ], children: _jsx(Input, { placeholder: "Url", disabled: damLocationType === "internal" }) }), _jsx(Form.Item, { label: "Region", name: ["damLocationDetails", "region"], rules: [
204
231
  {
205
- required: true,
232
+ required: damLocationType === "external",
206
233
  message: "Region is required",
207
234
  },
208
- ], children: _jsx(Input, { placeholder: "Region" }) })] }))] }), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
235
+ ], children: _jsx(Input, { placeholder: "Region", disabled: damLocationType === "internal" }) })] }))] }), _jsx(Form.Item, { label: "Subdomain", name: "subdomain", rules: [
209
236
  {
210
237
  required: true,
211
238
  message: "Subdomain is required",
212
239
  },
213
- ], children: _jsx(Input, { placeholder: "Subdomain" }) }), _jsx(Form.Item, { name: "showFilePreview", valuePropName: "checked", initialValue: false, children: _jsx(Checkbox, { children: "Show File Preview" }) }), _jsx(Form.Item, { children: _jsx(Button, { htmlType: "submit", type: "primary", block: true, loading: loading, children: "Submit" }) })] })) }));
240
+ ], 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" }) })] })) }));
214
241
  };
215
242
  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.153",
3
+ "version": "5.8.154",
4
4
  "dependencies": {
5
5
  "@ant-design/icons": "^5.0.1",
6
6
  "@emoji-mart/data": "^1.2.1",