Skip to content

Commit 39421c5

Browse files
authored
Merge pull request #2551 from Rushikesh-Sonawane99/feat-batch-revamp
Issue #PS-6251 fix: Fixed issue Edit center - the Google map link and Address field appear if the Type of Center set Remote
2 parents c74003c + db68adf commit 39421c5

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

apps/admin-app-repo/src/components/BatchFlow/BatchFlow.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,9 @@ const BatchFlow: React.FC<BatchFlowProps> = ({
149149
// Modify batch_type based on centerType
150150
if (centerType && alterSchema?.properties?.batch_type) {
151151
if (centerType === 'remote') {
152-
// For remote center: set default to "remote" and disable the field
152+
// For remote center: show only "remote" option
153+
alterSchema.properties.batch_type.enum = ['remote'];
154+
alterSchema.properties.batch_type.enumNames = ['REMOTE'];
153155
alterSchema.properties.batch_type.default = 'remote';
154156
if (alterUiSchema?.batch_type) {
155157
alterUiSchema.batch_type['ui:disabled'] = true;

apps/admin-app-repo/src/pages/centers.tsx

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ const Centers = () => {
5050
const [uiSchema, setUiSchema] = useState(CohortSearchUISchema);
5151
const [addSchema, setAddSchema] = useState(null);
5252
const [addUiSchema, setAddUiSchema] = useState(null);
53+
const [originalAddUiSchema, setOriginalAddUiSchema] = useState(null);
5354
const [prefilledAddFormData, setPrefilledAddFormData] = useState({});
5455
const [pageLimit, setPageLimit] = useState<number>(10);
5556
const [pageOffset, setPageOffset] = useState<number>(0);
@@ -164,6 +165,7 @@ const Centers = () => {
164165
alterUISchema = enhanceUiSchemaWithGrid(alterUISchema);
165166

166167
setAddUiSchema(alterUISchema);
168+
setOriginalAddUiSchema(alterUISchema);
167169

168170
// Uncomment for remote center changes
169171
// // console.log('####1:', alterSchema);
@@ -495,6 +497,32 @@ const Centers = () => {
495497
callback: (row: any) => {
496498
let tempFormData = extractMatchingKeys(row, addSchema);
497499
console.log('######## images value tempFormData', tempFormData);
500+
// console.log('######## images value row', row);
501+
// console.log('######## images value addSchema', addSchema);
502+
503+
// Hide address and google_map_link fields when center_type is 'remote'
504+
if (tempFormData.center_type === 'remote') {
505+
const modifiedUiSchema = JSON.parse(
506+
JSON.stringify(originalAddUiSchema || addUiSchema)
507+
);
508+
if (modifiedUiSchema.address) {
509+
modifiedUiSchema.address = {
510+
...modifiedUiSchema.address,
511+
'ui:widget': 'hidden',
512+
};
513+
}
514+
if (modifiedUiSchema.google_map_link) {
515+
modifiedUiSchema.google_map_link = {
516+
...modifiedUiSchema.google_map_link,
517+
'ui:widget': 'hidden',
518+
};
519+
}
520+
setAddUiSchema(modifiedUiSchema);
521+
} else {
522+
// Restore original UI schema for non-remote centers
523+
setAddUiSchema(originalAddUiSchema || addUiSchema);
524+
}
525+
498526
setPrefilledAddFormData(tempFormData);
499527
setIsEdit(true);
500528
setEditableUserId(row?.cohortId);
@@ -577,6 +605,10 @@ const Centers = () => {
577605
const handleOpenModal = () => setOpenModal(true);
578606

579607
const handleCloseModal = () => {
608+
// Restore original UI schema when closing modal
609+
if (originalAddUiSchema) {
610+
setAddUiSchema(originalAddUiSchema);
611+
}
580612
setOpenModal(false);
581613
};
582614

@@ -622,6 +654,10 @@ const Centers = () => {
622654
width: '200px',
623655
}}
624656
onClick={() => {
657+
// Restore original UI schema when creating new center
658+
if (originalAddUiSchema) {
659+
setAddUiSchema(originalAddUiSchema);
660+
}
625661
setPrefilledAddFormData(initialFormData);
626662
setIsEdit(false);
627663
setEditableUserId('');

0 commit comments

Comments
 (0)