Remove dynamic form builder and complete RoundProject→roundId migration

Major cleanup and schema migration:
- Remove unused dynamic form builder system (ApplicationForm, ApplicationFormField, etc.)
- Complete migration from RoundProject junction table to direct Project.roundId
- Add sortOrder and entryNotificationType fields to Round model
- Add country field to User model for mentor matching
- Enhance onboarding with profile photo and country selection steps
- Fix all TypeScript errors related to roundProjects references
- Remove unused libraries (@radix-ui/react-toast, embla-carousel-react, vaul)

Files removed:
- admin/forms/* pages and related components
- admin/onboarding/* pages
- applicationForm.ts and onboarding.ts routers
- Dynamic form builder Prisma models and enums

Schema changes:
- Removed ApplicationForm, ApplicationFormField, OnboardingStep, ApplicationFormSubmission, SubmissionFile models
- Removed FormFieldType and SpecialFieldType enums
- Added Round.sortOrder, Round.entryNotificationType
- Added User.country

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
2026-02-04 14:15:06 +01:00
parent 7bcd2ce6ca
commit 29827268b2
71 changed files with 2139 additions and 6609 deletions

View File

@@ -69,48 +69,29 @@ export const projectRouter = router({
// Build where clause
const where: Record<string, unknown> = {}
if (programId) where.programId = programId
// Filter by program via round
if (programId) where.round = { programId }
// Filter by round via RoundProject join
// Filter by round
if (roundId) {
where.roundProjects = { some: { roundId } }
where.roundId = roundId
}
// Exclude projects already in a specific round
// Exclude projects in a specific round
if (notInRoundId) {
where.roundProjects = {
...(where.roundProjects as Record<string, unknown> || {}),
none: { roundId: notInRoundId },
}
where.roundId = { not: notInRoundId }
}
// Filter by unassigned (not in any round)
// Filter by unassigned (no round)
if (unassignedOnly) {
where.roundProjects = { none: {} }
where.roundId = null
}
// Status filter via RoundProject
if (roundId && (statuses?.length || status)) {
// Status filter
if (statuses?.length || status) {
const statusValues = statuses?.length ? statuses : status ? [status] : []
if (statusValues.length > 0) {
where.roundProjects = {
some: {
roundId,
status: { in: statusValues },
},
}
}
} else if (statuses?.length || status) {
// Status filter without specific round — match any round with that status
const statusValues = statuses?.length ? statuses : status ? [status] : []
if (statusValues.length > 0) {
where.roundProjects = {
...(where.roundProjects as Record<string, unknown> || {}),
some: {
...((where.roundProjects as Record<string, unknown>)?.some as Record<string, unknown> || {}),
status: { in: statusValues },
},
}
where.status = { in: statusValues }
}
}
@@ -150,16 +131,12 @@ export const projectRouter = router({
orderBy: { createdAt: 'desc' },
include: {
files: true,
program: {
select: { id: true, name: true, year: true },
},
roundProjects: {
include: {
round: {
select: { id: true, name: true, sortOrder: true },
},
round: {
select: {
id: true,
name: true,
program: { select: { id: true, name: true, year: true } },
},
orderBy: { addedAt: 'desc' },
},
_count: { select: { assignments: true } },
},
@@ -183,8 +160,8 @@ export const projectRouter = router({
.query(async ({ ctx }) => {
const [rounds, countries, categories, issues] = await Promise.all([
ctx.prisma.round.findMany({
select: { id: true, name: true, sortOrder: true, program: { select: { name: true, year: true } } },
orderBy: [{ program: { year: 'desc' } }, { sortOrder: 'asc' }],
select: { id: true, name: true, program: { select: { name: true, year: true } } },
orderBy: [{ program: { year: 'desc' } }, { createdAt: 'asc' }],
}),
ctx.prisma.project.findMany({
where: { country: { not: null } },
@@ -228,17 +205,7 @@ export const projectRouter = router({
where: { id: input.id },
include: {
files: true,
program: {
select: { id: true, name: true, year: true },
},
roundProjects: {
include: {
round: {
select: { id: true, name: true, sortOrder: true, status: true },
},
},
orderBy: { round: { sortOrder: 'asc' } },
},
round: true,
teamMembers: {
include: {
user: {
@@ -307,13 +274,12 @@ export const projectRouter = router({
/**
* Create a single project (admin only)
* Projects belong to a program. Optionally assign to a round immediately.
* Projects belong to a round.
*/
create: adminProcedure
.input(
z.object({
programId: z.string(),
roundId: z.string().optional(),
roundId: z.string(),
title: z.string().min(1).max(500),
teamName: z.string().optional(),
description: z.string().optional(),
@@ -322,25 +288,15 @@ export const projectRouter = router({
})
)
.mutation(async ({ ctx, input }) => {
const { metadataJson, roundId, ...rest } = input
const { metadataJson, ...rest } = input
const project = await ctx.prisma.project.create({
data: {
...rest,
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
status: 'SUBMITTED',
},
})
// If roundId provided, also create RoundProject entry
if (roundId) {
await ctx.prisma.roundProject.create({
data: {
roundId,
projectId: project.id,
status: 'SUBMITTED',
},
})
}
// Audit log
await ctx.prisma.auditLog.create({
data: {
@@ -348,7 +304,7 @@ export const projectRouter = router({
action: 'CREATE',
entityType: 'Project',
entityId: project.id,
detailsJson: { title: input.title, programId: input.programId, roundId },
detailsJson: { title: input.title, roundId: input.roundId },
ipAddress: ctx.ip,
userAgent: ctx.userAgent,
},
@@ -391,22 +347,20 @@ export const projectRouter = router({
where: { id },
data: {
...data,
...(status && { status }),
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
},
})
// Update status on RoundProject if both status and roundId provided
if (status && roundId) {
await ctx.prisma.roundProject.updateMany({
where: { projectId: id, roundId },
data: { status },
// Send notifications if status changed
if (status) {
// Get round details for notification
const projectWithRound = await ctx.prisma.project.findUnique({
where: { id },
include: { round: { select: { name: true, entryNotificationType: true, program: { select: { name: true } } } } },
})
// Get round details including configured notification type
const round = await ctx.prisma.round.findUnique({
where: { id: roundId },
select: { name: true, entryNotificationType: true, program: { select: { name: true } } },
})
const round = projectWithRound?.round
// Helper to get notification title based on type
const getNotificationTitle = (type: string): string => {
@@ -445,7 +399,7 @@ export const projectRouter = router({
programName: round.program?.name,
},
})
} else {
} else if (round) {
// Fall back to hardcoded status-based notifications
const notificationConfig: Record<
string,
@@ -494,7 +448,7 @@ export const projectRouter = router({
action: 'UPDATE',
entityType: 'Project',
entityId: id,
detailsJson: { ...data, status, roundId, metadataJson } as Prisma.InputJsonValue,
detailsJson: { ...data, status, metadataJson } as Prisma.InputJsonValue,
ipAddress: ctx.ip,
userAgent: ctx.userAgent,
},
@@ -570,12 +524,13 @@ export const projectRouter = router({
// Create projects in a transaction
const result = await ctx.prisma.$transaction(async (tx) => {
// Create all projects
// Create all projects with roundId
const projectData = input.projects.map((p) => {
const { metadataJson, ...rest } = p
return {
...rest,
programId: input.programId,
roundId: input.roundId!,
status: 'SUBMITTED' as const,
metadataJson: metadataJson as Prisma.InputJsonValue ?? undefined,
}
})
@@ -585,17 +540,6 @@ export const projectRouter = router({
select: { id: true },
})
// If roundId provided, create RoundProject entries
if (input.roundId) {
await tx.roundProject.createMany({
data: created.map((p) => ({
roundId: input.roundId!,
projectId: p.id,
status: 'SUBMITTED' as const,
})),
})
}
return { imported: created.length }
})
@@ -624,8 +568,8 @@ export const projectRouter = router({
}))
.query(async ({ ctx, input }) => {
const where: Record<string, unknown> = {}
if (input.programId) where.programId = input.programId
if (input.roundId) where.roundProjects = { some: { roundId: input.roundId } }
if (input.programId) where.round = { programId: input.programId }
if (input.roundId) where.roundId = input.roundId
const projects = await ctx.prisma.project.findMany({
where: Object.keys(where).length > 0 ? where : undefined,
@@ -658,9 +602,9 @@ export const projectRouter = router({
})
)
.mutation(async ({ ctx, input }) => {
const updated = await ctx.prisma.roundProject.updateMany({
const updated = await ctx.prisma.project.updateMany({
where: {
projectId: { in: input.ids },
id: { in: input.ids },
roundId: input.roundId,
},
data: { status: input.status },
@@ -798,8 +742,8 @@ export const projectRouter = router({
const skip = (page - 1) * perPage
const where: Record<string, unknown> = {
programId,
roundProjects: { none: {} },
round: { programId },
roundId: null,
}
if (search) {