Navigation (for invitations)
This commit is contained in:
parent
d64eca488f
commit
ce873a72e5
|
@ -23,9 +23,10 @@ const Invitation: Component<Props> = (props) => {
|
||||||
props,
|
props,
|
||||||
values,
|
values,
|
||||||
args,
|
args,
|
||||||
|
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 ?? `invitation/${uuid()}`;
|
||||||
await put({
|
await put({
|
||||||
db,
|
db,
|
||||||
doc: {
|
doc: {
|
||||||
|
@ -51,7 +52,20 @@ const Invitation: Component<Props> = (props) => {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let { form } = createForm({
|
const cancelHandler = () => {
|
||||||
|
navigate(`/invitations/`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const deleteHandler = async () => {
|
||||||
|
console.log({
|
||||||
|
caller: 'Invitation / deleteHandler',
|
||||||
|
props,
|
||||||
|
});
|
||||||
|
await save({ props, values: { _deleted: true } });
|
||||||
|
navigate(`/invitations/`);
|
||||||
|
};
|
||||||
|
|
||||||
|
const { form } = createForm({
|
||||||
onSubmit: submitHandler,
|
onSubmit: submitHandler,
|
||||||
initialValues: props?.values,
|
initialValues: props?.values,
|
||||||
});
|
});
|
||||||
|
@ -100,11 +114,17 @@ const Invitation: Component<Props> = (props) => {
|
||||||
Please provide a valid password
|
Please provide a valid password
|
||||||
</TextField.ErrorMessage>
|
</TextField.ErrorMessage>
|
||||||
</TextField.Root>
|
</TextField.Root>
|
||||||
<Button.Root type='submit'>
|
<Switch>
|
||||||
<Switch fallback={<>Create</>}>
|
<Match when={!!props.values}>
|
||||||
<Match when={!!props.values}>Save</Match>
|
<Button.Root type='submit'>Save</Button.Root>
|
||||||
|
<Button.Root onclick={deleteHandler}>Delete</Button.Root>
|
||||||
|
<Button.Root onclick={cancelHandler}>Cancel</Button.Root>
|
||||||
|
</Match>
|
||||||
|
<Match when={!props.values}>
|
||||||
|
<Button.Root type='submit'>Create</Button.Root>
|
||||||
|
<Button.Root onclick={cancelHandler}>Cancel</Button.Root>
|
||||||
|
</Match>
|
||||||
</Switch>
|
</Switch>
|
||||||
</Button.Root>
|
|
||||||
</form>
|
</form>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,11 +1,15 @@
|
||||||
|
import { Button } from '@kobalte/core';
|
||||||
import { A } from '@solidjs/router';
|
import { A } from '@solidjs/router';
|
||||||
import PouchDb from 'pouchdb';
|
import PouchDb from 'pouchdb';
|
||||||
import { Component, createEffect, For } from 'solid-js';
|
import { Component, createEffect, For } from 'solid-js';
|
||||||
import { createServerAction$ } from 'solid-start/server';
|
import { createServerAction$ } from 'solid-start/server';
|
||||||
|
import { useNavigate } from 'solid-start';
|
||||||
|
|
||||||
interface Props {}
|
interface Props {}
|
||||||
|
|
||||||
const Invitations: Component<Props> = (props) => {
|
const Invitations: Component<Props> = (props) => {
|
||||||
|
const navigate = useNavigate();
|
||||||
|
|
||||||
const [invitations, getInvitations] = createServerAction$(
|
const [invitations, getInvitations] = createServerAction$(
|
||||||
async (values: any) => {
|
async (values: any) => {
|
||||||
const db = new PouchDb('.db');
|
const db = new PouchDb('.db');
|
||||||
|
@ -28,7 +32,13 @@ const Invitations: Component<Props> = (props) => {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const newHandler = () => {
|
||||||
|
navigate('/invitations/new');
|
||||||
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
|
<Button.Root onclick={newHandler}>New</Button.Root>
|
||||||
<ul>
|
<ul>
|
||||||
<For each={invitations.result}>
|
<For each={invitations.result}>
|
||||||
{(invitation: any) => {
|
{(invitation: any) => {
|
||||||
|
@ -38,12 +48,15 @@ const Invitations: Component<Props> = (props) => {
|
||||||
});
|
});
|
||||||
return (
|
return (
|
||||||
<li>
|
<li>
|
||||||
<A href={encodeURIComponent(invitation.id)}>{invitation.doc.mail}</A>
|
<A href={encodeURIComponent(invitation.id)}>
|
||||||
|
{invitation.doc.mail}
|
||||||
|
</A>
|
||||||
</li>
|
</li>
|
||||||
);
|
);
|
||||||
}}
|
}}
|
||||||
</For>
|
</For>
|
||||||
</ul>
|
</ul>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -3,6 +3,9 @@ export const put = async (params: { db: any; doc: any }) => {
|
||||||
try {
|
try {
|
||||||
const previous = await db.get(doc._id);
|
const previous = await db.get(doc._id);
|
||||||
doc._rev = previous._rev;
|
doc._rev = previous._rev;
|
||||||
} catch (error) {}
|
} catch (error) {
|
||||||
|
console.error({ caller: 'put', doc, error });
|
||||||
|
}
|
||||||
|
console.log({ caller: 'put', doc });
|
||||||
db.put(doc);
|
db.put(doc);
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue