Invitations are users actually...

This commit is contained in:
Eric van der Vlist 2023-02-22 21:18:57 +01:00
parent 4b36f167d5
commit 198653ce82
12 changed files with 62 additions and 62 deletions

View File

@ -1 +0,0 @@
export { default } from "./Invitation";

View File

@ -1 +0,0 @@
export { default } from "./Invitations";

View File

@ -16,7 +16,7 @@ interface Props {
values?: any; values?: any;
} }
const Invitation: Component<Props> = (props) => { const User: Component<Props> = (props) => {
const navigate = useNavigate(); const navigate = useNavigate();
const [openDialog, setOpenDialog] = createSignal(false); const [openDialog, setOpenDialog] = createSignal(false);
@ -28,20 +28,20 @@ const Invitation: Component<Props> = (props) => {
const [saving, save] = createServerAction$(async (args: any) => { const [saving, save] = createServerAction$(async (args: any) => {
const { props, values } = args; const { props, values } = args;
console.log({ console.log({
caller: 'Invitation / save', caller: 'User / save',
props, props,
values, values,
args, args,
id: props.values?._id, id: props.values?._id,
}); });
const db = new PouchDb('.db'); const db = new PouchDb('.db');
const id = props.values?._id ?? `invitation/${uuid()}`; const id = props.values?._id ?? `user/${uuid()}`;
await put({ await put({
db, db,
doc: { doc: {
_id: id, _id: id,
date: new Date().toISOString(), date: new Date().toISOString(),
type: 'invitation', type: 'user',
...values, ...values,
}, },
}); });
@ -50,7 +50,7 @@ const Invitation: Component<Props> = (props) => {
const [dbChecking, dbCheck] = createServerAction$(async (args: any) => { const [dbChecking, dbCheck] = createServerAction$(async (args: any) => {
console.log({ console.log({
caller: 'Invitation / dbCheck', caller: 'User / dbCheck',
args, args,
}); });
let baseDbInfoAuth; let baseDbInfoAuth;
@ -87,28 +87,28 @@ const Invitation: Component<Props> = (props) => {
const submitHandler = async (values: any, context: any) => { const submitHandler = async (values: any, context: any) => {
console.log({ console.log({
caller: 'Invitation / submitHandler', caller: 'User / submitHandler',
props, props,
values, values,
context, context,
}); });
const id = await save({ values, props }); const id = await save({ values, props });
if (!props.values) { if (!props.values) {
navigate(`/invitations/${encodeURIComponent(id)}`); navigate(`/user/${encodeURIComponent(id)}`);
} }
}; };
const cancelHandler = () => { const cancelHandler = () => {
navigate(`/invitations/`); navigate(`/user/`);
}; };
const deleteHandler = async () => { const deleteHandler = async () => {
console.log({ console.log({
caller: 'Invitation / deleteHandler', caller: 'User / deleteHandler',
props, props,
}); });
await save({ props, values: { _deleted: true } }); await save({ props, values: { _deleted: true } });
navigate(`/invitations/`); navigate(`/user/`);
}; };
const { form, data } = createForm({ const { form, data } = createForm({
@ -122,7 +122,7 @@ const Invitation: Component<Props> = (props) => {
auth: { username: data('username'), password: data('password') }, auth: { username: data('username'), password: data('password') },
}); });
console.log({ console.log({
caller: 'Invitation / dbCheckHandler', caller: 'User / dbCheckHandler',
props, props,
data: data(), data: data(),
result, result,
@ -144,7 +144,7 @@ const Invitation: Component<Props> = (props) => {
const createUserHandler = async () => { const createUserHandler = async () => {
console.log({ console.log({
caller: 'Invitation / createUserHandler', caller: 'User / createUserHandler',
props, props,
data: data(), data: data(),
}); });
@ -155,7 +155,7 @@ const Invitation: Component<Props> = (props) => {
usernamePassword: UsernamePassword usernamePassword: UsernamePassword
) => { ) => {
console.log({ console.log({
caller: 'Invitation / usernamePasswordHandler', caller: 'User / usernamePasswordHandler',
props, props,
usernamePassword, usernamePassword,
}); });
@ -163,7 +163,7 @@ const Invitation: Component<Props> = (props) => {
}; };
console.log({ console.log({
caller: 'Invitation ', caller: 'User ',
props, props,
}); });
@ -279,4 +279,4 @@ const Invitation: Component<Props> = (props) => {
); );
}; };
export default Invitation; export default User;

View File

@ -0,0 +1 @@
export { default } from "./User";

View File

@ -7,49 +7,49 @@ import { useNavigate } from 'solid-start';
interface Props {} interface Props {}
const Invitations: Component<Props> = (props) => { const Users: Component<Props> = (props) => {
const navigate = useNavigate(); const navigate = useNavigate();
const [invitations, getInvitations] = createServerAction$( const [users, getUsers] = createServerAction$(
async (values: any) => { async (values: any) => {
const db = new PouchDb('.db'); const db = new PouchDb('.db');
const results = await db.allDocs({ const results = await db.allDocs({
include_docs: true, include_docs: true,
startkey: 'invitation/', startkey: 'user/',
endkey: 'invitation/\ufff0', endkey: 'user/\ufff0',
}); });
console.log({ caller: 'Invitations / serverAction', results }); console.log({ caller: 'Users / serverAction', results });
return results.rows; return results.rows;
} }
); );
getInvitations(); getUsers();
createEffect(() => { createEffect(() => {
console.log({ console.log({
caller: 'Invitations', caller: 'Users',
invitations: invitations.result, users: users.result,
}); });
}); });
const newHandler = () => { const newHandler = () => {
navigate('/invitations/new'); navigate('/user/new');
}; };
return ( return (
<> <>
<Button.Root onclick={newHandler}>New</Button.Root> <Button.Root onclick={newHandler}>New</Button.Root>
<ul> <ul>
<For each={invitations.result}> <For each={users.result}>
{(invitation: any) => { {(user: any) => {
console.log({ console.log({
caller: 'Invitations / loop', caller: 'Users / loop',
invitations: invitation, users: user,
}); });
return ( return (
<li> <li>
<A href={encodeURIComponent(invitation.id)}> <A href={encodeURIComponent(user.id)}>
{invitation.doc.mail} {user.doc.mail}
</A> </A>
</li> </li>
); );
@ -60,4 +60,4 @@ const Invitations: Component<Props> = (props) => {
); );
}; };
export default Invitations; export default Users;

View File

@ -0,0 +1 @@
export { default } from "./Users";

View File

@ -1,10 +0,0 @@
import Invitations from "~/components/invitations";
export default () => {
return (
<main>
<h1>Invitations</h1>
<Invitations />
</main>
);
};

View File

@ -1,10 +0,0 @@
import Invitation from "~/components/invitation";
export default () => {
return (
<main>
<h1>New invitation</h1>
<Invitation />
</main>
);
};

View File

@ -1,35 +1,35 @@
import { useParams } from 'solid-start'; import { useParams } from 'solid-start';
import { createServerAction$ } from 'solid-start/server'; import { createServerAction$ } from 'solid-start/server';
import PouchDb from 'pouchdb'; import PouchDb from 'pouchdb';
import Invitation from '~/components/invitation'; import User from '~/components/user';
import { createEffect, Show } from 'solid-js'; import { createEffect, Show } from 'solid-js';
export default () => { export default () => {
const params = useParams(); const params = useParams();
const [invitation, getInvitation] = createServerAction$( const [user, getUser] = createServerAction$(
async (id: string) => { async (id: string) => {
const db = new PouchDb('.db'); const db = new PouchDb('.db');
const result = await db.get(id); const result = await db.get(id);
console.log({ caller: 'Invitations / serverAction', result }); console.log({ caller: 'Users / serverAction', result });
return result; return result;
} }
); );
getInvitation(decodeURIComponent(params.id)); getUser(decodeURIComponent(params.id));
createEffect(() => { createEffect(() => {
console.log({ console.log({
caller: 'Invitations/[id]', caller: 'Users/[id]',
params, params,
invitation: invitation.result, user: user.result,
}); });
}); });
return ( return (
<main> <main>
<h1>Invitation</h1> <h1>User</h1>
<Show when={!invitation.pending} fallback={<>Loading...</>}> <Show when={!user.pending} fallback={<>Loading...</>}>
<Invitation values={invitation.result} /> <User values={user.result} />
</Show> </Show>
</main> </main>
); );

10
src/routes/user/index.tsx Normal file
View File

@ -0,0 +1,10 @@
import Users from "~/components/users";
export default () => {
return (
<main>
<h1>Users</h1>
<Users />
</main>
);
};

10
src/routes/user/new.tsx Normal file
View File

@ -0,0 +1,10 @@
import User from "~/components/user";
export default () => {
return (
<main>
<h1>New user</h1>
<User />
</main>
);
};