From ce873a72e51ae77a660eeb7c744e650e9a005ddd Mon Sep 17 00:00:00 2001 From: evlist Date: Wed, 22 Feb 2023 11:58:56 +0100 Subject: [PATCH] Navigation (for invitations) --- src/components/invitation/Invitation.tsx | 34 +++++++++++++---- src/components/invitations/Invitations.tsx | 43 ++++++++++++++-------- src/lib/db.ts | 5 ++- 3 files changed, 59 insertions(+), 23 deletions(-) diff --git a/src/components/invitation/Invitation.tsx b/src/components/invitation/Invitation.tsx index 506b2f7..f7537a6 100644 --- a/src/components/invitation/Invitation.tsx +++ b/src/components/invitation/Invitation.tsx @@ -23,9 +23,10 @@ const Invitation: Component = (props) => { props, values, args, + id: props.values?._id, }); const db = new PouchDb('.db'); - const id = props.values?.id ?? `invitation/${uuid()}`; + const id = props.values?._id ?? `invitation/${uuid()}`; await put({ db, doc: { @@ -51,7 +52,20 @@ const Invitation: Component = (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, initialValues: props?.values, }); @@ -100,11 +114,17 @@ const Invitation: Component = (props) => { Please provide a valid password - - Create}> - Save - - + + + Save + Delete + Cancel + + + Create + Cancel + + ); }; diff --git a/src/components/invitations/Invitations.tsx b/src/components/invitations/Invitations.tsx index 491fe2c..c7042ab 100644 --- a/src/components/invitations/Invitations.tsx +++ b/src/components/invitations/Invitations.tsx @@ -1,11 +1,15 @@ +import { Button } from '@kobalte/core'; import { A } from '@solidjs/router'; import PouchDb from 'pouchdb'; import { Component, createEffect, For } from 'solid-js'; import { createServerAction$ } from 'solid-start/server'; +import { useNavigate } from 'solid-start'; interface Props {} const Invitations: Component = (props) => { + const navigate = useNavigate(); + const [invitations, getInvitations] = createServerAction$( async (values: any) => { const db = new PouchDb('.db'); @@ -28,22 +32,31 @@ const Invitations: Component = (props) => { }); }); + const newHandler = () => { + navigate('/invitations/new'); + }; + return ( -
    - - {(invitation: any) => { - console.log({ - caller: 'Invitations / loop', - invitations: invitation, - }); - return ( -
  • - {invitation.doc.mail} -
  • - ); - }} -
    -
+ <> + New +
    + + {(invitation: any) => { + console.log({ + caller: 'Invitations / loop', + invitations: invitation, + }); + return ( +
  • + + {invitation.doc.mail} + +
  • + ); + }} +
    +
+ ); }; diff --git a/src/lib/db.ts b/src/lib/db.ts index 5da1f9b..1796b33 100644 --- a/src/lib/db.ts +++ b/src/lib/db.ts @@ -3,6 +3,9 @@ export const put = async (params: { db: any; doc: any }) => { try { const previous = await db.get(doc._id); doc._rev = previous._rev; - } catch (error) {} + } catch (error) { + console.error({ caller: 'put', doc, error }); + } + console.log({ caller: 'put', doc }); db.put(doc); };