From e68a073a0ec4a06fb80665783227f0e76b07de25 Mon Sep 17 00:00:00 2001 From: William Wills Date: Thu, 2 Jan 2025 12:54:53 -0500 Subject: [PATCH 1/2] feat: updated organization import form for api changes --- .../v1/organizations/organizations.api.ts | 17 ++++++++------ .../blocks/forms/ImportOrganizationForm.tsx | 23 +++++++++++++++---- .../blocks/modals/CreateOrganizationModal.tsx | 7 +++--- src/renderer/components/proxy/CheckBox.tsx | 7 ++++++ src/renderer/components/proxy/index.ts | 1 + src/renderer/translations/tokens/en-US.json | 5 ++-- 6 files changed, 43 insertions(+), 17 deletions(-) create mode 100644 src/renderer/components/proxy/CheckBox.tsx diff --git a/src/renderer/api/cadt/v1/organizations/organizations.api.ts b/src/renderer/api/cadt/v1/organizations/organizations.api.ts index da85c3b9..58df70d0 100644 --- a/src/renderer/api/cadt/v1/organizations/organizations.api.ts +++ b/src/renderer/api/cadt/v1/organizations/organizations.api.ts @@ -9,7 +9,12 @@ interface GetOrgnaizationsMapResponse { interface CreateOrganizationResponse { message: string; - orgId: string; + orgUid: string; +} + +interface CreateOrganizationParams { + orgUid: string; + isHome: boolean; } export interface CreateOrganizatonParams { @@ -65,22 +70,20 @@ const organizationsApi = cadtApi.injectEndpoints({ invalidatesTags: [organizationsTag], }), - importOrganization: builder.mutation({ - query: (orgUid: string) => ({ + importOrganization: builder.mutation({ + query: (createOrgParams) => ({ url: `/v1/organizations`, method: 'PUT', headers: { 'Content-Type': 'application/json' }, - body: { orgUid }, + body: createOrgParams, }), invalidatesTags: [organizationsTag], }), deleteOrganization: builder.mutation({ query: (orgUid: string) => ({ - url: `/v1/organizations`, + url: `/v1/organizations/${orgUid}`, method: 'DELETE', - headers: { 'Content-Type': 'application/json' }, - body: { orgUid }, }), invalidatesTags: [organizationsTag], }), diff --git a/src/renderer/components/blocks/forms/ImportOrganizationForm.tsx b/src/renderer/components/blocks/forms/ImportOrganizationForm.tsx index 3d39141b..902fafb4 100644 --- a/src/renderer/components/blocks/forms/ImportOrganizationForm.tsx +++ b/src/renderer/components/blocks/forms/ImportOrganizationForm.tsx @@ -1,23 +1,28 @@ import React, { useCallback } from 'react'; import { ErrorMessage, Field, Form, Formik } from 'formik'; import * as yup from 'yup'; -import { FloatingLabel, FormButton } from '@/components'; +import { CheckBox, FloatingLabel, FormButton, Label } from '@/components'; import { FormattedMessage, IntlShape, useIntl } from 'react-intl'; const validationSchema = yup.object({ orgUid: yup.string().length(64).required('OrgUid is required'), }); +export interface ImportOrganizationProps { + orgUid: string; + isHome: boolean; +} + interface FormProps { - onSubmit: (orgUid: string) => Promise; + onSubmit: (params: ImportOrganizationProps) => Promise; } const ImportOrganizationForm: React.FC = ({ onSubmit }) => { const intl: IntlShape = useIntl(); const handleSubmit = useCallback( - async (values: { orgUid: string }, { setSubmitting }) => { - await onSubmit(values.orgUid); + async (values: ImportOrganizationProps, { setSubmitting }) => { + await onSubmit(values); setSubmitting(false); }, [onSubmit], @@ -25,7 +30,7 @@ const ImportOrganizationForm: React.FC = ({ onSubmit }) => { return ( <> - + {({ errors, touched, isSubmitting }) => (
@@ -42,6 +47,14 @@ const ImportOrganizationForm: React.FC = ({ onSubmit }) => { )} {touched.orgUid && } +
+ {({ field }) => } + +
diff --git a/src/renderer/components/blocks/modals/CreateOrganizationModal.tsx b/src/renderer/components/blocks/modals/CreateOrganizationModal.tsx index 9ea2f96b..427103d5 100644 --- a/src/renderer/components/blocks/modals/CreateOrganizationModal.tsx +++ b/src/renderer/components/blocks/modals/CreateOrganizationModal.tsx @@ -1,4 +1,4 @@ -import { Card, CreateOrganizationForm, Modal, Spinner, Tabs } from '@/components'; +import { Card, CreateOrganizationForm, ImportOrganizationProps, Modal, Spinner, Tabs } from '@/components'; import { FormattedMessage } from 'react-intl'; import { CreateOrganizatonParams, useCreateOrganizationMutation, useImportOrganizationMutation } from '@/api'; import { ImportOrganizationForm } from '@/components/blocks/forms/ImportOrganizationForm'; @@ -31,8 +31,9 @@ const CreateOrganizationModal: React.FC = ({ } }; - const handleSubmitImportOrg = async (orgName: string) => { - const createOrgResult: any = await triggerImportOrganization(orgName); + const handleSubmitImportOrg = async (importOrgFormValues: ImportOrganizationProps) => { + const { orgUid, isHome } = importOrgFormValues; + const createOrgResult: any = await triggerImportOrganization({ orgUid, isHome }); if (createOrgResult?.data.success) { onClose(); } else { diff --git a/src/renderer/components/proxy/CheckBox.tsx b/src/renderer/components/proxy/CheckBox.tsx new file mode 100644 index 00000000..7168e1e1 --- /dev/null +++ b/src/renderer/components/proxy/CheckBox.tsx @@ -0,0 +1,7 @@ +import { Checkbox as FlowbiteCheckBox, CheckboxProps } from 'flowbite-react'; + +function CheckBox({ children, ...props }: CheckboxProps) { + return {children}; +} + +export { CheckBox }; diff --git a/src/renderer/components/proxy/index.ts b/src/renderer/components/proxy/index.ts index 07f67578..89c759b4 100644 --- a/src/renderer/components/proxy/index.ts +++ b/src/renderer/components/proxy/index.ts @@ -16,3 +16,4 @@ export * from './FloatingLabel'; export * from './Select'; export * from './Badge'; export * from './Popover'; +export * from './CheckBox'; diff --git a/src/renderer/translations/tokens/en-US.json b/src/renderer/translations/tokens/en-US.json index 39b61f85..4921e31c 100644 --- a/src/renderer/translations/tokens/en-US.json +++ b/src/renderer/translations/tokens/en-US.json @@ -211,7 +211,8 @@ "name-is-required": "Name is required", "prefix-is-required": "Prefix is required", "unable-to-load-staging-data": "Unable to load staging data", - "new-unit": "New Unit", "cannot-connect-to-registry-api-with-current-settings": "Cannot connect to registry API with current settings", - "please-disconnect-to-edit-the-api-url-and-api-key": "Please disconnect to edit the API URL and API key" + "please-disconnect-to-edit-the-api-url-and-api-key": "Please disconnect to edit the API URL and API key", + "new-unit": "New Unit", + "import-as-home-organization": "Import as home organization" } From 1dfb55715fd675fc586eaa4feacbbbc2777a84f6 Mon Sep 17 00:00:00 2001 From: William Wills Date: Thu, 9 Jan 2025 15:46:20 -0500 Subject: [PATCH 2/2] fix: connect form address field to accept v4 ips --- src/renderer/components/blocks/forms/ConnectForm.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/renderer/components/blocks/forms/ConnectForm.tsx b/src/renderer/components/blocks/forms/ConnectForm.tsx index fe59ef6a..94b2db89 100644 --- a/src/renderer/components/blocks/forms/ConnectForm.tsx +++ b/src/renderer/components/blocks/forms/ConnectForm.tsx @@ -16,7 +16,7 @@ const validationSchema = yup.object({ .required('Server Address is required') .matches( // eslint-disable-next-line no-useless-escape - /^(https?:\/\/(www\.)?)?([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|localhost|[a-z0-9]+)(:[0-9]{1,5})?(\/.*)?$/, + /^(https?:\/\/(www\.)?)?([a-z0-9]+([\-\.]{1}[a-z0-9]+)*\.[a-z]{2,5}|localhost|[a-z0-9]+|((25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?))(:[0-9]{1,5})?(\/.*)?$/, 'Please enter a valid server address', ), apiKey: yup.string(),