Reset the form and refresh the list below
All checks were successful
Build and Push Docker Image / build (push) Successful in 2m11s

This commit is contained in:
2026-06-04 17:17:36 +02:00
parent 35043fc9e3
commit e0a74eeb9e
2 changed files with 32 additions and 3 deletions

View File

@@ -1,10 +1,18 @@
import { useConnectMutation } from "~/integrations/connect-query/solid"; import {
import { createURLRedirection } from "~/gen/proto/shorten/v1/shorten-ShortenService_connectquery"; useConnectMutation,
getConnectQueryKey,
} from "~/integrations/connect-query/solid";
import {
createURLRedirection,
listURLRedirections,
} from "~/gen/proto/shorten/v1/shorten-ShortenService_connectquery";
import useAppForm from "../form/appform"; import useAppForm from "../form/appform";
import { Button } from "../ui/button"; import { Button } from "../ui/button";
import { useQueryClient } from "@tanstack/solid-query";
const CreateRedirectionForm = () => { const CreateRedirectionForm = () => {
const mutation = useConnectMutation(createURLRedirection); const mutation = useConnectMutation(createURLRedirection);
const queryClient = useQueryClient();
const form = useAppForm(() => ({ const form = useAppForm(() => ({
defaultValues: { defaultValues: {
@@ -16,6 +24,10 @@ const CreateRedirectionForm = () => {
url: values.value.url, url: values.value.url,
shortCode: values.value.slug, shortCode: values.value.slug,
}); });
queryClient.invalidateQueries({
queryKey: getConnectQueryKey(listURLRedirections),
});
form.reset();
}, },
})); }));
return ( return (
@@ -36,7 +48,7 @@ const CreateRedirectionForm = () => {
<field.TextField <field.TextField
name="slug" name="slug"
label="Slug" label="Slug"
description={"The slug to redirect to"} description={"The slug which should redirect"}
placeholder="https://google.com" placeholder="https://google.com"
/> />
)} )}

View File

@@ -88,3 +88,20 @@ export function useConnectMutation<
}; };
}); });
} }
export function getConnectQueryKey<
I extends DescMessage,
O extends DescMessage
>(
schema: DescMethodUnary<I, O>,
input?: MessageInitShape<I>,
): [string, { serviceName: string; methodName: string; input?: MessageInitShape<I> }] {
return [
"connect-query",
{
serviceName: schema.parent.typeName,
methodName: schema.name,
...(input !== undefined ? { input } : {}),
},
];
}