diff --git a/apps/web/app/api/email-reset/request-change-email/route.ts b/apps/web/app/api/email-reset/request-change-email/route.ts index 4c929a74f..35c03719b 100644 --- a/apps/web/app/api/email-reset/request-change-email/route.ts +++ b/apps/web/app/api/email-reset/request-change-email/route.ts @@ -10,11 +10,11 @@ export async function POST(req: Request) { const { email } = (await req.json()) as IEmail; - return $res( - await emailResetRequest({ - email, - tenantId, - bearer_token: access_token - }) - ); + const response = await emailResetRequest({ + email, + tenantId, + bearer_token: access_token + }); + + return $res(response.data); } diff --git a/apps/web/app/api/email-reset/verify-change-email/route.ts b/apps/web/app/api/email-reset/verify-change-email/route.ts index 382970eb3..9960b18b3 100644 --- a/apps/web/app/api/email-reset/verify-change-email/route.ts +++ b/apps/web/app/api/email-reset/verify-change-email/route.ts @@ -10,11 +10,11 @@ export async function POST(req: Request) { const { code } = (await req.json()) as ICode; - return $res( - await verifyChangemailRequest({ - code, - tenantId, - bearer_token: access_token - }) - ); + const response = await verifyChangemailRequest({ + code, + tenantId, + bearer_token: access_token + }); + + return $res(response.data); } diff --git a/apps/web/app/hooks/features/useTimer.ts b/apps/web/app/hooks/features/useTimer.ts index b7a6bfc5a..479f5c803 100644 --- a/apps/web/app/hooks/features/useTimer.ts +++ b/apps/web/app/hooks/features/useTimer.ts @@ -153,7 +153,7 @@ function useLocalTimeCounter(timerStatus: ITimerStatus | null, activeTeamTask: I export function useTimer() { const { updateTask, activeTeamId, activeTeam, activeTeamTask } = useTeamTasks(); const { updateOrganizationTeamEmployeeActiveTask } = useOrganizationEmployeeTeams(); - const { user } = useAuthenticateUser(); + const { user, $user } = useAuthenticateUser(); const [timerStatus, setTimerStatus] = useRecoilState(timerStatusState); @@ -229,10 +229,10 @@ export function useTimer() { if (syncTimerLoading || syncTimerLoadingRef.current) { return; } - return syncTimerQueryCall(timerStatus?.lastLog?.source || TimerSource.TEAMS).then((res) => { + return syncTimerQueryCall(timerStatus?.lastLog?.source || TimerSource.TEAMS, $user.current).then((res) => { return res; }); - }, [syncTimerQueryCall, timerStatus, syncTimerLoading, syncTimerLoadingRef]); + }, [syncTimerQueryCall, timerStatus, syncTimerLoading, syncTimerLoadingRef, $user]); // Loading states useEffect(() => { diff --git a/apps/web/app/services/client/api/auth.ts b/apps/web/app/services/client/api/auth.ts index 3c9f7e0b8..6576e4bf7 100644 --- a/apps/web/app/services/client/api/auth.ts +++ b/apps/web/app/services/client/api/auth.ts @@ -1,7 +1,14 @@ import { getRefreshTokenCookie } from '@app/helpers/cookies'; import { ISuccessResponse, IUser } from '@app/interfaces'; import { ILoginResponse, IRegisterDataAPI, ISigninEmailConfirmResponse } from '@app/interfaces/IAuthentication'; -import api, { get } from '../axios'; +import api, { get, post } from '../axios'; +import { + APP_LOGO_URL, + APP_NAME, + APP_SIGNATURE, + VERIFY_EMAIL_CALLBACK_PATH, + VERIFY_EMAIL_CALLBACK_URL +} from '@app/constants'; export const signInWithEmailAndCodeAPI = (email: string, code: string) => { return api.post(`/auth/login`, { @@ -66,6 +73,20 @@ export const verifyUserEmailByTokenAPI = (email: string, token: string) => { return api.post(`/auth/verify/token`, { email, token }); }; -export const resentVerifyUserLinkAPI = () => { - return api.post(`/auth/verify/resend-link`); +export const resentVerifyUserLinkAPI = (user: IUser) => { + const appEmailConfirmationUrl = `${location.origin}${VERIFY_EMAIL_CALLBACK_PATH}`; + const registerDefaultValue = { + appName: APP_NAME, + appSignature: APP_SIGNATURE, + appLogo: APP_LOGO_URL + }; + + const body = { + email: user.email, + tenantId: user.tenantId, + ...registerDefaultValue, + appEmailConfirmationUrl: VERIFY_EMAIL_CALLBACK_URL || appEmailConfirmationUrl + }; + + return post(`/auth/verify/resend-link`, body); }; diff --git a/apps/web/app/services/client/api/email-reset.ts b/apps/web/app/services/client/api/email-reset.ts index 94e53c0cb..f53e9ee4a 100644 --- a/apps/web/app/services/client/api/email-reset.ts +++ b/apps/web/app/services/client/api/email-reset.ts @@ -1,11 +1,11 @@ -import { CreateResponse, ISuccessResponse } from '@app/interfaces'; -import api from '../axios'; +import { ISuccessResponse } from '@app/interfaces'; +import { post } from '../axios'; export function emailResetRequestAPI(email: string) { - return api.post>(`/email-reset/request-change-email`, { + return post(`/email-reset/request-change-email`, { email }); } export function verifyChangeEmailRequestAPI(code: string) { - return api.post>(`/email-reset/verify-change-email`, { code }); + return post(`/email-reset/verify-change-email`, { code }); } diff --git a/apps/web/app/services/client/api/timer.ts b/apps/web/app/services/client/api/timer.ts index 1172d7ae2..405720e1f 100644 --- a/apps/web/app/services/client/api/timer.ts +++ b/apps/web/app/services/client/api/timer.ts @@ -1,6 +1,8 @@ import { ITimerStatus, IToggleTimerParams, TimerSource } from '@app/interfaces/ITimer'; -import api, { get } from '../axios'; +import api, { get, post } from '../axios'; import { GAUZY_API_BASE_SERVER_URL } from '@app/constants'; +import { getActiveTaskIdCookie, getActiveTeamIdCookie, getOrganizationIdCookie, getTenantIdCookie } from '@app/helpers'; +import { IUser } from '@app/interfaces'; export async function getTimerStatusAPI(tenantId: string, organizationId: string) { const params = new URLSearchParams({ tenantId, organizationId }); @@ -9,21 +11,93 @@ export async function getTimerStatusAPI(tenantId: string, organizationId: string return get(endpoint); } -export function toggleTimerAPI(body: Pick) { +export async function toggleTimerAPI(body: Pick) { + const organizationId = getOrganizationIdCookie(); + const tenantId = getTenantIdCookie(); + + if (GAUZY_API_BASE_SERVER_URL.value) { + await post('/timesheet/timer/toggle', { + source: TimerSource.TEAMS, + logType: 'TRACKED', + taskId: body.taskId, + tenantId, + organizationId + }); + + await post('/timesheet/timer/stop', { + source: TimerSource.TEAMS, + logType: 'TRACKED', + taskId: body.taskId, + tenantId, + organizationId + }); + + return getTimerStatusAPI(tenantId, organizationId); + } + return api.post('/timer/toggle', body); } -export function startTimerAPI() { +export async function startTimerAPI() { + const organizationId = getOrganizationIdCookie(); + const tenantId = getTenantIdCookie(); + const teamId = getActiveTeamIdCookie(); + const taskId = getActiveTaskIdCookie(); + + if (GAUZY_API_BASE_SERVER_URL.value) { + await post('/timesheet/timer/start', { + tenantId, + organizationId, + taskId, + logType: 'TRACKED', + source: TimerSource.TEAMS, + tags: [], + organizationTeamId: teamId + }); + + return getTimerStatusAPI(tenantId, organizationId); + } + return api.post('/timer/start'); } -export function stopTimerAPI(source: TimerSource) { +export async function stopTimerAPI(source: TimerSource) { + const organizationId = getOrganizationIdCookie(); + const tenantId = getTenantIdCookie(); + const taskId = getActiveTaskIdCookie(); + + if (GAUZY_API_BASE_SERVER_URL.value) { + await post('/timesheet/timer/stop', { + source, + logType: 'TRACKED', + ...(taskId ? { taskId } : {}), + tenantId, + organizationId + }); + + return getTimerStatusAPI(tenantId, organizationId); + } + return api.post('/timer/stop', { source }); } -export function syncTimerAPI(source: TimerSource) { +export async function syncTimerAPI(source: TimerSource, user: IUser | undefined) { + const organizationId = getOrganizationIdCookie(); + const tenantId = getTenantIdCookie(); + + if (GAUZY_API_BASE_SERVER_URL.value) { + await post('/timesheet/timer/stop', { + tenantId, + organizationId, + logType: 'TRACKED', + source, + employeeId: user?.employee.id, + duration: 5 + }); + } + return api.post('/timer/sync', { source }); diff --git a/apps/web/lib/features/unverified-email.tsx b/apps/web/lib/features/unverified-email.tsx index 132454cd9..3abe9f9cc 100644 --- a/apps/web/lib/features/unverified-email.tsx +++ b/apps/web/lib/features/unverified-email.tsx @@ -2,6 +2,7 @@ import { getAccessTokenCookie } from '@app/helpers'; import { useAuthenticateUser, useModal, useQuery } from '@app/hooks'; +import { IUser } from '@app/interfaces'; import { resentVerifyUserLinkAPI, verifyUserEmailByCodeAPI } from '@app/services/client/api'; import { clsxm } from '@app/utils'; import { AuthCodeInputField, Button, Card, Modal, SpinnerLoader, Text } from 'lib/components'; @@ -57,7 +58,7 @@ export function UnverifiedEmail() { @@ -69,14 +70,14 @@ export function UnverifiedEmail() { */} - + ) : ( <> ); } -export function ConfirmUserModal({ open, closeModal }: { open: boolean; closeModal: () => void }) { +export function ConfirmUserModal({ open, user, closeModal }: { open: boolean; user?: IUser; closeModal: () => void }) { const { loading, queryCall } = useQuery(verifyUserEmailByCodeAPI); const { loading: resendLinkLoading, queryCall: resendLinkQueryCall } = useQuery(resentVerifyUserLinkAPI); @@ -128,7 +129,7 @@ export function ConfirmUserModal({ open, closeModal }: { open: boolean; closeMod