Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 28 additions & 19 deletions moon/apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { SCOPE_COOKIE_NAME } from '@gitmono/config';
import { ApiErrorTypes, OrganizationsPostRequest } from '@gitmono/types';
import { ApiErrorTypes } from '@gitmono/types';
import { GetServerSideProps } from 'next';
import { userAgentFromString } from 'next/server';
import { apiCookieHeaders } from '@/utils/apiCookieHeaders';
Expand All @@ -18,7 +18,7 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query }) =>
.getOrganizationMemberships()
.request({ headers })
.then((res) =>
res.map((m) => m.organization)
res.map(m => m.organization)
.filter(o => o !== null)
)

Expand Down Expand Up @@ -51,34 +51,43 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query }) =>
}
}
} else {
const defaultOrgData: OrganizationsPostRequest = {
name: "My First Organization",
slug: "my-first-organization",
avatar_path: null,
role: "software-engineer",
org_size: "1",
source: "google",
why: "Please enter your purpose."
}
const userData = await apiClient.users
.getMe()
.request({ headers })
.then((res) => res)

await apiClient.organizations.postInvitations().request(
'mega',
{
invitations: [
{
email: userData.email,
role: 'member'
}
]
},
{ headers }
)

apiClient.organizations
.postOrganizations()
.request(defaultOrgData,{ headers })
.catch((e) => {
throw new Error("postOrganizationError: " + e.message)
})
const invitations = await apiClient.users.getMeOrganizationInvitations().request({ headers })

for (let i of invitations) {
if (i.organization?.slug === 'mega') {
await apiClient.invitationsByToken.postInvitationsByTokenAccept().request(i.token!!, { headers })
}
}

if (device.type === 'mobile') {
return {
redirect: {
destination: `/${defaultOrgData.slug}/${query.path ?? 'home'}`,
destination: `/mega/${query.path ?? 'home'}`,
permanent: false
}
}
}
return {
redirect: {
destination: `/${defaultOrgData.slug}/${query.path ?? ''}`,
destination: `/mega/${query.path ?? ''}`,
permanent: false
}
}
Expand Down