From b21230c4d6899d921b3d95ed0973f1b924f59fba Mon Sep 17 00:00:00 2001
From: utin-francis-peter
Date: Wed, 3 Jul 2024 12:34:13 +0100
Subject: [PATCH] chore: migrated to using custom Input component to address
redundant twClasses
---
frontend/src/components/Input.tsx | 39 +++++++++++++++++
frontend/src/components/types/index.ts | 3 +-
frontend/src/preferences/APIKeyModal.tsx | 7 +--
frontend/src/preferences/PromptsModal.tsx | 15 ++++---
frontend/src/settings/APIKeys.tsx | 8 ++--
frontend/src/upload/Upload.tsx | 53 ++++++++++++-----------
6 files changed, 87 insertions(+), 38 deletions(-)
create mode 100644 frontend/src/components/Input.tsx
diff --git a/frontend/src/components/Input.tsx b/frontend/src/components/Input.tsx
new file mode 100644
index 00000000..fe5cdba2
--- /dev/null
+++ b/frontend/src/components/Input.tsx
@@ -0,0 +1,39 @@
+import { InputProps } from './types';
+
+const Input = ({
+ id,
+ name,
+ type,
+ value,
+ isAutoFocused = false,
+ placeholder,
+ maxLength,
+ className,
+ hasSilverBorder,
+ children,
+ onChange,
+ onPaste,
+ onKeyDown,
+}: InputProps) => {
+ return (
+
+ {children}
+
+ );
+};
+
+export default Input;
diff --git a/frontend/src/components/types/index.ts b/frontend/src/components/types/index.ts
index 3cebc1c2..3ee65ec4 100644
--- a/frontend/src/components/types/index.ts
+++ b/frontend/src/components/types/index.ts
@@ -1,6 +1,6 @@
export type TextAreaProps = {
value: string | string[] | number;
- isAutoFocused: boolean;
+ isAutoFocused?: boolean;
id?: string;
maxLength?: number;
name?: string;
@@ -20,4 +20,5 @@ export type TextAreaProps = {
export type InputProps = TextAreaProps & {
type: 'text' | 'number';
+ hasSilverBorder?: boolean;
};
diff --git a/frontend/src/preferences/APIKeyModal.tsx b/frontend/src/preferences/APIKeyModal.tsx
index dd7a1b88..18cf53f3 100644
--- a/frontend/src/preferences/APIKeyModal.tsx
+++ b/frontend/src/preferences/APIKeyModal.tsx
@@ -4,6 +4,7 @@ import { ActiveState } from '../models/misc';
import { selectApiKey, setApiKey } from './preferenceSlice';
import { useMediaQuery, useOutsideAlerter } from './../hooks';
import Modal from '../modals';
+import Input from '../components/Input';
export default function APIKeyModal({
modalState,
@@ -66,14 +67,14 @@ export default function APIKeyModal({
key for llm. Currently, we support only OpenAI but soon many more.
You can find it here.
- setKey(e.target.value)}
- />
+ >
);
}}
diff --git a/frontend/src/preferences/PromptsModal.tsx b/frontend/src/preferences/PromptsModal.tsx
index c16ddd2c..ce634c86 100644
--- a/frontend/src/preferences/PromptsModal.tsx
+++ b/frontend/src/preferences/PromptsModal.tsx
@@ -1,5 +1,6 @@
import { ActiveState } from '../models/misc';
import Exit from '../assets/exit.svg';
+import Input from '../components/Input';
function AddPrompt({
setModalState,
@@ -34,13 +35,14 @@ function AddPrompt({
Add your custom prompt and save it to DocsGPT
- setNewPromptName(e.target.value)}
- >
+ >
Prompt Name
@@ -105,13 +107,14 @@ function EditPrompt({
Edit your custom prompt and save it to DocsGPT
- setEditPromptName(e.target.value)}
- >
+ >
Prompt Name
diff --git a/frontend/src/settings/APIKeys.tsx b/frontend/src/settings/APIKeys.tsx
index 8264af08..dda68663 100644
--- a/frontend/src/settings/APIKeys.tsx
+++ b/frontend/src/settings/APIKeys.tsx
@@ -10,6 +10,7 @@ import { selectSourceDocs } from '../preferences/preferenceSlice';
import Exit from '../assets/exit.svg';
import Trash from '../assets/trash.svg';
import { useTranslation } from 'react-i18next';
+import Input from '../components/Input';
const apiHost = import.meta.env.VITE_API_HOST || 'https://docsapi.arc53.com';
const embeddingsName =
import.meta.env.VITE_EMBEDDINGS_NAME ||
@@ -237,12 +238,13 @@ const CreateAPIKeyModal: React.FC = ({
{t('modals.createAPIKey.apiKeyName')}
- setAPIKeyName(e.target.value)}
- />
+ >