Skip to content

Commit

Permalink
Merge pull request #216 from AkshataKatwal16/admin
Browse files Browse the repository at this point in the history
Issue feat: Add  cohort ids in combine response for option reacd an cohort search
  • Loading branch information
itsvick authored Sep 18, 2024
2 parents 825e708 + 0921f08 commit baeaca3
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 58 deletions.
36 changes: 13 additions & 23 deletions src/components/ReassignCenterModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import { useLocationState } from "@/utils/useLocationState";
import AreaSelection from "./AreaSelection";
import { transformArray } from "../utils/Helper";
import { firstLetterInUpperCase } from "./../utils/Helper";
import useSubmittedButtonStore from "@/utils/useSharedState";

interface ReassignCohortModalProps {
open: boolean;
Expand Down Expand Up @@ -104,7 +105,10 @@ const {
console.log(blockCode)
console.log(selectedBlock)
const names = cohortData.map((item : any)=> item.name);

const setReassignButtonStatus = useSubmittedButtonStore((state:any) => state.setReassignButtonStatus);
const reassignButtonStatus = useSubmittedButtonStore(
(state: any) => state.reassignButtonStatus
);
console.log(names);

const [searchInput, setSearchInput] = useState("");
Expand Down Expand Up @@ -290,32 +294,16 @@ const {

let unSelectedBlockCohortIds: string[] = [];

for (const code of unSelectedData) {
const reassignBlockObject = {
limit: 200,
offset: 0,
filters: {
status: ['active'],
name: code,
},
}
const centerResponse = await getCenterList(reassignBlockObject);
const cohortDetailsInfo = centerResponse?.result?.results?.cohortDetails;
const unSelectedBlockCohortIdValue = cohortDetailsInfo?.find(
(item: any) => item?.type === 'BLOCK'
)?.cohortId;

if (unSelectedBlockCohortIdValue) {
unSelectedBlockCohortIds.push(unSelectedBlockCohortIdValue);
}

}

unSelectedBlockCohortIds.push(previousBlockId);

let cohortIds = blocks
.filter((item:any) => item.label !== checkedCenters[0])
.map((item:any) => item.cohortId);
cohortIds.push(previousBlockId)
payload = {
userId: [userId],
cohortId: [selectedBlockCohortId],
removeCohortId:unSelectedBlockCohortIds,
removeCohortId:cohortIds,
};

await bulkCreateCohortMembers(payload);
Expand Down Expand Up @@ -359,6 +347,8 @@ const {
t("COMMON.BLOCKS_REASSIGN_SUCCESSFULLY"),
"success"
);
reassignButtonStatus ? setReassignButtonStatus(false) : setReassignButtonStatus(true);

}
} catch (error) {
showToastMessage(
Expand Down
7 changes: 6 additions & 1 deletion src/components/UserTable.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import { useQuery } from "@tanstack/react-query";
import ReassignCenterModal from "./ReassignCenterModal";
import { getCenterList, getStateBlockDistrictList } from "@/services/MasterDataService";
import { updateCohortMemberStatus } from "@/services/CohortService/cohortService";
import useSubmittedButtonStore from "@/utils/useSharedState";
type UserDetails = {
userId: any;
username: any;
Expand Down Expand Up @@ -153,6 +154,9 @@ const UserTable: React.FC<UserTableProps> = ({
const [openAddLearnerModal, setOpenAddLearnerModal] = React.useState(false);
const [userId, setUserId] = useState();
const [submitValue, setSubmitValue] = useState<boolean>(false);
const reassignButtonStatus = useSubmittedButtonStore(
(state: any) => state.reassignButtonStatus
);
const { data:teacherFormData ,isLoading: teacherFormDataLoading, error :teacherFormDataErrror } = useQuery<any[]>({
queryKey: ["teacherFormData"],
queryFn: () => Promise.resolve([]),
Expand Down Expand Up @@ -806,7 +810,8 @@ const UserTable: React.FC<UserTableProps> = ({
filters,
parentState,
deleteUserState,
sortByForCohortMemberList
sortByForCohortMemberList,
reassignButtonStatus
]);

useEffect(() => {
Expand Down
71 changes: 38 additions & 33 deletions src/services/formatedCohorts.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,47 +69,52 @@ export const formatedDistricts = async () => {

export const formatedBlocks = async (districtCode: string) => {
const adminState = JSON.parse(
localStorage.getItem("adminInfo") || "{}"
).customFields.find(
(field: any) => field.label === "STATES"
);;
try {
const reqParams = {
localStorage.getItem("adminInfo") || "{}"
).customFields.find(
(field: any) => field.label === "STATES"
);
try {
const reqParams = {
limit: 0,
offset: 0,
filters: {
// name: searchKeyword,
// name: searchKeyword,
states: adminState.code,
districts:districtCode,

districts: districtCode,
type: CohortTypes.BLOCK,
status: ["active"]
status: ["active"],
},
sort: ["name", "asc"],
sort: ["name", "asc"],
};

const response = await getCohortList(reqParams);
const cohortDetails = response?.results?.cohortDetails || [];

const cohortDetails = response?.results?.cohortDetails || [];
const object = {
controllingfieldfk:districtCode,
fieldName: "blocks",
};
const optionReadResponse = await getStateBlockDistrictList(object);
//console.log(blockFieldId)
const result = optionReadResponse?.result?.values;
console.log(cohortDetails)
console.log(result)
const matchedCohorts = result?.map((value: any) => {
const cohortMatch = cohortDetails.find((cohort: any )=> cohort.name === value.label);
return cohortMatch ? { ...value } : null;
}).filter(Boolean);
console.log(matchedCohorts);

return matchedCohorts;

} catch (error) {
console.log('Error in getting Channel Details', error);
return error;
}
const object = {
controllingfieldfk: districtCode,
fieldName: "blocks",
};
const optionReadResponse = await getStateBlockDistrictList(object);
const result = optionReadResponse?.result?.values;

console.log(cohortDetails);
console.log(result);

const matchedCohorts = result
?.map((value: any) => {
const cohortMatch = cohortDetails.find(
(cohort: any) => cohort.name === value.label
);
// Include cohortId if the match is found
return cohortMatch ? { ...value, cohortId: cohortMatch.cohortId } : null;
})
.filter(Boolean);


return matchedCohorts;
} catch (error) {
console.log("Error in getting Channel Details", error);
return error;
}
};

3 changes: 2 additions & 1 deletion src/utils/useLocationState.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,7 @@ export const useLocationState = (
useEffect(() => {
const fetchData = async () => {
try {
if(open){
const response = await queryClient.fetchQuery({
queryKey: [
QueryKeys.FIELD_OPTION_READ,
Expand Down Expand Up @@ -412,7 +413,7 @@ export const useLocationState = (
//console.log(result)
// setStates(result);
console.log(typeof states);
} catch (error) {
}} catch (error) {
console.log(error);
}
};
Expand Down
3 changes: 3 additions & 0 deletions src/utils/useSharedState.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ const useSubmittedButtonStore = create((set) => ({
submittedButtonStatus: false,
setSubmittedButtonStatus: (status: boolean) =>
set({ submittedButtonStatus: status }),
reassignButtonStatus: false,
setReassignButtonStatus: (status: boolean) =>
set({ reassignButtonStatus: status }),
adminInformation: {},
setAdminInformation: (data: any) => set({ adminInformation: data }),
// setSubmittedButtonStatus: (status: boolean) => set({ submittedButtonStatus: status }),
Expand Down

0 comments on commit baeaca3

Please sign in to comment.