Add dynamic apply wizard customization with admin settings UI
- Create wizard config types, utilities, and defaults (wizard-config.ts) - Add admin apply settings page with drag-and-drop step ordering, dropdown option management, feature toggles, welcome message customization, and custom field builder with select/multiselect options editor - Build dynamic apply wizard component with animated step transitions, mobile-first responsive design, and config-driven form validation - Update step components to accept dynamic config (categories, ocean issues, field visibility, feature flags) - Replace hardcoded enum validation with string-based validation for admin-configurable dropdown values, with safe enum casting at storage layer - Add wizard template system (model, router, admin UI) with built-in MOPC Classic preset - Add program wizard config CRUD procedures to program router - Update application router getConfig to return wizardConfig, submit handler to store custom field data in metadataJson - Add edition-based apply page, project pool page, and supporting routers - Fix CSS (invalid sm:fixed-none), Enter key handler (skip textarea), safe area insets for notched phones, buildStepsArray field visibility Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,6 +1,9 @@
|
||||
import { z } from 'zod'
|
||||
import type { Prisma } from '@prisma/client'
|
||||
import { router, protectedProcedure, adminProcedure } from '../trpc'
|
||||
import { logAudit } from '../utils/audit'
|
||||
import { wizardConfigSchema } from '@/types/wizard-config'
|
||||
import { parseWizardConfig } from '@/lib/wizard-config'
|
||||
|
||||
export const programRouter = router({
|
||||
/**
|
||||
@@ -93,8 +96,10 @@ export const programRouter = router({
|
||||
z.object({
|
||||
id: z.string(),
|
||||
name: z.string().min(1).max(255).optional(),
|
||||
slug: z.string().min(1).max(100).optional(),
|
||||
status: z.enum(['DRAFT', 'ACTIVE', 'ARCHIVED']).optional(),
|
||||
description: z.string().optional(),
|
||||
settingsJson: z.record(z.any()).optional(),
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
@@ -145,4 +150,66 @@ export const programRouter = router({
|
||||
|
||||
return program
|
||||
}),
|
||||
|
||||
/**
|
||||
* Get wizard config for a program (parsed from settingsJson)
|
||||
*/
|
||||
getWizardConfig: protectedProcedure
|
||||
.input(z.object({ programId: z.string() }))
|
||||
.query(async ({ ctx, input }) => {
|
||||
const program = await ctx.prisma.program.findUniqueOrThrow({
|
||||
where: { id: input.programId },
|
||||
select: { settingsJson: true },
|
||||
})
|
||||
return parseWizardConfig(program.settingsJson)
|
||||
}),
|
||||
|
||||
/**
|
||||
* Update wizard config for a program (admin only)
|
||||
*/
|
||||
updateWizardConfig: adminProcedure
|
||||
.input(
|
||||
z.object({
|
||||
programId: z.string(),
|
||||
wizardConfig: wizardConfigSchema,
|
||||
})
|
||||
)
|
||||
.mutation(async ({ ctx, input }) => {
|
||||
const program = await ctx.prisma.program.findUniqueOrThrow({
|
||||
where: { id: input.programId },
|
||||
select: { settingsJson: true },
|
||||
})
|
||||
|
||||
const currentSettings = (program.settingsJson || {}) as Record<string, unknown>
|
||||
|
||||
const updatedSettings = {
|
||||
...currentSettings,
|
||||
wizardConfig: input.wizardConfig,
|
||||
}
|
||||
|
||||
await ctx.prisma.program.update({
|
||||
where: { id: input.programId },
|
||||
data: {
|
||||
settingsJson: updatedSettings as Prisma.InputJsonValue,
|
||||
},
|
||||
})
|
||||
|
||||
await logAudit({
|
||||
prisma: ctx.prisma,
|
||||
userId: ctx.user.id,
|
||||
action: 'UPDATE',
|
||||
entityType: 'Program',
|
||||
entityId: input.programId,
|
||||
detailsJson: {
|
||||
field: 'wizardConfig',
|
||||
stepsEnabled: input.wizardConfig.steps.filter((s) => s.enabled).length,
|
||||
totalSteps: input.wizardConfig.steps.length,
|
||||
customFieldsCount: input.wizardConfig.customFields?.length ?? 0,
|
||||
},
|
||||
ipAddress: ctx.ip,
|
||||
userAgent: ctx.userAgent,
|
||||
})
|
||||
|
||||
return { success: true }
|
||||
}),
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user