Skip to content

Commit 480c0d3

Browse files
authored
fix(webapp): toast message issue after gh app installation (#2546)
* fix(webapp): toast message issue after gh app installation Fixes an issue with displaying toasts messages in the project settings page. The github callback cookie was interfering with the flash cookie used for toast messages. * Do not set a tracking branch in the staging env by default
1 parent 700a6ea commit 480c0d3

File tree

3 files changed

+30
-64
lines changed

3 files changed

+30
-64
lines changed

apps/webapp/app/routes/_app.github.callback/route.tsx

Lines changed: 5 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
1-
import { type LoaderFunctionArgs, redirect } from "@remix-run/node";
1+
import { type LoaderFunctionArgs } from "@remix-run/node";
22
import { z } from "zod";
33
import { validateGitHubAppInstallSession } from "~/services/gitHubSession.server";
44
import { linkGitHubAppInstallation, updateGitHubAppInstallation } from "~/services/gitHub.server";
55
import { logger } from "~/services/logger.server";
6-
import {
7-
redirectWithErrorMessage,
8-
setRequestSuccessMessage,
9-
commitSession,
10-
} from "~/models/message.server";
6+
import { redirectWithErrorMessage, redirectWithSuccessMessage } from "~/models/message.server";
117
import { tryCatch } from "@trigger.dev/core";
128
import { $replica } from "~/db.server";
139
import { requireUser } from "~/services/session.server";
@@ -92,14 +88,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
9288
return redirectWithErrorMessage(redirectTo, request, "Failed to install GitHub App");
9389
}
9490

95-
const session = await setRequestSuccessMessage(request, "GitHub App installed successfully");
96-
session.flash("gitHubAppInstalled", true);
97-
98-
return redirect(redirectTo, {
99-
headers: {
100-
"Set-Cookie": await commitSession(session),
101-
},
102-
});
91+
return redirectWithSuccessMessage(redirectTo, request, "GitHub App installed successfully");
10392
}
10493

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

115-
const session = await setRequestSuccessMessage(request, "GitHub App updated successfully");
116-
session.flash("gitHubAppInstalled", true);
117-
118-
return redirect(redirectTo, {
119-
headers: {
120-
"Set-Cookie": await commitSession(session),
121-
},
122-
});
104+
return redirectWithSuccessMessage(redirectTo, request, "GitHub App updated successfully");
123105
}
124106

125107
case "request": {
@@ -129,13 +111,7 @@ export async function loader({ request }: LoaderFunctionArgs) {
129111
callbackData,
130112
});
131113

132-
const session = await setRequestSuccessMessage(request, "GitHub App installation requested");
133-
134-
return redirect(redirectTo, {
135-
headers: {
136-
"Set-Cookie": await commitSession(session),
137-
},
138-
});
114+
return redirectWithSuccessMessage(redirectTo, request, "GitHub App installation requested");
139115
}
140116

141117
default:

apps/webapp/app/routes/_app.orgs.$organizationSlug.projects.$projectParam.env.$envParam.settings/route.tsx

