Skip to content

Commit

Permalink
fix: update TimeEntry so that it uses data from backend to show proje…
Browse files Browse the repository at this point in the history
…ctName and taskName instead of relying on the requests of project and tasks
  • Loading branch information
wang9hu committed Jun 8, 2024
1 parent ff6b376 commit b832bc7
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 43 deletions.
46 changes: 4 additions & 42 deletions src/components/Timelog/TimeEntry.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -41,49 +41,15 @@ const TimeEntry = (props) => {
isTangible,
hours,
minutes,
projectId,
projectName,
taskName,
taskId,
notes,
} = data;

const projectDetailsSetup = () => {
try {
if (from === 'TaskTab' && data) {
return {
projectName: data?.projectName || "",
projectCategory: data?.projectCategory || "",
taskName: data?.taskName || "",
taskClassification: data?.taskClassification || ""
}
} else {
const timeEntryProject = displayUserProjects.find(project => project.projectId === projectId);
let returnObj = {}
if (timeEntryProject !== undefined) {
returnObj = {
projectName: timeEntryProject?.projectName || "",
projectCategory: timeEntryProject?.projectCategory || "",
}
}
if (taskId) {
const timeEntryTask = displayUserTasks.find(task => task._id === taskId);
if (timeEntryTask) {
returnObj = {
...returnObj,
taskName: timeEntryTask?.taskName || "",
taskClassification: ""
}
}
}
return returnObj;
}
} catch (error) {
console.log(error);
}
}
const [timeEntryFormModal, setTimeEntryFormModal] = useState(false);
const [isProcessing, setIsProcessing] = useState(false);
const [filteredColor,setFilteredColor] = useState(hrsFilterBtnColorMap[7]);
const [projectDetails,setProjectDetails] = useState(projectDetailsSetup())
const dispatch = useDispatch();

const cantEditJaeRelatedRecord = cantUpdateDevAdminDetails(timeEntryUserProfile?.email ? timeEntryUserProfile.email : '', authUser.email);
Expand Down Expand Up @@ -159,10 +125,6 @@ const TimeEntry = (props) => {
editFilteredColor();
}, [])

useEffect(() => {
setProjectDetails(projectDetailsSetup());
}, [from])

return (
<div style={{ display: "flex" }}>
<div
Expand Down Expand Up @@ -190,9 +152,9 @@ const TimeEntry = (props) => {
</h4>
<div className="text-muted">Project/Task:</div>
<p>
{projectDetails?.projectName}
{projectName}
<br />
{projectDetails?.taskName && `\u2003 ↳ ${projectDetails?.taskName}`}
{taskName && `\u2003 ↳ ${taskName}`}
</p>
<div className='mb-3'>
{
Expand Down
1 change: 0 additions & 1 deletion src/components/Timelog/TimeEntryForm/TimeEntryForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ const TimeEntryForm = props => {
const canPutUserProfileImportantInfo = props.hasPermission('putUserProfileImportantInfo');

// Administrator/Owner can add time entries for any dates, and other roles can only edit their own time entry in the same day.
const canUserEditDate = canEditTimeEntry && canPutUserProfileImportantInfo;
const canChangeTime = from !== 'Timer' && (from === 'TimeLog' || canEditTimeEntry || isSameDayAuthUserEdit) ;

/*---------------- methods -------------- */
Expand Down

0 comments on commit b832bc7

Please sign in to comment.