-
Notifications
You must be signed in to change notification settings - Fork 49
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2124 from ever-co/feat/taskActivity
Feat: user Activity on Task ( Hooks, API Routes)
- Loading branch information
Showing
17 changed files
with
260 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,27 @@ | ||
import { authenticatedGuard } from '@app/services/server/guards/authenticated-guard-app'; | ||
import { taskActivityRequest } from '@app/services/server/requests'; | ||
import { NextResponse } from 'next/server'; | ||
|
||
export async function GET(req: Request) { | ||
const res = new NextResponse(); | ||
const { $res, user } = await authenticatedGuard(req, res); | ||
if (!user) return $res('unauthorized'); | ||
const { $res, user, tenantId, organizationId, access_token } = await authenticatedGuard(req, res); | ||
if (!user) return $res('Unauthorized'); | ||
|
||
const { searchParams } = new URL(req.url); | ||
|
||
const { taskId } = searchParams as unknown as { | ||
taskId: string; | ||
}; | ||
|
||
const { data } = await taskActivityRequest( | ||
{ | ||
'taskIds[0]': taskId, | ||
tenantId, | ||
organizationId, | ||
defaultRange: 'false' | ||
}, | ||
access_token | ||
); | ||
|
||
return $res(data); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { useCallback, useEffect } from 'react'; | ||
import { useQuery } from '../useQuery'; | ||
import { useRecoilState, useRecoilValue } from 'recoil'; | ||
|
||
import { useAuthenticateUser } from './useAuthenticateUser'; | ||
import { useUserProfilePage } from './useUserProfilePage'; | ||
import { activityTypeState } from '@app/stores/activity-type'; | ||
import { taskTimesheetState } from '@app/stores/task-timesheet'; | ||
import { getTaskTimesheetRequestAPI } from '@app/services/client/api'; | ||
|
||
export function useTaskTimeSheets(id: string) { | ||
const { user } = useAuthenticateUser(); | ||
const [taskTimesheets, setTaskTimesheets] = useRecoilState(taskTimesheetState); | ||
const activityFilter = useRecoilValue(activityTypeState); | ||
const profile = useUserProfilePage(); | ||
|
||
const { loading, queryCall } = useQuery(getTaskTimesheetRequestAPI); | ||
const getTaskTimesheets = useCallback(() => { | ||
if (activityFilter.member?.employeeId === user?.employee.id || user?.role?.name?.toUpperCase() == 'MANAGER') { | ||
queryCall({ | ||
tenantId: user?.tenantId ?? '', | ||
organizationId: user?.employee.organizationId ?? '', | ||
taskId: id | ||
}).then((response) => { | ||
console.log(response); | ||
if (response.data) { | ||
console.log(response.data); | ||
setTaskTimesheets(response.data); | ||
} | ||
}); | ||
} else setTaskTimesheets([]); | ||
// eslint-disable-next-line react-hooks/exhaustive-deps | ||
}, [activityFilter.member?.employeeId, profile.member?.employeeId, user?.id, queryCall, setTaskTimesheets]); | ||
|
||
useEffect(() => { | ||
getTaskTimesheets(); | ||
}, [getTaskTimesheets]); | ||
|
||
return { | ||
taskTimesheets, | ||
getTaskTimesheets, | ||
loading | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { IEmployee } from './IEmployee'; | ||
import { IProject } from './IProject'; | ||
import { ITeamTask } from './ITask'; | ||
import { ITimerSlot } from './timer/ITimerSlot'; | ||
|
||
export interface ITaskTimesheet { | ||
id: string | ||
title: string; | ||
description?: string; | ||
metaData?: string; | ||
date: Date; | ||
time: string; | ||
duration?: number; | ||
type?: string; | ||
source?: string; | ||
employee?: IEmployee; | ||
employeeId?: IEmployee['id']; | ||
project?: IProject; | ||
projectId?: IProject['id']; | ||
timeSlot?: ITimerSlot; | ||
timeSlotId?: ITimerSlot['id']; | ||
task?: ITeamTask; | ||
taskId?: ITeamTask['id']; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { ITaskTimesheet } from '@app/interfaces'; | ||
import { get } from '@app/services/client/axios'; | ||
import { GAUZY_API_BASE_SERVER_URL } from '@app/constants'; | ||
|
||
export async function getTaskTimesheetRequestAPI({ | ||
taskId, | ||
tenantId, | ||
organizationId, | ||
defaultRange, | ||
unitOfTime | ||
}: { | ||
tenantId: string; | ||
organizationId: string; | ||
defaultRange?: string; | ||
taskId?: string; | ||
unitOfTime?: 'day'; | ||
}) { | ||
const params: { | ||
tenantId: string; | ||
organizationId: string; | ||
defaultRange?: string; | ||
'taskIds[0]'?: string; | ||
unitOfTime?: 'day'; | ||
} = { | ||
'taskIds[0]': taskId, | ||
tenantId, | ||
organizationId, | ||
defaultRange, | ||
unitOfTime | ||
}; | ||
const query = new URLSearchParams(params); | ||
const endpoint = GAUZY_API_BASE_SERVER_URL.value | ||
? `/timesheet/activity?${query.toString()}` | ||
: `/timer/timesheet?${query.toString()}`; | ||
|
||
return get<ITaskTimesheet[]>(endpoint); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ITaskTimesheet } from '@app/interfaces'; | ||
import { atom } from 'recoil'; | ||
|
||
export const taskTimesheetState = atom<ITaskTimesheet[]>({ | ||
key: 'taskTimesheetState', | ||
default: [] | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
apps/web/lib/features/task/activity/user-task-activity.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { clsxm } from '@app/utils'; | ||
import { Tab } from '@headlessui/react'; | ||
import { ActivityFilters } from '@app/constants'; | ||
|
||
export const UserTaskActivity = () => { | ||
// get slots related to Task Id | ||
// get apps visited related to Task Id | ||
// get visited Sites related to Task Id | ||
return ( | ||
<div className="shadow-md rounded-md p-4 my-4 bg-[#00000014] dark:bg-[#26272C]"> | ||
<div className="flex items-center gap-2 my-2"> | ||
<h4 className="text-lg">{'Cedric medium'}</h4> | ||
<span>{'05:30'}</span> | ||
</div> | ||
<Tab.Group> | ||
<Tab.List className="w-full flex rounded-xl bg-gray-200 dark:bg-[#FFFFFF14] p-2"> | ||
{Object.values(ActivityFilters) | ||
.filter((filter) => filter !== 'Tasks') | ||
.map((filter: string) => ( | ||
<Tab | ||
key={filter} | ||
className={({ selected }) => | ||
clsxm( | ||
'w-full rounded-lg py-2.5 text-sm font-medium leading-5', | ||
' focus:outline-none focus:ring-2', | ||
selected | ||
? 'bg-white dark:bg-dark text-blue-700 shadow' | ||
: ' hover:bg-white/[0.50]' | ||
) | ||
} | ||
> | ||
{filter} | ||
</Tab> | ||
))} | ||
</Tab.List> | ||
<Tab.Panels> | ||
<Tab.Panel className="w-full mx-4 py-4">{'Screenshoot Team Tab'}</Tab.Panel> | ||
<Tab.Panel className="w-full mx-4 py-4">{'Apps Tab'}</Tab.Panel> | ||
<Tab.Panel className="w-full mx-4 py-4">{'VisitedSites Tab'}</Tab.Panel> | ||
</Tab.Panels> | ||
</Tab.Group> | ||
</div> | ||
); | ||
}; |
Oops, something went wrong.