From 5b1126843103dc059a60255d2ee14a2956744136 Mon Sep 17 00:00:00 2001 From: Peterson Rodrigues dos Santos Date: Fri, 1 Mar 2024 13:39:16 -0300 Subject: [PATCH 1/3] =?UTF-8?q?Peterson=5FFix=5FWeekly=5FSummaries=5Fedit?= =?UTF-8?q?=5FLast=5Fweek=E2=80=99s?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/actions/weeklySummaries.js | 3 +- src/components/Timelog/WeeklySummaries.jsx | 37 +++++++++++++++++++--- 2 files changed, 34 insertions(+), 6 deletions(-) diff --git a/src/actions/weeklySummaries.js b/src/actions/weeklySummaries.js index 6d05bf3f54..731941b2fc 100644 --- a/src/actions/weeklySummaries.js +++ b/src/actions/weeklySummaries.js @@ -79,7 +79,8 @@ export const updateWeeklySummaries = (userId, weeklySummariesData) => { // Merge the weekly summaries related changes with the user's profile. const {mediaUrl, weeklySummaries, weeklySummariesCount } = weeklySummariesData; - console.log('respon get', response.data) + + // console.log('respon get', response.data) // update the changes on weekly summaries link into admin links let doesMediaFolderExist = false; for (const link of adminLinks) { diff --git a/src/components/Timelog/WeeklySummaries.jsx b/src/components/Timelog/WeeklySummaries.jsx index 200215e4c2..4ad6ff3c1e 100644 --- a/src/components/Timelog/WeeklySummaries.jsx +++ b/src/components/Timelog/WeeklySummaries.jsx @@ -1,16 +1,29 @@ -import React, { useState, useEffect } from 'react'; +import React, { useState, useEffect} from 'react'; import parse from 'html-react-parser'; import './Timelog.css' -import updateWeeklySummaries from 'actions/weeklySummaries'; +import {updateWeeklySummaries} from '../../actions/weeklySummaries'; import { getUserProfile, updateUserProfile } from 'actions/userProfile'; import hasPermission from 'utils/permissions'; import { connect, useDispatch, useSelector } from 'react-redux'; import { Editor } from '@tinymce/tinymce-react'; import { userProfileByIdReducer } from 'reducers/userProfileByIdReducer'; +import Spinner from 'react-bootstrap/Spinner'; const WeeklySummaries = ({ userProfile }) => { + + useEffect(() => { + setEditedSummaries([ + userProfile.weeklySummaries[0]?.summary || '', + userProfile.weeklySummaries[1]?.summary || '', + userProfile.weeklySummaries[2]?.summary || '', + ]); + + }, [userProfile]); + // Initialize state variables for editing and original summaries + const [editing, setEditing] = useState([false, false, false]); + const [editedSummaries, setEditedSummaries] = useState([ userProfile.weeklySummaries[0]?.summary || '', userProfile.weeklySummaries[1]?.summary || '', @@ -18,6 +31,8 @@ const WeeklySummaries = ({ userProfile }) => { ]); const [originalSummaries, setOriginalSummaries] = useState([...editedSummaries]); + const [LoadingHandleSave, setLoadingHandleSave] = useState(null); + const dispatch = useDispatch(); const canEdit = dispatch(hasPermission('putUserProfile')); @@ -54,10 +69,12 @@ const WeeklySummaries = ({ userProfile }) => { }; const handleSave = async (index) => { + setLoadingHandleSave(index); // Save the edited summary content and toggle off editing mode const editedSummary = editedSummaries[index]; // Check if the edited summary is not blank and contains at least 50 words const wordCount = editedSummary.split(/\s+/).filter(Boolean).length; + if (editedSummary.trim() !== '' && wordCount >= 50) { const updatedUserProfile = { ...userProfile, @@ -65,9 +82,14 @@ const WeeklySummaries = ({ userProfile }) => { i === index ? { ...item, summary: editedSummary } : item ) }; - - await dispatch(updateUserProfile(userProfile._id, updatedUserProfile)); + + // This code updates the summary. + await dispatch(updateUserProfile(userProfile)); + + // This code saves edited weekly summaries in MongoDB. + await dispatch(updateWeeklySummaries(userProfile._id, updatedUserProfile)); await dispatch(getUserProfile(userProfile._id)); + await setLoadingHandleSave(null); // Toggle off editing mode toggleEdit(index); } else { @@ -96,7 +118,12 @@ const WeeklySummaries = ({ userProfile }) => { value={editedSummaries[index]} onEditorChange={(content) => handleSummaryChange({ target: { value: content } }, index)} /> - + + + ); From c67131d3681f232419489cbeb9c5bfe6bf119a14 Mon Sep 17 00:00:00 2001 From: Peterson Rodrigues dos Santos Date: Wed, 13 Mar 2024 13:32:18 -0300 Subject: [PATCH 2/3] Peterson_impl_feature_Finish_My_Team_filter_or_Tasks_Tab --- src/actions/weeklySummaries.js | 1 - src/components/Timelog/WeeklySummaries.jsx | 39 ++++++++++++---------- 2 files changed, 21 insertions(+), 19 deletions(-) diff --git a/src/actions/weeklySummaries.js b/src/actions/weeklySummaries.js index 731941b2fc..aabadbadc1 100644 --- a/src/actions/weeklySummaries.js +++ b/src/actions/weeklySummaries.js @@ -80,7 +80,6 @@ export const updateWeeklySummaries = (userId, weeklySummariesData) => { // Merge the weekly summaries related changes with the user's profile. const {mediaUrl, weeklySummaries, weeklySummariesCount } = weeklySummariesData; - // console.log('respon get', response.data) // update the changes on weekly summaries link into admin links let doesMediaFolderExist = false; for (const link of adminLinks) { diff --git a/src/components/Timelog/WeeklySummaries.jsx b/src/components/Timelog/WeeklySummaries.jsx index 4ad6ff3c1e..b20be74782 100644 --- a/src/components/Timelog/WeeklySummaries.jsx +++ b/src/components/Timelog/WeeklySummaries.jsx @@ -33,6 +33,8 @@ const WeeklySummaries = ({ userProfile }) => { const [LoadingHandleSave, setLoadingHandleSave] = useState(null); + const [wordCount, setWordCount] = useState(0); + const dispatch = useDispatch(); const canEdit = dispatch(hasPermission('putUserProfile')); @@ -45,14 +47,13 @@ const WeeklySummaries = ({ userProfile }) => { } const toggleEdit = (index) => { - // Toggle the editing state for the specified summary - const newEditing = [...editing]; - newEditing[index] = !newEditing[index]; - setEditing(newEditing); + const newEditing = editing.map((value, i) => (i === index ? !value : false)); + setEditing(newEditing); }; - const handleSummaryChange = (event, index) => { - // Update the edited summary content + const handleSummaryChange = (event, index, editor) => { + const wordCounter = editor.plugins.wordcount.getCount(); + setWordCount(wordCounter) const newEditedSummaries = [...editedSummaries]; newEditedSummaries[index] = event.target.value; setEditedSummaries(newEditedSummaries); @@ -63,26 +64,25 @@ const WeeklySummaries = ({ userProfile }) => { const newEditedSummaries = [...editedSummaries]; newEditedSummaries[index] = userProfile.weeklySummaries[index]?.summary || ''; setEditedSummaries(newEditedSummaries); - + // Toggle off editing mode toggleEdit(index); - }; + }; + const handleSave = async (index) => { setLoadingHandleSave(index); // Save the edited summary content and toggle off editing mode const editedSummary = editedSummaries[index]; - // Check if the edited summary is not blank and contains at least 50 words - const wordCount = editedSummary.split(/\s+/).filter(Boolean).length; if (editedSummary.trim() !== '' && wordCount >= 50) { const updatedUserProfile = { ...userProfile, weeklySummaries: userProfile.weeklySummaries.map((item, i) => - i === index ? { ...item, summary: editedSummary } : item + i === index ? { ...item, summary: editedSummary } : item ) }; - + // This code updates the summary. await dispatch(updateUserProfile(userProfile)); @@ -90,11 +90,13 @@ const WeeklySummaries = ({ userProfile }) => { await dispatch(updateWeeklySummaries(userProfile._id, updatedUserProfile)); await dispatch(getUserProfile(userProfile._id)); await setLoadingHandleSave(null); - // Toggle off editing mode - toggleEdit(index); - } else { - // Invalid summary, show an error message or handle it as needed - alert('Please enter a valid summary with at least 50 words.'); + setLoadingHandleSave(null); + // Toggle off editing mode + toggleEdit(index); + } else { + // Invalid summary, show an error message or handle it as needed + alert('Please enter a valid summary with at least 50 words.'); + setLoadingHandleSave(null); } }; @@ -116,7 +118,8 @@ const WeeklySummaries = ({ userProfile }) => { autoresize_bottom_margin: 1, }} value={editedSummaries[index]} - onEditorChange={(content) => handleSummaryChange({ target: { value: content } }, index)} + onEditorChange={(content, editor) => handleSummaryChange({ target: { value: content } }, index, editor)} + onGetContent={(content, editor) => setWordCount(editor.plugins.wordcount.getCount())} /> + + ); } else if (summary && (canEdit || currentUserID == loggedInUserId)) {