Skip to content

Commit

Permalink
update campaign
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehobbs committed Mar 19, 2024
1 parent 07e19dd commit 9d80f9a
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 157 deletions.
86 changes: 8 additions & 78 deletions components/HomePage/Letter.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useCallback, useEffect, useMemo, useRef, useState } from "react";
import { useCallback, useMemo, useRef, useState } from "react";
import { useForm } from "react-hook-form";
import { zodResolver } from "@hookform/resolvers/zod";
import {
Expand All @@ -7,7 +7,6 @@ import {
PetitionFormSchema,
} from "../../data/petition";
import ky from "ky";
import { SonomaCities } from "../../data/zipcodes";
import { Alert, AlertDescription, AlertTitle } from "../ui/alert";
import { LoaderIcon, MailCheckIcon } from "lucide-react";
import {
Expand All @@ -20,14 +19,6 @@ import {
FormMessage,
} from "../ui/form";
import { Input } from "../ui/input";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "../ui/select";
import { cn } from "../../utils";
import { Checkbox } from "../ui/checkbox";
import { Textarea } from "../ui/textarea";
import { Button } from "../ui/button";
Expand Down Expand Up @@ -73,7 +64,6 @@ export const LetterForm = () => {
phone: "",
outsideUS: false,
zip: "",
city: "",
message: DEFAULT_MESSAGE,
},
});
Expand Down Expand Up @@ -117,7 +107,6 @@ export const LetterForm = () => {
email: data.email,
...(data.phone && { phone: data.phone }),
...(data.zip && { zip: data.zip }),
...(data.city && { city: data.city }),
...(!data.outsideUS && { country: "United States" }),
fullHref: window.location.href,
}),
Expand All @@ -138,9 +127,8 @@ export const LetterForm = () => {
...(data.phone && { phone: data.phone }),
outside_us: data.outsideUS,
...(data.zip && { zip: data.zip }),
...(data.city && { city: data.city }),
message: data.message,
campaign: "sonoma",
campaign: "ridglan",
token,
},
headers: {
Expand All @@ -160,39 +148,20 @@ export const LetterForm = () => {
);

const outsideUS = watch("outsideUS");
const zip = watch("zip");
const isInSonomaCounty = useMemo(() => {
return zip && zip in SonomaCities;
}, [zip]);
const cities = useMemo(() => {
if (!isInSonomaCounty) {
return [];
}
return SonomaCities[zip as keyof typeof SonomaCities];
}, [isInSonomaCounty, zip]);

// When cities change, just select it if there's only one. Else, reset the city.
useEffect(() => {
if (cities.length === 1) {
setValue("city", cities[0]);
} else {
setValue("city", "");
}
}, [cities, setValue]);

const injectValuesIntoMessage = useCallback(
(name: string | undefined, city: string | undefined) => {
(name: string | undefined) => {
if (dirtyFields.message) {
console.log(
"Skipped updating message with name or city since it has been customized."
"Skipped updating message with name since it has been customized."
);
return;
}
resetField("message", {
defaultValue: DEFAULT_MESSAGE.replace(
"[Your name]",
name || "[Your name]"
).replace("[Your city if you live in Sonoma County]", city || ""),
),
});
},
[dirtyFields.message, resetField]
Expand Down Expand Up @@ -231,7 +200,7 @@ export const LetterForm = () => {
{...field}
onBlur={() => {
field.onBlur();
injectValuesIntoMessage(field.value, getValues("city"));
injectValuesIntoMessage(field.value);
}}
/>
</FormControl>
Expand Down Expand Up @@ -285,59 +254,20 @@ export const LetterForm = () => {
{...field}
onBlur={() => {
field.onBlur();
injectValuesIntoMessage(
getValues("name"),
getValues("city")
);
injectValuesIntoMessage(getValues("name"));
}}
/>
</FormControl>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={control}
name="city"
disabled={outsideUS || isSubmitting}
render={({ field }) => (
<FormItem className={cn({ "tw-hidden": !cities.length })}>
<FormLabel>City</FormLabel>
<Select
onValueChange={(val) => {
field.onChange(val);
injectValuesIntoMessage(getValues("name"), val);
}}
defaultValue={field.value}
value={field.value}
>
<FormControl>
<SelectTrigger>
<SelectValue placeholder="Select a city" />
</SelectTrigger>
</FormControl>
<SelectContent>
{cities?.map((city) => (
<SelectItem value={city} key={city} onBlur={field.onBlur}>
{city}
</SelectItem>
))}
</SelectContent>
</Select>
<FormMessage />
</FormItem>
)}
/>
<FormField
control={control}
name="outsideUS"
disabled={isSubmitting}
render={({ field }) => (
<FormItem
className={cn("tw-flex tw-gap-2 tw-items-center", {
"tw-hidden": cities.length,
})}
>
<FormItem className="tw-flex tw-gap-2 tw-items-center">
<FormControl>
<Checkbox
checked={field.value}
Expand Down
5 changes: 3 additions & 2 deletions components/Support.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ export const Support = () => {
}}
>
Your support allows us to stand up to legal repression and
continue our groundbreaking work.<br /><br />

continue our groundbreaking work.
<br />
<br />
All monthly donations are being matched with $100 from an
anonymous&nbsp;donor.
</h2>
Expand Down
26 changes: 1 addition & 25 deletions data/petition.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { z } from "zod";
import { SonomaCities } from "./zipcodes";

const EmptyStringToUndefined = z.literal("").transform(() => undefined);

Expand All @@ -26,11 +25,6 @@ export const PetitionFormSchema = z
.length(5, { message: "Zip code must be 5 digits or empty" })
.or(EmptyStringToUndefined)
.optional(),
city: z
.string()
.max(255, { message: "City too long" })
.or(EmptyStringToUndefined)
.optional(),
message: z
.string()
.min(10, { message: "Message must be at least 10 characters" })
Expand All @@ -50,28 +44,11 @@ export const PetitionFormSchema = z
});
}
}
const isInSonoma = !!(
data.zip &&
data.zip in SonomaCities &&
SonomaCities[data.zip as keyof typeof SonomaCities]
);
// If outside of Sonoma, throw away the city.
if (!isInSonoma) {
data.city = undefined;
}
// If in Sonoma, city is required.
if (isInSonoma && !data.city) {
ctx.addIssue({
code: z.ZodIssueCode.custom,
message: "City is required",
path: ["city"],
});
}
});

