Skip to content

Commit

Permalink
Merge pull request #195 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #PS-1625 feat: edit events data mapping for extra -online and offline events - API integration done
  • Loading branch information
itsvick authored Aug 27, 2024
2 parents b81cd52 + cf500e7 commit 1a2f828
Show file tree
Hide file tree
Showing 3 changed files with 152 additions and 47 deletions.
159 changes: 127 additions & 32 deletions src/components/PlannedSession.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ import { TimePicker } from '@mui/x-date-pickers/TimePicker';
import dayjs, { Dayjs } from 'dayjs';
import utc from 'dayjs/plugin/utc';
import { useTranslation } from 'next-i18next';
import { ChangeEvent, useEffect, useState } from 'react';
import { ChangeEvent, useEffect, useRef, useState } from 'react';
import ReactGA from 'react-ga4';
import {
DaysOfWeek,
Expand Down Expand Up @@ -89,7 +89,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
editSession,
onEventDeleted,
eventData,
onEventEdited,
updateEvent,
}) => {
const { t } = useTranslation();
const theme = useTheme<any>();
Expand All @@ -106,6 +106,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
t('CENTER_SESSION.EDIT_THIS_SESSION')
);
const [subjects, setSubjects] = useState<string[]>();
const [initialEventData, setInitialEventData] = useState(null);
const [shortDescription, setShortDescription] = useState<string>();
const [meetingPasscode, setMeetingPasscode] = useState<string>();
const [selectedDays, setSelectedDays] = useState<number[]>();
Expand Down Expand Up @@ -139,9 +140,8 @@ const PlannedSession: React.FC<PlannedModalProps> = ({

useEffect(() => {
console.log(eventData);
console.log(eventData?.metadata?.framework?.subject);

if (eventData) {
setInitialEventData(eventData);
const mode =
eventData?.meetingDetails?.url !== undefined
? sessionMode.ONLINE
Expand All @@ -162,7 +162,7 @@ const PlannedSession: React.FC<PlannedModalProps> = ({

const localStartDateTime = dayjs.utc(startDateTime).tz(timeZone);
const localEndDateTime = dayjs.utc(endDateTime).tz(timeZone);
const localEndDateValue = dayjs.utc(endDateValue).tz('Asia/Kolkata');
const localEndDateValue = dayjs.utc(endDateValue).tz(timeZone);

setStartDate(localStartDateTime.startOf('day'));
setStartTime(localStartDateTime);
Expand All @@ -176,6 +176,15 @@ const PlannedSession: React.FC<PlannedModalProps> = ({

const recurrencePattern = eventData?.recurrencePattern?.daysOfWeek;
setSelectedDays(recurrencePattern);
setSessionBlocks([
{
subject: sub,
subjectTitle: sessionTitle,
startDatetime: startDateTime,
endDatetime: endDateTime,
endDateValue: endDateValue,
},
]);
}
}, [eventData, editSelection]);

Expand Down Expand Up @@ -232,17 +241,6 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
setSessionBlocks(updatedSessionBlocks);
};

// const handleSessionTypeChange = (
// event: ChangeEvent<HTMLInputElement>,
// id: string | number | undefined
// ) => {
// setEventType(event.target.value as type);
// const updatedSessionBlocks = sessionBlocks.map((block) =>
// block.id === id ? { ...block, sessionType: event.target.value } : block
// );
// setSessionBlocks(updatedSessionBlocks);
// };

useEffect(() => {
const getAddFacilitatorFormData = async () => {
try {
Expand Down Expand Up @@ -757,9 +755,119 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
}
};

const handelEditEvent = (eventData: any, deleteSelection: string) => {
console.log(eventData);
};
useEffect(() => {
const onUpdateEvent = async () => {
if (updateEvent && eventData) {
console.log('eventData', eventData);
try {
const isMainEvent = true;
const eventRepetitionId = eventData?.eventRepetitionId;
const apiBody: any = {
isMainEvent: isMainEvent,
status: 'live',
};

let startDateTime = sessionBlocks?.[0]?.startDatetime;
if (
new Date(eventData?.startDateTime).getTime() !==
new Date(startDateTime).getTime()
) {
apiBody['startDateTime'] = startDateTime;
}

let endDateTime = sessionBlocks?.[0]?.endDatetime;
if (
new Date(eventData?.endDateTime).getTime() !==
new Date(endDateTime).getTime()
) {
apiBody['endDateTime'] = endDateTime;
}

const metadata = {
framework: {
board: eventData?.metadata?.framework?.board || '',
medium: eventData?.metadata?.framework?.medium || '',
grade: eventData?.metadata?.framework?.grade || '',
subject: eventData?.metadata?.framework?.subject || '',
topic: eventData?.metadata?.framework?.topic || '',
subTopic: eventData?.metadata?.framework?.subTopic || '',
teacherName: eventData?.metadata?.framework?.teacherName || '',
},
eventType: eventData?.metadata?.clickedBox || '',
doId: eventData?.metadata?.doId || '',
cohortId: eventData?.metadata?.cohortId || '',
cycleId: eventData?.metadata?.cycleId || '',
tenant: eventData?.metadata?.tenant || '',
};

const sessionSubject = sessionBlocks?.[0]?.subject || '';

if (
sessionSubject &&
eventData?.metadata?.framework?.subject !== sessionSubject
) {
metadata.framework.subject = sessionSubject;
apiBody['metadata'] = metadata;
}

const sessionTitle = sessionBlocks?.[0]?.subjectTitle;
if (
eventData?.shortDescription !== sessionTitle &&
sessionTitle !== ''
) {
apiBody['shortDescription'] = sessionTitle;
}
if (sessionBlocks?.[0]?.sessionMode === 'online') {
const meetingDetails = {
id: eventData?.meetingDetails?.id || '',
onlineProvider:
eventData?.meetingDetails?.onlineProvider || 'zoom',
password: eventData?.meetingDetails?.password || '',
providerGenerated:
eventData?.meetingDetails?.providerGenerated || false,
url: eventData?.meetingDetails?.url || '',
};

const meetingUrl = sessionBlocks?.[0]?.meetingLink;
if (
eventData?.meetingDetails?.url !== meetingUrl &&
meetingUrl !== ''
) {
meetingDetails.url = meetingUrl;
apiBody['meetingDetails'] = meetingDetails;
}

const meetingPassword = sessionBlocks?.[0]?.meetingPasscode;
if (
eventData?.meetingDetails?.password !== meetingPassword &&
meetingPasscode !== ''
) {
meetingDetails.password = meetingPassword;
apiBody['meetingDetails'] = meetingDetails;
}
}
if (sessionBlocks?.[0]?.sessionMode === 'offline') {
apiBody['meetingDetails'] = null;
}

console.log('apiBody', apiBody);

const response = await editEvent(eventRepetitionId, apiBody);
if (response?.responseCode === 'OK') {
showToastMessage(
t('COMMON.SESSION_EDITED_SUCCESSFULLY'),
'success'
);
} else {
showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error');
}
} catch (error) {
console.error('Error in editing event:', error);
}
}
};
onUpdateEvent();
}, [updateEvent, eventData, sessionBlocks]);

return (
<Box overflow={'hidden'}>
Expand Down Expand Up @@ -1267,19 +1375,6 @@ const PlannedSession: React.FC<PlannedModalProps> = ({
modalOpen={modalOpen}
/>
)}

{onEventEdited && (
<ConfirmationModal
message={t('CENTER_SESSION.UPDATE_CHANGES')}
buttonNames={{
primary: t('COMMON.YES'),
secondary: t('COMMON.NO_GO_BACK'),
}}
handleCloseModal={handleCloseModal}
handleAction={() => handelEditEvent(editSession, editSelection)}
modalOpen={modalOpen}
/>
)}
</Box>
);
};
Expand Down
34 changes: 22 additions & 12 deletions src/components/SessionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,20 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
data,
children,
isEventDeleted,
isEventEdited,
isEventUpdated,
}) => {
const theme = useTheme<any>();
const { t } = useTranslation();
const [open, setOpen] = React.useState(false);
const [snackbarOpen, setSnackbarOpen] = React.useState(false);
const [eventDeleted, setEventDeleted] = React.useState(false);
const [eventEdited, setEventEdited] = React.useState(false);
const [onEventEdited, setOnEventEdited] = React.useState(false);
const [startTime, setStartTime] = React.useState('');
const [endTime, setEndTime] = React.useState('');
const [startDate, setStartDate] = React.useState('');
const [modalOpen, setModalOpen] = React.useState<boolean>(false);
const [editSelection, setEditSelection] = React.useState('EDIT_SESSION');
const [updateEvent, setUpdateEvent] = React.useState(false);
const [editSession, setEditSession] = React.useState();
const handleEditSelection = (selection: string) => {
setEditSelection(selection);
Expand All @@ -49,14 +49,6 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
}
};

// const onEventEdited = () => {
// setOpen(false);
// setEventEdited(true);
// if (isEventEdited) {
// isEventEdited();
// }
// };

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

const handleCopyUrl = () => {
Expand Down Expand Up @@ -93,7 +85,14 @@ const SessionsCard: React.FC<SessionsCardProps> = ({

const handleEditModal = () => {
setModalOpen(true);
setOnEventEdited(true);
};

const onUpdateClick = () => {
console.log('update the event');
setUpdateEvent(true);
// if (isEventUpdated) {
// isEventUpdated();
// }
};

return (
Expand Down Expand Up @@ -189,12 +188,23 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
editSession={editSession}
handleEditSelection={handleEditSelection}
onEventDeleted={onEventDeleted}
onEventEdited={onEventEdited}
eventDeleted={eventDeleted}
eventData={data}
updateEvent={updateEvent}
/>
</CenterSessionModal>

<ConfirmationModal
message={t('CENTER_SESSION.UPDATE_CHANGES')}
buttonNames={{
primary: t('COMMON.YES'),
secondary: t('COMMON.NO_GO_BACK'),
}}
handleCloseModal={handleCloseModal}
handleAction={onUpdateClick}
modalOpen={modalOpen}
/>

<Box>{children}</Box>
<Snackbar
open={snackbarOpen}
Expand Down
6 changes: 3 additions & 3 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ export interface SessionsCardProps {
data: any;
children?: React.ReactNode;
isEventDeleted?: () => void;
isEventEdited?: () => void;
isEventUpdated?: () => void;
}
export interface SessionsModalProps {
children?: React.ReactNode;
Expand All @@ -156,7 +156,7 @@ export interface PlannedModalProps {
editSelection?: string;
handleEditSelection?: (selection: string) => void;
onEventDeleted?: () => void;
onEventEdited?: boolean;
updateEvent?: boolean;
editSession?: any;
eventData?: any;
}
Expand Down Expand Up @@ -614,7 +614,7 @@ export interface GetUserProjectDetailsParams {

export interface EditEvent {
isMainEvent: boolean;
status: string;
status?: string;
}

export interface ISearchAssessment {
Expand Down

0 comments on commit 1a2f828

Please sign in to comment.