Skip to content

Commit

Permalink
Merge pull request #15 from chaitanyakole/bug_fixes3
Browse files Browse the repository at this point in the history
[fix] Creating tenant admin,Tenant Archive hide,Cohort creation fails,Creating Cohort admin
  • Loading branch information
sudeeppr1998 authored Dec 26, 2024
2 parents 3c78bdc + 40031a2 commit 3176f22
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 53 deletions.
5 changes: 0 additions & 5 deletions src/components/TenantSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,6 @@
"fieldId": null,
"validation": [],
"description": "Enter tenant name."
},
"domain": {
"title": "Domain",
"type": "string",
"fieldId": null
}
},
"dependencies": {}
Expand Down
2 changes: 1 addition & 1 deletion src/pages/cohortAdminSchema.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"type": "string",
"fieldId": null,
"validation": [],
"description": "Enter the cohort name."
"description": "Enter Full Name."
},
"mobileNo": {
"title": "Mobile Number",
Expand Down
60 changes: 31 additions & 29 deletions src/pages/cohorts.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,14 @@ interface centerData {
customFieldValues?: string;
}

interface Roles {
code: string;
roleId: string;
}

interface RoleList {
result: Roles[];
}
const Center: React.FC = () => {
// use hooks
const queryClient = useQueryClient();
Expand Down Expand Up @@ -137,6 +145,7 @@ const Center: React.FC = () => {
const [updateBtnDisabled, setUpdateBtnDisabled] = React.useState(true);
const [addFormData, setAddFormData] = useState({});
const [addBtnDisabled, setAddBtnDisabled] = useState(true);
const [roleList, setRolelist] = useState<RoleList | undefined>(undefined);
const [previousTenantId, setPreviousTenantId] = useState<string | null>(null);
const [isCreateCohortAdminModalOpen, setIsCreateCohortAdminModalOpen] =
useState(false);
Expand Down Expand Up @@ -903,8 +912,6 @@ const Center: React.FC = () => {
};

const handleAdd = (rowData: any) => {
console.log("fnction called");

// const tenantId = rowData?.tenantId;
// const currentTenantId = localStorage.getItem("tenantId");
// setPreviousTenantId(currentTenantId);
Expand All @@ -917,7 +924,6 @@ const Center: React.FC = () => {
setAddmodalopen(true);
setLoading(false);
};
console.log({ previousTenantId });

// add extra buttons
const extraActions: any = [
Expand Down Expand Up @@ -1156,18 +1162,10 @@ const Center: React.FC = () => {
}>;
}

const roleObj = {
limit: "10",
page: 1,
filters: {
tenantId: selectedRowData?.tenantId,
},
};
const response = await rolesList(roleObj);
const matchedRole = response?.result?.find(
const matchedRole = roleList?.result?.find(
(role: any) => role.code === formData?.role
);
const roleId = matchedRole ? matchedRole?.roleId : null;
const roleId = matchedRole ? matchedRole?.roleId : "";

let obj: UserCreateData = {
name: formData?.name,
Expand All @@ -1184,8 +1182,6 @@ const Center: React.FC = () => {
],
};
const resp = await userCreate(obj as any, selectedRowData?.tenantId);
console.log({ selectedRowData, matchedRole, formData, response, resp });

if (resp?.responseCode === 200 || resp?.responseCode === 201) {
showToastMessage(t("USER.CREATE_SUCCESSFULLY"), "success");
setLoading(false);
Expand Down Expand Up @@ -1219,6 +1215,22 @@ const Center: React.FC = () => {
setIsCreateCohortAdminModalOpen(true);
};

useEffect(() => {
const fetchData = async () => {
const roleObj = {
limit: "10",
page: 1,
filters: {
tenantId: selectedRowData?.tenantId,
},
};

const response = await rolesList(roleObj, selectedRowData?.tenantId);
setRolelist(response);
};
fetchData();
}, [isCreateCohortAdminModalOpen, Addmodalopen]);

const handleAddCohortAdminAction = async (
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
Expand All @@ -1230,30 +1242,20 @@ const Center: React.FC = () => {
setLoading(true);
setConfirmButtonDisable(true);

const roleObj = {
limit: "10",
page: 1,
filters: {
tenantId: selectedRowData?.tenantId,
},
};
const response = await rolesList(roleObj);
console.log({ selectedRowData, response, formData });

const cohortAdminRole = response?.result.find(
const cohortAdminRole = roleList?.result.find(
(item: any) => item.code === "cohort_admin"
);

let obj = {
name: formData?.name,
username: formData?.username,
password: formData?.password,
mobile: formData?.mobileNo ? formData?.mobileNo : "",
email: formData?.email ? formData?.email : "",
mobile: formData?.mobileNo,
email: formData?.email,

tenantCohortRoleMapping: [
{
roleId: cohortAdminRole.roleId,
roleId: cohortAdminRole?.roleId,
tenantId: selectedRowData?.tenantId,
cohortId: [selectedRowData?.cohortId],
},
Expand Down
10 changes: 5 additions & 5 deletions src/pages/tenant.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ const Tenant: React.FC = () => {
status: formData?.status,
type: formData?.type,
};
const resp = await cohortCreate(obj);
const resp = await cohortCreate(obj, selectedRowData?.tenantId);

if (resp?.responseCode === 200 || resp?.responseCode === 201) {
showToastMessage(t("COHORTS.CREATE_SUCCESSFULLY"), "success");
Expand Down Expand Up @@ -966,7 +966,7 @@ const Tenant: React.FC = () => {
tenantId: selectedRowData?.tenantId,
},
};
const response = await rolesList(roleObj);
const response = await rolesList(roleObj, selectedRowData?.tenantId);
const tenantAdminRole = response?.result.find(
(item: any) => item.code === "tenant_admin"
);
Expand All @@ -975,8 +975,8 @@ const Tenant: React.FC = () => {
name: formData?.name,
username: formData?.username,
password: formData?.password,
mobile: formData?.mobileNo ? formData?.mobileNo : "",
email: formData?.email ? formData?.email : "",
mobile: formData?.mobileNo,
email: formData?.email,
tenantCohortRoleMapping: [
{
roleId: tenantAdminRole.roleId,
Expand Down Expand Up @@ -1264,7 +1264,7 @@ const Tenant: React.FC = () => {
showAddNew: adminRole == true ? true : false,
// showAddNew: true,
showSearch: false,
statusArchived: true,
statusArchived: false,
handleAddUserClick: handleAddUserClick,
statusValue: statusValue,
setStatusValue: setStatusValue,
Expand Down
34 changes: 21 additions & 13 deletions src/services/CohortService/cohortService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,22 +139,28 @@ export const updateCohortMemberStatus = async ({
status: memberStatus,
statusReason,
});
console.log('data', response?.data);
return response?.data;
} catch (error) {
console.error('error in attendance report api ', error);
// throw error;
}
};

export const cohortCreate = async (data: cohortListData): Promise<any> => {
export const cohortCreate = async (data: cohortListData, tenantId: string): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/${config.URLS.COHORT_CREATE}`;

try {
const response = await post(apiUrl, data);
const token=localStorage.getItem('token')
const response = await axios.post(apiUrl, data, {
headers: {
'Authorization': `Bearer ${token}`,
'Content-Type':'application/json',
'tenantId': tenantId,
},
});
return response?.data;
} catch (error) {
console.error("Error in Getting cohort List Details", error);
console.error("Error in Creating Cohort", error);
return error;
}
};
Expand Down Expand Up @@ -212,9 +218,7 @@ data:any
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/${config.URLS.TENANT_CREATE}`;

try {
const response = await post(apiUrl, data);
console.log({response});

const response = await post(apiUrl, data);
return response?.data;
} catch (error) {
console.error("Error in Getting cohort List Details", error);
Expand All @@ -226,7 +230,6 @@ data:any

try {
const response = await post(apiUrl, data);
console.log({response});

return response?.data;
} catch (error) {
Expand All @@ -249,21 +252,27 @@ data:any
throw error;
}
};
export const rolesList = async (data: cohortListData): Promise<any> => {
export const rolesList = async (data: cohortListData, tenantId: string): Promise<any> => {
let apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/${config.URLS.ROLES_LIST}`;

try {
const response = await post(apiUrl, data);
const token=localStorage.getItem('token')
const response = await axios.post(apiUrl, data, {
headers: { 'Authorization': `Bearer ${token}`,
'Content-Type':'application/json',
'tenantId': tenantId,
},
});
return response?.data;
} catch (error) {
console.error("Error in Getting cohort List Details", error);
console.error("Error in Getting Roles List", error);
return error;
}
};

export const userCreate = async (data: cohortListData, userTenantId: string): Promise<any> => {
const apiUrl: string = `${process.env.NEXT_PUBLIC_BASE_URL}/${config.URLS.USER_CREATE}`;

try {
const token=localStorage.getItem('token')
const headers = {
Expand All @@ -273,7 +282,6 @@ data:any
};

const response = await axios.post(apiUrl, data, { headers });
console.log({response});
return response?.data;
} catch (error) {
console.error('Error in Creating User:', error);
Expand Down

0 comments on commit 3176f22

Please sign in to comment.