From 0b735d94f116ff20907e77d0e745fedba110ccc7 Mon Sep 17 00:00:00 2001 From: Sukhman S Date: Sat, 1 Jul 2023 23:03:29 +0530 Subject: [PATCH 1/5] feat: add generic Modal component --- frontend/src/Modal/index.tsx | 46 ++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 frontend/src/Modal/index.tsx diff --git a/frontend/src/Modal/index.tsx b/frontend/src/Modal/index.tsx new file mode 100644 index 00000000..a6cfda14 --- /dev/null +++ b/frontend/src/Modal/index.tsx @@ -0,0 +1,46 @@ +import * as React from 'react'; + +interface ModalProps { + handleSubmit: () => void; + isCancellable: boolean; + handleCancel?: () => void; + render: () => JSX.Element; + modalState: string; + isError: boolean; +} +const Modal = (props: ModalProps) => { + return ( +
+ {props.render()} +
+
+ + {props.isCancellable && ( + + )} +
+ {props.isError && ( +

+ Please enter a valid API key +

+ )} +
+
+ ); +}; + +export default Modal; From 00ba7b78ca79e7c11c886580ca7a310b64896402 Mon Sep 17 00:00:00 2001 From: Sukhman S Date: Sat, 1 Jul 2023 23:04:45 +0530 Subject: [PATCH 2/5] feat: use generic Modal with render props --- frontend/src/preferences/APIKeyModal.tsx | 77 +++++++++--------------- 1 file changed, 30 insertions(+), 47 deletions(-) diff --git a/frontend/src/preferences/APIKeyModal.tsx b/frontend/src/preferences/APIKeyModal.tsx index d068aa42..e8f9f224 100644 --- a/frontend/src/preferences/APIKeyModal.tsx +++ b/frontend/src/preferences/APIKeyModal.tsx @@ -3,6 +3,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { ActiveState } from '../models/misc'; import { selectApiKey, setApiKey } from './preferenceSlice'; import { useOutsideAlerter } from './../hooks'; +import Modal from '../Modal'; export default function APIKeyModal({ modalState, @@ -49,53 +50,35 @@ export default function APIKeyModal({ } return ( -
-
-

OpenAI API Key

-

- Before you can start using DocsGPT we need you to provide an API key - for llm. Currently, we support only OpenAI but soon many more. You can - find it here. -

- setKey(e.target.value)} - /> -
-
- - {isCancellable && ( - - )} -
- {isError && ( -

- Please enter a valid API key + { + return ( +

+

OpenAI API Key

+

+ Before you can start using DocsGPT we need you to provide an API + key for llm. Currently, we support only OpenAI but soon many more. + You can find it here.

- )} -
-
-
+ setKey(e.target.value)} + /> + + ); + }} + /> ); } From d9988158477638e3b6618b599ecdf7d28d036ba9 Mon Sep 17 00:00:00 2001 From: Sukhman S Date: Sat, 1 Jul 2023 23:19:27 +0530 Subject: [PATCH 3/5] fix: fix styles for error message --- frontend/src/Modal/index.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/frontend/src/Modal/index.tsx b/frontend/src/Modal/index.tsx index a6cfda14..919a40d4 100644 --- a/frontend/src/Modal/index.tsx +++ b/frontend/src/Modal/index.tsx @@ -34,7 +34,7 @@ const Modal = (props: ModalProps) => { )} {props.isError && ( -

+

Please enter a valid API key

)} From bf78bdd6d4ff1be4c6c42bbe25ea45b8e039637b Mon Sep 17 00:00:00 2001 From: Sukhman S Date: Sun, 2 Jul 2023 10:34:43 +0530 Subject: [PATCH 4/5] feat: pass ErrorMessage as a prop to Modal --- frontend/src/Modal/index.tsx | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/frontend/src/Modal/index.tsx b/frontend/src/Modal/index.tsx index 919a40d4..bed32181 100644 --- a/frontend/src/Modal/index.tsx +++ b/frontend/src/Modal/index.tsx @@ -7,6 +7,7 @@ interface ModalProps { render: () => JSX.Element; modalState: string; isError: boolean; + errorMessage?: string; } const Modal = (props: ModalProps) => { return ( @@ -35,7 +36,7 @@ const Modal = (props: ModalProps) => { {props.isError && (

- Please enter a valid API key + {props.errorMessage}

)} From 96eb68e042de869183e5f9fd30e2a8770cc62367 Mon Sep 17 00:00:00 2001 From: Sukhman S Date: Sun, 2 Jul 2023 10:35:03 +0530 Subject: [PATCH 5/5] feat: use generic Modal with render props --- frontend/src/preferences/SelectDocsModal.tsx | 135 ++++++++----------- 1 file changed, 59 insertions(+), 76 deletions(-) diff --git a/frontend/src/preferences/SelectDocsModal.tsx b/frontend/src/preferences/SelectDocsModal.tsx index c4764878..c514ab86 100644 --- a/frontend/src/preferences/SelectDocsModal.tsx +++ b/frontend/src/preferences/SelectDocsModal.tsx @@ -1,6 +1,7 @@ import { useEffect, useState } from 'react'; import { useDispatch, useSelector } from 'react-redux'; import { ActiveState } from '../models/misc'; +import Modal from '../Modal'; import { setSelectedDocs, setSourceDocs, @@ -50,85 +51,67 @@ export default function APIKeyModal({ requestDocs(); }, []); - return ( -
-
-

Select Source Documentation

-

- Please select the library of documentation that you would like to use - with our app. -

-
-
setIsDocsListOpen(!isDocsListOpen)} - > - {!localSelectedDocs ? ( -

Select

- ) : ( -

- {localSelectedDocs.name} {localSelectedDocs.version} -

- )} -
- {isDocsListOpen && ( -
- {docs ? ( - docs.map((doc, index) => { - if (doc.model) { - return ( -
{ - setLocalSelectedDocs(doc); - setIsDocsListOpen(false); - }} - className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100" - > -

- {doc.name} {doc.version} -

-
- ); - } - }) - ) : ( -
-

No default documentation.

+ { + return ( +
+

Select Source Documentation

+

+ Please select the library of documentation that you would like to + use with our app. +

+
+
setIsDocsListOpen(!isDocsListOpen)} + > + {!localSelectedDocs ? ( +

Select

+ ) : ( +

+ {localSelectedDocs.name} {localSelectedDocs.version} +

+ )} +
+ {isDocsListOpen && ( +
+ {docs ? ( + docs.map((doc, index) => { + if (doc.model) { + return ( +
{ + setLocalSelectedDocs(doc); + setIsDocsListOpen(false); + }} + className="h-10 w-full cursor-pointer border-x-2 border-b-2 hover:bg-gray-100" + > +

+ {doc.name} {doc.version} +

+
+ ); + } + }) + ) : ( +
+

No default documentation.

+
+ )}
)}
- )} -
-
- {isCancellable && ( - - )} - - {isError && ( -

- Please select source documentation. -

- )} -
-
-
+ + ); + }} + /> ); }