Skip to content
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion moon/apps/web/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
First, run the development server:

```bash
yarn dev
turbo run dev --parallel
```

Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
Expand Down
49 changes: 36 additions & 13 deletions moon/apps/web/pages/index.tsx
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
import { GetServerSideProps } from 'next'
import { userAgentFromString } from 'next/server'

import { SCOPE_COOKIE_NAME } from '@gitmono/config'
import { ApiErrorTypes } from '@gitmono/types'

import { apiCookieHeaders } from '@/utils/apiCookieHeaders'
import { apiClient, signinUrl } from '@/utils/queryClient'
import { SCOPE_COOKIE_NAME } from '@gitmono/config';
import { ApiErrorTypes, OrganizationsPostRequest } from '@gitmono/types';
import { GetServerSideProps } from 'next';
import { userAgentFromString } from 'next/server';
import { apiCookieHeaders } from '@/utils/apiCookieHeaders';
import { apiClient, signinUrl } from '@/utils/queryClient';

export default function IndexPage() {
return <></>
}

export const getServerSideProps: GetServerSideProps = async ({ req, query }) => {
try {
const { device } = userAgentFromString(req.headers['user-agent'])
const headers = apiCookieHeaders(req.cookies)

const organizations = await apiClient.organizationMemberships
.getOrganizationMemberships()
.request({ headers })
.then((res) => res.map((m) => m.organization))

// if we have orgs redirect to one of the user orgs
// if we have orgs redirect to one of the user orgs,
// otherwise redirect to the new org page
if (organizations.length > 0) {
let org = organizations[0]
let org = organizations[organizations.length - 1]
const scope = req.cookies[SCOPE_COOKIE_NAME]

if (scope) {
Expand All @@ -33,8 +33,6 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query }) =>
}
}

const { device } = userAgentFromString(req.headers['user-agent'])

if (device.type === 'mobile') {
return {
redirect: {
Expand All @@ -50,9 +48,34 @@ 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."
}

apiClient.organizations
.postOrganizations()
.request(defaultOrgData)
.catch((e) => {
throw new Error("postOrganizationError: " + e.message)
})

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