backend/src/components/invitation/Invitation.tsx

69 lines
1.7 KiB
TypeScript
Raw Normal View History

2023-02-21 10:23:35 +00:00
import { createForm } from "@felte/solid";
2023-02-21 12:38:43 +00:00
import { Component, createUniqueId } from "solid-js";
import { TextField, Button } from "@kobalte/core";
import "./style.css";
2023-02-21 12:38:43 +00:00
import { createServerAction$ } from "solid-start/server";
import PouchDb from "pouchdb";
2023-02-21 15:12:52 +00:00
import { v4 as uuid } from "uuid";
2023-02-21 10:23:35 +00:00
interface Props {}
const Invitation: Component<Props> = (props) => {
2023-02-21 12:38:43 +00:00
const [saving, save] = createServerAction$(async (values: any) => {
const db = new PouchDb(".db");
2023-02-21 19:40:54 +00:00
const id = `invitation/${uuid()}`;
2023-02-21 12:38:43 +00:00
await db.put({
2023-02-21 15:12:52 +00:00
_id: id,
2023-02-21 12:38:43 +00:00
type: "invitation",
doc: values,
});
2023-02-21 15:12:52 +00:00
return id;
2023-02-21 12:38:43 +00:00
});
2023-02-21 10:23:35 +00:00
const submitHandler = (values: any, context: any) => {
console.log({
caller: "Invitation / submitHandler",
props,
values,
context,
});
2023-02-21 12:38:43 +00:00
save(values);
2023-02-21 10:23:35 +00:00
};
const { form } = createForm({ onSubmit: submitHandler });
return (
<form use:form>
<TextField.Root>
<TextField.Label>Database</TextField.Label>
<TextField.Input
type="url"
name="database"
required={true}
placeholder="Database URL"
/>
<TextField.ErrorMessage>
Please provide a valid URL
</TextField.ErrorMessage>
</TextField.Root>
<TextField.Root>
<TextField.Label>Password</TextField.Label>
<TextField.Input
type="text"
name="password"
required={true}
placeholder="Password"
autocomplete="off"
/>
<TextField.ErrorMessage>
Please provide a valid password
</TextField.ErrorMessage>
</TextField.Root>
<Button.Root type="submit">Create</Button.Root>
2023-02-21 10:23:35 +00:00
</form>
);
};
export default Invitation;