Skip to content

Commit

Permalink
Merge pull request #2151 from ever-co/feat/static-build-support-11
Browse files Browse the repository at this point in the history
Feat/Next-Frontend APIs
  • Loading branch information
evereq authored Feb 4, 2024
2 parents 660f782 + 233bcee commit 966f5b6
Show file tree
Hide file tree
Showing 48 changed files with 868 additions and 653 deletions.
735 changes: 344 additions & 391 deletions apps/web/app/[locale]/auth/passcode/page.tsx

Large diffs are not rendered by default.

13 changes: 2 additions & 11 deletions apps/web/app/[locale]/integration/github/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,10 @@ const GitHub = () => {

const installing = useRef<boolean>(false);

const { installGitHub, getRepositories } = useGitHubIntegration();
// const { loading: integrationLoading } = useIntegration();
const { installGitHub, getRepositories } = useGitHubIntegration();
const { getIntegrationTenant, loading: integrationTenantLoading, integrationTenant } = useIntegrationTenant();

const { loading: loadingIntegrationTypes, integrationTypes, getIntegrationTypes } = useIntegrationTypes();

// const params = {
// state: 'http://localhost:3001/integration/github'
// } as { [x: string]: string };

// const queries = new URLSearchParams(params || {});
// const url = `https://github.com/apps/badal-ever-testing-probot/installations/new?${queries.toString()}`;


const handleInstallGitHub = useCallback(() => {
installing.current = true;

Expand Down
6 changes: 2 additions & 4 deletions apps/web/app/api/auth/_signin-workspace/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,7 @@ export async function POST(req: Request) {
noTeamPopup: true,
userId
},
req,
res
{ req, res }
);
return NextResponse.json({ team, loginResponse });
}
Expand Down Expand Up @@ -173,8 +172,7 @@ export async function POST(req: Request) {
noTeamPopup: true,
userId
},
req,
res
{ req, res }
);

return NextResponse.json({ loginResponse: data });
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/api/auth/login/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ export async function POST(req: Request) {
noTeamPopup: true,
userId
},
req,
res
{ req, res }
);

return NextResponse.json({ team, loginResponse });
Expand Down
3 changes: 1 addition & 2 deletions apps/web/app/api/auth/register/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,8 +137,7 @@ export async function POST(req: Request) {
languageId: 'en', // TODO: not sure what should be here
userId: user.id
},
req,
res
{ req, res }
);

return NextResponse.json({ loginRes, team, employee });
Expand Down
52 changes: 33 additions & 19 deletions apps/web/app/api/auth/signin-email-confirm/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ export async function POST(req: Request) {
const { errors, valid: formValid } = authFormValidate(['email', 'code'], body as any);

if (!formValid) {
return NextResponse.json({ errors });
return NextResponse.json({ errors }, { status: 400 });
}

// Accept Invite Flow Start
Expand Down Expand Up @@ -55,22 +55,31 @@ export async function POST(req: Request) {
acceptInviteRes.response.status === 400 ||
(acceptInviteRes?.data as any).response?.statusCode
) {
return NextResponse.json({
errors: {
email: 'Authentication code or email address invalid'
}
});
return NextResponse.json(
{
errors: {
email: 'Authentication code or email address invalid'
}
},
{ status: 400 }
);
}

loginResponse = acceptInviteRes.data;

if (!loginResponse) {
return NextResponse.json({
errors: {
email: 'Authentication code or email address invalid'
}
});
return NextResponse.json(
{
errors: {
email: 'Authentication code or email address invalid'
}
},
{ status: 400 }
);
}
}

