From 29b6a87c3f42acf57ed03b7ce01bb0cb837d8251 Mon Sep 17 00:00:00 2001 From: Berra Karaman Date: Thu, 22 Feb 2024 19:09:52 +0300 Subject: [PATCH] show unpublished activities for staff and educators --- .../views/activities/activitiesStyles.js | 3 + .../src/store/actions/activityActions.js | 4 +- .../src/store/reducers/activityReducer.js | 1 + .../src/views/activities/activities.jsx | 141 +++++++++++------- 4 files changed, 91 insertions(+), 58 deletions(-) diff --git a/zubhub_frontend/zubhub/src/assets/js/styles/views/activities/activitiesStyles.js b/zubhub_frontend/zubhub/src/assets/js/styles/views/activities/activitiesStyles.js index 8e7ca3ef7..48a463112 100644 --- a/zubhub_frontend/zubhub/src/assets/js/styles/views/activities/activitiesStyles.js +++ b/zubhub_frontend/zubhub/src/assets/js/styles/views/activities/activitiesStyles.js @@ -21,6 +21,9 @@ const styles = theme => ({ width: '95%', }, }, + activitiesContainer: { + marginTop: 0 + }, activityBoxContainer: { padding: '5vh 10px', position: 'relative', diff --git a/zubhub_frontend/zubhub/src/store/actions/activityActions.js b/zubhub_frontend/zubhub/src/store/actions/activityActions.js index 4e1498b25..373b17e8a 100644 --- a/zubhub_frontend/zubhub/src/store/actions/activityActions.js +++ b/zubhub_frontend/zubhub/src/store/actions/activityActions.js @@ -36,7 +36,7 @@ export const getMyActivities = ({ t, token }) => { dispatch({ type: at.SET_ACTIVITIES, payload: { - all_activities: all, + userActivities: all, }, }); }); @@ -70,7 +70,7 @@ export const getUnPublishedActivities = ({ t, token }) => { dispatch({ type: at.SET_ACTIVITIES, payload: { - all_activities: all, + unPublishedActivities: all, }, }); }); diff --git a/zubhub_frontend/zubhub/src/store/reducers/activityReducer.js b/zubhub_frontend/zubhub/src/store/reducers/activityReducer.js index b07334b3f..61ad5fff3 100644 --- a/zubhub_frontend/zubhub/src/store/reducers/activityReducer.js +++ b/zubhub_frontend/zubhub/src/store/reducers/activityReducer.js @@ -4,6 +4,7 @@ const default_state = { published: [], unPublishedActivities: [], selectedActivity: {}, + userActivities: [], }; const activities = (state = default_state, action) => { switch (action.type) { diff --git a/zubhub_frontend/zubhub/src/views/activities/activities.jsx b/zubhub_frontend/zubhub/src/views/activities/activities.jsx index 02589f07a..679cb8e29 100644 --- a/zubhub_frontend/zubhub/src/views/activities/activities.jsx +++ b/zubhub_frontend/zubhub/src/views/activities/activities.jsx @@ -1,6 +1,5 @@ import React, { useEffect, useState } from 'react'; import { connect, useSelector } from 'react-redux'; -import { useLocation } from 'react-router-dom'; import { getActivities, getMyActivities, @@ -21,46 +20,69 @@ import LoadingPage from '../loading/LoadingPage'; const useStyles = makeStyles(styles); function Activities(props) { - const location = useLocation(); const classes = useStyles(); const [loading, setLoading] = useState(true); const { activities } = useSelector(state => state); - let [activityList, setActivityList] = useState([]); + let [activityList, setActivityList] = useState({ + published: [], + unPublishedActivities: [], + userActivities: [] + }); const [tab, setTab] = useState("published"); const commonClasses = makeStyles(DefaultStyles)(); const { t } = useTranslation(); useEffect(() => { - setActivityList(activities.all_activities); + setActivityList(activities); }, [activities]); - - const flagMap = { - staff: () => - props.getUnPublishedActivities({ - t: props.t, - token: props.auth.token, - }), - educator: () => - props.getMyActivities({ - t: props.t, - token: props.auth.token, - }), - }; - useEffect(async () => { + + useEffect(() => { setLoading(true); - if (location.state?.flag && flagMap[location.state.flag]) { - await flagMap[location.state.flag](); - } else { - await props.getActivities(props.t); + async function getActivityList () { + if (props.auth?.tags.includes('staff')) { + await props.getUnPublishedActivities({ + t: props.t, + token: props.auth.token, + }) + } else if (props.auth?.tags.includes('educator')) { + await props.getMyActivities({ + t: props.t, + token: props.auth.token, + }) + } + await props.getActivities(props.t) } - setActivityList(activities.all_activities); + getActivityList() setLoading(false); - }, [location]); + }, []); const handleTabChange = (event, newTab) => { setTab(newTab) } + const ActivityCard = ({ activity }) => { + return ( + + + + ) + } + if (loading) { return ; } else { @@ -72,39 +94,46 @@ function Activities(props) { {t('activities.title')} - - - - - - {activityList && - activityList.map((activity, index) => ( - - - + {(props.auth?.tags.includes('staff') || props.auth?.tags.includes('educator')) && ( + + + !activity.publish).length}) + `} + className={classes.tab} + /> + + )} + + {activityList.published && tab === "published" && + activityList.published.map((activity) => ( + ))} + {activityList.unPublishedActivities && tab === "unpublished" && props.auth?.tags.includes('staff') && + activityList.unPublishedActivities.map(activity => ( + + )) + } + {activityList.userActivities && tab === "unpublished" && props.auth?.tags.includes('educator') && + activityList.userActivities.filter(activity => !activity.publish).map(activity => ( + + )) + } );