Skip to content

Commit

Permalink
Merge pull request #241 from upendraTekdi/latest_code_admin_oblf
Browse files Browse the repository at this point in the history
Task #226317 : User can create same class with 2 different school codes which should not happen
  • Loading branch information
itsvick authored Oct 8, 2024
2 parents 9c64b27 + 589452a commit 82d897b
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 17 deletions.
10 changes: 7 additions & 3 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,9 @@
"CLASS_ADDED_SUCCESS": "Class Added Successfully!",
"CLASS_NOT_FOUND": "Class not found",
"SCHOOL_NAME_REQUIRED": "School Name Required",
"SCHOOL_CODE_REQUIRED": "School Code Required"
"SCHOOL_CODE_REQUIRED": "School Code Required",
"CLUSTER_NAME_REQUIRED": "Cluster Name Required",
"SCHOOL_CODE_NOT_UNIQUE": "School Code Not Unique"
},
"LOGIN_PAGE": {
"USERNAME": "Username",
Expand Down Expand Up @@ -305,7 +307,7 @@
"DUPLICATION_ENTRY": "Duplicate Entry",
"CENTER_CREATED_SUCCESSFULLY": "Center Created Successfully",
"NOT_ABLE_CREATE_CENTER": "Not Able To Create Center",
"NO_COHORT_ID_SELECTED":"No Cohort Id Selected"
"NO_COHORT_ID_SELECTED": "No Cohort Id Selected"
},
"FORM": {
"FULL_NAME": "Full Name",
Expand Down Expand Up @@ -409,7 +411,9 @@
"REASON_FOR_LEAVING": "Reason For Leaving",
"EMPLOYEE_ID": "Employee Id",
"FROM_TIME": "From Time",
"TO_TIME": "To Time"
"TO_TIME": "To Time",
"CLUSTER_NAME_REQUIRED": "Cluster Name Required",
"SCHOOL_CODE_NOT_UNIQUE": "School Code Not Unique"
},
"FORM_ERROR_MESSAGES": {
"INVALID_INPUT": "Invalid Input.",
Expand Down
12 changes: 8 additions & 4 deletions src/components/AddSchoolModal.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ interface AddSchoolModalProps {
controllingField?: string;
};
districtId?: string;
validateDuplicateData: any;
}

