Files
smoothschedule/frontend/src/hooks/useCustomDomains.ts
poduck d158c1ddb0 feat: Implement tenant invitation system with onboarding wizard
Backend Implementation:
- Add TenantInvitation model with lifecycle management (PENDING/ACCEPTED/EXPIRED/CANCELLED)
- Create platform admin API endpoints for invitation CRUD operations
- Add public token-based endpoints for invitation retrieval and acceptance
- Implement schema_context wrappers to ensure tenant operations run in public schema
- Add tenant permissions: can_manage_oauth_credentials, can_accept_payments, can_use_custom_domain, can_white_label, can_api_access
- Fix tenant update/create serializers to handle multi-schema environment
- Add migrations for tenant permissions and invitation system

Frontend Implementation:
- Create TenantInviteModal with comprehensive invitation form (350 lines)
  - Email, business name, subscription tier configuration
  - Custom user/resource limits
  - Platform permissions toggles
  - Future feature flags (video conferencing, event types, calendars, 2FA, logs, data deletion, POS, mobile app)
- Build TenantOnboardPage with 4-step wizard for invitation acceptance
  - Step 1: Account setup (email, password, name)
  - Step 2: Business details (name, subdomain, contact)
  - Step 3: Payment setup (conditional based on permissions)
  - Step 4: Success confirmation with redirect
- Extract BusinessCreateModal and BusinessEditModal into separate components
- Refactor PlatformBusinesses from 1080 lines to 220 lines (80% reduction)
- Add inactive businesses dropdown section (similar to staff page pattern)
- Update masquerade button styling to match Users page
- Remove deprecated "Add New Tenant" functionality in favor of invitation flow
- Add /tenant-onboard route for public access

API Integration:
- Add platform.ts API functions for tenant invitations
- Create React Query hooks in usePlatform.ts for invitation management
- Implement proper error handling and success states
- Add TypeScript interfaces for invitation types

Testing:
- Verified end-to-end invitation flow from creation to acceptance
- Confirmed tenant, domain, and owner user creation
- Validated schema context fixes for multi-tenant environment
- Tested active/inactive business filtering

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
2025-11-28 03:55:07 -05:00

86 lines
2.1 KiB
TypeScript

/**
* React Query hooks for custom domain management
*/
import { useQuery, useMutation, useQueryClient } from '@tanstack/react-query';
import {
getCustomDomains,
addCustomDomain,
deleteCustomDomain,
verifyCustomDomain,
setPrimaryDomain,
} from '../api/customDomains';
import { CustomDomain } from '../types';
/**
* Hook to fetch all custom domains for the current business
*/
export const useCustomDomains = () => {
return useQuery<CustomDomain[], Error>({
queryKey: ['customDomains'],
queryFn: getCustomDomains,
retry: false, // Don't retry on 404
staleTime: 5 * 60 * 1000, // 5 minutes
});
};
/**
* Hook to add a new custom domain
*/
export const useAddCustomDomain = () => {
const queryClient = useQueryClient();
return useMutation<CustomDomain, Error, string>({
mutationFn: addCustomDomain,
onSuccess: () => {
// Invalidate and refetch custom domains
queryClient.invalidateQueries({ queryKey: ['customDomains'] });
},
});
};
/**
* Hook to delete a custom domain
*/
export const useDeleteCustomDomain = () => {
const queryClient = useQueryClient();
return useMutation<void, Error, number>({
mutationFn: deleteCustomDomain,
onSuccess: () => {
// Invalidate and refetch custom domains
queryClient.invalidateQueries({ queryKey: ['customDomains'] });
},
});
};
/**
* Hook to verify a custom domain
*/
export const useVerifyCustomDomain = () => {
const queryClient = useQueryClient();
return useMutation<{ verified: boolean; message: string }, Error, number>({
mutationFn: verifyCustomDomain,
onSuccess: () => {
// Invalidate and refetch custom domains
queryClient.invalidateQueries({ queryKey: ['customDomains'] });
},
});
};
/**
* Hook to set a custom domain as primary
*/
export const useSetPrimaryDomain = () => {
const queryClient = useQueryClient();
return useMutation<CustomDomain, Error, number>({
mutationFn: setPrimaryDomain,
onSuccess: () => {
// Invalidate and refetch custom domains
queryClient.invalidateQueries({ queryKey: ['customDomains'] });
},
});
};