export type PetitionForm = z.infer<typeof PetitionFormSchema>;

export const DEFAULT_MESSAGE = `Dear District Attorney Rodriguez,
export const DEFAULT_MESSAGE = `Dear District Attorney Ozanne,
I urge you to prosecute animal cruelty, not animal rescue. National polls consistently show overwhelming public support for strong legal protection for animals. Yet, countless investigations have shown that animal-using industries routinely violate animal welfare laws with no repercussions. It is time for a change. Your office should be working with whistleblowers and rescuers to protect animals from abuse. Prosecuting these good samaritans who expose animal mistreatment is wildly out of line with the values of the public. A 2015 Gallup poll¹ found that a third of Americans believe “animals deserve the exact same rights as people to be free from harm and exploitation,” a 2022 YouGov poll² found that nearly half of Americans believe that animal cruelty laws in the U.S. are not strict enough, and a 2024 poll by Positive Sum Strategies³ found that 68% of Americans believe it should not be a crime to take an animal out of an environment where they are being mistreated. The same sentiments are evidenced by two recent acquittals of animal rescuers. In October 2022, a Utah jury issued a groundbreaking “not guilty” verdict⁴ for two DxE investigators who openly rescued sick piglets from a Smithfield Foods factory pig farm. In March 2023, a California jury acquitted⁵ two more DxE investigators of theft charges for rescuing two sick chickens from a slaughter truck.
Expand All @@ -84,7 +61,6 @@ Your office’s resources could be much better spent investigating and stopping
Sincerely,
[Your name]
[Your city if you live in Sonoma County]
References:
1. https://news.gallup.com/poll/183275/say-animals-rights-people.aspx
Expand Down
52 changes: 0 additions & 52 deletions data/zipcodes.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
"start": "next start",
"lint": "next lint",
"fmt": "npx prettier --write .",
"typecheck": "tsc --noEmit",
"analyze": "cross-env ANALYZE=true next build",
"analyze:server": "cross-env BUNDLE_ANALYZE=server next build",
"analyze:browser": "cross-env BUNDLE_ANALYZE=browser next build"
Expand Down

0 comments on commit 9d80f9a

Please sign in to comment.