export const AddSchoolModal: React.FC<AddSchoolModalProps> = ({
Expand All @@ -43,6 +44,7 @@ export const AddSchoolModal: React.FC<AddSchoolModalProps> = ({
fieldId,
initialValues = {},
districtId,
validateDuplicateData,
}) => {
const [formData, setFormData] = useState({
name: initialValues.name || "",
Expand Down Expand Up @@ -99,7 +101,10 @@ export const AddSchoolModal: React.FC<AddSchoolModalProps> = ({
return t("COMMON.INVALID_TEXT");

const isUnique = (fieldName: string, value: string) => {
return true;
const exists = validateDuplicateData?.some(
(item: any) => item[fieldName] === value
);
return !exists;
};

if (field === "name" && !isUnique("name", value)) {
Expand Down Expand Up @@ -143,9 +148,6 @@ export const AddSchoolModal: React.FC<AddSchoolModalProps> = ({
(e: React.ChangeEvent<HTMLInputElement | { value: unknown }>) => {
let value = typeof e.target.value === "string" ? e.target.value : "";

// if (field === "value") {
// value = value.toUpperCase().slice(0, 3);
// }
setFormData((prev) => ({ ...prev, [field]: value }));

let errorMessage: string | null = null;
Expand All @@ -162,13 +164,15 @@ export const AddSchoolModal: React.FC<AddSchoolModalProps> = ({
value,
t("COMMON.SCHOOL_CODE_REQUIRED")
);

} else if (field === "controllingField") {
errorMessage = validateField(
field,
value,
t("COMMON.CLUSTER_NAME_REQUIRED")
);
}

setErrors((prev) => ({
...prev,
[field]: errorMessage,
Expand Down
43 changes: 34 additions & 9 deletions src/pages/centers.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ import { showToastMessage } from "@/components/Toastify";
import AddNewCenters from "@/components/AddNewCenters";
import { getCenterTableData } from "@/data/tableColumns";
import { Theme } from "@mui/system";
import { adjustTime, firstLetterInUpperCase, mapFields } from "@/utils/Helper";
import { adjustTime, convertTo12HourFormat, firstLetterInUpperCase, mapFields } from "@/utils/Helper";
import SimpleModal from "@/components/SimpleModal";
import { IChangeEvent } from "@rjsf/core";
import { RJSFSchema } from "@rjsf/utils";
Expand Down Expand Up @@ -744,6 +744,7 @@ const Center: React.FC = () => {
// }
// };


const handleUpdateAction = async (
data: IChangeEvent<any, RJSFSchema, any>,
event: React.FormEvent<any>
Expand Down Expand Up @@ -782,6 +783,13 @@ const Center: React.FC = () => {
(item: any) => item.name === "to_time"
);

const slotFieldOptions = centerFormData?.fields.find(
(item: any) => item.name === "slots"
);

const slotField = slotFieldOptions?.options.find(
(item: any) => item.value === formData?.slots
);
console.log("fromTimeOption", fromTimeOption);

// Extract the field IDs dynamically
Expand All @@ -790,11 +798,20 @@ const Center: React.FC = () => {
const schoolFieldId = schoolOption?.fieldId || "";
const classFieldId = classOption?.fieldId || "";

console.log("formDataFOR EDIT", formData);

const getFromTime = convertTo12HourFormat(formData?.from_time);
const getToTime = convertTo12HourFormat(formData?.to_time);

// Initialize the API body similar to handleSubmit
let cohortDetails: CohortDetails = {
name: schoolField.label + ", " + classField.label + ", ",
name:
schoolField.label +
", " +
classField.label +
", " +
getFromTime +
" - " +
getToTime,
customFields: [
{
fieldId: fromTimeFieldId,
Expand Down Expand Up @@ -1029,11 +1046,19 @@ const Center: React.FC = () => {

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

// const { timePlus5, timeMinus5 } = getModifiedTimes(slotField.label);
const getFromTime = convertTo12HourFormat(formData?.from_time);
const getToTime = convertTo12HourFormat(formData?.to_time);
// const { timePlus5, timeMinus5 } = getModifiedTimes(slotField?.label);

const newClassCohort = {
name: schoolField.label + ", " + classField.label + ", ",
name:
schoolField.label +
", " +
classField.label +
", " +
getFromTime +
" - " +
getToTime,
type: "COHORT",
parentId: parentCohort.cohortId,
params: {
Expand Down Expand Up @@ -1092,9 +1117,9 @@ const Center: React.FC = () => {
};

const convertTo24HourFormat = (time12h: any) => {
const [time, modifier] = time12h.split(" ");
const [time, modifier] = time12h?.split(" ");

let [hours, minutes] = time.split(":");
let [hours, minutes] = time?.split(":");
hours = parseInt(hours, 10);

if (modifier === "PM" && hours !== 12) {
Expand All @@ -1120,7 +1145,7 @@ const Center: React.FC = () => {
};

const getModifiedTimes = (timeRange: any) => {
const startTime12h = timeRange.split(" - ")[0];
const startTime12h = timeRange?.split(" - ")[0];
const startTime24h = convertTo24HourFormat(startTime12h);

const timePlus5 = addMinutes(startTime24h, 5);
Expand Down
4 changes: 3 additions & 1 deletion src/pages/school.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ const Block: React.FC = () => {
}
};
fetchUserDetail();

}, []);

useEffect(() => {
Expand Down Expand Up @@ -272,7 +273,7 @@ const Block: React.FC = () => {
setLoading(false);
}
};

console.log("blockData2",blockData)
useEffect(() => {
fetchSchools(selectedCluster);
}, [searchKeyword, selectedCluster, sortBy, pageOffset, pageLimit]);
Expand Down Expand Up @@ -558,6 +559,7 @@ const Block: React.FC = () => {
}
: {}
}
validateDuplicateData = {blockData}
/>

<ConfirmationModal
Expand Down
9 changes: 9 additions & 0 deletions src/utils/Helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -299,3 +299,12 @@ export const adjustTime = (timeStr: any, minutes: any) => {

return `${hours}:${minutesStr}:${seconds}`;
};


export const convertTo12HourFormat=(time: any)=> {
const [hours, minutes] = time?.split(":").map(Number);
const period = hours >= 12 ? "PM" : "AM";
const convertedHours = hours % 12 || 12; // Converts 0 to 12 for midnight and noon

return `${convertedHours}:${String(minutes).padStart(2, "0")} ${period}`;
}

0 comments on commit 82d897b

Please sign in to comment.