Skip to content

Commit 788b8a4

Browse files
committed
feat: updated organization import form for api changes
1 parent 9d0b0bc commit 788b8a4

File tree

6 files changed

+42
-16
lines changed

6 files changed

+42
-16
lines changed

src/renderer/api/cadt/v1/organizations/organizations.api.ts

+10-7
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,12 @@ interface GetOrgnaizationsMapResponse {
99

1010
interface CreateOrganizationResponse {
1111
message: string;
12-
orgId: string;
12+
orgUid: string;
13+
}
14+
15+
interface CreateOrganizationParams {
16+
orgUid: string;
17+
isHome: boolean;
1318
}
1419

1520
const organizationsApi = cadtApi.injectEndpoints({
@@ -59,22 +64,20 @@ const organizationsApi = cadtApi.injectEndpoints({
5964
invalidatesTags: [organizationsTag],
6065
}),
6166

62-
importOrganization: builder.mutation<CreateOrganizationResponse, string>({
63-
query: (orgUid: string) => ({
67+
importOrganization: builder.mutation<CreateOrganizationResponse, CreateOrganizationParams>({
68+
query: (createOrgParams) => ({
6469
url: `/v1/organizations`,
6570
method: 'PUT',
6671
headers: { 'Content-Type': 'application/json' },
67-
body: { orgUid },
72+
body: createOrgParams,
6873
}),
6974
invalidatesTags: [organizationsTag],
7075
}),
7176

7277
deleteOrganization: builder.mutation<any, string>({
7378
query: (orgUid: string) => ({
74-
url: `/v1/organizations`,
79+
url: `/v1/organizations/${orgUid}`,
7580
method: 'DELETE',
76-
headers: { 'Content-Type': 'application/json' },
77-
body: { orgUid },
7881
}),
7982
invalidatesTags: [organizationsTag],
8083
}),

src/renderer/components/blocks/forms/ImportOrganizationForm.tsx

+18-5
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,36 @@
11
import React, { useCallback } from 'react';
22
import { ErrorMessage, Field, Form, Formik } from 'formik';
33
import * as yup from 'yup';
4-
import { FloatingLabel, FormButton } from '@/components';
4+
import { CheckBox, FloatingLabel, FormButton, Label } from '@/components';
55
import { FormattedMessage, IntlShape, useIntl } from 'react-intl';
66

77
const validationSchema = yup.object({
88
orgUid: yup.string().length(64).required('OrgUid is required'),
99
});
1010

11+
export interface ImportOrganizationProps {
12+
orgUid: string;
13+
isHome: boolean;
14+
}
15+
1116
interface FormProps {
12-
onSubmit: (orgUid: string) => Promise<any>;
17+
onSubmit: (params: ImportOrganizationProps) => Promise<any>;
1318
}
1419

1520
const ImportOrganizationForm: React.FC<FormProps> = ({ onSubmit }) => {
1621
const intl: IntlShape = useIntl();
1722

1823
const handleSubmit = useCallback(
19-
async (values: { orgUid: string }, { setSubmitting }) => {
20-
await onSubmit(values.orgUid);
24+
async (values: ImportOrganizationProps, { setSubmitting }) => {
25+
await onSubmit(values);
2126
setSubmitting(false);
2227
},
2328
[onSubmit],
2429
); // Include onSuccess in the dependencies array
2530

2631
return (
2732
<>
28-
<Formik initialValues={{ orgUid: '' }} validationSchema={validationSchema} onSubmit={handleSubmit}>
33+
<Formik initialValues={{ orgUid: '', isHome: true }} validationSchema={validationSchema} onSubmit={handleSubmit}>
2934
{({ errors, touched, isSubmitting }) => (
3035
<Form>
3136
<div className="mb-4">
@@ -42,6 +47,14 @@ const ImportOrganizationForm: React.FC<FormProps> = ({ onSubmit }) => {
4247
)}
4348
</Field>
4449
{touched.orgUid && <ErrorMessage name="orgUid" component="div" className="text-red-600" />}
50+
<div className="flex space-x-2.5">
51+
<Field name="isHome">{({ field }) => <CheckBox id="isHome" checked {...field} />}</Field>
52+
<Label htmlFor="isHome">
53+
<p className="text-gray-600">
54+
<FormattedMessage id="import-as-home-organization" />
55+
</p>
56+
</Label>
57+
</div>
4558
</div>
4659
<FormButton isSubmitting={isSubmitting} formikErrors={errors}>
4760
<FormattedMessage id="submit" />

src/renderer/components/blocks/modals/CreateOrganizationModal.tsx

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Card, CreateOrganizationForm, Modal, Spinner, Tabs } from '@/components';
1+
import { Card, CreateOrganizationForm, ImportOrganizationProps, Modal, Spinner, Tabs } from '@/components';
22
import { FormattedMessage } from 'react-intl';
33
import { useCreateOrganizationMutation, useImportOrganizationMutation } from '@/api';
44
import { ImportOrganizationForm } from '@/components/blocks/forms/ImportOrganizationForm';
@@ -31,8 +31,9 @@ const CreateOrganizationModal: React.FC<CreateOrganizationModalProps> = ({
3131
}
3232
};
3333

34-
const handleSubmitImportOrg = async (orgName: string) => {
35-
const createOrgResult: any = await triggerImportOrganization(orgName);
34+
const handleSubmitImportOrg = async (importOrgFormValues: ImportOrganizationProps) => {
35+
const { orgUid, isHome } = importOrgFormValues;
36+
const createOrgResult: any = await triggerImportOrganization({ orgUid, isHome });
3637
if (createOrgResult?.data.success) {
3738
onClose();
3839
} else {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import { Checkbox as FlowbiteCheckBox, CheckboxProps } from 'flowbite-react';
2+
3+
function CheckBox({ children, ...props }: CheckboxProps) {
4+
return <FlowbiteCheckBox {...props}>{children}</FlowbiteCheckBox>;
5+
}
6+
7+
export { CheckBox };

src/renderer/components/proxy/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -16,3 +16,4 @@ export * from './FloatingLabel';
1616
export * from './Select';
1717
export * from './Badge';
1818
export * from './Popover';
19+
export * from './CheckBox';

src/renderer/translations/tokens/en-US.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -208,5 +208,6 @@
208208
"api-host-loaded-from-configuration": "API host loaded from configuration",
209209
"not-specified": "not specified",
210210
"unable-to-load-staging-data": "Unable to load staging data",
211-
"new-unit": "New Unit"
211+
"new-unit": "New Unit",
212+
"import-as-home-organization": "Import as home organization"
212213
}

0 commit comments

Comments
 (0)