diff --git a/apps/mobile/app/screens/Authenticated/ProfileScreen/components/UserProfileTasks.tsx b/apps/mobile/app/screens/Authenticated/ProfileScreen/components/UserProfileTasks.tsx index ac2e127c0..e7d029532 100644 --- a/apps/mobile/app/screens/Authenticated/ProfileScreen/components/UserProfileTasks.tsx +++ b/apps/mobile/app/screens/Authenticated/ProfileScreen/components/UserProfileTasks.tsx @@ -41,7 +41,7 @@ const UserProfileTasks: FC = observer(({ profile, content }) > {content.tab === 'worked' && profile.activeUserTeamTask && - (profile.member?.timerStatus === 'running' || (profile.isAuthUser && timerStatus?.running)) ? ( + (profile.member?.employee?.isTrackingTime || (profile.isAuthUser && timerStatus?.running)) ? ( <> {hook.tab == 'worked' && canSeeActivity && ( -
+
{Object.keys(activityScreens).map((filter, i) => (
{i !== 0 && } diff --git a/apps/web/app/api/auth/register/route.ts b/apps/web/app/api/auth/register/route.ts index c5ae81330..30aa95656 100644 --- a/apps/web/app/api/auth/register/route.ts +++ b/apps/web/app/api/auth/register/route.ts @@ -8,8 +8,8 @@ import { createTenantRequest, createTenantSmtpRequest, loginUserRequest, - registerUserRequest, - refreshTokenRequest + refreshTokenRequest, + registerUserRequest } from '@app/services/server/requests'; import { setAuthCookies } from '@app/helpers/cookies'; import { recaptchaVerification } from '@app/services/server/recaptcha'; @@ -18,7 +18,7 @@ import { NextResponse } from 'next/server'; export async function POST(req: Request) { const url = new URL(req.url); - const res = new NextResponse(); + const response = new NextResponse(); const appEmailConfirmationUrl = `${url.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; @@ -137,8 +137,8 @@ export async function POST(req: Request) { languageId: 'en', // TODO: not sure what should be here userId: user.id }, - { req, res } + { req, res: response } ); - return NextResponse.json({ loginRes, team, employee }); + return response; } diff --git a/apps/web/app/helpers/cookies/index.ts b/apps/web/app/helpers/cookies/index.ts index 431e42694..44629f59a 100644 --- a/apps/web/app/helpers/cookies/index.ts +++ b/apps/web/app/helpers/cookies/index.ts @@ -40,8 +40,7 @@ type NextCtx = { export const setLargeStringInCookies = ( COOKIE_NAME: string, largeString: string, - req: any, - res: any, + ctx: NextCtx | undefined, crossSite = false ) => { const chunkSize = 4000; @@ -50,10 +49,10 @@ export const setLargeStringInCookies = ( chunks.forEach((chunk, index) => { const cookieValue = chunk.join(''); - setCookie(`${COOKIE_NAME}${index}`, cookieValue, { res, req }, crossSite); + setCookie(`${COOKIE_NAME}${index}`, cookieValue, ctx, crossSite); }); - setCookie(`${COOKIE_NAME}_totalChunks`, chunks.length, { res, req }, crossSite); + setCookie(`${COOKIE_NAME}_totalChunks`, chunks.length, ctx, crossSite); }; export const getLargeStringFromCookies = (COOKIE_NAME: string, ctx?: NextCtx) => { @@ -95,12 +94,12 @@ export function setAuthCookies(datas: DataParams, ctx?: NextCtx) { // Handle Large Access Token // Cookie can support upto 4096 characters only! if (access_token.length <= 4096) { - setCookie(TOKEN_COOKIE_NAME, access_token, ctx, true); // cross site cookie + setCookie(TOKEN_COOKIE_NAME, access_token, ctx); // cross site cookie } else { - setLargeStringInCookies(TOKEN_COOKIE_NAME, access_token, ctx?.req, ctx?.res, true); // cross site cookie + setLargeStringInCookies(TOKEN_COOKIE_NAME, access_token, ctx); // cross site cookie } - setCookie(REFRESH_TOKEN_COOKIE_NAME, refresh_token.token, ctx, true); // cross site cookie + setCookie(REFRESH_TOKEN_COOKIE_NAME, refresh_token.token, ctx); // cross site cookie setCookie(ACTIVE_TEAM_COOKIE_NAME, teamId, ctx); setCookie(TENANT_ID_COOKIE_NAME, tenantId, ctx); setCookie(ORGANIZATION_ID_COOKIE_NAME, organizationId, ctx); diff --git a/apps/web/app/hooks/auth/useAuthenticationTeam.ts b/apps/web/app/hooks/auth/useAuthenticationTeam.ts index eebec90fe..d43ace7dc 100644 --- a/apps/web/app/hooks/auth/useAuthenticationTeam.ts +++ b/apps/web/app/hooks/auth/useAuthenticationTeam.ts @@ -9,7 +9,7 @@ import { AxiosError } from 'axios'; import { useCallback, useMemo, useState } from 'react'; import { useQuery } from '../useQuery'; import { RECAPTCHA_SITE_KEY } from '@app/constants'; -import { useSearchParams } from 'next/navigation'; +import { useRouter, useSearchParams } from 'next/navigation'; const FIRST_STEP = 'STEP1' as const; const SECOND_STEP = 'STEP2' as const; @@ -25,15 +25,17 @@ const initialValues: IRegisterDataAPI = RECAPTCHA_SITE_KEY email: '', team: '', recaptcha: '' - } + } : { name: '', email: '', team: '' - }; + }; export function useAuthenticationTeam() { const query = useSearchParams(); + const router = useRouter(); + const queryEmail = useMemo(() => { let localEmail: null | string = null; @@ -78,7 +80,7 @@ export function useAuthenticationTeam() { infiniteLoading.current = true; queryCall(formValues) - .then(() => window.location.reload()) + .then(() => router.push('/')) .catch((err: AxiosError) => { if (err.response?.status === 400) { setErrors((err.response?.data as any)?.errors || {}); diff --git a/apps/web/app/interfaces/IEmployee.ts b/apps/web/app/interfaces/IEmployee.ts index dea78b974..cfdcf00ed 100644 --- a/apps/web/app/interfaces/IEmployee.ts +++ b/apps/web/app/interfaces/IEmployee.ts @@ -11,6 +11,7 @@ export interface IEmployee { short_description: any; description: any; startedWorkOn: any; + isTrackingTime?: boolean; endWork: any; payPeriod: string; billRateValue: number; diff --git a/apps/web/app/services/client/axios.ts b/apps/web/app/services/client/axios.ts index a940e724f..5b4af5a0e 100644 --- a/apps/web/app/services/client/axios.ts +++ b/apps/web/app/services/client/axios.ts @@ -1,11 +1,6 @@ /* eslint-disable no-mixed-spaces-and-tabs */ import { API_BASE_URL, DEFAULT_APP_PATH, GAUZY_API_BASE_SERVER_URL } from '@app/constants'; -import { - getAccessTokenCookie, - getActiveTeamIdCookie, - getOrganizationIdCookie, - getTenantIdCookie -} from '@app/helpers/cookies'; +import { getAccessTokenCookie, getOrganizationIdCookie, getTenantIdCookie } from '@app/helpers/cookies'; import axios, { AxiosRequestConfig, AxiosResponse } from 'axios'; const api = axios.create({ @@ -13,9 +8,10 @@ const api = axios.create({ withCredentials: true, timeout: 60 * 1000 }); + api.interceptors.request.use( async (config: any) => { - const cookie = getActiveTeamIdCookie(); + const cookie = getAccessTokenCookie(); if (cookie) { config.headers['Authorization'] = `Bearer ${cookie}`; @@ -27,6 +23,7 @@ api.interceptors.request.use( Promise.reject(error); } ); + api.interceptors.response.use( (response: AxiosResponse) => response, async (error: { response: AxiosResponse }) => { diff --git a/apps/web/app/stores/fullWidth.ts b/apps/web/app/stores/fullWidth.ts index 85485c666..ace0453fd 100644 --- a/apps/web/app/stores/fullWidth.ts +++ b/apps/web/app/stores/fullWidth.ts @@ -1,6 +1,6 @@ import { atom } from 'recoil'; -export const fullWidthState = atom({ +export const fullWidthState = atom({ key: 'fullWidth', default: true }); diff --git a/apps/web/lib/components/dropdown.tsx b/apps/web/lib/components/dropdown.tsx index 76da4b7ca..bad425fcf 100644 --- a/apps/web/lib/components/dropdown.tsx +++ b/apps/web/lib/components/dropdown.tsx @@ -115,7 +115,7 @@ export function Dropdown({
)} -
+
{items.map((Item, index) => ( item.name) - ).length === statusFilters[k].length + ).length === statusFilters[k].length : statusFilters[k].includes(task[k]); }); }); @@ -346,7 +346,7 @@ export function TaskStatusFilter({ hook }: { hook: I_TaskFilter }) { const t = useTranslations(); return ( -
+
= ({ const dragTeamMember = React.useRef(0); const draggedOverTeamMember = React.useRef(0); + useEffect(() => setMemberOrdereds(members), [members]); + function handleSort() { const peopleClone = [...memberOrdereds]; const temp = peopleClone[dragTeamMember.current]; diff --git a/apps/web/lib/features/timer/timer-status.tsx b/apps/web/lib/features/timer/timer-status.tsx index 258af4023..95be0e0b0 100644 --- a/apps/web/lib/features/timer/timer-status.tsx +++ b/apps/web/lib/features/timer/timer-status.tsx @@ -53,20 +53,33 @@ export function getTimerStatusValue( member: OT_Member | undefined, publicTeam?: boolean ): ITimerStatusEnum { - return !member?.employee?.isActive && !publicTeam - ? 'suspended' - : member?.timerStatus === 'pause' - ? 'pause' - : !timerStatus?.running && - timerStatus?.lastLog && - timerStatus?.lastLog?.startedAt && - timerStatus?.lastLog?.employeeId === member?.employeeId && - moment().diff(moment(timerStatus?.lastLog?.startedAt), 'hours') < 24 && - timerStatus?.lastLog?.source !== 'TEAMS' - ? 'pause' - : member?.employee?.isOnline && member?.timerStatus === 'running' - ? 'online' - : !member?.totalTodayTasks?.length - ? 'idle' - : member?.timerStatus || 'idle'; + const isSuspended = () => !member?.employee?.isActive && !publicTeam; + const isPaused = () => member?.timerStatus === 'pause'; + const shouldPauseDueToTimerStatus = () => { + return ( + !timerStatus?.running && + timerStatus?.lastLog?.startedAt && + timerStatus?.lastLog?.employeeId === member?.employeeId && + moment().diff(moment(timerStatus?.lastLog?.startedAt), 'hours') < 24 && + timerStatus?.lastLog?.source !== 'TEAMS' + ); + }; + const isOnline = () => member?.employee?.isOnline && member?.employee?.isTrackingTime; + const isIdle = () => !member?.totalTodayTasks?.length; + + let status: ITimerStatusEnum; + + if (isOnline()) { + status = 'online'; + } else if (isIdle()) { + status = 'idle'; + } else if (isPaused() || shouldPauseDueToTimerStatus()) { + status = 'pause'; + } else if (isSuspended()) { + status = 'suspended'; + } else { + status = member?.timerStatus || 'idle'; + } + + return status; } diff --git a/apps/web/lib/features/unverified-email.tsx b/apps/web/lib/features/unverified-email.tsx index 104c6a73c..dab1cf4e5 100644 --- a/apps/web/lib/features/unverified-email.tsx +++ b/apps/web/lib/features/unverified-email.tsx @@ -45,7 +45,7 @@ export function UnverifiedEmail() { 'border dark:border-[#28292F] dark:shadow-lg dark:bg-[#1B1D22]' )} > - + {t('pages.home.SENT_EMAIL_VERIFICATION_YOU_NEED_TO')} {t('common.VERIFY')} diff --git a/apps/web/lib/features/user-profile-tasks.tsx b/apps/web/lib/features/user-profile-tasks.tsx index 5fb45f85d..623afdc3e 100644 --- a/apps/web/lib/features/user-profile-tasks.tsx +++ b/apps/web/lib/features/user-profile-tasks.tsx @@ -35,7 +35,7 @@ export function UserProfileTask({ profile, tabFiltered }: Props) { return (
{tabFiltered.tab === 'worked' && - (profile.member?.timerStatus === 'running' || (profile.isAuthUser && timerStatus?.running)) && + (profile.member?.employee?.isTrackingTime || (profile.isAuthUser && timerStatus?.running)) && otherTasks.length > 0 && ( /* Displaying the current time. */
@@ -55,7 +55,7 @@ export function UserProfileTask({ profile, tabFiltered }: Props) { )} {tabFiltered.tab === 'worked' && - (profile.member?.timerStatus === 'running' || (profile.isAuthUser && timerStatus?.running)) && ( + (profile.member?.employee?.isTrackingTime || (profile.isAuthUser && timerStatus?.running)) && (