Skip to content

Commit

Permalink
Merge pull request #244 from suvarnakale/release-1.0.0
Browse files Browse the repository at this point in the history
Issue #1553 feat : Remove topic and subtopic of a session - done
  • Loading branch information
itsvick authored Sep 10, 2024
2 parents 9b020a4 + e0fd739 commit ab70a8f
Show file tree
Hide file tree
Showing 6 changed files with 118 additions and 22 deletions.
3 changes: 2 additions & 1 deletion public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion src/components/SessionCard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ const SessionsCard: React.FC<SessionsCardProps> = ({
{showCenterName ? data?.location : data?.metadata?.teacherName}
</Typography>
</Box>
{showEdit && (
{eventStatus === EventStatus.UPCOMING && (
<EditOutlined
onClick={() => handleOpen(data)}
sx={{ cursor: 'pointer' }}
Expand Down
78 changes: 67 additions & 11 deletions src/components/SessionCardFooter.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,32 @@ 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<SessionCardFooterProps> = ({
item,
cohortName,
isTopicSubTopicAdded,
}) => {
const theme = useTheme<any>();
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);
const handleClose = () => setOpen(false);
const [selectedTopic, setSelectedTopic] = useState<string | null>(null);
const [selectedSubtopics, setSelectedSubtopics] = useState<string[]>([]);
const [learningResources, setLearningResources] = useState<any>();
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 () => {
Expand Down Expand Up @@ -99,10 +107,15 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({

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;
Expand All @@ -124,10 +137,20 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
};
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');
}
Expand All @@ -143,6 +166,37 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
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 ? (
Expand Down Expand Up @@ -255,7 +309,7 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
handleClose={handleClose}
title={item?.metadata?.framework?.subject || item?.metadata?.subject}
center={cohortName}
date={Date}
date={EventDate}
primary={t('COMMON.SAVE')}
handlePrimaryModel={updateTopicSubtopic}
>
Expand All @@ -265,6 +319,8 @@ const SessionCardFooter: React.FC<SessionCardFooterProps> = ({
subTopic={item?.erMetaData?.subTopic}
learningResources={learningResources}
handleOpen={handleOpenSelectTopic}
handleRemove={handleRemovetTopicSubTopic}
eventStatus={eventStatus}
/>
) : (
<SelectTopic
Expand Down
41 changes: 35 additions & 6 deletions src/components/TopicDetails.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,23 @@ import CreateOutlinedIcon from '@mui/icons-material/CreateOutlined';
import DeleteOutlineIcon from '@mui/icons-material/DeleteOutline';
import { useTheme } from '@mui/material/styles';
import { useTranslation } from 'next-i18next';
import { EventStatus } from '@/utils/app.constant';
interface TopicDetailsProps {
topic: string;
subTopic: [];
learningResources: any;
handleOpen: any;
handleRemove: any;
eventStatus?: string;
}

const TopicDetails: React.FC<TopicDetailsProps> = ({
topic,
subTopic,
learningResources,
handleOpen,
handleRemove,
eventStatus,
}) => {
const { t } = useTranslation();
const theme = useTheme<any>();
Expand All @@ -45,6 +50,11 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
handleOpen();
};

const onRemoveTopicSubtopic = () => {
console.log('remove');
handleRemove();
};

return (
<>
<Box sx={{ padding: '8px 16px' }}>
Expand All @@ -68,10 +78,12 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
{topic}
</Box>
</Box>
<CreateOutlinedIcon
sx={{ fontSize: '18px', color: '#0D599E', cursor: 'pointer' }}
onClick={openTopicModal}
/>
{eventStatus === EventStatus.UPCOMING && (
<CreateOutlinedIcon
sx={{ fontSize: '18px', color: '#0D599E', cursor: 'pointer' }}
onClick={openTopicModal}
/>
)}
</Box>

<Box
Expand Down Expand Up @@ -100,14 +112,31 @@ const TopicDetails: React.FC<TopicDetailsProps> = ({
<Box
sx={{
fontSize: '14px',
color: theme?.palette?.secondary.main,
color:
eventStatus === EventStatus.UPCOMING
? theme?.palette?.secondary.main
: theme?.palette?.grey[500],
fontWeight: '500',
cursor:
eventStatus === EventStatus.UPCOMING
? 'pointer'
: 'not-allowed',
pointerEvents:
eventStatus === EventStatus.UPCOMING ? 'auto' : 'none',
}}
onClick={
eventStatus === EventStatus.UPCOMING
? onRemoveTopicSubtopic
: undefined
}
>
{t('CENTER_SESSION.REMOVE_THIS_SESSION')}
</Box>
<DeleteOutlineIcon
sx={{ fontSize: '18px', color: theme?.palette?.error.main }}
sx={{
fontSize: '18px',
color: theme?.palette?.error.main,
}}
/>
</Box>
</Box>
Expand Down
15 changes: 12 additions & 3 deletions src/pages/centers/[cohortId]/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 = () => {
Expand Down Expand Up @@ -621,6 +625,7 @@ const CohortPage = () => {
<SessionCardFooter
item={item}
cohortName={cohortName}
isTopicSubTopicAdded={handleEventUpdated}
/>
</SessionCard>
</SwiperSlide>
Expand Down Expand Up @@ -693,7 +698,11 @@ const CohortPage = () => {
isEventDeleted={handleEventDeleted}
isEventUpdated={handleEventUpdated}
>
<SessionCardFooter item={item} cohortName={cohortName} />
<SessionCardFooter
item={item}
cohortName={cohortName}
isTopicSubTopicAdded={handleEventUpdated}
/>
</SessionCard>
</Grid>
))}
Expand Down Expand Up @@ -796,4 +805,4 @@ export const getStaticPaths: GetStaticPaths<{ slug: string }> = async () => {
};
};

export default withAccessControl('accessCenters', accessControl)(CohortPage);
export default withAccessControl('accessCenters', accessControl)(CohortPage);
1 change: 1 addition & 0 deletions src/utils/Interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,7 @@ export interface CoursePlanner {
export interface SessionCardFooterProps {
item: any;
cohortName?: string;
isTopicSubTopicAdded?: any;
}

export interface TopicSubtopicProps {
Expand Down

0 comments on commit ab70a8f

Please sign in to comment.