diff --git a/src/renderer/api/cadt/v1/organizations/organizations.api.ts b/src/renderer/api/cadt/v1/organizations/organizations.api.ts index 86a461f4..ab754b8e 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; } const organizationsApi = cadtApi.injectEndpoints({ @@ -59,22 +64,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 2192e365..56f2b509 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 { 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 427d6fe1..b74174a5 100644 --- a/src/renderer/translations/tokens/en-US.json +++ b/src/renderer/translations/tokens/en-US.json @@ -208,5 +208,6 @@ "api-host-loaded-from-configuration": "API host loaded from configuration", "not-specified": "not specified", "unable-to-load-staging-data": "Unable to load staging data", - "new-unit": "New Unit" + "new-unit": "New Unit", + "import-as-home-organization": "Import as home organization" }