Skip to content

Commit

Permalink
Merge pull request #198 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1625 chore: list api called on event edit
  • Loading branch information
itsvick authored Aug 27, 2024
2 parents aa76a2d + 2283ae1 commit 91fd74d
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 17 deletions.
10 changes: 6 additions & 4 deletions public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,9 @@
"DELETE_ALL_SESSION_MSG": "Are you sure you want to delete all sessions in this series?",
"DELETE_THIS_SESSION": "Delete this session",
"DELETE_FOLLOWING_SESSION": "Delete this and following sessions",
"UPDATE_CHANGES": "Are you sure you want to update the changes?"
"UPDATE_CHANGES": "Are you sure you want to update the changes?",
"SESSION_DELETED_SUCCESSFULLY": "Session deleted successfully",
"SESSION_EDITED_SUCCESSFULLY": "Session updated successfully"
},
"MANAGE_USERS": {
"CENTERS_REQUESTED_SUCCESSFULLY": "Center requested successfully",
Expand Down Expand Up @@ -515,9 +517,9 @@
},
"BOARD_ENROLMENT": {
"BOARD_ENROLLMENT": "Board Enrollment",
"BOARD_SELECTION":"Board Selection",
"BOARD_SELECTION": "Board Selection",
"SUBJECTS_SELECTION": "Subjects Selection",
"REGISTRATION_COMPLETED":"Registration Completed",
"DROPPED_OUT":" Dropped Out"
"REGISTRATION_COMPLETED": "Registration Completed",
"DROPPED_OUT": " Dropped Out"
}
}
25 changes: 21 additions & 4 deletions src/components/PlannedSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
onEventDeleted,
eventData,
updateEvent,
onEventUpdated,
}) => {
const { t } = useTranslation();
const theme = useTheme<any>();
Expand Down Expand Up @@ -743,7 +744,10 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
};
const response = await editEvent(eventRepetitionId, apiBody);
if (response?.responseCode === 'OK') {
showToastMessage(t('COMMON.SESSION_DELETED_SUCCESSFULLY'), 'success');
showToastMessage(
t('CENTER_SESSION.SESSION_DELETED_SUCCESSFULLY'),
'success'
);
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
Expand All @@ -760,7 +764,17 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
if (updateEvent && eventData) {
console.log('eventData', eventData);
try {
const isMainEvent = true;
let isMainEvent;
if (eventData?.isRecurring === false) {
isMainEvent = true;
}
if (eventData?.isRecurring === true) {
if (editSelection === t('CENTER_SESSION.EDIT_THIS_SESSION')) {
isMainEvent = false;
} else {
isMainEvent = true;
}
}
const eventRepetitionId = eventData?.eventRepetitionId;
const apiBody: any = {
isMainEvent: isMainEvent,
Expand Down Expand Up @@ -860,9 +874,12 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
const response = await editEvent(eventRepetitionId, apiBody);
if (response?.responseCode === 'OK') {
showToastMessage(
t('COMMON.SESSION_EDITED_SUCCESSFULLY'),
t('CENTER_SESSION.SESSION_EDITED_SUCCESSFULLY'),
'success'
);
if (onEventUpdated) {
onEventUpdated();
}
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
Expand All @@ -872,7 +889,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
}
};
onUpdateEvent();
}, [updateEvent, eventData, sessionBlocks]);
}, [updateEvent]);

return (
<Box overflow={'hidden'}>
Expand Down
9 changes: 9 additions & 0 deletions src/components/SessionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
}
};

const onEventUpdated = () => {
setOpen(false);
if (isEventUpdated) {
isEventUpdated();
}
setUpdateEvent(false);
};

const handleSnackbarClose = () => setSnackbarOpen(false);

const handleCopyUrl = () => {
Expand Down Expand Up @@ -189,6 +197,7 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
editSession={editSession}
handleEditSelection={handleEditSelection}
onEventDeleted={onEventDeleted}
onEventUpdated={onEventUpdated}
eventDeleted={eventDeleted}
eventData={data}
updateEvent={updateEvent}
Expand Down
22 changes: 17 additions & 5 deletions src/pages/centers/[cohortId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const CohortPage = () => {
const [openAddLearnerModal, setOpenAddLearnerModal] = React.useState(false);
const [openSchedule, setOpenSchedule] = React.useState(false);
const [eventDeleted, setEventDeleted] = React.useState(false);

const [eventUpdated, setEventUpdated] = React.useState(false);
const [deleteModal, setDeleteModal] = React.useState(false);
const [cohortName, setCohortName] = React.useState<string>();
const [clickedBox, setClickedBox] = useState<string | null>(null);
Expand Down Expand Up @@ -226,13 +226,15 @@ const CohortPage = () => {
});
}
setSessions(sessionArray);
setEventUpdated(false);
setEventDeleted(false);
} catch (error) {
setSessions([]);
}
};

getSessionsData();
}, [selectedDate, eventCreated, eventDeleted]);
}, [selectedDate, eventCreated, eventDeleted, eventUpdated]);

useEffect(() => {
const getExtraSessionsData = async () => {
Expand Down Expand Up @@ -271,14 +273,19 @@ const CohortPage = () => {
setExtraSessions([]);
}
};

setEventUpdated(false);
setEventDeleted(false);
getExtraSessionsData();
}, [eventCreated, eventDeleted]);
}, [eventCreated, eventDeleted, eventUpdated]);

const handleEventDeleted = () => {
setEventDeleted(true);
};

const handleEventUpdated = () => {
setEventUpdated(true);
};

const handleChange = (event: React.SyntheticEvent, newValue: number) => {
setValue(newValue);
};
Expand Down Expand Up @@ -583,6 +590,7 @@ const CohortPage = () => {
<SessionCard
data={item}
isEventDeleted={handleEventDeleted}
isEventUpdated={handleEventUpdated}
>
<SessionCardFooter item={item} />
</SessionCard>
Expand Down Expand Up @@ -651,7 +659,11 @@ const CohortPage = () => {
<Grid container spacing={3}>
{sessions?.map((item) => (
<Grid item xs={12} sm={6} md={4} key={item.id}>
<SessionCard data={item} isEventDeleted={handleEventDeleted}>
<SessionCard
data={item}
isEventDeleted={handleEventDeleted}
isEventUpdated={handleEventUpdated}
>
<SessionCardFooter item={item} />
</SessionCard>
</Grid>
Expand Down
7 changes: 3 additions & 4 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ export interface PlannedModalProps {
editSelection?: string;
handleEditSelection?: (selection: string) => void;
onEventDeleted?: () => void;
onEventUpdated?: () => void;
updateEvent?: boolean;
editSession?: any;
eventData?: any;
Expand Down Expand Up @@ -446,7 +447,6 @@ export interface FacilitatorDrawerProps {
}
export interface CoursePlannerCardsProps {
resources: any;

}

export interface scheduleEventParam {
Expand Down Expand Up @@ -501,11 +501,10 @@ export interface Assessment {
export interface BoardEnrollment {
userId: number;
studentName: string;
center:string;
isDropout:boolean
center: string;
isDropout: boolean;
}


export interface AssessmentSubject {
userId: number;
subject: string;
Expand Down

0 comments on commit 91fd74d

Please sign in to comment.