Compare commits
2 Commits
42ceb798d1
...
e0a74eeb9e
| Author | SHA1 | Date | |
|---|---|---|---|
| e0a74eeb9e | |||
| 35043fc9e3 |
@@ -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"
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -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 } : {}),
|
||||||
|
},
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
import { useConnectQuery } from "~/integrations/connect-query/solid";
|
|
||||||
import { createFileRoute } from "@tanstack/solid-router";
|
import { createFileRoute } from "@tanstack/solid-router";
|
||||||
import { listURLRedirections } from "~/gen/proto/shorten/v1/shorten-ShortenService_connectquery";
|
|
||||||
import { For, Match, Switch } from "solid-js";
|
|
||||||
import ListRedirections from "~/components/shortener/listRedirections";
|
import ListRedirections from "~/components/shortener/listRedirections";
|
||||||
import CreateRedirectionForm from "~/components/shortener/createRedirectionForm";
|
import CreateRedirectionForm from "~/components/shortener/createRedirectionForm";
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user