mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-26 11:21:16 +01:00
Consolidate any* hooks
This commit is contained in:
@@ -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 },
|
||||
}),
|
||||
});
|
||||
}
|
||||
}}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user