Skip to content

Commit

Permalink
Task #223476: remove array
Browse files Browse the repository at this point in the history
  • Loading branch information
upendraTekdi committed Jul 30, 2024
1 parent a42d627 commit cd25825
Showing 1 changed file with 26 additions and 23 deletions.
49 changes: 26 additions & 23 deletions src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -362,30 +362,36 @@ const UserTable: React.FC<UserTableProps> = ({
let initialFormData: any = {};
formFields.fields.forEach((item: any) => {
const userData = response?.userData;
const customField = userData?.customFields?.find((field: any) => field.fieldId === item.fieldId);

const customField = userData?.customFields?.find(
(field: any) => field.fieldId === item.fieldId
);

const getValue = (data: any, field: any) => {
if (item?.isMultiSelect) {
if (item?.type === 'checkbox') {
return String(field.value).split(',');
if (item?.type === "checkbox") {
return String(field.value).split(",");
}
return [field.value];
} else {
if (item?.type === 'numeric') {
if (item?.type === "numeric") {
return Number(field.value);
} else if (item?.type === 'text') {
} else if (item?.type === "text") {
return String(field.value);
} else {
return field.value;
}
}
};

if (item.coreField) {
initialFormData[item.name] = item?.isMultiSelect
? userData[item.name] ? [userData[item.name]] : userData[item.name] || ''
: item?.type === 'numeric' ? Number(userData[item.name])
: item?.type === 'text' ? String(userData[item.name])
? userData[item.name]
? [userData[item.name]]
: userData[item.name] || ""
: item?.type === "numeric"
? Number(userData[item.name])
: item?.type === "text"
? String(userData[item.name])
: userData[item.name];
} else {
initialFormData[item.name] = getValue(userData, customField);
Expand All @@ -395,14 +401,14 @@ const UserTable: React.FC<UserTableProps> = ({
};
const handleEdit = async (rowData: any) => {
console.log("Edit row:", rowData);

try {
const userId = rowData.userId;
setUserId(userId);
const fieldValue = true;
const response = await getUserDetails(userId, fieldValue);
console.log(role);

let formFields;
if (Role.STUDENT === role) {
formFields = await getFormRead("USERS", "STUDENT");
Expand All @@ -413,7 +419,7 @@ const UserTable: React.FC<UserTableProps> = ({
setFormData(mapFields(formFields, response));
handleOpenAddFacilitatorModal();
}

console.log("response", response);
console.log("formFields", formFields);
} catch (error) {
Expand Down Expand Up @@ -553,12 +559,10 @@ const UserTable: React.FC<UserTableProps> = ({
console.log(selectedUserId);
const userId = selectedUserId;
const userData = {
userData: [
{
reason: selectedReason,
status: "archived",
},
],
userData: {
reason: selectedReason,
status: "archived",
},
};
const response = await deleteUser(userId, userData);
handleCloseDeleteModal();
Expand Down Expand Up @@ -587,10 +591,9 @@ const UserTable: React.FC<UserTableProps> = ({
handleFilterChange: handleFilterChange,
handleSearch: handleSearch,
handleAddUserClick: handleAddUserClick,
selectedBlockCode:selectedBlockCode,
selectedDistrictCode:selectedDistrictCode,
selectedStateCode:selectedStateCode

selectedBlockCode: selectedBlockCode,
selectedDistrictCode: selectedDistrictCode,
selectedStateCode: selectedStateCode,
};

return (
Expand Down

0 comments on commit cd25825

Please sign in to comment.