Lines changed: 24 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
useActionData,
1515
useNavigation,
1616
useNavigate,
17+
useSearchParams,
1718
} from "@remix-run/react";
1819
import { type ActionFunction, type LoaderFunctionArgs, json } from "@remix-run/server-runtime";
1920
import { typedjson, useTypedLoaderData } from "remix-typedjson";
@@ -49,8 +50,6 @@ import {
4950
redirectBackWithSuccessMessage,
5051
redirectWithErrorMessage,
5152
redirectWithSuccessMessage,
52-
getSession,
53-
commitSession,
5453
} from "~/models/message.server";
5554
import { ProjectSettingsService } from "~/services/projectSettings.server";
5655
import { logger } from "~/services/logger.server";
@@ -123,22 +122,12 @@ export const loader = async ({ request, params }: LoaderFunctionArgs) => {
123122

124123
const { gitHubApp, buildSettings } = resultOrFail.value;
125124

126-
const session = await getSession(request.headers.get("Cookie"));
127-
const openGitHubRepoConnectionModal = session.get("gitHubAppInstalled") === true;
128-
const headers = new Headers({
129-
"Set-Cookie": await commitSession(session),
125+
return typedjson({
126+
githubAppEnabled: gitHubApp.enabled,
127+
githubAppInstallations: gitHubApp.installations,
128+
connectedGithubRepository: gitHubApp.connectedRepository,
129+
buildSettings,
130130
});
131-
132-
return typedjson(
133-
{
134-
githubAppEnabled: gitHubApp.enabled,
135-
githubAppInstallations: gitHubApp.installations,
136-
connectedGithubRepository: gitHubApp.connectedRepository,
137-
openGitHubRepoConnectionModal,
138-
buildSettings,
139-
},
140-
{ headers }
141-
);
142131
};
143132

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

446435
export default function Page() {
447-
const {
448-
githubAppInstallations,
449-
connectedGithubRepository,
450-
githubAppEnabled,
451-
openGitHubRepoConnectionModal,
452-
buildSettings,
453-
} = useTypedLoaderData<typeof loader>();
436+
const { githubAppInstallations, connectedGithubRepository, githubAppEnabled, buildSettings } =
437+
useTypedLoaderData<typeof loader>();
454438
const project = useProject();
455439
const organization = useOrganization();
456440
const environment = useEnvironment();
@@ -584,7 +568,6 @@ export default function Page() {
584568
organizationSlug={organization.slug}
585569
projectSlug={project.slug}
586570
environmentSlug={environment.slug}
587-
openGitHubRepoConnectionModal={openGitHubRepoConnectionModal}
588571
/>
589572
)}
590573
</div>
@@ -667,15 +650,14 @@ function ConnectGitHubRepoModal({
667650
organizationSlug,
668651
projectSlug,
669652
environmentSlug,
670-
open = false,
671653
}: {
672654
gitHubAppInstallations: GitHubAppInstallation[];
673655
organizationSlug: string;
674656
projectSlug: string;
675657
environmentSlug: string;
676658
open?: boolean;
677659
}) {
678-
const [isModalOpen, setIsModalOpen] = useState(open);
660+
const [isModalOpen, setIsModalOpen] = useState(false);
679661
const lastSubmission = useActionData() as any;
680662
const navigate = useNavigate();
681663

@@ -703,6 +685,17 @@ function ConnectGitHubRepoModal({
703685
},
704686
});
705687

688+
const [searchParams, setSearchParams] = useSearchParams();
689+
useEffect(() => {
690+
const params = new URLSearchParams(searchParams);
691+
692+
if (params.get("openGithubRepoModal") === "1") {
693+
setIsModalOpen(true);
694+
params.delete("openGithubRepoModal");
695+
setSearchParams(params);
696+
}
697+
}, [searchParams, setSearchParams]);
698+
706699
useEffect(() => {
707700
if (lastSubmission && "success" in lastSubmission && lastSubmission.success === true) {
708701
setIsModalOpen(false);
@@ -759,11 +752,11 @@ function ConnectGitHubRepoModal({
759752
navigate(
760753
githubAppInstallPath(
761754
organizationSlug,
762-
v3ProjectSettingsPath(
755+
`${v3ProjectSettingsPath(
763756
{ slug: organizationSlug },
764757
{ slug: projectSlug },
765758
{ slug: environmentSlug }
766-
)
759+
)}?openGithubRepoModal=1`
767760
)
768761
);
769762
}}
@@ -856,13 +849,11 @@ function GitHubConnectionPrompt({
856849
organizationSlug,
857850
projectSlug,
858851
environmentSlug,
859-
openGitHubRepoConnectionModal = false,
860852
}: {
861853
gitHubAppInstallations: GitHubAppInstallation[];
862854
organizationSlug: string;
863855
projectSlug: string;
864856
environmentSlug: string;
865-
openGitHubRepoConnectionModal?: boolean;
866857
}) {
867858
return (
868859
<Fieldset>
@@ -871,11 +862,11 @@ function GitHubConnectionPrompt({
871862
<LinkButton
872863
to={githubAppInstallPath(
873864
organizationSlug,
874-
v3ProjectSettingsPath(
865+
`${v3ProjectSettingsPath(
875866
{ slug: organizationSlug },
876867
{ slug: projectSlug },
877868
{ slug: environmentSlug }
878-
)
869+
)}?openGithubRepoModal=1`
879870
)}
880871
variant={"secondary/medium"}
881872
LeadingIcon={OctoKitty}
@@ -890,7 +881,6 @@ function GitHubConnectionPrompt({
890881
organizationSlug={organizationSlug}
891882
projectSlug={projectSlug}
892883
environmentSlug={environmentSlug}
893-
open={openGitHubRepoConnectionModal}
894884
/>
895885
<span className="flex items-center gap-1 text-xs text-text-dimmed">
896886
<CheckCircleIcon className="size-4 text-success" /> GitHub app is installed

apps/webapp/app/services/projectSettings.server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class ProjectSettingsService {
9090
repositoryId: repositoryId,
9191
branchTracking: {
9292
prod: { branch: defaultBranch },
93-
staging: { branch: defaultBranch },
93+
staging: {},
9494
} satisfies BranchTrackingConfig,
9595
previewDeploymentsEnabled: true,
9696
},

0 commit comments

Comments
 (0)