Onboarding guard/resume is now in place and respects “no package” deep links to billing.
This commit is contained in:
93
resources/js/admin/mobile/lib/onboardingGuard.test.ts
Normal file
93
resources/js/admin/mobile/lib/onboardingGuard.test.ts
Normal file
@@ -0,0 +1,93 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { resolveOnboardingRedirect } from './onboardingGuard';
|
||||
import {
|
||||
ADMIN_WELCOME_EVENT_PATH,
|
||||
ADMIN_WELCOME_PACKAGES_PATH,
|
||||
ADMIN_WELCOME_SUMMARY_PATH,
|
||||
} from '../../constants';
|
||||
|
||||
describe('resolveOnboardingRedirect', () => {
|
||||
it('returns null when events exist', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: true,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: null,
|
||||
pathname: '/event-admin/mobile/dashboard',
|
||||
isWelcomePath: false,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for welcome paths', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: null,
|
||||
pathname: ADMIN_WELCOME_PACKAGES_PATH,
|
||||
isWelcomePath: true,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('returns null for billing paths', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: null,
|
||||
pathname: '/event-admin/mobile/billing',
|
||||
isWelcomePath: false,
|
||||
isBillingPath: true,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
|
||||
it('redirects to event setup when package active', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: true,
|
||||
selectedPackageId: null,
|
||||
pathname: '/event-admin/mobile/dashboard',
|
||||
isWelcomePath: false,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBe(ADMIN_WELCOME_EVENT_PATH);
|
||||
});
|
||||
|
||||
it('redirects to summary when selection exists', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: 5,
|
||||
pathname: '/event-admin/mobile/dashboard',
|
||||
isWelcomePath: false,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBe(ADMIN_WELCOME_SUMMARY_PATH);
|
||||
});
|
||||
|
||||
it('redirects to packages when no selection exists', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: null,
|
||||
pathname: '/event-admin/mobile/dashboard',
|
||||
isWelcomePath: false,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBe(ADMIN_WELCOME_PACKAGES_PATH);
|
||||
});
|
||||
|
||||
it('does not redirect when already on target', () => {
|
||||
const result = resolveOnboardingRedirect({
|
||||
hasEvents: false,
|
||||
hasActivePackage: false,
|
||||
selectedPackageId: null,
|
||||
pathname: ADMIN_WELCOME_PACKAGES_PATH,
|
||||
isWelcomePath: false,
|
||||
isBillingPath: false,
|
||||
});
|
||||
expect(result).toBeNull();
|
||||
});
|
||||
});
|
||||
44
resources/js/admin/mobile/lib/onboardingGuard.ts
Normal file
44
resources/js/admin/mobile/lib/onboardingGuard.ts
Normal file
@@ -0,0 +1,44 @@
|
||||
import {
|
||||
ADMIN_WELCOME_EVENT_PATH,
|
||||
ADMIN_WELCOME_PACKAGES_PATH,
|
||||
ADMIN_WELCOME_SUMMARY_PATH,
|
||||
} from '../../constants';
|
||||
|
||||
type OnboardingRedirectInput = {
|
||||
hasEvents: boolean;
|
||||
hasActivePackage: boolean;
|
||||
selectedPackageId?: number | null;
|
||||
pathname: string;
|
||||
isWelcomePath: boolean;
|
||||
isBillingPath: boolean;
|
||||
};
|
||||
|
||||
export function resolveOnboardingRedirect({
|
||||
hasEvents,
|
||||
hasActivePackage,
|
||||
selectedPackageId,
|
||||
pathname,
|
||||
isWelcomePath,
|
||||
isBillingPath,
|
||||
}: OnboardingRedirectInput): string | null {
|
||||
if (hasEvents) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (isWelcomePath || isBillingPath) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const shouldContinueSummary = Boolean(selectedPackageId && selectedPackageId > 0);
|
||||
const target = hasActivePackage
|
||||
? ADMIN_WELCOME_EVENT_PATH
|
||||
: shouldContinueSummary
|
||||
? ADMIN_WELCOME_SUMMARY_PATH
|
||||
: ADMIN_WELCOME_PACKAGES_PATH;
|
||||
|
||||
if (pathname === target) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
Reference in New Issue
Block a user