From 7228a360e40e3715cfee0dbe7c21f47e378f44f3 Mon Sep 17 00:00:00 2001 From: Yume <2839681263@qq.com> Date: Tue, 20 May 2025 11:30:12 +0800 Subject: [PATCH 1/2] feat(UI): Create default organization when user first sign-in --- moon/apps/web/README.md | 2 +- moon/apps/web/pages/index.tsx | 61 +++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 14 deletions(-) diff --git a/moon/apps/web/README.md b/moon/apps/web/README.md index 1d67ece73..a931a8315 100644 --- a/moon/apps/web/README.md +++ b/moon/apps/web/README.md @@ -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. diff --git a/moon/apps/web/pages/index.tsx b/moon/apps/web/pages/index.tsx index 4cc426ec3..ef165e04d 100644 --- a/moon/apps/web/pages/index.tsx +++ b/moon/apps/web/pages/index.tsx @@ -1,11 +1,9 @@ -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 <> @@ -13,16 +11,18 @@ export default function IndexPage() { 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) { @@ -33,8 +33,6 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query }) => } } - const { device } = userAgentFromString(req.headers['user-agent']) - if (device.type === 'mobile') { return { redirect: { @@ -50,9 +48,46 @@ 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) + }) + + //新建organization时会自动创建第一个channel(General) + + // const defaultChannel = "default channel" + // + // apiClient.organizations + // .postProjects() + // .request(`my-first-organization`,{ name: defaultChannel }, {headers}) + // .catch(e => { + // throw new Error("postProjectError: " + 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 } } From 358cfa80e233acbcc725ab07da45c0f2fc31886c Mon Sep 17 00:00:00 2001 From: Yume <2839681263@qq.com> Date: Tue, 20 May 2025 12:03:44 +0800 Subject: [PATCH 2/2] chore(UI): Remove comments --- moon/apps/web/pages/index.tsx | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/moon/apps/web/pages/index.tsx b/moon/apps/web/pages/index.tsx index ef165e04d..dd2e524cc 100644 --- a/moon/apps/web/pages/index.tsx +++ b/moon/apps/web/pages/index.tsx @@ -65,18 +65,6 @@ export const getServerSideProps: GetServerSideProps = async ({ req, query }) => throw new Error("postOrganizationError: " + e.message) }) - //新建organization时会自动创建第一个channel(General) - - // const defaultChannel = "default channel" - // - // apiClient.organizations - // .postProjects() - // .request(`my-first-organization`,{ name: defaultChannel }, {headers}) - // .catch(e => { - // throw new Error("postProjectError: " + e.message) - // } - // ) - if (device.type === 'mobile') { return { redirect: {