Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 78 additions & 0 deletions app/applications/application-form.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,10 @@ const applicationSchema = z
campaignBlurb: z
.string()
.min(50, 'Please provide a detailed response (at least 50 characters)'),
bostonCampus: z.boolean({
error: 'Please indicate if you will be on the Boston campus',
}),
bostonCampusExplanation: z.string().optional(),
})
.refine(
(data) => {
Expand All @@ -85,6 +89,19 @@ const applicationSchema = z
message: 'Constituency must be one of the selected colleges',
path: ['constituency'],
},
)
.refine(
(data) => {
// If not on Boston campus, explanation is required
if (data.bostonCampus === false) {
return data.bostonCampusExplanation && data.bostonCampusExplanation.trim().length > 0;
}
return true;
},
{
message: 'Please explain your situation if you will not be on the Boston campus for the entirety of your term',
path: ['bostonCampusExplanation'],
},
);

type ApplicationFormData = z.infer<typeof applicationSchema>;
Expand Down Expand Up @@ -133,11 +150,13 @@ export default function ApplicationForm({
diversityEquityInclusionLongAnswer: '',
conflictSituationLongAnswer: '',
campaignBlurb: '',
bostonCampusExplanation: '',
},
});

const colleges = watch('college');
const constituency = watch('constituency');
const bostonCampus = watch('bostonCampus');

// Auto-select constituency if only one college is selected, clear if invalid
useEffect(() => {
Expand Down Expand Up @@ -795,6 +814,65 @@ export default function ApplicationForm({
</p>
)}
</div>

<div className="space-y-2">
<Label>
Do you plan to be on the Boston campus for the
entirety of your potential term?
</Label>
<div className="flex gap-6">
<label className="flex items-center gap-2 cursor-pointer">
<input
type="radio"
value="yes"
checked={bostonCampus === true}
onChange={() =>
setValue('bostonCampus', true, {
shouldValidate: true,
})
}
/>
Yes
</label>
<label className="flex items-center gap-2 cursor-pointer">
<input
type="radio"
value="no"
checked={bostonCampus === false}
onChange={() =>
setValue('bostonCampus', false, {
shouldValidate: true,
})
}
/>
No
</label>
</div>
{errors.bostonCampus && (
<p className="text-sm text-destructive">
{errors.bostonCampus.message}
</p>
)}
</div>

{bostonCampus === false && (
<div className="space-y-2">
<Label htmlFor="bostonCampusExplanation">
Please explain your situation.
</Label>
<textarea
id="bostonCampusExplanation"
className="w-full min-h-[120px] px-3 py-2 text-sm border border-input bg-background rounded-md focus:outline-none focus:ring-2 focus:ring-ring"
placeholder="Please explain why you will not be on the Boston campus for the entirety of your term"
{...register('bostonCampusExplanation')}
/>
{errors.bostonCampusExplanation && (
<p className="text-sm text-destructive">
{errors.bostonCampusExplanation.message}
</p>
)}
</div>
)}
</div>
</div>

Expand Down
4 changes: 4 additions & 0 deletions lib/actions/applications.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ type ApplicationData = {
diversityEquityInclusionLongAnswer: string;
conflictSituationLongAnswer: string;
campaignBlurb: string;
bostonCampus: boolean;
bostonCampusExplanation?: string;
};

export async function submitApplication(formData: ApplicationData) {
Expand Down Expand Up @@ -70,6 +72,8 @@ export async function submitApplication(formData: ApplicationData) {
diversityEquityInclusionLongAnswer: formData.diversityEquityInclusionLongAnswer,
conflictSituationLongAnswer: formData.conflictSituationLongAnswer,
campaignBlurb: formData.campaignBlurb,
bostonCampus: formData.bostonCampus,
bostonCampusExplanation: formData.bostonCampusExplanation || null,
};

await createOrUpdateApplication(data);
Expand Down
23 changes: 3 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-- AlterTable
ALTER TABLE "applications" ADD COLUMN "bostonCampus" BOOLEAN NOT NULL DEFAULT true;
ALTER TABLE "applications" ADD COLUMN "bostonCampusExplanation" TEXT;
2 changes: 2 additions & 0 deletions prisma/schema.prisma
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ model Application {
diversityEquityInclusionLongAnswer String
conflictSituationLongAnswer String
campaignBlurb String @default("")
bostonCampus Boolean @default(true)
bostonCampusExplanation String?
nominationFormPdfUrl String?
createdAt DateTime @default(now())

Expand Down