소스 검색

improved error handling (#29)

Bernt Christian Egeland 7 달 전
부모
커밋
227a23850d
3개의 변경된 파일과 19개의 추가작업 그리고 1개의 파일을 삭제
  1. 2 0
      src/app/(authenticated)/settings/company/company-settings.tsx
  2. 3 0
      src/components/app-sidebar.tsx
  3. 14 1
      src/features/team/Actions/teamActions.ts

+ 2 - 0
src/app/(authenticated)/settings/company/company-settings.tsx

@@ -86,6 +86,8 @@ export function CompanySettings({ settings, organizationName }: { settings: Reco
       setNewOrgName("");
       router.refresh();
       toast.success(t('company.companyCreated'));
+    } else if (result.error) {
+      toast.error(result.error);
     }
   };
   const handleRemoveLogo = async () => {

+ 3 - 0
src/components/app-sidebar.tsx

@@ -4,6 +4,7 @@ import * as React from 'react'
 import Link from 'next/link'
 import Image from 'next/image'
 import { usePathname, useRouter } from 'next/navigation'
+import { toast } from 'sonner'
 import { signOut, useSession } from '@/lib/auth-client'
 import { Avatar, AvatarFallback } from '@/components/ui/avatar'
 import { Dialog, DialogContent, DialogHeader, DialogTitle } from '@/components/ui/dialog'
@@ -153,6 +154,8 @@ export function AppSidebar({
       setShowCreateOrg(false)
       setNewOrgName('')
       router.refresh()
+    } else if (result.error) {
+      toast.error(result.error)
     }
   }
 

+ 14 - 1
src/features/team/Actions/teamActions.ts

@@ -6,7 +6,7 @@ import { withAuth } from "@/lib/with-auth";
 import { createOrganizationSchema, inviteMemberSchema, updateMemberRoleSchema } from "../Schema/teamSchema";
 import { revalidatePath } from "next/cache";
 import { PermissionAction, PermissionSubject } from "@/lib/permissions";
-import { getFeatures, FeatureGatedError } from "@/lib/features";
+import { getFeatures, getMaxOrganizations, isCloudMode, FeatureGatedError } from "@/lib/features";
 
 export async function getOrganization() {
   return withAuth(async ({ userId, organizationId }) => {
@@ -60,6 +60,19 @@ export async function createOrganization(input: unknown) {
   return withAuth(async ({ userId }) => {
     const data = createOrganizationSchema.parse(input);
 
+    if (isCloudMode()) {
+      const ownedCount = await db.organizationMember.count({
+        where: { userId, role: "owner" },
+      });
+      const maxOrgs = await getMaxOrganizations(userId);
+
+      if (ownedCount >= maxOrgs) {
+        throw new Error(
+          `You have reached the maximum number of organizations (${maxOrgs}) for your plan. Upgrade to create more.`,
+        );
+      }
+    }
+
     const org = await db.$transaction(async (tx) => {
       const created = await tx.organization.create({
         data: { name: data.name },