From 75a715d002f005e327442015dc322b278f59bc8e Mon Sep 17 00:00:00 2001 From: Stixx Date: Tue, 10 Sep 2024 16:00:48 +0200 Subject: [PATCH 01/13] feat: Add Sigit ID as a path param --- src/components/DisplaySigit/index.tsx | 5 +-- src/pages/home/index.tsx | 1 + src/pages/sign/index.tsx | 51 +++++++++++++++++++++++---- src/routes/index.tsx | 5 +++ 4 files changed, 54 insertions(+), 8 deletions(-) diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx index 473a942..00716a3 100644 --- a/src/components/DisplaySigit/index.tsx +++ b/src/components/DisplaySigit/index.tsx @@ -24,11 +24,12 @@ import { useSigitMeta } from '../../hooks/useSigitMeta' import { extractFileExtensions } from '../../utils/file' type SigitProps = { + sigitKey: string meta: Meta parsedMeta: SigitCardDisplayInfo } -export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => { +export const DisplaySigit = ({ meta, parsedMeta, sigitKey }: SigitProps) => { const { title, createdAt, submittedBy, signers, signedStatus, isValid } = parsedMeta @@ -47,7 +48,7 @@ export const DisplaySigit = ({ meta, parsedMeta }: SigitProps) => { to={ signedStatus === SigitStatus.Complete ? appPublicRoutes.verify - : appPrivateRoutes.sign + : `${appPrivateRoutes.sign}/${sigitKey}` } state={{ meta }} className={styles.insetLink} diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index c93c9f8..3e333d3 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -257,6 +257,7 @@ export const HomePage = () => { .map((key) => ( diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 8720954..70d9784 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -7,7 +7,7 @@ import { MuiFileInput } from 'mui-file-input' import { Event, verifyEvent } from 'nostr-tools' import { useCallback, useEffect, useState } from 'react' import { useSelector } from 'react-redux' -import { useLocation, useNavigate } from 'react-router-dom' +import { useLocation, useNavigate, useParams } from 'react-router-dom' import { toast } from 'react-toastify' import { LoadingSpinner } from '../../components/LoadingSpinner' import { NostrController } from '../../controllers' @@ -53,6 +53,7 @@ import { SigitFile } from '../../utils/file.ts' import { ARRAY_BUFFER, DEFLATE } from '../../utils/const.ts' +import { useAppSelector } from '../../hooks/store.ts' enum SignedStatus { Fully_Signed, User_Is_Next_Signer, @@ -62,17 +63,20 @@ enum SignedStatus { export const SignPage = () => { const navigate = useNavigate() const location = useLocation() + const params = useParams() /** + * Received from `location.state` + * * uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains keys.json * arrayBuffer will be received in navigation from create page in offline mode * meta will be received in navigation from create & home page in online mode */ - const { - meta: metaInNavState, - arrayBuffer: decryptedArrayBuffer, - uploadedZip - } = location.state || {} + const [metaInNavState, setMetaInNavState] = useState() + const [decryptedArrayBuffer, setDecryptedArrayBuffer] = useState< + ArrayBuffer | undefined + >() + const [uploadedZip, setUploadedZip] = useState() const [displayInput, setDisplayInput] = useState(false) @@ -115,6 +119,41 @@ export const SignPage = () => { const [isMarksCompleted, setIsMarksCompleted] = useState(false) const [otherUserMarks, setOtherUserMarks] = useState([]) + const usersAppData = useAppSelector((state) => state.userAppData) + + /** + * When location state changes, update the states in the component + * If sigit id is found in the URL PARAM we will set metaInNavState manually + * after we do the fetching based on the ID + */ + useEffect(() => { + if (location.state) { + const { meta, arrayBuffer, uploadedZip } = location.state + + setMetaInNavState(meta) + setDecryptedArrayBuffer(arrayBuffer) + setUploadedZip(uploadedZip) + } + }, [location.state]) + + useEffect(() => { + // If meta in nav state is populated we will not try to fetch sigit details + // from the redux store + if (metaInNavState) return + + if (usersAppData) { + const sigitId = params.id + + if (sigitId) { + const sigit = usersAppData.sigits[sigitId] + + if (sigit) { + setMetaInNavState(sigit) + } + } + } + }, [usersAppData, metaInNavState, params.id]) + useEffect(() => { if (signers.length > 0) { // check if all signers have signed then its fully signed diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 2d36db1..643017f 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -19,6 +19,7 @@ export const appPrivateRoutes = { homePage: '/', create: '/create', sign: '/sign', + signId: '/sign/:id', settings: '/settings', profileSettings: '/settings/profile/:npub', cacheSettings: '/settings/cache', @@ -132,6 +133,10 @@ export const privateRoutes = [ path: appPrivateRoutes.sign, element: }, + { + path: appPrivateRoutes.signId, + element: + }, { path: appPrivateRoutes.settings, element: -- 2.34.1 From 8e71592d8815471bde6fb74230ba9742308daad8 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 11:59:12 +0200 Subject: [PATCH 02/13] fix: routing, removed useEffect --- src/components/DisplaySigit/index.tsx | 1 - src/pages/sign/index.tsx | 63 ++++++++++----------------- src/routes/index.tsx | 7 +-- 3 files changed, 24 insertions(+), 47 deletions(-) diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx index 00716a3..641e9d6 100644 --- a/src/components/DisplaySigit/index.tsx +++ b/src/components/DisplaySigit/index.tsx @@ -50,7 +50,6 @@ export const DisplaySigit = ({ meta, parsedMeta, sigitKey }: SigitProps) => { ? appPublicRoutes.verify : `${appPrivateRoutes.sign}/${sigitKey}` } - state={{ meta }} className={styles.insetLink} >

{title}

diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 70d9784..fa11fb7 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -65,6 +65,8 @@ export const SignPage = () => { const location = useLocation() const params = useParams() + const usersAppData = useAppSelector((state) => state.userAppData) + /** * Received from `location.state` * @@ -72,11 +74,27 @@ export const SignPage = () => { * arrayBuffer will be received in navigation from create page in offline mode * meta will be received in navigation from create & home page in online mode */ - const [metaInNavState, setMetaInNavState] = useState() - const [decryptedArrayBuffer, setDecryptedArrayBuffer] = useState< - ArrayBuffer | undefined - >() - const [uploadedZip, setUploadedZip] = useState() + const { + meta: metaInNavState, + arrayBuffer: decryptedArrayBuffer, + uploadedZip + } = location.state || { + meta: undefined, + arrayBuffer: undefined, + uploadedZip: undefined + } + + if (usersAppData) { + const sigitId = params.id + + if (sigitId) { + const sigit = usersAppData.sigits[sigitId] + + if (sigit) { + metaInNavState = sigit + } + } + } const [displayInput, setDisplayInput] = useState(false) @@ -119,41 +137,6 @@ export const SignPage = () => { const [isMarksCompleted, setIsMarksCompleted] = useState(false) const [otherUserMarks, setOtherUserMarks] = useState([]) - const usersAppData = useAppSelector((state) => state.userAppData) - - /** - * When location state changes, update the states in the component - * If sigit id is found in the URL PARAM we will set metaInNavState manually - * after we do the fetching based on the ID - */ - useEffect(() => { - if (location.state) { - const { meta, arrayBuffer, uploadedZip } = location.state - - setMetaInNavState(meta) - setDecryptedArrayBuffer(arrayBuffer) - setUploadedZip(uploadedZip) - } - }, [location.state]) - - useEffect(() => { - // If meta in nav state is populated we will not try to fetch sigit details - // from the redux store - if (metaInNavState) return - - if (usersAppData) { - const sigitId = params.id - - if (sigitId) { - const sigit = usersAppData.sigits[sigitId] - - if (sigit) { - setMetaInNavState(sigit) - } - } - } - }, [usersAppData, metaInNavState, params.id]) - useEffect(() => { if (signers.length > 0) { // check if all signers have signed then its fully signed diff --git a/src/routes/index.tsx b/src/routes/index.tsx index 643017f..3e42e78 100644 --- a/src/routes/index.tsx +++ b/src/routes/index.tsx @@ -19,7 +19,6 @@ export const appPrivateRoutes = { homePage: '/', create: '/create', sign: '/sign', - signId: '/sign/:id', settings: '/settings', profileSettings: '/settings/profile/:npub', cacheSettings: '/settings/cache', @@ -130,11 +129,7 @@ export const privateRoutes = [ element: }, { - path: appPrivateRoutes.sign, - element: - }, - { - path: appPrivateRoutes.signId, + path: `${appPrivateRoutes.sign}/:id?`, element: }, { -- 2.34.1 From 7c027825cdce6e36ba23b726200d36eb7aa50d70 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 12:03:23 +0200 Subject: [PATCH 03/13] style: lint fix --- src/pages/sign/index.tsx | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index fa11fb7..ef22eb8 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -74,11 +74,9 @@ export const SignPage = () => { * arrayBuffer will be received in navigation from create page in offline mode * meta will be received in navigation from create & home page in online mode */ - const { - meta: metaInNavState, - arrayBuffer: decryptedArrayBuffer, - uploadedZip - } = location.state || { + let metaInNavState = location.state.meta + + const { arrayBuffer: decryptedArrayBuffer, uploadedZip } = location.state || { meta: undefined, arrayBuffer: undefined, uploadedZip: undefined -- 2.34.1 From 86a16c13ced0b2ce1dcd8470db17c83aebd57042 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 12:29:38 +0200 Subject: [PATCH 04/13] chore: comments and lint (typing) --- src/pages/sign/index.tsx | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index ef22eb8..74194de 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -71,18 +71,22 @@ export const SignPage = () => { * Received from `location.state` * * uploadedZip will be received from home page when a user uploads a sigit zip wrapper that contains keys.json - * arrayBuffer will be received in navigation from create page in offline mode - * meta will be received in navigation from create & home page in online mode + * arrayBuffer (decryptedArrayBuffer) will be received in navigation from create page in offline mode + * meta (metaInNavState) will be received in navigation from create & home page in online mode */ - let metaInNavState = location.state.meta - + let metaInNavState = location?.state?.meta || undefined const { arrayBuffer: decryptedArrayBuffer, uploadedZip } = location.state || { - meta: undefined, - arrayBuffer: undefined, + decryptedArrayBuffer: undefined, uploadedZip: undefined } + /** + * If userAppData (redux) is available, and we have route param (sigit id) + * we will fetch a sigit based on the provided route ID and set it + * to the metaInNavState + */ if (usersAppData) { + // Sigit id is a createEventId const sigitId = params.id if (sigitId) { -- 2.34.1 From 5dc8d53503e72bd92a04f4034b6be68929cbc4f5 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 12:33:40 +0200 Subject: [PATCH 05/13] chore: sigitCreateId naming --- src/pages/sign/index.tsx | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 74194de..47fa7a7 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -86,11 +86,10 @@ export const SignPage = () => { * to the metaInNavState */ if (usersAppData) { - // Sigit id is a createEventId - const sigitId = params.id + const sigitCreateId = params.id - if (sigitId) { - const sigit = usersAppData.sigits[sigitId] + if (sigitCreateId) { + const sigit = usersAppData.sigits[sigitCreateId] if (sigit) { metaInNavState = sigit -- 2.34.1 From 64e8ebba85313169a451bbfd2258f7ed3b2b14c6 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 13:30:39 +0200 Subject: [PATCH 06/13] chore: renamed sigitKey to sigitCreateId --- src/components/DisplaySigit/index.tsx | 10 +++++++--- src/pages/home/index.tsx | 2 +- 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx index 641e9d6..0b02383 100644 --- a/src/components/DisplaySigit/index.tsx +++ b/src/components/DisplaySigit/index.tsx @@ -24,12 +24,16 @@ import { useSigitMeta } from '../../hooks/useSigitMeta' import { extractFileExtensions } from '../../utils/file' type SigitProps = { - sigitKey: string + sigitCreateId: string meta: Meta parsedMeta: SigitCardDisplayInfo } -export const DisplaySigit = ({ meta, parsedMeta, sigitKey }: SigitProps) => { +export const DisplaySigit = ({ + meta, + parsedMeta, + sigitCreateId: sigitCreateId +}: SigitProps) => { const { title, createdAt, submittedBy, signers, signedStatus, isValid } = parsedMeta @@ -48,7 +52,7 @@ export const DisplaySigit = ({ meta, parsedMeta, sigitKey }: SigitProps) => { to={ signedStatus === SigitStatus.Complete ? appPublicRoutes.verify - : `${appPrivateRoutes.sign}/${sigitKey}` + : `${appPrivateRoutes.sign}/${sigitCreateId}` } className={styles.insetLink} > diff --git a/src/pages/home/index.tsx b/src/pages/home/index.tsx index 3e333d3..1a29021 100644 --- a/src/pages/home/index.tsx +++ b/src/pages/home/index.tsx @@ -257,7 +257,7 @@ export const HomePage = () => { .map((key) => ( -- 2.34.1 From 79e14d45a12076ada7f1884c8885d751c9bdb013 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 15:41:42 +0200 Subject: [PATCH 07/13] chore: comment fix --- src/pages/sign/index.tsx | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/pages/sign/index.tsx b/src/pages/sign/index.tsx index 47fa7a7..f6e2ef4 100644 --- a/src/pages/sign/index.tsx +++ b/src/pages/sign/index.tsx @@ -81,9 +81,9 @@ export const SignPage = () => { } /** - * If userAppData (redux) is available, and we have route param (sigit id) - * we will fetch a sigit based on the provided route ID and set it - * to the metaInNavState + * If userAppData (redux) is available, and we have the route param (sigit id) + * which is actually a `createEventId`, we will fetch a `sigit` + * based on the provided route ID and set fetched `sigit` to the `metaInNavState` */ if (usersAppData) { const sigitCreateId = params.id -- 2.34.1 From e48a3969904c1ec9759a60e9b21f998569ce6b13 Mon Sep 17 00:00:00 2001 From: Stixx Date: Wed, 11 Sep 2024 17:29:47 +0200 Subject: [PATCH 08/13] fix: verify/sign link --- src/components/DisplaySigit/index.tsx | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/components/DisplaySigit/index.tsx b/src/components/DisplaySigit/index.tsx index 0b02383..7d9cd3b 100644 --- a/src/components/DisplaySigit/index.tsx +++ b/src/components/DisplaySigit/index.tsx @@ -48,14 +48,19 @@ export const DisplaySigit = ({ return (
- + {signedStatus === SigitStatus.Complete && ( + + )} + {signedStatus !== SigitStatus.Complete && ( + + )}

{title}

{submittedBy && -- 2.34.1 From 55abe814c967e3e126d40408239f62ac111ba9e7 Mon Sep 17 00:00:00 2001 From: "." <> Date: Sun, 6 Oct 2024 20:28:27 +0100 Subject: [PATCH 09/13] fix: AGPL Licence, closes #197 --- src/pages/landing/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/landing/index.tsx b/src/pages/landing/index.tsx index deae096..2bee544 100644 --- a/src/pages/landing/index.tsx +++ b/src/pages/landing/index.tsx @@ -35,7 +35,7 @@ export const LandingPage = () => { title: <>Open Source, description: ( <> - Code is MIT licenced and available at{' '} + Code is AGPL licenced and available at{' '} https://git.nostrdev.com/sigit/sigit.io -- 2.34.1 From c4d50293ffa80d1b4cc39cb6d7002e187a0a9b33 Mon Sep 17 00:00:00 2001 From: enes Date: Mon, 7 Oct 2024 12:53:43 +0200 Subject: [PATCH 10/13] refactor: toolbox order --- src/utils/mark.ts | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/utils/mark.ts b/src/utils/mark.ts index 0f437c4..b77818a 100644 --- a/src/utils/mark.ts +++ b/src/utils/mark.ts @@ -153,6 +153,11 @@ const findOtherUserMarks = (marks: Mark[], pubkey: string): Mark[] => { } export const DEFAULT_TOOLBOX: DrawTool[] = [ + { + identifier: MarkType.TEXT, + icon: faT, + label: 'Text' + }, { identifier: MarkType.FULLNAME, icon: faIdCard, @@ -177,11 +182,6 @@ export const DEFAULT_TOOLBOX: DrawTool[] = [ label: 'Date Time', isComingSoon: true }, - { - identifier: MarkType.TEXT, - icon: faT, - label: 'Text' - }, { identifier: MarkType.NUMBER, icon: fa1, -- 2.34.1 From 2d7bb234f417daf2a3a4066b1680666bdc07d57b Mon Sep 17 00:00:00 2001 From: enes Date: Mon, 7 Oct 2024 12:59:55 +0200 Subject: [PATCH 11/13] refactor: next on each mark, including the final one --- src/components/MarkFormField/index.tsx | 6 +++--- src/utils/const.ts | 2 -- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/src/components/MarkFormField/index.tsx b/src/components/MarkFormField/index.tsx index e1003a0..02f34cc 100644 --- a/src/components/MarkFormField/index.tsx +++ b/src/components/MarkFormField/index.tsx @@ -1,7 +1,7 @@ import { CurrentUserMark } from '../../types/mark.ts' import styles from './style.module.scss' -import { MARK_TYPE_TRANSLATION, NEXT, SIGN } from '../../utils/const.ts' +import { MARK_TYPE_TRANSLATION } from '../../utils/const.ts' import { findNextIncompleteCurrentUserMark, isCurrentUserMarksComplete, @@ -32,7 +32,6 @@ const MarkFormField = ({ handleCurrentUserMarkChange }: MarkFormFieldProps) => { const [displayActions, setDisplayActions] = useState(true) - const getSubmitButtonText = () => (isReadyToSign() ? SIGN : NEXT) const isReadyToSign = () => isCurrentUserMarksComplete(currentUserMarks) || isCurrentValueLast(currentUserMarks, selectedMark, selectedMarkValue) @@ -61,6 +60,7 @@ const MarkFormField = ({ onClick={toggleActions} className={styles.triggerBtn} type="button" + title="Toggle" >
diff --git a/src/utils/const.ts b/src/utils/const.ts index a512c2f..8e53a46 100644 --- a/src/utils/const.ts +++ b/src/utils/const.ts @@ -4,8 +4,6 @@ export const EMPTY: string = '' export const MARK_TYPE_TRANSLATION: { [key: string]: string } = { [MarkType.FULLNAME.valueOf()]: 'Full Name' } -export const SIGN: string = 'Sign' -export const NEXT: string = 'Next' export const ARRAY_BUFFER = 'arraybuffer' export const DEFLATE = 'DEFLATE' -- 2.34.1 From 9091bbc25142897a9acbba6f21c059a2502839e5 Mon Sep 17 00:00:00 2001 From: "." <> Date: Mon, 7 Oct 2024 22:55:48 +0100 Subject: [PATCH 12/13] chore: landing page wording --- src/pages/landing/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/pages/landing/index.tsx b/src/pages/landing/index.tsx index 2bee544..12e1991 100644 --- a/src/pages/landing/index.tsx +++ b/src/pages/landing/index.tsx @@ -121,7 +121,7 @@ export const LandingPage = () => { Logo

- Secure & Private Document Signing + Secure & Private Agreements

An open-source and self-hostable solution for secure document -- 2.34.1 From 51e2ab6f8a5e52a74aca7286579965054707ffae Mon Sep 17 00:00:00 2001 From: "." <> Date: Tue, 8 Oct 2024 09:57:44 +0100 Subject: [PATCH 13/13] chore: lint fix --- src/pages/landing/index.tsx | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/pages/landing/index.tsx b/src/pages/landing/index.tsx index 12e1991..28990c2 100644 --- a/src/pages/landing/index.tsx +++ b/src/pages/landing/index.tsx @@ -120,9 +120,7 @@ export const LandingPage = () => { Logo

-

- Secure & Private Agreements -

+

Secure & Private Agreements

An open-source and self-hostable solution for secure document signing and verification. -- 2.34.1