From be146fa0fa9538a7eac899354443031ed6b40d55 Mon Sep 17 00:00:00 2001 From: enes Date: Mon, 18 Nov 2024 17:20:20 +0100 Subject: [PATCH] refactor(signature): apply strategy pattern and make it easier to expand with new tools --- src/components/MarkFormField/index.tsx | 22 ++--- src/components/MarkTypeStrategy/MarkInput.tsx | 16 ++++ .../MarkTypeStrategy/MarkRender.tsx | 20 ++++ .../MarkTypeStrategy/MarkStrategy.tsx | 32 +++++++ .../Signature/Input.module.scss} | 2 +- .../Signature/Input.tsx} | 8 +- .../Signature/Render.module.scss} | 0 .../Signature/Render.tsx} | 6 +- .../MarkTypeStrategy/Signature/index.tsx | 86 +++++++++++++++++ .../Text/Input.tsx} | 4 +- .../MarkTypeStrategy/Text/index.tsx | 7 ++ src/components/PDFView/PdfMarkItem.tsx | 17 ++-- src/components/PDFView/PdfPageItem.tsx | 7 +- src/components/getMarkComponents.tsx | 92 ------------------- src/hooks/useSigitMeta.tsx | 2 +- src/pages/sign/index.tsx | 2 +- src/pages/verify/index.tsx | 12 +-- src/types/mark.ts | 23 ----- src/utils/file.ts | 2 +- src/utils/mark.ts | 2 +- 20 files changed, 200 insertions(+), 162 deletions(-) create mode 100644 src/components/MarkTypeStrategy/MarkInput.tsx create mode 100644 src/components/MarkTypeStrategy/MarkRender.tsx create mode 100644 src/components/MarkTypeStrategy/MarkStrategy.tsx rename src/components/{MarkInputs/Signature.module.scss => MarkTypeStrategy/Signature/Input.module.scss} (94%) rename src/components/{MarkInputs/Signature.tsx => MarkTypeStrategy/Signature/Input.tsx} (93%) rename src/components/{MarkRender/Signature.module.scss => MarkTypeStrategy/Signature/Render.module.scss} (100%) rename src/components/{MarkRender/Signature.tsx => MarkTypeStrategy/Signature/Render.tsx} (89%) create mode 100644 src/components/MarkTypeStrategy/Signature/index.tsx rename src/components/{MarkInputs/Text.tsx => MarkTypeStrategy/Text/Input.tsx} (72%) create mode 100644 src/components/MarkTypeStrategy/Text/index.tsx delete mode 100644 src/components/getMarkComponents.tsx diff --git a/src/components/MarkFormField/index.tsx b/src/components/MarkFormField/index.tsx index fef3f17..18bbf31 100644 --- a/src/components/MarkFormField/index.tsx +++ b/src/components/MarkFormField/index.tsx @@ -7,7 +7,7 @@ import { isCurrentValueLast } from '../../utils' import React, { useState } from 'react' -import { MARK_TYPE_CONFIG } from '../getMarkComponents.tsx' +import { MarkInput } from '../MarkTypeStrategy/MarkInput.tsx' interface MarkFormFieldProps { currentUserMarks: CurrentUserMark[] @@ -52,8 +52,7 @@ const MarkFormField = ({ } const toggleActions = () => setDisplayActions(!displayActions) const markLabel = getToolboxLabelByMarkType(selectedMark.mark.type) - const { input: MarkInputComponent } = - MARK_TYPE_CONFIG[selectedMark.mark.type] || {} + return (
@@ -84,15 +83,14 @@ const MarkFormField = ({
handleFormSubmit(e)}> - {typeof MarkInputComponent !== 'undefined' && ( - - )} +