From 3ba062dedc861d8d9097d03fe1eac4f8d4a5282f Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Fri, 22 Mar 2024 03:09:37 -0400 Subject: [PATCH 1/3] email works again --- app/api.ts | 17 +++++++++++++---- components/QueryForm/QueryForm.tsx | 3 ++- 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/api.ts b/app/api.ts index fe646d9..f3f9af1 100644 --- a/app/api.ts +++ b/app/api.ts @@ -4,6 +4,10 @@ if (process.env.NEXT_PUBLIC_MESHDB_URL === undefined) { throw new Error('Expected API url environment variable'); } +//if (process.env.MESHDB_TOKEN === undefined) { +// throw new Error('Expected API token environment variable'); +//} + const API_BASE = new URL(process.env.NEXT_PUBLIC_MESHDB_URL as string + "/api/v1/"); export const JoinFormInput = z.object({ @@ -54,7 +58,11 @@ export const QueryFormInput = z.object({ }) export type QueryFormInput = z.infer -export const QueryFormResponse = z.array(z.object({ +export const QueryFormResponse = z.object({ + count: z.number(), + next: z.object({}).nullable(), + previous: z.object({}).nullable(), + results: z.array(z.object({ install_number: z.number(), street_address: z.string().nullable(), unit: z.string(), @@ -67,8 +75,9 @@ export const QueryFormResponse = z.array(z.object({ additional_email_addresses: z.array(z.string()).nullable(), notes: z.string(), network_number: z.number().nullable(), - install_status: z.string(), -})) + status: z.string(), + })) +}) export type QueryFormResponse = z.infer const get = async (url: string, schema: S, auth?: string, nextOptions?: NextFetchRequestConfig): Promise> => { @@ -102,4 +111,4 @@ const post = async (url: string, schema: S, input: unknown, export const submitJoinForm = (input: JoinFormInput) => post(`/api/v1/join/`, JoinFormResponse, JoinFormInput.parse(input)) export const submitNNAssignForm = (input: NNAssignFormInput) => post(`/api/v1/nn-assign/`, NNAssignFormResponse, NNAssignFormInput.parse(input)) -export const submitQueryForm = (route: string, input_type: string, input: string, password: string) => get(`/api/v1/query/${route}/?${input_type}=${input}&password=${password}`, QueryFormResponse) +export const submitQueryForm = (route: string, input_type: string, input: string, password: string) => get(`/api/v1/query/${route}/?${input_type}=${input}`, QueryFormResponse, password) diff --git a/components/QueryForm/QueryForm.tsx b/components/QueryForm/QueryForm.tsx index 02cc8d0..996dda2 100644 --- a/components/QueryForm/QueryForm.tsx +++ b/components/QueryForm/QueryForm.tsx @@ -70,6 +70,7 @@ export function QueryForm() { queryForm.data, queryForm.password ); + console.log('response is:'); console.log(resp); if (resp.length === 0) { toast.warning('Query returned no results.', { @@ -78,7 +79,7 @@ export function QueryForm() { setIsLoading(false); return; } - setQueryResult(resp); + setQueryResult(resp.results); toast.success('Success!', { hideProgressBar: true, }); From 718e48810a6c330ea47b62debecb8bb82b892928 Mon Sep 17 00:00:00 2001 From: Willard Nilges Date: Fri, 22 Mar 2024 09:11:09 -0400 Subject: [PATCH 2/3] fix object -> string --- app/api.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/api.ts b/app/api.ts index f3f9af1..2379467 100644 --- a/app/api.ts +++ b/app/api.ts @@ -60,8 +60,8 @@ export type QueryFormInput = z.infer export const QueryFormResponse = z.object({ count: z.number(), - next: z.object({}).nullable(), - previous: z.object({}).nullable(), + next: z.string().nullable(), + previous: z.string().nullable(), results: z.array(z.object({ install_number: z.number(), street_address: z.string().nullable(), From 2855968a39600d97640951f7d356d4516463b452 Mon Sep 17 00:00:00 2001 From: Will Nilges Date: Sat, 23 Mar 2024 01:23:48 -0400 Subject: [PATCH 3/3] resp.results.length --- components/QueryForm/QueryForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/QueryForm/QueryForm.tsx b/components/QueryForm/QueryForm.tsx index 996dda2..868c543 100644 --- a/components/QueryForm/QueryForm.tsx +++ b/components/QueryForm/QueryForm.tsx @@ -72,7 +72,7 @@ export function QueryForm() { ); console.log('response is:'); console.log(resp); - if (resp.length === 0) { + if (resp.results.length === 0) { toast.warning('Query returned no results.', { hideProgressBar: true, });