// Login from Invitation
if (loginResponse) {
console.log('loginResponse>>>', loginResponse);

Expand All @@ -85,12 +94,16 @@ export async function POST(req: Request) {
const organization = organizations?.items[0];

if (!organization) {
return NextResponse.json({
errors: {
email: 'Your account is not yet ready to be used on the Ever Teams Platform'
}
});
return NextResponse.json(
{
errors: {
email: 'Your account is not yet ready to be used on the Ever Teams Platform'
}
},
{ status: 400 }
);
}

const { data: teams } = await getAllOrganizationTeamRequest(
{ tenantId, organizationId: organization.organizationId },
access_token
Expand All @@ -100,6 +113,7 @@ export async function POST(req: Request) {
if (!team) {
setNoTeamPopupShowCookie(true);
}

setAuthCookies(
{
access_token: loginResponse.token,
Expand All @@ -113,13 +127,13 @@ export async function POST(req: Request) {
noTeamPopup: true,
userId
},
req,
res
{ req, res }
);

return NextResponse.json({ team, loginResponse });
}
// Accept Invite Flow End

// Accept Invite Flow End
const { data } = await signInEmailConfirmRequest({
code: body.code,
email: body.email
Expand Down
80 changes: 35 additions & 45 deletions apps/web/app/helpers/cookies/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export const getLargeStringFromCookies = (COOKIE_NAME: string, ctx?: NextCtx) =>
return chunks.join('');
};

export function setAuthCookies(datas: DataParams, req: any, res: any) {
export function setAuthCookies(datas: DataParams, ctx?: NextCtx) {
const {
refresh_token,
access_token,
Expand All @@ -95,18 +95,18 @@ export function setAuthCookies(datas: DataParams, req: any, res: any) {
// Handle Large Access Token
// Cookie can support upto 4096 characters only!
if (access_token.length <= 4096) {
setCookie(TOKEN_COOKIE_NAME, access_token, { res, req }, true); // cross site cookie
setCookie(TOKEN_COOKIE_NAME, access_token, ctx, true); // cross site cookie
} else {
setLargeStringInCookies(TOKEN_COOKIE_NAME, access_token, req, res, true); // cross site cookie
setLargeStringInCookies(TOKEN_COOKIE_NAME, access_token, ctx?.req, ctx?.res, true); // cross site cookie
}

setCookie(REFRESH_TOKEN_COOKIE_NAME, refresh_token.token, { res, req }, true); // cross site cookie
setCookie(ACTIVE_TEAM_COOKIE_NAME, teamId, { res, req });
setCookie(TENANT_ID_COOKIE_NAME, tenantId, { res, req });
setCookie(ORGANIZATION_ID_COOKIE_NAME, organizationId, { res, req });
setCookie(ACTIVE_LANGUAGE_COOKIE_NAME, languageId, { res, req });
setCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, noTeamPopup, { res, req });
setCookie(ACTIVE_USER_ID_COOKIE_NAME, userId, { res, req });
setCookie(REFRESH_TOKEN_COOKIE_NAME, refresh_token.token, ctx, true); // cross site cookie
setCookie(ACTIVE_TEAM_COOKIE_NAME, teamId, ctx);
setCookie(TENANT_ID_COOKIE_NAME, tenantId, ctx);
setCookie(ORGANIZATION_ID_COOKIE_NAME, organizationId, ctx);
setCookie(ACTIVE_LANGUAGE_COOKIE_NAME, languageId, ctx);
setCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, noTeamPopup, ctx);
setCookie(ACTIVE_USER_ID_COOKIE_NAME, userId, ctx);
}

export function cookiesKeys() {
Expand Down Expand Up @@ -144,94 +144,86 @@ export function getAccessTokenCookie(ctx?: NextCtx) {
return getLargeStringFromCookies(TOKEN_COOKIE_NAME, ctx); // Total chunks cookie not found.
}

return getCookie(TOKEN_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(TOKEN_COOKIE_NAME, ctx) as string;
}

export function getTotalChunksCookie(COOKIE_NAME: string, ctx?: NextCtx) {
return getCookie(`${COOKIE_NAME}_totalChunks`, {
...(ctx || {})
}) as string;
return getCookie(`${COOKIE_NAME}_totalChunks`, ctx) as string;
}

// Refresh Token
export function getRefreshTokenCookie(ctx?: NextCtx) {
return getCookie(REFRESH_TOKEN_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(REFRESH_TOKEN_COOKIE_NAME, ctx) as string;
}

export function setAccessTokenCookie(accessToken: string, ctx?: NextCtx) {
return setCookie(TOKEN_COOKIE_NAME, accessToken, { ...(ctx || {}) }, true); // cross site cookie
return setCookie(TOKEN_COOKIE_NAME, accessToken, ctx, true); // cross site cookie
}

// Active team id
export function getActiveTeamIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_TEAM_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_TEAM_COOKIE_NAME, ctx) as string;
}

export function setActiveTeamIdCookie(teamIds: string, ctx?: NextCtx) {
return setCookie(ACTIVE_TEAM_COOKIE_NAME, teamIds, { ...(ctx || {}) });
return setCookie(ACTIVE_TEAM_COOKIE_NAME, teamIds, ctx);
}

// Active Project id
export function getActiveProjectIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_PROJECT_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_PROJECT_COOKIE_NAME, ctx) as string;
}

export function setActiveProjectIdCookie(teamIds: string, ctx?: NextCtx) {
return setCookie(ACTIVE_PROJECT_COOKIE_NAME, teamIds, { ...(ctx || {}) });
return setCookie(ACTIVE_PROJECT_COOKIE_NAME, teamIds, ctx);
}

// Organization Id
export function getOrganizationIdCookie(ctx?: NextCtx) {
return getCookie(ORGANIZATION_ID_COOKIE_NAME, { ...ctx }) as string;
return getCookie(ORGANIZATION_ID_COOKIE_NAME, ctx) as string;
}

export function setOrganizationIdCookie(orgId: string, ctx?: NextCtx) {
return setCookie(ORGANIZATION_ID_COOKIE_NAME, orgId, { ...(ctx || {}) });
return setCookie(ORGANIZATION_ID_COOKIE_NAME, orgId, ctx);
}

// Tenant Id
export function getTenantIdCookie(ctx?: NextCtx) {
return getCookie(TENANT_ID_COOKIE_NAME, { ...ctx }) as string;
return getCookie(TENANT_ID_COOKIE_NAME, ctx) as string;
}

// Active tasks

export function getActiveTaskIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_TASK_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_TASK_COOKIE_NAME, ctx) as string;
}

export function setActiveTaskIdCookie(taskId: string, ctx?: NextCtx) {
return setCookie(ACTIVE_TASK_COOKIE_NAME, taskId, { ...(ctx || {}) });
return setCookie(ACTIVE_TASK_COOKIE_NAME, taskId, ctx);
}

// Active userId
export function getActiveUserIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_USER_ID_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_USER_ID_COOKIE_NAME, ctx) as string;
}

