diff --git a/public/locales/en/common.json b/public/locales/en/common.json index 1126d4ff..50064c07 100644 --- a/public/locales/en/common.json +++ b/public/locales/en/common.json @@ -409,7 +409,8 @@ "UPDATE_CHANGES": "Are you sure you want to update the changes?", "SESSION_DELETED_SUCCESSFULLY": "Session deleted successfully", "SESSION_EDITED_SUCCESSFULLY": "Session updated successfully", - "TOPIC_SUBTOPIC_ADDED_SUCCESSFULLY": "Topic and Subtopic added successfully!" + "TOPIC_SUBTOPIC_ADDED_SUCCESSFULLY": "Topic and Subtopic added successfully!", + "TOPIC_SUBTOPIC_REMOVED_SUCCESSFULLY": "Topic and Subtopic removed successfully!" }, "MANAGE_USERS": { "CENTERS_REQUESTED_SUCCESSFULLY": "Center requested successfully", diff --git a/src/components/SessionCard.tsx b/src/components/SessionCard.tsx index 25bd1b23..54b620e5 100644 --- a/src/components/SessionCard.tsx +++ b/src/components/SessionCard.tsx @@ -201,7 +201,7 @@ const SessionsCard: React.FC = ({ {showCenterName ? data?.location : data?.metadata?.teacherName} - {showEdit && ( + {eventStatus === EventStatus.UPCOMING && ( handleOpen(data)} sx={{ cursor: 'pointer' }} diff --git a/src/components/SessionCardFooter.tsx b/src/components/SessionCardFooter.tsx index ed4a8a2a..3c77f246 100644 --- a/src/components/SessionCardFooter.tsx +++ b/src/components/SessionCardFooter.tsx @@ -21,16 +21,19 @@ import { } from '@/services/CoursePlannerService'; import { editEvent } from '@/services/EventService'; import { showToastMessage } from './Toastify'; -import { getDayMonthYearFormat } from '@/utils/Helper'; +import { convertUTCToIST, getDayMonthYearFormat } from '@/utils/Helper'; +import { EventStatus } from '@/utils/app.constant'; const SessionCardFooter: React.FC = ({ item, cohortName, + isTopicSubTopicAdded, }) => { const theme = useTheme(); const { t } = useTranslation(); const [open, setOpen] = React.useState(false); const [editTopic, setEditTopic] = React.useState(false); + const [removeTopic, setRemoveTopic] = React.useState(false); const [topicList, setTopicList] = React.useState([]); const [transformedTasks, setTransformedTasks] = React.useState(); const handleOpen = () => setOpen(true); @@ -38,7 +41,12 @@ const SessionCardFooter: React.FC = ({ const [selectedTopic, setSelectedTopic] = useState(null); const [selectedSubtopics, setSelectedSubtopics] = useState([]); const [learningResources, setLearningResources] = useState(); - const Date = getDayMonthYearFormat(item?.startDateTime); + const [startTime, setStartTime] = React.useState(''); + const [endTime, setEndTime] = React.useState(''); + const [startDate, setStartDate] = React.useState(''); + const [eventStatus, setEventStatus] = React.useState(''); + + const EventDate = getDayMonthYearFormat(item?.startDateTime); useEffect(() => { const fetchTopicSubtopic = async () => { @@ -99,10 +107,15 @@ const SessionCardFooter: React.FC = ({ const updateTopicSubtopic = async () => { try { - const erMetaData = { - topic: selectedTopic, - subTopic: selectedSubtopics, - }; + let erMetaData; + if (removeTopic) { + erMetaData = {}; + } else { + erMetaData = { + topic: selectedTopic, + subTopic: selectedSubtopics, + }; + } console.log(erMetaData); let isMainEvent; @@ -124,10 +137,20 @@ const SessionCardFooter: React.FC = ({ }; const response = await editEvent(eventRepetitionId, apiBody); if (response) { - showToastMessage( - 'CENTER_SESSION.TOPIC_SUBTOPIC_ADDED_SUCCESSFULLY', - 'success' - ); + if (erMetaData?.topic === undefined || erMetaData?.topic === null) { + showToastMessage( + t('CENTER_SESSION.TOPIC_SUBTOPIC_REMOVED_SUCCESSFULLY'), + 'success' + ); + } else { + showToastMessage( + t('CENTER_SESSION.TOPIC_SUBTOPIC_ADDED_SUCCESSFULLY'), + 'success' + ); + } + if (isTopicSubTopicAdded) { + isTopicSubTopicAdded(); + } } else { showToastMessage(t('COMMON.SOMETHING_WENT_WRONG'), 'error'); } @@ -143,6 +166,37 @@ const SessionCardFooter: React.FC = ({ setEditTopic(true); }; + const handleRemovetTopicSubTopic = () => { + setRemoveTopic(true); + updateTopicSubtopic(); + }; + + useEffect(() => { + const startDateTime = convertUTCToIST(item?.startDateTime); + const startDate = startDateTime.date; + const startTime = startDateTime.time; + setStartTime(startTime); + setStartDate(startDate); + + const endDateTime = convertUTCToIST(item?.endDateTime); + const endDate = endDateTime.date; + const endTime = endDateTime.time; + setEndTime(endTime); + + const currentTime = new Date(); + const eventStart = new Date(item?.startDateTime); + const eventEnd = new Date(item?.endDateTime); + + if (currentTime < eventStart) { + setEventStatus(EventStatus.UPCOMING); + } else if (currentTime >= eventStart && currentTime <= eventEnd) { + setEventStatus(EventStatus.LIVE); + } else if (currentTime > eventEnd) { + setEventStatus(EventStatus.PASSED); + } + console.log(startDate, startTime, endDate, endTime); + }, [item]); + return ( <> {item?.erMetaData?.topic ? ( @@ -255,7 +309,7 @@ const SessionCardFooter: React.FC = ({ handleClose={handleClose} title={item?.metadata?.framework?.subject || item?.metadata?.subject} center={cohortName} - date={Date} + date={EventDate} primary={t('COMMON.SAVE')} handlePrimaryModel={updateTopicSubtopic} > @@ -265,6 +319,8 @@ const SessionCardFooter: React.FC = ({ subTopic={item?.erMetaData?.subTopic} learningResources={learningResources} handleOpen={handleOpenSelectTopic} + handleRemove={handleRemovetTopicSubTopic} + eventStatus={eventStatus} /> ) : ( = ({ @@ -24,6 +27,8 @@ const TopicDetails: React.FC = ({ subTopic, learningResources, handleOpen, + handleRemove, + eventStatus, }) => { const { t } = useTranslation(); const theme = useTheme(); @@ -45,6 +50,11 @@ const TopicDetails: React.FC = ({ handleOpen(); }; + const onRemoveTopicSubtopic = () => { + console.log('remove'); + handleRemove(); + }; + return ( <> @@ -68,10 +78,12 @@ const TopicDetails: React.FC = ({ {topic} - + {eventStatus === EventStatus.UPCOMING && ( + + )} = ({ {t('CENTER_SESSION.REMOVE_THIS_SESSION')} diff --git a/src/pages/centers/[cohortId]/index.tsx b/src/pages/centers/[cohortId]/index.tsx index 6e333e56..6223ed94 100644 --- a/src/pages/centers/[cohortId]/index.tsx +++ b/src/pages/centers/[cohortId]/index.tsx @@ -61,7 +61,11 @@ import Schedule from '../../../components/Schedule'; import { Session } from '../../../utils/Interfaces'; import manageUserStore from '@/store/manageUserStore'; -import { accessControl, eventDaysLimit, modifyAttendanceLimit } from '../../../../app.config'; +import { + accessControl, + eventDaysLimit, + modifyAttendanceLimit, +} from '../../../../app.config'; import withAccessControl from '@/utils/hoc/withAccessControl'; const CohortPage = () => { @@ -621,6 +625,7 @@ const CohortPage = () => { @@ -693,7 +698,11 @@ const CohortPage = () => { isEventDeleted={handleEventDeleted} isEventUpdated={handleEventUpdated} > - + ))} @@ -796,4 +805,4 @@ export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => { }; }; -export default withAccessControl('accessCenters', accessControl)(CohortPage); \ No newline at end of file +export default withAccessControl('accessCenters', accessControl)(CohortPage); diff --git a/src/utils/Interfaces.ts b/src/utils/Interfaces.ts index 81b36de3..1b9326d0 100644 --- a/src/utils/Interfaces.ts +++ b/src/utils/Interfaces.ts @@ -384,6 +384,7 @@ export interface CoursePlanner { export interface SessionCardFooterProps { item: any; cohortName?: string; + isTopicSubTopicAdded?: any; } export interface TopicSubtopicProps {