Skip to content

Commit

Permalink
Merge pull request #2140 from ever-co/feat/static-build-support-10
Browse files Browse the repository at this point in the history
Feat/Next-Frontend APIs
  • Loading branch information
evereq authored Jan 31, 2024
2 parents 3f0b492 + ba74263 commit e7c0b14
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 33 deletions.
14 changes: 7 additions & 7 deletions apps/web/app/api/email-reset/request-change-email/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
14 changes: 7 additions & 7 deletions apps/web/app/api/email-reset/verify-change-email/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
6 changes: 3 additions & 3 deletions apps/web/app/hooks/features/useTimer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down Expand Up @@ -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(() => {
Expand Down
27 changes: 24 additions & 3 deletions apps/web/app/services/client/api/auth.ts
Original file line number Diff line number Diff line change
@@ -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<ILoginResponse>(`/auth/login`, {
Expand Down Expand Up @@ -66,6 +73,20 @@ export const verifyUserEmailByTokenAPI = (email: string, token: string) => {
return api.post<ISuccessResponse>(`/auth/verify/token`, { email, token });
};

export const resentVerifyUserLinkAPI = () => {
return api.post<ISuccessResponse>(`/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<ISuccessResponse>(`/auth/verify/resend-link`, body);
};
8 changes: 4 additions & 4 deletions apps/web/app/services/client/api/email-reset.ts
Original file line number Diff line number Diff line change
@@ -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<CreateResponse<ISuccessResponse>>(`/email-reset/request-change-email`, {
return post<ISuccessResponse>(`/email-reset/request-change-email`, {
email
});
}
export function verifyChangeEmailRequestAPI(code: string) {
return api.post<CreateResponse<ISuccessResponse>>(`/email-reset/verify-change-email`, { code });
return post<ISuccessResponse>(`/email-reset/verify-change-email`, { code });
}
84 changes: 79 additions & 5 deletions apps/web/app/services/client/api/timer.ts
Original file line number Diff line number Diff line change
@@ -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 });
Expand All @@ -9,21 +11,93 @@ export async function getTimerStatusAPI(tenantId: string, organizationId: string
return get<ITimerStatus>(endpoint);
}

export function toggleTimerAPI(body: Pick<IToggleTimerParams, 'taskId'>) {
export async function toggleTimerAPI(body: Pick<IToggleTimerParams, 'taskId'>) {
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<ITimerStatus>('/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<ITimerStatus>('/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<ITimerStatus>('/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<ITimerStatus>('/timer/sync', {
source
});
Expand Down
9 changes: 5 additions & 4 deletions apps/web/lib/features/unverified-email.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -57,7 +58,7 @@ export function UnverifiedEmail() {
<button
type="button"
className="cursor-pointer text-primary dark:text-primary-light"
onClick={resendLinkQueryCall}
onClick={() => user && resendLinkQueryCall(user)}
>
{t('common.HERE')}
</button>
Expand All @@ -69,14 +70,14 @@ export function UnverifiedEmail() {
<CloseIcon />
</button> */}
</Card>
<ConfirmUserModal open={isOpen} closeModal={closeModal} />
<ConfirmUserModal open={isOpen} user={user} closeModal={closeModal} />
</>
) : (
<></>
);
}

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);

Expand Down Expand Up @@ -128,7 +129,7 @@ export function ConfirmUserModal({ open, closeModal }: { open: boolean; closeMod
<button
type="button"
className="text-xs font-normal text-gray-500 dark:text-gray-400"
onClick={resendLinkQueryCall}
onClick={() => user && resendLinkQueryCall(user)}
>
{'Re'}
<span className="text-primary dark:text-primary-light">
Expand Down

0 comments on commit e7c0b14

Please sign in to comment.