From ab24a40a0e247338fd1717393a43710f331996a9 Mon Sep 17 00:00:00 2001 From: Timofey Boyko Date: Wed, 26 Jun 2024 15:19:13 +0300 Subject: [PATCH] Client:OAuth: refactoring --- .../developer-tools/OAuth/OAuth.types.ts | 3 +- .../developer-tools/OAuth/index.tsx | 3 +- .../ClientForm/ClientForm.styled.ts | 11 +++ .../ClientForm/ClientForm.types.ts | 2 +- .../ClientForm/components/BasicBlock.tsx | 35 +++++++- .../ClientForm/components/ButtonsBlock.tsx | 3 +- .../ClientForm/components/MultiInputGroup.tsx | 2 +- .../ClientForm/components/OAuthBlock.tsx | 2 +- .../ClientForm/components/ScopesBlock.tsx | 2 +- .../ClientForm/components/SupportBlock.tsx | 2 +- .../OAuth/sub-components/ClientForm/index.tsx | 38 +++++---- .../EmptyScreen/EmptyScreen.types.ts | 5 -- .../sub-components/EmptyScreen/index.tsx | 8 +- .../OAuth/sub-components/InfoDialog.tsx | 2 +- .../OAuth/sub-components/List/RowView/Row.tsx | 1 - .../List/RowView/RowContent.tsx | 2 - .../List/RowView/RowView.types.ts | 2 +- .../sub-components/List/TableView/Header.tsx | 1 + .../List/TableView/TableView.types.ts | 2 +- .../List/TableView/columns/creator.tsx | 1 - .../List/TableView/columns/name.tsx | 1 - .../sub-components/List/TableView/index.tsx | 4 +- .../OAuth/sub-components/List/index.tsx | 10 +-- .../OAuth/sub-components/PreviewDialog.tsx | 2 +- .../RegisterNewButton.types.ts | 4 - .../RegisterNewButton/index.tsx | 8 +- packages/client/src/store/OAuthStore.ts | 35 ++++---- packages/runtime.json | 2 +- packages/shared/api/management/index.ts | 14 ++++ packages/shared/api/oauth/index.ts | 81 ++++++++----------- packages/shared/themes/dark.ts | 2 +- packages/shared/utils/next-ssr-helper.ts | 7 +- packages/shared/utils/oauth/ScopeList.tsx | 2 +- packages/shared/utils/oauth/index.ts | 7 +- .../utils/oauth/{interfaces.ts => types.ts} | 61 ++++++++------ 35 files changed, 205 insertions(+), 162 deletions(-) delete mode 100644 packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/EmptyScreen.types.ts rename packages/shared/utils/oauth/{interfaces.ts => types.ts} (87%) diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/OAuth.types.ts b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/OAuth.types.ts index 68f9eef853..f2aac319aa 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/OAuth.types.ts +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/OAuth.types.ts @@ -1,7 +1,6 @@ -import { IClientProps } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientProps } from "@docspace/shared/utils/oauth/types"; import { DeviceUnionType } from "SRC_DIR/Hooks/useViewEffect"; - import { ViewAsType } from "SRC_DIR/store/OAuthStore"; export interface OAuthProps { diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/index.tsx index fb42d268b7..52f8f78692 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/index.tsx @@ -39,6 +39,7 @@ const OAuth = ({ const { t } = useTranslation(["OAuth"]); const [isLoading, setIsLoading] = React.useState(true); + const startLoadingRef = React.useRef(null); const getData = React.useCallback(async () => { @@ -88,7 +89,7 @@ const OAuth = ({ {isLoading ? ( ) : isEmptyClientList ? ( - + ) : ( void; + changeValue: ( + name: keyof IClientReqDTO, + value: string | boolean, + remove?: boolean, + ) => void; isEdit: boolean; errorFields: string[]; @@ -73,6 +80,7 @@ const BasicBlock = ({ logoValue, descriptionValue, allowPkce, + isPublic, changeValue, isEdit, @@ -140,6 +148,8 @@ const BasicBlock = ({ ); + const publicClientHelpButtonText = "Help text"; + const isNameRequiredError = requiredErrorFields.includes("name"); const isWebsiteRequiredError = requiredErrorFields.includes("website_url"); const isNameError = errorFields.includes("name"); @@ -203,7 +213,7 @@ const BasicBlock = ({ /> + {}} + > +
+ { + changeValue("is_public", e.target.checked); + }} + /> + Public client + +
+
); diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ButtonsBlock.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ButtonsBlock.tsx index cdbbbe9165..22915b6be7 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ButtonsBlock.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ButtonsBlock.tsx @@ -1,7 +1,6 @@ -import React from "react"; - import { DeviceType } from "@docspace/shared/enums"; import { Button, ButtonSize } from "@docspace/shared/components/button"; + import { StyledButtonContainer } from "../ClientForm.styled"; interface ButtonsBlockProps { diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/MultiInputGroup.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/MultiInputGroup.tsx index fc053178ed..59cf91f402 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/MultiInputGroup.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/MultiInputGroup.tsx @@ -6,7 +6,7 @@ import { SelectorAddButton } from "@docspace/shared/components/selector-add-butt import { SelectedItem } from "@docspace/shared/components/selected-item"; import { InputSize, InputType } from "@docspace/shared/components/text-input"; import { TTranslation } from "@docspace/shared/types"; -import { IClientReqDTO } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientReqDTO } from "@docspace/shared/utils/oauth/types"; import ArrowIcon from "PUBLIC_DIR/images/arrow.right.react.svg"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/OAuthBlock.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/OAuthBlock.tsx index 43f0785819..b71d17c35f 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/OAuthBlock.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/OAuthBlock.tsx @@ -1,7 +1,7 @@ import React from "react"; import { TTranslation } from "@docspace/shared/types"; -import { IClientReqDTO } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientReqDTO } from "@docspace/shared/utils/oauth/types"; import { StyledBlock, StyledInputBlock } from "../ClientForm.styled"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ScopesBlock.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ScopesBlock.tsx index 26f869981e..a003b4ee30 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ScopesBlock.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/ScopesBlock.tsx @@ -4,7 +4,7 @@ import { IClientReqDTO, IFilteredScopes, IScope, -} from "@docspace/shared/utils/oauth/interfaces"; +} from "@docspace/shared/utils/oauth/types"; import { filterScopeByGroup, getScopeTKeyName, diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/SupportBlock.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/SupportBlock.tsx index ba7c9c2768..278adbbf1d 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/SupportBlock.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/components/SupportBlock.tsx @@ -1,7 +1,7 @@ import React from "react"; import { TTranslation } from "@docspace/shared/types"; -import { IClientReqDTO } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientReqDTO } from "@docspace/shared/utils/oauth/types"; import { StyledBlock, StyledInputBlock } from "../ClientForm.styled"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/index.tsx index c8eed57278..7376a46239 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/ClientForm/index.tsx @@ -6,8 +6,7 @@ import { useTranslation } from "react-i18next"; import { IClientProps, IClientReqDTO, - INoAuthClientProps, -} from "@docspace/shared/utils/oauth/interfaces"; +} from "@docspace/shared/utils/oauth/types"; import { AuthenticationMethod } from "@docspace/shared/enums"; import { toastr } from "@docspace/shared/components/toast"; import { TData } from "@docspace/shared/components/toast/Toast.type"; @@ -54,9 +53,9 @@ const ClientForm = ({ const [isRequestRunning, setIsRequestRunning] = React.useState(false); - const [initialClient, setInitialClient] = React.useState< - IClientProps | INoAuthClientProps - >({} as IClientProps); + const [initialClient, setInitialClient] = React.useState( + {} as IClientProps, + ); const [form, setForm] = React.useState({ name: "", logo: "", @@ -70,6 +69,7 @@ const ClientForm = ({ terms_url: "", policy_url: "", + is_public: false, allow_pkce: false, scopes: [], @@ -212,6 +212,7 @@ const ClientForm = ({ allow_pkce: item.authenticationMethods ? item.authenticationMethods.includes(AuthenticationMethod.none) : false, + is_public: item.isPublic ?? false, scopes: item.scopes ? [...item.scopes] : [], }); @@ -302,18 +303,20 @@ const ClientForm = ({ }); return ( - isValid && - form.name && - form.logo && - form.allowed_origins.length > 0 && - (form.name !== initialClient.name || - form.logo !== initialClient.logo || - form.description !== initialClient.description || - form.allowed_origins.length !== initialClient.allowedOrigins.length || - form.allow_pkce !== - initialClient.authenticationMethods.includes( - AuthenticationMethod.none, - )) + (isValid && + form.name && + form.logo && + form.allowed_origins.length > 0 && + (form.name !== initialClient.name || + form.logo !== initialClient.logo || + form.description !== initialClient.description || + form.allowed_origins.length !== + initialClient.allowedOrigins.length || + form.allow_pkce !== + initialClient.authenticationMethods.includes( + AuthenticationMethod.none, + ))) || + form.is_public !== initialClient.isPublic ); } @@ -377,6 +380,7 @@ const ClientForm = ({ descriptionValue={form.description} logoValue={form.logo} allowPkce={form.allow_pkce} + isPublic={form.is_public} changeValue={onChangeForm} isEdit={isEdit} errorFields={errorFields} diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/EmptyScreen.types.ts b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/EmptyScreen.types.ts deleted file mode 100644 index 85943f7e16..0000000000 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/EmptyScreen.types.ts +++ /dev/null @@ -1,5 +0,0 @@ -import { TTranslation } from "@docspace/shared/types"; - -export interface EmptyScreenProps { - t: TTranslation; -} diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/index.tsx index 94c3f6022f..4897234666 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/EmptyScreen/index.tsx @@ -1,19 +1,21 @@ +import { useTranslation } from "react-i18next"; + import { EmptyScreenContainer } from "@docspace/shared/components/empty-screen-container"; import EmptyScreenOauthSvgUrl from "PUBLIC_DIR/images/empty_screen_oauth.svg?url"; import RegisterNewButton from "../RegisterNewButton"; -import { EmptyScreenProps } from "./EmptyScreen.types"; +const OAuthEmptyScreen = () => { + const { t } = useTranslation(["OAuth"]); -const OAuthEmptyScreen = ({ t }: EmptyScreenProps) => { return ( } + buttons={} /> ); }; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/InfoDialog.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/InfoDialog.tsx index 586a15595f..b382e38138 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/InfoDialog.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/InfoDialog.tsx @@ -3,7 +3,7 @@ import { inject, observer } from "mobx-react"; import styled from "styled-components"; import { useTranslation } from "react-i18next"; -import { IClientProps, IScope } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientProps, IScope } from "@docspace/shared/utils/oauth/types"; import ScopeList from "@docspace/shared/utils/oauth/ScopeList"; import getCorrectDate from "@docspace/shared/utils/getCorrectDate"; import { getCookie } from "@docspace/shared/utils/cookie"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/RowView/Row.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/RowView/Row.tsx index e64ec29984..dd023e2f97 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/RowView/Row.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/RowView/Row.tsx @@ -59,7 +59,6 @@ export const OAuthRow = (props: RowProps) => { return ( { containerRef={{ current: tableRef }} columns={defaultColumns} columnStorageName={columnStorageName} + tableStorageName={columnStorageName} sectionWidth={sectionWidth} showSettings={false} useReactWindow diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/TableView.types.ts b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/TableView.types.ts index 248f8a3ba2..7cd009da14 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/TableView.types.ts +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/TableView.types.ts @@ -1,4 +1,4 @@ -import { IClientProps } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientProps } from "@docspace/shared/utils/oauth/types"; import { TTranslation } from "@docspace/shared/types"; import { ContextMenuModel } from "@docspace/shared/components/context-menu"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/creator.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/creator.tsx index 6b2b40d33e..2c67399670 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/creator.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/creator.tsx @@ -1,4 +1,3 @@ -import React from "react"; import styled from "styled-components"; import { Text } from "@docspace/shared/components/text"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/name.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/name.tsx index 9f2693854d..60dda50ee9 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/name.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/columns/name.tsx @@ -1,4 +1,3 @@ -import React from "react"; import styled from "styled-components"; import { Text } from "@docspace/shared/components/text"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/index.tsx index 5327b3e98c..359ff07020 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/TableView/index.tsx @@ -14,7 +14,7 @@ import { TableViewProps } from "./TableView.types"; import { TableWrapper } from "./TableView.styled"; const TABLE_VERSION = "1"; -const COLUMNS_SIZE = `oauthConfigColumnsSize_ver-${TABLE_VERSION}`; +const COLUMNS_NAME = `oauthConfigColumnsSize_ver-${TABLE_VERSION}`; const elementResizeDetector = elementResizeDetectorMaker({ strategy: "scroll", @@ -99,7 +99,7 @@ const TableView = ({ }; }, [clickOutside, setSelection]); - const columnStorageName = `${COLUMNS_SIZE}=${userId}`; + const columnStorageName = `${COLUMNS_NAME}=${userId}`; const fetchMoreFiles = React.useCallback( async ({ startIndex }: { startIndex: number; stopIndex: number }) => { diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/index.tsx index 905ea5f753..05731eab3c 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/List/index.tsx @@ -1,7 +1,7 @@ import styled from "styled-components"; import { useTranslation } from "react-i18next"; -import { IClientProps } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientProps } from "@docspace/shared/utils/oauth/types"; import { Text } from "@docspace/shared/components/text"; import { Consumer } from "@docspace/shared/utils/context"; @@ -47,16 +47,12 @@ const List = ({ clients, viewAs, currentDeviceType }: ListProps) => { fontSize="12px" fontWeight={400} lineHeight="16px" - title="OAuth description" - tag="" - as="p" - color="" - textAlign="" + title={t("OAuthAppDescription")} className="description" > {t("OAuthAppDescription")} - + {(context) => viewAs === "table" ? ( diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/PreviewDialog.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/PreviewDialog.tsx index fed02eb059..828e7e678f 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/PreviewDialog.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/PreviewDialog.tsx @@ -3,7 +3,7 @@ import { inject, observer } from "mobx-react"; import styled, { useTheme } from "styled-components"; import { useTranslation } from "react-i18next"; -import { IClientProps } from "@docspace/shared/utils/oauth/interfaces"; +import { IClientProps } from "@docspace/shared/utils/oauth/types"; import { ModalDialog } from "@docspace/shared/components/modal-dialog"; import { ModalDialogType } from "@docspace/shared/components/modal-dialog/ModalDialog.enums"; import { SocialButton } from "@docspace/shared/components/social-button"; diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/RegisterNewButton.types.ts b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/RegisterNewButton.types.ts index be569e9602..3aae1b3b7c 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/RegisterNewButton.types.ts +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/RegisterNewButton.types.ts @@ -1,9 +1,5 @@ -import { TTranslation } from "@docspace/shared/types"; - -//@ts-ignore import { DeviceUnionType } from "SRC_DIR/Hooks/useViewEffect"; export interface RegisterNewButtonProps { - t: TTranslation; currentDeviceType?: DeviceUnionType; } diff --git a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/index.tsx b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/index.tsx index ef9c5609f9..7051a67e31 100644 --- a/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/index.tsx +++ b/packages/client/src/pages/PortalSettings/categories/developer-tools/OAuth/sub-components/RegisterNewButton/index.tsx @@ -1,13 +1,13 @@ import { useNavigate } from "react-router-dom"; +import { useTranslation } from "react-i18next"; import { Button, ButtonSize } from "@docspace/shared/components/button"; import { RegisterNewButtonProps } from "./RegisterNewButton.types"; -const RegisterNewButton = ({ - t, - currentDeviceType, -}: RegisterNewButtonProps) => { +const RegisterNewButton = ({ currentDeviceType }: RegisterNewButtonProps) => { + const { t } = useTranslation(["OAuth", "Common"]); + const navigate = useNavigate(); const onClick = () => { diff --git a/packages/client/src/store/OAuthStore.ts b/packages/client/src/store/OAuthStore.ts index 191e2a6758..62938faac5 100644 --- a/packages/client/src/store/OAuthStore.ts +++ b/packages/client/src/store/OAuthStore.ts @@ -16,7 +16,7 @@ import { IClientProps, IClientReqDTO, IScope, -} from "@docspace/shared/utils/oauth/interfaces"; +} from "@docspace/shared/utils/oauth/types"; import { toastr } from "@docspace/shared/components/toast"; import { AuthenticationMethod } from "@docspace/shared/enums"; import { TData } from "@docspace/shared/components/toast/Toast.type"; @@ -202,7 +202,7 @@ class OAuthStore implements OAuthStoreProps { this.clientSecret = value; }; - setSelection = (clientId: string) => { + setSelection = (clientId?: string) => { if (!clientId) { this.selection = []; } else if (this.selection.includes(clientId)) { @@ -229,7 +229,7 @@ class OAuthStore implements OAuthStoreProps { this.clientsIsLoading = value; }; - setActiveClient = (clientId: string) => { + setActiveClient = (clientId?: string) => { if (!clientId) { this.activeClients = []; } else if (this.activeClients.includes(clientId)) { @@ -257,7 +257,7 @@ class OAuthStore implements OAuthStoreProps { this.clients = [...clientList.content]; this.selection = []; this.currentPage = clientList.page; - this.nextPage = clientList.next || null; + this.nextPage = clientList.next; if (clientList.next) { this.itemCount = clientList.content.length + 2; @@ -272,19 +272,6 @@ class OAuthStore implements OAuthStoreProps { } }; - fetchConsents = async () => { - try { - const consentList: IClientProps[] = await getConsentList(); - - runInAction(() => { - this.consents = [...consentList]; - }); - } catch (e) { - const err = e as TData; - toastr.error(err); - } - }; - fetchNextClients = async (startIndex: number) => { if (this.clientsIsLoading) return; @@ -312,6 +299,19 @@ class OAuthStore implements OAuthStoreProps { this.setClientsIsLoading(false); }; + fetchConsents = async () => { + try { + const consentList: IClientProps[] = await getConsentList(); + + runInAction(() => { + this.consents = [...consentList]; + }); + } catch (e) { + const err = e as TData; + toastr.error(err); + } + }; + saveClient = async (client: IClientReqDTO) => { try { const newClient = await addClient(client); @@ -343,6 +343,7 @@ class OAuthStore implements OAuthStoreProps { newClient.allowedOrigins = client.allowed_origins; newClient.logo = client.logo; newClient.description = client.description; + newClient.isPublic = client.is_public; if ( client.allow_pkce && diff --git a/packages/runtime.json b/packages/runtime.json index 1b3de8413b..2a137eecee 100644 --- a/packages/runtime.json +++ b/packages/runtime.json @@ -1,5 +1,5 @@ { - "date": "2024624_152825", + "date": "2024626_125743", "checksums": { "api.js": "0efbae3383bf6c6b6f26d573eee164d2", "api.poly.js": "2a2ac2c0e4a7007b61d2d1ff7b00a22e", diff --git a/packages/shared/api/management/index.ts b/packages/shared/api/management/index.ts index 51d87d7bfd..bdb8e3eafc 100644 --- a/packages/shared/api/management/index.ts +++ b/packages/shared/api/management/index.ts @@ -142,3 +142,17 @@ export const checkDomain = async (domain: string) => { }); return res; }; + +export const getAvailablePortals = async (data: { + Email: string; + PasswordHash: string; +}) => { + const res = (await request({ + baseURL, + method: "post", + url: `/portal/signin?Email=${data.Email}&PasswordHash=${data.PasswordHash}`, + data, + })) as { tenants: { portalLink: string; portalName: string }[] }; + + return res.tenants; +}; diff --git a/packages/shared/api/oauth/index.ts b/packages/shared/api/oauth/index.ts index 838918a45c..fac421e806 100644 --- a/packages/shared/api/oauth/index.ts +++ b/packages/shared/api/oauth/index.ts @@ -8,26 +8,11 @@ import { IClientListProps, IClientListDTO, IScope, - INoAuthClientProps, IClientReqDTO, IGetConsentList, -} from "../../utils/oauth/interfaces"; - -export const getClient = async ( - clientId: string, - isAuth: boolean = true, -): Promise => { - if (!isAuth) { - const client = (await request({ - method: "get", - url: `/clients/${clientId}/info`, - })) as INoAuthClientProps; - - return { - ...client, - }; - } +} from "../../utils/oauth/types"; +export const getClient = async (clientId: string): Promise => { const client = (await request({ method: "get", url: `/clients/${clientId}`, @@ -45,7 +30,7 @@ export const getClientList = async ( url: `/clients?page=${page}&limit=${limit}`, })) as IClientListDTO; - const clients: IClientListProps = { ...data, content: [] as IClientProps[] }; + const clients: IClientListProps = { ...data, content: [] }; data.data.forEach((item) => { const client = transformToClientProps(item); @@ -123,6 +108,36 @@ export const getScopeList = async (): Promise => { return scopeList; }; +export const getConsentList = async (): Promise => { + const clients = (await request({ + method: "get", + url: "/clients/consents", + })) as IGetConsentList[]; + + const consents: IClientProps[] = []; + + clients.forEach(({ client, invalidated, modified_at }: IGetConsentList) => { + const consentClient: IClientResDTO = { + ...client, + client_secret: "", + logout_redirect_uri: "", + }; + + const cl = transformToClientProps(consentClient); + + if (!invalidated) consents.push({ ...cl, modifiedOn: modified_at }); + }); + + return consents; +}; + +export const revokeUserClient = async (clientId: string): Promise => { + await request({ + method: "delete", + url: `/clients/${clientId}/revoke`, + }); +}; + export const onOAuthLogin = (clientId: string) => { const formData = new FormData(); @@ -182,33 +197,3 @@ export const onOAuthCancel = (clientId: string, clientState: string) => { }, }); }; - -export const getConsentList = async (): Promise => { - const clients = (await request({ - method: "get", - url: "/clients/consents", - })) as IGetConsentList[]; - - const consents: IClientProps[] = []; - - clients.forEach(({ client, invalidated, modified_at }: IGetConsentList) => { - const consentClient: IClientResDTO = { - ...client, - client_secret: "", - logout_redirect_uri: "", - }; - - const cl = transformToClientProps(consentClient); - - if (!invalidated) consents.push({ ...cl, modifiedOn: modified_at }); - }); - - return consents; -}; - -export const revokeUserClient = async (clientId: string): Promise => { - await request({ - method: "delete", - url: `/clients/${clientId}/revoke`, - }); -}; diff --git a/packages/shared/themes/dark.ts b/packages/shared/themes/dark.ts index 82cd9ace43..765a318335 100644 --- a/packages/shared/themes/dark.ts +++ b/packages/shared/themes/dark.ts @@ -992,7 +992,7 @@ const Dark: TTheme = { border: "none", }, }, - + fieldContainer: { horizontal: { margin: "0 0 16px 0", diff --git a/packages/shared/utils/next-ssr-helper.ts b/packages/shared/utils/next-ssr-helper.ts index efc609dd37..b863d0a14f 100644 --- a/packages/shared/utils/next-ssr-helper.ts +++ b/packages/shared/utils/next-ssr-helper.ts @@ -39,10 +39,10 @@ export const getBaseUrl = () => { return baseURL; }; -export const getAPIUrl = () => { +export const getAPIUrl = (apiSystem?: boolean) => { const baseUrl = process.env.API_HOST?.trim() ?? getBaseUrl(); - const baseAPIUrl = `${baseUrl}/${API_PREFIX}`; + const baseAPIUrl = `${baseUrl}/${!apiSystem ? API_PREFIX : "apisystem"}`; return baseAPIUrl; }; @@ -52,11 +52,12 @@ export const createRequest = ( newHeaders: [string, string][], method: string, body?: string, + apiSystem?: boolean, ) => { const hdrs = new Headers(headers()); const cookieStore = cookies(); - const apiURL = getAPIUrl(); + const apiURL = getAPIUrl(apiSystem); newHeaders.forEach((hdr) => { if (hdr[0]) hdrs.set(hdr[0], hdr[1]); diff --git a/packages/shared/utils/oauth/ScopeList.tsx b/packages/shared/utils/oauth/ScopeList.tsx index fc7fb7884b..db6fde3ae4 100644 --- a/packages/shared/utils/oauth/ScopeList.tsx +++ b/packages/shared/utils/oauth/ScopeList.tsx @@ -5,7 +5,7 @@ import { Base } from "../../themes"; import { ScopeType } from "../../enums"; import { TTranslation } from "../../types"; -import { IFilteredScopes, IScope } from "./interfaces"; +import { IFilteredScopes, IScope } from "./types"; import { filterScopeByGroup } from "."; const StyledScopeList = styled.div` diff --git a/packages/shared/utils/oauth/index.ts b/packages/shared/utils/oauth/index.ts index 4b3ed7c78a..e8cfa6cadb 100644 --- a/packages/shared/utils/oauth/index.ts +++ b/packages/shared/utils/oauth/index.ts @@ -9,7 +9,7 @@ import { IClientProps, IScope, IFilteredScopes, -} from "./interfaces"; +} from "./types"; export const transformToClientProps = ( clientDto: IClientResDTO, @@ -37,6 +37,7 @@ export const transformToClientProps = ( allowed_origins, creator_avatar, creator_display_name, + is_public, } = clientDto; const client: IClientProps = { @@ -62,6 +63,7 @@ export const transformToClientProps = ( allowedOrigins: allowed_origins, creatorAvatar: creator_avatar, creatorDisplayName: creator_display_name, + isPublic: is_public, }; return client; @@ -82,6 +84,7 @@ export const transformToClientReqDTO = ( scopes, websiteUrl, allowedOrigins, + isPublic, } = clientProps; const client: IClientReqDTO = { @@ -92,7 +95,7 @@ export const transformToClientReqDTO = ( logout_redirect_uri, terms_url, policy_url, - + is_public: isPublic, scopes, allow_pkce: authenticationMethods.includes(AuthenticationMethod.none), website_url: websiteUrl, diff --git a/packages/shared/utils/oauth/interfaces.ts b/packages/shared/utils/oauth/types.ts similarity index 87% rename from packages/shared/utils/oauth/interfaces.ts rename to packages/shared/utils/oauth/types.ts index e7b1e514a7..5c28d892b4 100644 --- a/packages/shared/utils/oauth/interfaces.ts +++ b/packages/shared/utils/oauth/types.ts @@ -1,3 +1,4 @@ +import { Nullable } from "../../types"; import { AuthenticationMethod, ScopeGroup, ScopeType } from "../../enums"; export interface IScope { @@ -61,12 +62,13 @@ export interface IClientProps { scopes: string[]; websiteUrl: string; allowedOrigins: string[]; - createdOn?: Date; - modifiedOn?: Date; - createdBy?: string; - modifiedBy?: string; + createdOn: Date; + modifiedOn: Date; + createdBy: string; + modifiedBy: string; creatorAvatar?: string; creatorDisplayName?: string; + isPublic: boolean; } export interface IClientReqDTO { @@ -81,54 +83,61 @@ export interface IClientReqDTO { scopes: string[]; website_url: string; allowed_origins: string[]; + is_public: boolean; } export interface IClientResDTO { - name: string; + allowed_origins: string[]; + authentication_methods: AuthenticationMethod[]; client_id: string; client_secret: string; - description: string; - logo: string; + created_by: string; + created_on: Date; - redirect_uris: string[]; - terms_url: string; - policy_url: string; + creator_avatar?: string; + creator_display_name?: string; + + description: string; + + enabled: boolean; + invalidated: boolean; + is_public: boolean; + + logo: string; logout_redirect_uri: string; - authentication_methods: AuthenticationMethod[]; + modified_by: string; + modified_on: Date; + + name: string; + + policy_url: string; + redirect_uris: string[]; scopes: string[]; - enabled: boolean; + terms_url: string; tenant: number; - invalidated: boolean; - website_url: string; - allowed_origins: string[]; - created_on?: Date; - modified_on?: Date; - created_by?: string; - modified_by?: string; - creator_avatar?: string; - creator_display_name?: string; + website_url: string; } export interface IClientListProps { content: IClientProps[]; page: number; - next?: number; - previous?: number; limit: number; + next: Nullable; + previous: Nullable; } export interface IClientListDTO { data: IClientResDTO[]; page: number; - next?: number; - previous?: number; limit: number; + next: Nullable; + previous: Nullable; } export interface ISubmitReqDTO { @@ -159,6 +168,7 @@ export type TConsentClient = { redirect_uris: string[]; scopes: string[]; allowed_origins: string[]; + is_public: boolean; }; export interface IGetConsentList { @@ -168,4 +178,5 @@ export interface IGetConsentList { principal_name: string; registered_client_id: string; scopes: string; + is_public: boolean; }