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
34 changes: 5 additions & 29 deletions apps/webapp/app/routes/_app.github.callback/route.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { type LoaderFunctionArgs, redirect } from "@remix-run/node";
import { type LoaderFunctionArgs } from "@remix-run/node";
import { z } from "zod";
import { validateGitHubAppInstallSession } from "~/services/gitHubSession.server";
import { linkGitHubAppInstallation, updateGitHubAppInstallation } from "~/services/gitHub.server";
import { logger } from "~/services/logger.server";
import {
redirectWithErrorMessage,
setRequestSuccessMessage,
commitSession,
} from "~/models/message.server";
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
import { tryCatch } from "@trigger.dev/core";
import { $replica } from "~/db.server";
import { requireUser } from "~/services/session.server";
Expand Down Expand Up @@ -92,14 +88,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
return redirectWithErrorMessage(redirectTo, request, "Failed to install GitHub App");
}

const session = await setRequestSuccessMessage(request, "GitHub App installed successfully");
session.flash("gitHubAppInstalled", true);

return redirect(redirectTo, {
headers: {
"Set-Cookie": await commitSession(session),
},
});
return redirectWithSuccessMessage(redirectTo, request, "GitHub App installed successfully");
}

case "update": {
Expand All @@ -112,14 +101,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
return redirectWithErrorMessage(redirectTo, request, "Failed to update GitHub App");
}

const session = await setRequestSuccessMessage(request, "GitHub App updated successfully");
session.flash("gitHubAppInstalled", true);

return redirect(redirectTo, {
headers: {
"Set-Cookie": await commitSession(session),
},
});
return redirectWithSuccessMessage(redirectTo, request, "GitHub App updated successfully");
}

case "request": {
Expand All @@ -129,13 +111,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
callbackData,
});

const session = await setRequestSuccessMessage(request, "GitHub App installation requested");

return redirect(redirectTo, {
headers: {
"Set-Cookie": await commitSession(session),
},
});
return redirectWithSuccessMessage(redirectTo, request, "GitHub App installation requested");
}

default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
useActionData,
useNavigation,
useNavigate,
useSearchParams,
} from "@remix-run/react";
import { type ActionFunction, type LoaderFunctionArgs, json } from "@remix-run/server-runtime";
import { typedjson, useTypedLoaderData } from "remix-typedjson";
Expand Down Expand Up @@ -49,8 +50,6 @@ import {
redirectBackWithSuccessMessage,
redirectWithErrorMessage,
redirectWithSuccessMessage,
getSession,
commitSession,
} from "~/models/message.server";
import { ProjectSettingsService } from "~/services/projectSettings.server";
import { logger } from "~/services/logger.server";
Expand Down Expand Up @@ -123,22 +122,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {

const { gitHubApp, buildSettings } = resultOrFail.value;

const session = await getSession(request.headers.get("Cookie"));
const openGitHubRepoConnectionModal = session.get("gitHubAppInstalled") === true;
const headers = new Headers({
"Set-Cookie": await commitSession(session),
return typedjson({
githubAppEnabled: gitHubApp.enabled,
githubAppInstallations: gitHubApp.installations,
connectedGithubRepository: gitHubApp.connectedRepository,
buildSettings,
});

return typedjson(
{
githubAppEnabled: gitHubApp.enabled,
githubAppInstallations: gitHubApp.installations,
connectedGithubRepository: gitHubApp.connectedRepository,
openGitHubRepoConnectionModal,
buildSettings,
},
{ headers }
);
};

const ConnectGitHubRepoFormSchema = z.object({
Expand Down Expand Up @@ -444,13 +433,8 @@ export const action: ActionFunction = async ({ request, params }) => {
};

export default function Page() {
const {
githubAppInstallations,
connectedGithubRepository,
githubAppEnabled,
openGitHubRepoConnectionModal,
buildSettings,
} = useTypedLoaderData<typeof loader>();
const { githubAppInstallations, connectedGithubRepository, githubAppEnabled, buildSettings } =
useTypedLoaderData<typeof loader>();
const project = useProject();
const organization = useOrganization();
const environment = useEnvironment();
Expand Down Expand Up @@ -584,7 +568,6 @@ export default function Page() {
organizationSlug={organization.slug}
projectSlug={project.slug}
environmentSlug={environment.slug}
openGitHubRepoConnectionModal={openGitHubRepoConnectionModal}
/>
)}
</div>
Expand Down Expand Up @@ -667,15 +650,14 @@ function ConnectGitHubRepoModal({
organizationSlug,
projectSlug,
environmentSlug,
open = false,
}: {
gitHubAppInstallations: GitHubAppInstallation[];
organizationSlug: string;
projectSlug: string;
environmentSlug: string;
open?: boolean;
}) {
const [isModalOpen, setIsModalOpen] = useState(open);
const [isModalOpen, setIsModalOpen] = useState(false);
const lastSubmission = useActionData() as any;
const navigate = useNavigate();

Expand Down Expand Up @@ -703,6 +685,17 @@ function ConnectGitHubRepoModal({
},
});

const [searchParams, setSearchParams] = useSearchParams();
useEffect(() => {
const params = new URLSearchParams(searchParams);

if (params.get("openGithubRepoModal") === "1") {
setIsModalOpen(true);
params.delete("openGithubRepoModal");
setSearchParams(params);
}
}, [searchParams, setSearchParams]);

useEffect(() => {
if (lastSubmission && "success" in lastSubmission && lastSubmission.success === true) {
setIsModalOpen(false);
Expand Down Expand Up @@ -759,11 +752,11 @@ function ConnectGitHubRepoModal({
navigate(
githubAppInstallPath(
organizationSlug,
v3ProjectSettingsPath(
`${v3ProjectSettingsPath(
{ slug: organizationSlug },
{ slug: projectSlug },
{ slug: environmentSlug }
)
)}?openGithubRepoModal=1`
)
);
}}
Expand Down Expand Up @@ -856,13 +849,11 @@ function GitHubConnectionPrompt({
organizationSlug,
projectSlug,
environmentSlug,
openGitHubRepoConnectionModal = false,
}: {
gitHubAppInstallations: GitHubAppInstallation[];
organizationSlug: string;
projectSlug: string;
environmentSlug: string;
openGitHubRepoConnectionModal?: boolean;
}) {
return (
<Fieldset>
Expand All @@ -871,11 +862,11 @@ function GitHubConnectionPrompt({
<LinkButton
to={githubAppInstallPath(
organizationSlug,
v3ProjectSettingsPath(
`${v3ProjectSettingsPath(
{ slug: organizationSlug },
{ slug: projectSlug },
{ slug: environmentSlug }
)
)}?openGithubRepoModal=1`
)}
variant={"secondary/medium"}
LeadingIcon={OctoKitty}
Expand All @@ -890,7 +881,6 @@ function GitHubConnectionPrompt({
organizationSlug={organizationSlug}
projectSlug={projectSlug}
environmentSlug={environmentSlug}
open={openGitHubRepoConnectionModal}
/>
<span className="flex items-center gap-1 text-xs text-text-dimmed">
<CheckCircleIcon className="size-4 text-success" /> GitHub app is installed
Expand Down
2 changes: 1 addition & 1 deletion apps/webapp/app/services/projectSettings.server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class ProjectSettingsService {
repositoryId: repositoryId,
branchTracking: {
prod: { branch: defaultBranch },
staging: { branch: defaultBranch },
staging: {},
} satisfies BranchTrackingConfig,
previewDeploymentsEnabled: true,
},
Expand Down
Loading