Skip to content

Commit

Permalink
fix message query
Browse files Browse the repository at this point in the history
  • Loading branch information
jakehobbs committed Jan 19, 2024
1 parent 2d8e93f commit 1d20615
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 5 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"@tanstack/react-router": "^1.4.7",
"class-variance-authority": "^0.7.0",
"clsx": "^2.1.0",
"ky": "^1.2.0",
"lucide-react": "^0.309.0",
"react": "^18.2.0",
"react-dom": "^18.2.0",
Expand Down
8 changes: 8 additions & 0 deletions pnpm-lock.yaml

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

5 changes: 3 additions & 2 deletions service/model/message.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ func GetMessagesToProcess(db *sqlx.DB) ([]Message, error) {
tx.Rollback()
return nil, nil
}
ids := make([]int, len(messages))
ids := make([]interface{}, len(messages))
for i, message := range messages {
ids[i] = message.ID
}
Expand All @@ -77,7 +77,8 @@ func GetMessagesToProcess(db *sqlx.DB) ([]Message, error) {
placeholders[i] = "?"
}

_, err = tx.Exec("UPDATE messages SET status = 'IN_PROGRESS' WHERE id IN (%s)", strings.Join(placeholders, ","))
query := fmt.Sprintf("UPDATE messages SET status = 'IN_PROGRESS' WHERE id IN (%s)", strings.Join(placeholders, ","))
_, err = tx.Exec(query, ids...)
if err != nil {
tx.Rollback()
return nil, fmt.Errorf("error updating message status to IN_PROGRESS: %v", err)
Expand Down
58 changes: 55 additions & 3 deletions src/components/petition.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ import {
SelectTrigger,
SelectValue,
} from "./ui/select.tsx";
import ky from "ky";

const PETITION_API_URL = "https://petitions-229503.appspot.com/api/sign";

const CAMPAIGN_MAILER_API_URL = "https://helptheducks.dxe.io/message/create";

export const Petition = () => {
const form = useForm<PetitionForm>({
Expand All @@ -53,9 +58,56 @@ export const Petition = () => {

const onSubmit = useMemo(
() =>
handleSubmit((data) => {
// TODO: submit to petition service & new backend for sending email to district attorney.
console.log(data);
handleSubmit(async (data) => {
console.log(data); // TODO: remove
const params = {
id: "helptheducks",
name: data.name,
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,
};
console.log(params);
const resp = await ky.post(PETITION_API_URL, {
body: new URLSearchParams(params),
headers: {
"Content-Type": "application/x-www-form-urlencoded",
},
throwHttpErrors: false,
});
console.log(resp.status);
if (resp.status !== 200) {
// TODO: handle error
alert(
"There was an error submitting your petition. Please try again.",
);
return;
}
// TODO: submit to new duck service too. (json)
const resp2 = await ky.post(CAMPAIGN_MAILER_API_URL, {
json: {
name: data.name,
email: data.email,
...(data.phone && { phone: data.phone }),
outside_us: data.outsideUS,
...(data.zip && { zip: data.zip }),
...(data.city && { city: data.city }),
message: data.message,
},
headers: {
"Content-Type": "application/json",
},
throwHttpErrors: false,
});
console.log(resp2.status);
if (resp2.status !== 200) {
alert(
"There was an error submitting to duck service. Please try again.",
);
}
}),
[handleSubmit],
);
Expand Down

0 comments on commit 1d20615

Please sign in to comment.