Consolidate any* hooks

This commit is contained in:
Gregory Schier
2024-06-21 10:01:45 -07:00
parent cd9e720835
commit d361a40903
13 changed files with 133 additions and 130 deletions

View File

@@ -1,5 +1,5 @@
import { useUpdateGrpcRequest } from '../hooks/useUpdateGrpcRequest';
import { useUpdateHttpRequest } from '../hooks/useUpdateHttpRequest';
import { useUpdateAnyGrpcRequest } from '../hooks/useUpdateAnyGrpcRequest';
import { useUpdateAnyHttpRequest } from '../hooks/useUpdateAnyHttpRequest';
import type { GrpcRequest, HttpRequest } from '../lib/models';
import { Input } from './core/Input';
import { VStack } from './core/Stacks';
@@ -9,8 +9,8 @@ interface Props<T> {
}
export function BasicAuth<T extends HttpRequest | GrpcRequest>({ request }: Props<T>) {
const updateHttpRequest = useUpdateHttpRequest(request.id);
const updateGrpcRequest = useUpdateGrpcRequest(request.id);
const updateHttpRequest = useUpdateAnyHttpRequest();
const updateGrpcRequest = useUpdateAnyGrpcRequest();
return (
<VStack className="py-2 overflow-y-auto h-full" space={2}>
@@ -25,15 +25,21 @@ export function BasicAuth<T extends HttpRequest | GrpcRequest>({ request }: Prop
defaultValue={`${request.authentication.username}`}
onChange={(username: string) => {
if (request.model === 'http_request') {
updateHttpRequest.mutate((r) => ({
...r,
authentication: { password: r.authentication.password, username },
}));
updateHttpRequest.mutate({
id: request.id,
update: (r) => ({
...r,
authentication: { password: r.authentication.password, username },
}),
});
} else {
updateGrpcRequest.mutate((r) => ({
...r,
authentication: { password: r.authentication.password, username },
}));
updateGrpcRequest.mutate({
id: request.id,
update: (r) => ({
...r,
authentication: { password: r.authentication.password, username },
}),
});
}
}}
/>
@@ -49,15 +55,21 @@ export function BasicAuth<T extends HttpRequest | GrpcRequest>({ request }: Prop
defaultValue={`${request.authentication.password}`}
onChange={(password: string) => {
if (request.model === 'http_request') {
updateHttpRequest.mutate((r) => ({
...r,
authentication: { username: r.authentication.username, password },
}));
updateHttpRequest.mutate({
id: request.id,
update: (r) => ({
...r,
authentication: { username: r.authentication.username, password },
}),
});
} else {
updateGrpcRequest.mutate((r) => ({
...r,
authentication: { username: r.authentication.username, password },
}));
updateGrpcRequest.mutate({
id: request.id,
update: (r) => ({
...r,
authentication: { username: r.authentication.username, password },
}),
});
}
}}
/>