Skip to content

Commit 9f92f92

Browse files
committed
change to checkboxes
1 parent 78eec15 commit 9f92f92

5 files changed

Lines changed: 53 additions & 47 deletions

File tree

app/(main)/(top-level-pages)/sponsorships/page.tsx

Lines changed: 45 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import {
2121
SelectTrigger,
2222
SelectValue,
2323
} from "@/components/ui/select";
24+
import { Checkbox } from "@/components/ui/checkbox";
2425
import { Textarea } from "@/components/ui/textarea";
2526
import { Card, CardContent, CardHeader, CardTitle } from "@/components/ui/card";
2627
import { CloudflareTurnstileWidget } from "@/components/cloudflare-turnstile";
@@ -71,7 +72,9 @@ const formSchema = z.object({
7172
message: "Please enter a valid email address.",
7273
}),
7374
companyName: z.string().optional(),
74-
sponsorshipTier: z.string().min(1, "Please select a sponsorship tier."),
75+
sponsorshipTier: z.array(z.string()).refine((value) => value.some((item) => item), {
76+
message: "You have to select at least one item.",
77+
}),
7578
message: z.string().optional(),
7679
honeypot: z.string().optional(), // Honeypot field
7780
"cf-turnstile-response": z.string().min(1, { message: "Please complete the CAPTCHA." }),
@@ -84,7 +87,7 @@ export default function SponsorshipsPage() {
8487
fullName: "",
8588
email: "",
8689
companyName: "",
87-
sponsorshipTier: undefined,
90+
sponsorshipTier: [],
8891
message: "",
8992
honeypot: "",
9093
"cf-turnstile-response": "",
@@ -207,26 +210,47 @@ export default function SponsorshipsPage() {
207210
<FormField
208211
control={form.control}
209212
name="sponsorshipTier"
210-
render={({ field }) => (
213+
render={() => (
211214
<FormItem>
212-
<FormLabel>Sponsorship Tier of Interest</FormLabel>
213-
<Select
214-
onValueChange={field.onChange}
215-
defaultValue={field.value}
216-
>
217-
<FormControl>
218-
<SelectTrigger>
219-
<SelectValue placeholder="Select a tier" />
220-
</SelectTrigger>
221-
</FormControl>
222-
<SelectContent>
223-
{sponsorshipTiers.map((tier) => (
224-
<SelectItem key={tier.value} value={tier.value}>
225-
{tier.name}
226-
</SelectItem>
227-
))}
228-
</SelectContent>
229-
</Select>
215+
<div className="mb-4">
216+
<FormLabel className="text-base">Sponsorship Tiers of Interest</FormLabel>
217+
<FormDescription>
218+
Select all that apply.
219+
</FormDescription>
220+
</div>
221+
{sponsorshipTiers.map((item) => (
222+
<FormField
223+
key={item.value}
224+
control={form.control}
225+
name="sponsorshipTier"
226+
render={({ field }) => {
227+
return (
228+
<FormItem
229+
key={item.value}
230+
className="flex flex-row items-start space-x-3 space-y-0"
231+
>
232+
<FormControl>
233+
<Checkbox
234+
checked={field.value?.includes(item.value)}
235+
onCheckedChange={(checked) => {
236+
return checked
237+
? field.onChange([...field.value, item.value])
238+
: field.onChange(
239+
field.value?.filter(
240+
(value) => value !== item.value,
241+
),
242+
);
243+
}}
244+
/>
245+
</FormControl>
246+
<FormLabel className="font-normal">
247+
{item.name}
248+
</FormLabel>
249+
</FormItem>
250+
);
251+
}}
252+
/>
253+
))}
230254
<FormMessage />
231255
</FormItem>
232256
)}

app/api/sponsorship/route.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const formSchema = z.object({
77
fullName: z.string(),
88
email: z.string().email(),
99
companyName: z.string().optional(),
10-
sponsorshipTier: z.string(),
10+
sponsorshipTier: z.array(z.string()),
1111
message: z.string().optional(),
1212
honeypot: z.string().optional(),
1313
});

sanity/extract.json

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -58,29 +58,10 @@
5858
"sponsorshipTier": {
5959
"type": "objectAttribute",
6060
"value": {
61-
"type": "union",
62-
"of": [
63-
{
64-
"type": "string",
65-
"value": "dedicated-video"
66-
},
67-
{
68-
"type": "string",
69-
"value": "mid-roll-ad"
70-
},
71-
{
72-
"type": "string",
73-
"value": "shout-out"
74-
},
75-
{
76-
"type": "string",
77-
"value": "blog-newsletter"
78-
},
79-
{
80-
"type": "string",
81-
"value": "video-series"
82-
}
83-
]
61+
"type": "array",
62+
"of": {
63+
"type": "string"
64+
}
8465
},
8566
"optional": true
8667
},

sanity/schemas/documents/sponsorshipRequest.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ export default defineType({
2626
defineField({
2727
name: 'sponsorshipTier',
2828
title: 'Sponsorship Tier',
29-
type: 'string',
29+
type: 'array',
30+
of: [{type: 'string'}],
3031
options: {
3132
list: [
3233
{title: 'Dedicated Video', value: 'dedicated-video'},

sanity/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ export type SponsorshipRequest = {
2222
fullName?: string;
2323
email?: string;
2424
companyName?: string;
25-
sponsorshipTier?: "dedicated-video" | "mid-roll-ad" | "shout-out" | "blog-newsletter" | "video-series";
25+
sponsorshipTier?: Array<string>;
2626
message?: string;
2727
};
2828

0 commit comments

Comments
 (0)