Skip to content

Commit

Permalink
fix: useAcitivityData for each user
Browse files Browse the repository at this point in the history
  • Loading branch information
Cedric921 committed Jan 18, 2024
1 parent 87a6e4a commit 323dc5a
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
7 changes: 5 additions & 2 deletions apps/web/app/hooks/features/useTimeDailyActivity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { useAuthenticateUser } from './useAuthenticateUser';
import { getTimerDailyRequestAPI } from '@app/services/client/api';
import { activityTypeState } from '@app/stores/activity-type';

export function useTimeDailyActivity(type: string) {
export function useTimeDailyActivity(type?: string) {
const { user } = useAuthenticateUser();
const [visitedApps, setVisitedApps] = useRecoilState(timeAppsState);
const activityFilter = useRecoilValue(activityTypeState);
Expand All @@ -22,7 +22,10 @@ export function useTimeDailyActivity(type: string) {
const todayStart = moment().startOf('day').toDate();
const todayEnd = moment().endOf('day').toDate();
const employeeId = activityFilter.member ? activityFilter.member?.employeeId : user?.employee?.id;
if (activityFilter.member?.id === user?.id || user?.role?.name?.toUpperCase() == 'MANAGER') {
if (
activityFilter.member?.employeeId === user?.employee.id ||
user?.role?.name?.toUpperCase() == 'MANAGER'
) {
queryCall({
tenantId: user?.tenantId ?? '',
organizationId: user?.employee.organizationId ?? '',
Expand Down
18 changes: 4 additions & 14 deletions apps/web/app/hooks/features/useTimeSlot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ export function useTimeSlots(hasFilter?: boolean) {
const getTimeSlots = useCallback(() => {
const todayStart = moment().startOf('day').toDate();
const todayEnd = moment().endOf('day').toDate();
const employeeId = hasFilter ? activityFilter.member?.employeeId : profile.member?.employeeId;
if (profile.userProfile?.id === user?.id || user?.role?.name?.toUpperCase() == 'MANAGER') {
const employeeId = activityFilter.member ? activityFilter.member?.employeeId : user?.employee?.id;
if (activityFilter.member?.employeeId === user?.employee.id || user?.role?.name?.toUpperCase() == 'MANAGER') {
queryCall({
tenantId: user?.tenantId ?? '',
organizationId: user?.employee.organizationId ?? '',
Expand All @@ -37,18 +37,8 @@ export function useTimeSlots(hasFilter?: boolean) {
}
});
}
}, [
hasFilter,
activityFilter.member?.employeeId,
profile.member?.employeeId,
profile.userProfile?.id,
user?.id,
user?.role?.name,
user?.tenantId,
user?.employee.organizationId,
queryCall,
setTimeSlots
]);
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [hasFilter, activityFilter.member?.employeeId, profile.member?.employeeId, user?.id, queryCall, setTimeSlots]);

const deleteTimeSlots = useCallback(
(ids: string[]) => {
Expand Down
9 changes: 5 additions & 4 deletions apps/web/app/services/client/api/activity/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export async function getTimerDailyRequestAPI({
employeeId: string;
todayEnd: Date;
todayStart: Date;
type: string;
type?: string | undefined;
title?: string;
}) {
const params: {
Expand All @@ -25,18 +25,19 @@ export async function getTimerDailyRequestAPI({
'employeeIds[0]': string;
startDate: string;
endDate: string;
'types[0]': string;
'types[0]'?: string;
'title[0]'?: string;
} = {
tenantId: tenantId,
organizationId: organizationId,
'employeeIds[0]': employeeId,
startDate: todayStart.toISOString(),
endDate: todayEnd.toISOString(),
'types[0]': type
endDate: todayEnd.toISOString()
};
if (type) params['types[0]'] = type;
if (title) params['title[0]'] = title;
const query = new URLSearchParams(params);
console.log('QUERY', query);
const endpoint = GAUZY_API_BASE_SERVER_URL.value
? `/timesheet/activity/daily?${query.toString()}`
: `/timer/daily?${query.toString()}`;
Expand Down
3 changes: 1 addition & 2 deletions apps/web/lib/features/activity/apps.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,9 @@ import AppVisitedItem from './components/app-visited-Item';
// import { AppVisitedModal } from './components/app-visited-details';

export function AppsTab() {
const { visitedApps, loading } = useTimeDailyActivity('APPS');
const { visitedApps, loading } = useTimeDailyActivity();
const t = useTranslations();
const apps = groupAppsByHour(visitedApps);
console.log('INTO APP TAB');
return (
<div>
<div className="flex justify-end w-full">{/* TODO: Filters components */}</div>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ export function UserWorkedTaskTab() {
const profile = useUserDetails(activityFilter.member?.employeeId ?? '');
const hook = useTaskFilter(profile);

console.log({ hook, profile });

return <UserProfileTask profile={profile} tabFiltered={hook} />;
}

0 comments on commit 323dc5a

Please sign in to comment.