Skip to content

Commit f80a11d

Browse files
refactor some actions
1 parent 41967e1 commit f80a11d

File tree

10 files changed

+411
-450
lines changed

10 files changed

+411
-450
lines changed

packages/web/src/actions.ts

Lines changed: 2 additions & 424 deletions
Large diffs are not rendered by default.

packages/web/src/app/(app)/@sidebar/components/defaultSidebar/index.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ import { cookies } from "next/headers";
22
import { auth } from "@/auth";
33
import { HOME_VIEW_COOKIE_NAME } from "@/lib/constants";
44
import { HomeView } from "@/hooks/useHomeView";
5-
import { getConnectionStats, getOrgAccountRequests } from "@/actions";
5+
import { getConnectionStats } from "@/actions";
6+
import { getOrgAccountRequests } from "@/features/userManagement/actions";
67
import { isServiceError } from "@/lib/utils";
78
import { ServiceErrorException } from "@/lib/serviceError";
89
import { __unsafePrisma } from "@/prisma";

packages/web/src/app/(app)/layout.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import { SubmitJoinRequest } from "./components/submitJoinRequest";
2121
import { env } from "@sourcebot/shared";
2222
import { hasEntitlement, isAnonymousAccessEnabled } from "@/lib/entitlements";
2323
import { GcpIapAuth } from "./components/gcpIapAuth";
24-
import { getMemberApprovalRequired } from "@/actions";
2524
import { JoinOrganizationCard } from "@/app/components/joinOrganizationCard";
2625
import { LogoutEscapeHatch } from "@/app/components/logoutEscapeHatch";
2726
import { GitHubStarToast } from "./components/githubStarToast";
@@ -74,8 +73,7 @@ export default async function Layout(props: LayoutProps) {
7473
// the join organization card to allow them to join the org if seat capacity is freed up. This card handles checking if the org has available seats.
7574
// 2. The org requires member approval, and they haven't been approved yet. In this case, we allow them to submit a request to join the org.
7675
if (!membership) {
77-
const memberApprovalRequired = await getMemberApprovalRequired();
78-
if (!memberApprovalRequired) {
76+
if (!org.memberApprovalRequired) {
7977
return (
8078
<div className="min-h-screen flex items-center justify-center p-6">
8179
<LogoutEscapeHatch className="absolute top-0 right-0 p-6" />

packages/web/src/app/(app)/settings/layout.tsx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@ import { Metadata } from "next"
33
import { redirect } from "next/navigation";
44
import { auth } from "@/auth";
55
import { isServiceError } from "@/lib/utils";
6-
import { getConnectionStats, getOrgAccountRequests } from "@/actions";
6+
import { getConnectionStats } from "@/actions";
7+
import { getOrgAccountRequests } from "@/features/userManagement/actions";
78
import { ServiceErrorException } from "@/lib/serviceError";
89
import { OrgRole } from "@prisma/client";
910
import { env } from "@sourcebot/shared";

packages/web/src/app/(app)/settings/members/components/inviteMemberCard.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import { zodResolver } from "@hookform/resolvers/zod";
88
import { useForm } from "react-hook-form";
99
import { useCallback, useState } from "react";
1010
import { z } from "zod";
11-
import { PlusCircleIcon, Loader2, AlertCircle, AlertTriangle } from "lucide-react";
11+
import { PlusCircleIcon, Loader2, AlertTriangle } from "lucide-react";
1212
import { OrgRole } from "@prisma/client";
1313
import { AlertDialog, AlertDialogAction, AlertDialogCancel, AlertDialogContent, AlertDialogDescription, AlertDialogFooter, AlertDialogHeader, AlertDialogTitle } from "@/components/ui/alert-dialog";
14-
import { createInvites } from "@/actions";
14+
import { createInvites } from "@/features/userManagement/actions";
1515
import { isServiceError } from "@/lib/utils";
1616
import { useToast } from "@/components/hooks/use-toast";
1717
import { useRouter } from "next/navigation";

packages/web/src/app/(app)/settings/members/components/invitesList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { createPathWithQueryParams, isServiceError } from "@/lib/utils";
1111
import { UserAvatar } from "@/components/userAvatar";
1212
import { Copy, MoreVertical, Search } from "lucide-react";
1313
import { useCallback, useMemo, useState } from "react";
14-
import { cancelInvite } from "@/actions";
14+
import { cancelInvite } from "@/features/userManagement/actions";
1515
import { useRouter } from "next/navigation";
1616
import useCaptureEvent from "@/hooks/useCaptureEvent";
1717
interface Invite {

packages/web/src/app/(app)/settings/members/components/requestsList.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import { isServiceError } from "@/lib/utils";
1010
import { UserAvatar } from "@/components/userAvatar";
1111
import { CheckCircle, Search, XCircle } from "lucide-react";
1212
import { useCallback, useMemo, useState } from "react";
13-
import { approveAccountRequest, rejectAccountRequest } from "@/actions";
13+
import { rejectAccountRequest, approveAccountRequest } from "@/features/userManagement/actions";
1414
import { useRouter } from "next/navigation";
1515
import useCaptureEvent from "@/hooks/useCaptureEvent";
1616

packages/web/src/app/(app)/settings/members/page.tsx

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import { MembersList } from "./components/membersList";
2-
import { getOrgMembers } from "@/actions";
2+
import { getOrgMembers, getOrgInvites, getOrgAccountRequests } from "@/features/userManagement/actions";
33
import { isServiceError } from "@/lib/utils";
44
import { InviteMemberCard } from "./components/inviteMemberCard";
55
import { Tabs, TabsContent } from "@/components/ui/tabs";
66
import { TabSwitcher } from "@/components/ui/tab-switcher";
77
import { InvitesList } from "./components/invitesList";
8-
import { getOrgInvites, getMe, getOrgAccountRequests } from "@/actions";
98
import { ServiceErrorException } from "@/lib/serviceError";
109
import { hasEntitlement } from "@/lib/entitlements";
1110
import { RequestsList } from "./components/requestsList";
@@ -22,18 +21,13 @@ type MembersSettingsPageProps = {
2221
}>
2322
}
2423

25-
export default authenticatedPage<MembersSettingsPageProps>(async ({ org, role }, props) => {
24+
export default authenticatedPage<MembersSettingsPageProps>(async ({ org, role, user }, props) => {
2625
const searchParams = await props.searchParams;
2726

2827
const {
2928
tab
3029
} = searchParams;
3130

32-
const me = await getMe();
33-
if (isServiceError(me)) {
34-
throw new ServiceErrorException(me);
35-
}
36-
3731
const members = await getOrgMembers();
3832
if (isServiceError(members)) {
3933
throw new ServiceErrorException(members);
@@ -132,7 +126,7 @@ export default authenticatedPage<MembersSettingsPageProps>(async ({ org, role },
132126
<TabsContent value="members">
133127
<MembersList
134128
members={members}
135-
currentUserId={me.id}
129+
currentUserId={user.id}
136130
currentUserRole={role}
137131
orgName={org.name}
138132
hasOrgManagement={await hasEntitlement('org-management')}

packages/web/src/app/invite/actions.ts

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
"use server";
22

3-
import { isServiceError } from "@/lib/utils";
4-
import { notAuthenticated, notFound, orgNotFound, ServiceError } from "@/lib/serviceError";
5-
import { sew } from "@/middleware/sew";
3+
import { createAudit } from "@/ee/features/audit/audit";
64
import { addUserToOrganization, orgHasAvailability } from "@/lib/authUtils";
7-
import { StatusCodes } from "http-status-codes";
5+
import { SINGLE_TENANT_ORG_ID } from "@/lib/constants";
86
import { ErrorCode } from "@/lib/errorCodes";
7+
import { notAuthenticated, notFound, orgNotFound, ServiceError } from "@/lib/serviceError";
8+
import { isServiceError } from "@/lib/utils";
9+
import { sew } from "@/middleware/sew";
910
import { getAuthenticatedUser } from "@/middleware/withAuth";
1011
import { __unsafePrisma } from "@/prisma";
11-
import { SINGLE_TENANT_ORG_ID } from "@/lib/constants";
12-
import { createAudit } from "@/ee/features/audit/audit";
12+
import { StatusCodes } from "http-status-codes";
1313

1414
export const joinOrganization = async (inviteLinkId?: string) => sew(async () => {
1515
const authResult = await getAuthenticatedUser();
@@ -180,4 +180,3 @@ export const getInviteInfo = async (inviteId: string) => sew(async () => {
180180
}
181181
};
182182
});
183-

0 commit comments

Comments
 (0)