Skip to content

Commit

Permalink
Merge branch 'release-1.0.0' of github.com:tekdi/shiksha-admin
Browse files Browse the repository at this point in the history
  • Loading branch information
itsvick committed Nov 29, 2024
2 parents 5f7dd11 + e17e3eb commit 51c4022
Show file tree
Hide file tree
Showing 3 changed files with 175 additions and 160 deletions.
148 changes: 75 additions & 73 deletions src/pages/block.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -826,45 +826,46 @@ const setIsArchived = useSubmittedButtonStore(
};

try {
const response = await createOrUpdateOption(blocksFieldId, newDistrict);
const response = await createOrUpdateOption(blocksFieldId, newDistrict, t);

if (response) {
await fetchBlocks();
}
} catch (error) {
console.error("Error adding district:", error);
}

const queryParameters = {
name: name,
type: CohortTypes.BLOCK,
status: Status.ACTIVE,
parentId: cohortId || "",
customFields: [
{
fieldId: stateFieldId, // state fieldId
value: [stateCode], // state code
},

{
fieldId: districtFieldId, // district fieldId
value: [controllingField], // district code
},
],
};

try {
const cohortCreateResponse = await createCohort(queryParameters);
if (cohortCreateResponse) {
filteredCohortOptionData();
showToastMessage(t("COMMON.BLOCK_ADDED_SUCCESS"), "success");
} else if (cohortCreateResponse.responseCode === 409) {
const queryParameters = {
name: name,
type: CohortTypes.BLOCK,
status: Status.ACTIVE,
parentId: cohortId || "",
customFields: [
{
fieldId: stateFieldId, // state fieldId
value: [stateCode], // state code
},

{
fieldId: districtFieldId, // district fieldId
value: [controllingField], // district code
},
],
};

try {
const cohortCreateResponse = await createCohort(queryParameters);
if (cohortCreateResponse) {
filteredCohortOptionData();
showToastMessage(t("COMMON.BLOCK_ADDED_SUCCESS"), "success");
} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
console.error("Error adding district:", error);
}


setModalOpen(false);
setSelectedStateForEdit(null);
};
Expand Down Expand Up @@ -892,56 +893,57 @@ if(updatedBy)
],
};
try {
const response = await createOrUpdateOption(blocksFieldId, newDistrict);
const response = await createOrUpdateOption(blocksFieldId, newDistrict, t);

if (response) {
filteredCohortOptionData();
}
} catch (error) {
console.error("Error adding district:", error);
}

const queryParameters = {
name: name,
updatedBy:localStorage.getItem('userId'),

};

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);
if (cohortCreateResponse) {
await fetchBlocks();
await getCohortSearchBlock(selectedDistrict);
showToastMessage(t("COMMON.BLOCK_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];


const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'block-update-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
const queryParameters = {
name: name,
updatedBy:localStorage.getItem('userId'),
};

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);
if (cohortCreateResponse) {
await fetchBlocks();
await getCohortSearchBlock(selectedDistrict);
showToastMessage(t("COMMON.BLOCK_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];


const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'block-update-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.BLOCK_DUPLICATION_FAILURE"), "error");
console.error("Error adding district:", error);
}


setModalOpen(false);
setSelectedStateForEdit(null);
}
Expand Down
174 changes: 89 additions & 85 deletions src/pages/district.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -442,60 +442,61 @@ const response= await getCohortList(reqParams)
],
};
try {
const response = await createOrUpdateOption(districtFieldId, newDistrict);
const response = await createOrUpdateOption(districtFieldId, newDistrict, t);

if (response) {
queryClient.invalidateQueries({
queryKey: [QueryKeys.FIELD_OPTION_READ, stateCode || "", "districts"],
});
await fetchDistricts();
}
} catch (error) {
console.error("Error adding district:", error);
}

const queryParameters = {
name: name,
type: CohortTypes.DISTRICT,
status: Status.ACTIVE,
parentId: cohortIdofState,
customFields: [
{
fieldId: stateFieldId,
value: [stateCode],
const queryParameters = {
name: name,
type: CohortTypes.DISTRICT,
status: Status.ACTIVE,
parentId: cohortIdofState,
customFields: [
{
fieldId: stateFieldId,
value: [stateCode],
},
],
};

try {
const cohortCreateResponse = await createCohort(queryParameters);
if (cohortCreateResponse) {
filteredCohortOptionData();
showToastMessage(t("COMMON.DISTRICT_ADDED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];

const telemetryInteract = {
context: {
env: env,
cdata: [],
},
],
};

try {
const cohortCreateResponse = await createCohort(queryParameters);
if (cohortCreateResponse) {
filteredCohortOptionData();
showToastMessage(t("COMMON.DISTRICT_ADDED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];

const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'district-created-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);
} else if (cohortCreateResponse.responseCode === 409) {
edata: {
id: 'district-created-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);
} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
console.error("Error adding district:", error);
}


setModalOpen(false);
setSelectedStateForEdit(null);
};
Expand Down Expand Up @@ -525,7 +526,7 @@ if(updatedBy)
};

try {
const response = await createOrUpdateOption(districtFieldId, newDistrict);
const response = await createOrUpdateOption(districtFieldId, newDistrict, t);

if (response) {
setDistrictsOptionRead((prevDistricts: any[]) =>
Expand All @@ -539,54 +540,57 @@ if(updatedBy)
queryKey: [QueryKeys.FIELD_OPTION_READ, stateCode, "districts"],
});
}
} catch (error) {
console.error("Error adding district:", error);
}

const queryParameters = {
name: name,
updatedBy:localStorage.getItem('userId'),

};

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);

if (cohortCreateResponse) {
queryClient.invalidateQueries({
queryKey: [QueryKeys.FIELD_OPTION_READ, stateCode, "districts"],
});

showToastMessage(t("COMMON.DISTRICT_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];
const queryParameters = {
name: name,
updatedBy:localStorage.getItem('userId'),

const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'district-updated-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
};

try {
const cohortCreateResponse = await updateCohort(
cohortIdForEdit,
queryParameters
);

if (cohortCreateResponse) {
queryClient.invalidateQueries({
queryKey: [QueryKeys.FIELD_OPTION_READ, stateCode, "districts"],
});

showToastMessage(t("COMMON.DISTRICT_UPDATED_SUCCESS"), "success");
const windowUrl = window.location.pathname;
const cleanedUrl = windowUrl.replace(/^\//, '');
const env = cleanedUrl.split("/")[0];

const telemetryInteract = {
context: {
env: env,
cdata: [],
},
edata: {
id: 'district-updated-success',
type: TelemetryEventType.CLICK,
subtype: '',
pageid: cleanedUrl,
},
};
telemetryFactory.interact(telemetryInteract);

} else if (cohortCreateResponse.responseCode === 409) {
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
}
} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
}


} catch (error) {
console.error("Error creating cohort:", error);
showToastMessage(t("COMMON.DISTRICT_DUPLICATION_FAILURE"), "error");
console.error("Error adding district:", error);
}



setModalOpen(false);
setSelectedStateForEdit(null);
}
Expand Down
Loading

0 comments on commit 51c4022

Please sign in to comment.