Skip to content

Commit

Permalink
Merge pull request #2449 from ever-co/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
evereq authored Apr 29, 2024
2 parents 4b5bcba + 6110c1a commit 686df33
Show file tree
Hide file tree
Showing 16 changed files with 68 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ const UserProfileTasks: FC<IUserProfileTasks> = observer(({ profile, content })
>
{content.tab === 'worked' &&
profile.activeUserTeamTask &&
(profile.member?.timerStatus === 'running' || (profile.isAuthUser && timerStatus?.running)) ? (
(profile.member?.employee?.isTrackingTime || (profile.isAuthUser && timerStatus?.running)) ? (
<>
<View
style={{
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/app/services/interfaces/IEmployee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export interface IEmployee {
startedWorkOn: any;
endWork: any;
payPeriod: string;
isTrackingTime?: boolean;
billRateValue: number;
billRateCurrency: string;
reWeeklyLimit: number;
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/[locale]/profile/[memberId]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const Profile = React.memo(function ProfilePage({ params }: { params: { memberId
<div className="h-0.5 bg-[#FFFFFF14]"></div>
{hook.tab == 'worked' && canSeeActivity && (
<Container fullWidth={fullWidth} className="py-8">
<div className={clsxm('flex justify-start items-center gap-4')}>
<div className={clsxm('flex justify-start items-center gap-4 mt-3')}>
{Object.keys(activityScreens).map((filter, i) => (
<div key={i} className="flex cursor-pointer justify-start items-center gap-4">
{i !== 0 && <VerticalSeparator />}
Expand Down
10 changes: 5 additions & 5 deletions apps/web/app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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}`;

Expand Down Expand Up @@ -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;
}
13 changes: 6 additions & 7 deletions apps/web/app/helpers/cookies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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) => {
Expand Down Expand Up @@ -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);
Expand Down
10 changes: 6 additions & 4 deletions apps/web/app/hooks/auth/useAuthenticationTeam.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;

Expand Down Expand Up @@ -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 || {});
Expand Down
1 change: 1 addition & 0 deletions apps/web/app/interfaces/IEmployee.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export interface IEmployee {
short_description: any;
description: any;
startedWorkOn: any;
isTrackingTime?: boolean;
endWork: any;
payPeriod: string;
billRateValue: number;
Expand Down
11 changes: 4 additions & 7 deletions apps/web/app/services/client/axios.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
/* 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({
baseURL: API_BASE_URL,
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}`;
Expand All @@ -27,6 +23,7 @@ api.interceptors.request.use(
Promise.reject(error);
}
);

api.interceptors.response.use(
(response: AxiosResponse) => response,
async (error: { response: AxiosResponse }) => {
Expand Down
2 changes: 1 addition & 1 deletion apps/web/app/stores/fullWidth.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { atom } from 'recoil';

export const fullWidthState = atom<any>({
export const fullWidthState = atom<boolean>({
key: 'fullWidth',
default: true
});
2 changes: 1 addition & 1 deletion apps/web/lib/components/dropdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ export function Dropdown<T extends DropdownItem>({
</div>
)}
<ScrollArea>
<section className={'min-w-[100px]'}>
<section className={'max-h-96 min-w-[100px]'}>
{items.map((Item, index) => (
<Listbox.Option
key={Item.key ? Item.key : index}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/lib/features/task/task-filters.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ export function useTaskFilter(profile: I_UserProfilePage) {
? intersection(
statusFilters[k],
task['tags'].map((item) => item.name)
).length === statusFilters[k].length
).length === statusFilters[k].length
: statusFilters[k].includes(task[k]);
});
});
Expand Down Expand Up @@ -346,7 +346,7 @@ export function TaskStatusFilter({ hook }: { hook: I_TaskFilter }) {
const t = useTranslations();

return (
<div className="flex flex-col items-center mt-4 space-x-2 md:justify-between md:flex-row">
<div className="flex flex-col items-center mt-4 space-x-2 md:justify-between md:flex-row pt-2">
<div className="flex flex-wrap justify-center flex-1 space-x-3 md:justify-start">
<TaskStatusDropdown
key={key + 1}
Expand Down
4 changes: 3 additions & 1 deletion apps/web/lib/features/team-members-card-view.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { InviteFormModal } from './team/invite/invite-form-modal';
import { InvitedCard, InviteUserTeamCard } from './team/invite/user-invite-card';
import { InviteUserTeamSkeleton, UserTeamCard, UserTeamCardSkeleton } from '.';
import { OT_Member } from '@app/interfaces';
import React from 'react';
import React, { useEffect } from 'react';

interface Props {
teamMembers: OT_Member[];
Expand All @@ -30,6 +30,8 @@ const TeamMembersCardView: React.FC<Props> = ({
const dragTeamMember = React.useRef<number>(0);
const draggedOverTeamMember = React.useRef<number>(0);

useEffect(() => setMemberOrdereds(members), [members]);

function handleSort() {
const peopleClone = [...memberOrdereds];
const temp = peopleClone[dragTeamMember.current];
Expand Down
45 changes: 29 additions & 16 deletions apps/web/lib/features/timer/timer-status.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion apps/web/lib/features/unverified-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function UnverifiedEmail() {
'border dark:border-[#28292F] dark:shadow-lg dark:bg-[#1B1D22]'
)}
>
<Text>
<Text className="flex items-center gap-1">
{t('pages.home.SENT_EMAIL_VERIFICATION_YOU_NEED_TO')}
<span className="cursor-pointer text-primary dark:text-primary-light" onClick={openModal}>
{t('common.VERIFY')}
Expand Down
4 changes: 2 additions & 2 deletions apps/web/lib/features/user-profile-tasks.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export function UserProfileTask({ profile, tabFiltered }: Props) {
return (
<div className="mt-10">
{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. */
<div className="flex items-center mb-3 space-x-2">
Expand All @@ -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)) && (
<TaskCard
active
task={profile.activeUserTeamTask}
Expand Down
8 changes: 4 additions & 4 deletions apps/web/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
"clsx": "^2.0.0",
"cmdk": "^0.2.0",
"cookie": "^0.5.0",
"cookies-next": "^4.1.0",
"cookies-next": "^4.1.1",
"date-fns": "^2.30.0",
"domhandler": "^5.0.3",
"embla-carousel-react": "^8.0.0-rc11",
Expand Down Expand Up @@ -102,6 +102,7 @@
"tailwindcss-animate": "^1.0.6"
},
"devDependencies": {
"@svgr/webpack": "^8.1.0",
"@tailwindcss/typography": "^0.5.9",
"@types/cookie": "^0.5.1",
"@types/js-cookie": "^3.0.2",
Expand All @@ -112,11 +113,10 @@
"@types/react-beautiful-dnd": "^13.1.6",
"@types/react-dom": "18.0.6",
"@types/react-google-recaptcha": "^2.1.5",
"@svgr/webpack": "^8.1.0",
"dotenv": "^16.4.1",
"eslint": "^8.28.0",
"eslint-plugin-unused-imports": "^3.0.0",
"eslint-config-next": "^14.0.4",
"dotenv": "^16.4.1",
"eslint-plugin-unused-imports": "^3.0.0",
"typescript": "^4.9.4"
},
"prettier": {
Expand Down

0 comments on commit 686df33

Please sign in to comment.