export function setActiveUserIdCookie(userId: string, ctx?: NextCtx) {
return setCookie(ACTIVE_USER_ID_COOKIE_NAME, userId, { ...(ctx || {}) });
return setCookie(ACTIVE_USER_ID_COOKIE_NAME, userId, ctx);
}

export function getNoTeamPopupShowCookie(ctx?: NextCtx) {
return !!getCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, {
...(ctx || {})
});
return !!getCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, ctx);
}
export function setNoTeamPopupShowCookie(show: boolean, ctx?: NextCtx) {
return setCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, show, { ...(ctx || {}) });
return setCookie(NO_TEAM_POPUP_SHOW_COOKIE_NAME, show, ctx);
}

export function setActiveUserTaskCookie(data: { taskId: string; userId: string }, ctx?: NextCtx) {
return setCookie(ACTIVE_USER_TASK_COOKIE_NAME, JSON.stringify(data), {
...(ctx || {})
});
return setCookie(ACTIVE_USER_TASK_COOKIE_NAME, JSON.stringify(data), ctx);
}

export function getActiveUserTaskCookie(ctx?: NextCtx) {
const data = getCookie(ACTIVE_USER_TASK_COOKIE_NAME, {
...(ctx || {})
});
const data = getCookie(ACTIVE_USER_TASK_COOKIE_NAME, ctx);

try {
return JSON.parse(data as string) as { taskId: string; userId: string };
Expand All @@ -244,27 +236,25 @@ export function getActiveUserTaskCookie(ctx?: NextCtx) {

// Active language id
export function getActiveLanguageIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_LANGUAGE_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_LANGUAGE_COOKIE_NAME, ctx) as string;
}

export function setActiveLanguageIdCookie(languageIds: string, ctx?: NextCtx) {
return setCookie(ACTIVE_LANGUAGE_COOKIE_NAME, languageIds, {
...(ctx || {})
});
return setCookie(ACTIVE_LANGUAGE_COOKIE_NAME, languageIds, ctx);
}

// Timezone
export function setActiveTimezoneCookie(timezone: string, ctx?: NextCtx) {
return setCookie(ACTIVE_TIMEZONE_COOKIE_NAME, timezone, { ...(ctx || {}) });
return setCookie(ACTIVE_TIMEZONE_COOKIE_NAME, timezone, ctx);
}
export function getActiveTimezoneIdCookie(ctx?: NextCtx) {
return getCookie(ACTIVE_TIMEZONE_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(ACTIVE_TIMEZONE_COOKIE_NAME, ctx) as string;
}

// Jitsi
export function setMeetJwtSessionCookie(token: string, ctx?: NextCtx) {
return setCookie(MEET_JWT_TOKEN_COOKIE_NAME, token, { ...(ctx || {}) });
return setCookie(MEET_JWT_TOKEN_COOKIE_NAME, token, ctx);
}
export function getMeetJwtSessionCookie(ctx?: NextCtx) {
return getCookie(MEET_JWT_TOKEN_COOKIE_NAME, { ...(ctx || {}) }) as string;
return getCookie(MEET_JWT_TOKEN_COOKIE_NAME, ctx) as string;
}
Loading

0 comments on commit 966f5b6

Please sign in to comment.