Skip to content

Commit

Permalink
Merge pull request #192 from mikepsinn/develop
Browse files Browse the repository at this point in the history
Better handling of dFDA get responses
  • Loading branch information
mikepsinn authored Apr 28, 2024
2 parents e28517f + ccc538b commit 72b4d62
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 11 deletions.
8 changes: 6 additions & 2 deletions apps/nextjs/app/api/dfda/[dfdaPath]/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ export async function GET(req: Request, context: z.infer<typeof routeContextSche
const urlParams = Object.fromEntries(new URL(req.url).searchParams);
const session = await getServerSession(authOptions);
try {
return dfdaGET(params.dfdaPath, urlParams, session?.user.id);
const response = await dfdaGET(params.dfdaPath, urlParams, session?.user.id);
const data = response.data ?? response;
return new Response(JSON.stringify(data), { status: 200, headers: { 'Content-Type': 'application/json' } });
} catch (error) {
return handleError(error);
}
Expand All @@ -28,7 +30,9 @@ export async function POST(req: Request, context: z.infer<typeof routeContextSch
const body = await req.json();
const session = await getServerSession(authOptions);
try {
return dfdaPOST(params.dfdaPath, body, session?.user.id, urlParams);
const response = await dfdaPOST(params.dfdaPath, body, session?.user.id, urlParams);
const data = response.data ?? response;
return new Response(JSON.stringify(data), { status: response.status, headers: { 'Content-Type': 'application/json' } });
} catch (error) {
return handleError(error);
}
Expand Down
8 changes: 1 addition & 7 deletions apps/nextjs/components/userVariable/measurement-button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,6 @@ interface MeasurementButtonProps extends ButtonProps {
"combinationOperation" | "unitAbbreviatedName" | "variableCategoryName" |
"lastValue" | "unitName" | "userId" | "variableId"
>
className: string;
size: string;
variant: string;
}

export function MeasurementButton({ userVariable, ...props }: MeasurementButtonProps) {
Expand All @@ -35,13 +32,10 @@ export function MeasurementButton({ userVariable, ...props }: MeasurementButtonP
//router.refresh();
}

// Destructure `ref` and `size` out of props to avoid passing it to the Button component if not valid
const { ref, size, ...buttonProps } = props;


return (
<>
<Button onClick={onClick} {...buttonProps} size={"default"} variant={"default"}>
<Button onClick={onClick} {...props}>
<Icons.add className="h-4 w-4" />
</Button>
{isFormOpen && (
Expand Down
4 changes: 2 additions & 2 deletions apps/nextjs/components/userVariable/user-variable-item.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ export function UserVariableItem({ userVariable }: UserVariableItemProps) {
variant="outline"
size="icon"
/>
{/* <QuickMeasurementButton
<QuickMeasurementButton
userVariable={userVariable}
className="flex h-8 w-8 items-center justify-center rounded-md border transition-colors hover:bg-muted"
variant="outline"
size="icon"
/>*/}
/>
<Link
href={`/dashboard/userVariables/${userVariable.variableId}`}
className="flex h-8 w-8 items-center justify-center rounded-md border transition-colors hover:bg-muted"
Expand Down

0 comments on commit 72b4d62

Please sign in to comment.