Adding a Step‑by‑Step Onboarding TI Module with Auto‑Growing Textareas and a New Prisma Model
Adding a Step‑by‑Step Onboarding TI Module with Auto‑Growing Textareas and a New Prisma Model TL;DR: I introduced a full‑stack Onboarding TI feature that guides users through phases one at a time, added an auto‑growing
Adding a Step‑by‑Step Onboarding TI Module with Auto‑Growing Textareas and a New Prisma Model
TL;DR: I introduced a full‑stack Onboarding TI feature that guides users through phases one at a time, added an auto‑growing <Textarea> component, and created a new Prisma OnboardingTask model with supporting seed and migration scripts. The changes tighten the UI flow, prevent scroll‑jank, and expose a clean API for task management.
The Problem
Our internal service desk needed a way to onboard new IT collaborators directly from a ticket. The existing UI displayed all onboarding phases in a single scrollable page, which caused three issues:
- Scroll fatigue – users had to hunt for the next phase among many inputs.
-
Fixed‑height comment boxes – long comments triggered scrollbars inside the
<textarea>, breaking the visual consistency. - No data model – there was no Prisma schema to persist onboarding tasks, so we were manually inserting rows with raw SQL scripts that were hard to version.
The result was a clunky experience and a fragile backend. I needed a solution that would:
- Show one phase at a time (step‑by‑step wizard).
- Let comment fields expand automatically as the user types.
- Persist onboarding tasks in a typed Prisma model, with idempotent seed scripts.
What I Tried First
My first attempt was to keep the long‑scroll layout and simply add CSS overflow: auto to the comment <textarea>. I also tried to create the OnboardingTask table manually with a raw CREATE TABLE statement and then run a node scripts/apply-sql.mjs script each time I needed to tweak the schema.
Why it failed
- The CSS fix only hid the problem—users still had to scroll through dozens of fields.
- Manual SQL migrations bypassed Prisma’s migration engine, leading to drift between the Prisma schema and the actual DB. Running the raw script repeatedly caused duplicate key errors because the script wasn’t idempotent.
- The comment boxes still showed internal scrollbars; the height never adjusted to the content.
The Implementation
1. Auto‑Growing Textarea Component
File: src/components/ui/textarea.tsx
// src/components/ui/textarea.tsx
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
export function Textarea({
className,
...props
}: React.TextareaHTMLAttributes<HTMLTextAreaElement>) {
const ref = React.useRef<HTMLTextAreaElement>(null);
// Adjust height on mount and on every input event
React.useEffect(() => {
const el = ref.current;
if (!el) return;
const resize = () => {
el.style.height = "auto";
el.style.height = `${el.scrollHeight}px`;
};
resize(); // initial size
el.addEventListener("input", resize);
return () => el.removeEventListener("input", resize);
}, []);
return (
<textarea
ref={ref}
className={cn(
"flex w-full rounded-md border border-input bg-background px-3 py-2 text-sm",
"file:border-0 file:bg-transparent file:text-sm file:font-medium",
"placeholder:text-muted-foreground focus-visible:outline-none focus-visible:ring-2",
"focus-visible:ring-ring focus-visible:ring-offset-2 disabled:cursor-not-allowed disabled:opacity-50",
className
)}
{...props}
/>
);
}
Added use client to ensure the component runs only on the client side.
The useEffect hook measures scrollHeight after each keystroke and forces the <textarea> height to match, eliminating internal scrollbars.
2. Step‑by‑Step Onboarding UI
File: src/app/onboarding/[id]/page.tsx
Key changes:
- Imported navigation icons
ChevronLeftandChevronRight. - Added a
phaseIndexstate to control which phase is visible. - Rendered only the current phase, with “Previous” / “Next” buttons that update
phaseIndex.
// src/app/onboarding/[id]/page.tsx
import {
AlertTriangle,
ArrowLeft,
Ban,
ChevronLeft,
ChevronRight,
Check,
CheckCircle2,
Cpu,
} from "lucide-react";
function OnboardingDetailInner() {
const [phaseIndex, setPhaseIndex] = React.useState(0);
const phases = onboardingData.phases; // fetched from lib/onboarding.ts
const goPrev = () => setPhaseIndex((i) => Math.max(i - 1, 0));
const goNext = () => setPhaseIndex((i) => Math.min(i + 1, phases.length - 1));
return (
<div className="max-w-2xl mx-auto">
{/* Phase Header */}
<h2 className="text-xl font-semibold mb-4">
{phases[phaseIndex].phaseName}
</h2>
{/* Render only the current phase */}
<PhaseForm phase={phases[phaseIndex]} />
{/* Navigation */}
<div className="flex justify-between mt-6">
<button
onClick={goPrev}
disabled={phaseIndex === 0}
className="btn disabled:opacity-50"
>
<ChevronLeft className="mr-1" /> Previous
</button>
<button
onClick={goNext}
disabled={phaseIndex === phases.length - 1}
className="btn"
>
Next <ChevronRight className="ml-1" />
</button>
</div>
</div>
);
}
The UI now behaves like a wizard, reducing cognitive load and preventing the long scroll that previously broke the onboarding flow.
3. Prisma Model for Onboarding Tasks
File: prisma/schema.prisma
// prisma/schema.prisma
// =========================================================================
// Onboarding TI (Technical Integration) model
model OnboardingTask {
id String @id @default(uuid())
phase Int
phaseName String
name String
description String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedAt
@@unique([phase, name])
}
Added a unique constraint on (phase, name) to prevent duplicate tasks per phase.
The model lives alongside existing tables (e.g., AssetRoster) and inherits the same datasource.
4. Migration Script
File: scripts/sql/2026-11-onboarding-ti.sql
-- scripts/sql/2026-11-onboarding-ti.sql
-- CreateTable
CREATE TABLE "OnboardingTask" (
"id" TEXT NOT NULL PRIMARY KEY,
"phase" INTEGER NOT NULL,
"phaseName" TEXT NOT NULL,
"name" TEXT NOT NULL,
"description" TEXT,
"createdAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP,
"updatedAt" TIMESTAMP(3) NOT NULL DEFAULT CURRENT_TIMESTAMP
);
-- Indexes for fast lookup
CREATE INDEX "OnboardingTask_phase_idx" ON "OnboardingTask"("phase");
The script is pure DDL; it does not drop or modify existing tables, making it safe to run in production.
5. Idempotent Seed Script
File: scripts/seed-onboarding.mjs
// scripts/seed-onboarding.mjs
import { PrismaClient } from "@prisma/client";
import tasks from "./data/onboarding-tasks.json";
const prisma = new PrismaClient();
async function main() {
for (const task of tasks) {
await prisma.onboardingTask.upsert({
where: { phase_name: { phase: task.phase, name: task.name } },
update: { description: task.description, phaseName: task.phaseName },
create: {
id: crypto.randomUUID(),
phase: task.phase,
phaseName: task.phaseName,
name: task.name,
description: task.description,
},
});
}
console.log("✅ Onboarding tasks seeded");
}
main()
.catch((e) => {
console.error(e);
process.exit(1);
})
.finally(() => prisma.$disconnect());
Uses upsert to guarantee idempotency: running the script again updates any changed description without creating duplicates.
Part of my Build in Public series — sharing the real process of building SaaS projects from Playa del Carmen, México.
Repo: zaerohell/appcheck-uhpcm · 2026-11-28
#playadev #buildinpublic
Originally published by Dev.to WebDev. Aggregated on AIWithGhost for educational purposes — full credit and traffic to the original publisher.