|
1 |
| -import React, { FunctionComponent, useMemo } from 'react' |
2 |
| -import { |
3 |
| - BUILD_INFRA_BREADCRUMB, |
4 |
| - BuildInfraDescriptor, |
5 |
| - BuildInfraFooter, |
6 |
| - useBreadcrumb, |
7 |
| - BuildInfraConfigForm, |
8 |
| - useBuildInfraForm, |
9 |
| - DEFAULT_PROFILE_NAME, |
10 |
| - APIResponseHandler, |
11 |
| - ErrorScreenNotAuthorized, |
12 |
| -} from '@devtron-labs/devtron-fe-common-lib' |
| 1 | +import React, { FunctionComponent } from 'react' |
| 2 | +import { ErrorScreenNotAuthorized } from '@devtron-labs/devtron-fe-common-lib' |
| 3 | +import { importComponentFromFELibrary } from '../../../components/common' |
13 | 4 | import { BuildInfraProps } from './types'
|
14 |
| -import './styles.scss' |
| 5 | +import ProfileForm from './ProfileForm' |
15 | 6 |
|
16 |
| -const BuildInfra: FunctionComponent<BuildInfraProps> = ({ isSuperAdmin }) => { |
17 |
| - const { breadcrumbs } = useBreadcrumb(BUILD_INFRA_BREADCRUMB) |
18 |
| - // Sending isSuperAdmin since don't even want to send API Request for that case |
19 |
| - const { |
20 |
| - isLoading, |
21 |
| - profileResponse, |
22 |
| - responseError, |
23 |
| - reloadRequest, |
24 |
| - profileInput, |
25 |
| - profileInputErrors, |
26 |
| - handleProfileInputChange, |
27 |
| - loadingActionRequest, |
28 |
| - handleSubmit, |
29 |
| - } = useBuildInfraForm({ name: DEFAULT_PROFILE_NAME, isSuperAdmin, editProfile: true }) |
30 |
| - // Would use this to disable the save button, if all keys in profileInputErrors are null, then there are no errors |
31 |
| - // Might enhance this check later for other operations |
32 |
| - const formErrorCount = useMemo( |
33 |
| - () => Object.keys(profileInputErrors).filter((item) => profileInputErrors[item]).length, |
34 |
| - [profileInputErrors], |
35 |
| - ) |
36 |
| - const showActionItems = isSuperAdmin && !isLoading && !responseError && profileInput?.configurations |
| 7 | +const BuildInfraRouter = importComponentFromFELibrary('BuildInfraRouter') |
37 | 8 |
|
| 9 | +export const BuildInfra: FunctionComponent<BuildInfraProps> = ({ isSuperAdmin }) => { |
38 | 10 | if (!isSuperAdmin) {
|
39 | 11 | return <ErrorScreenNotAuthorized />
|
40 | 12 | }
|
41 | 13 |
|
42 |
| - return ( |
43 |
| - <form className="h-100 flexbox-col build-infra pl pr pt pb dc__content-space bcn-0" onSubmit={handleSubmit}> |
44 |
| - <div className="flexbox-col dc__gap-24 pt pr pb pl h-100 dc__overflow-scroll"> |
45 |
| - <BuildInfraDescriptor breadCrumbs={breadcrumbs} /> |
46 |
| - |
47 |
| - <APIResponseHandler |
48 |
| - isLoading={isLoading} |
49 |
| - progressingProps={{ |
50 |
| - pageLoader: true, |
51 |
| - }} |
52 |
| - error={responseError} |
53 |
| - notAuthorized={!isSuperAdmin} |
54 |
| - reloadProps={{ |
55 |
| - reload: reloadRequest, |
56 |
| - }} |
57 |
| - > |
58 |
| - <BuildInfraConfigForm |
59 |
| - profileInput={profileInput} |
60 |
| - profileInputErrors={profileInputErrors} |
61 |
| - handleProfileInputChange={handleProfileInputChange} |
62 |
| - isDefaultProfile |
63 |
| - unitsMap={profileResponse?.configurationUnits} |
64 |
| - /> |
65 |
| - </APIResponseHandler> |
66 |
| - </div> |
| 14 | + if (BuildInfraRouter) { |
| 15 | + return <BuildInfraRouter /> |
| 16 | + } |
67 | 17 |
|
68 |
| - {showActionItems && ( |
69 |
| - <BuildInfraFooter |
70 |
| - disabled={formErrorCount !== 0} |
71 |
| - hideCancelButton |
72 |
| - editProfile |
73 |
| - loading={loadingActionRequest} |
74 |
| - /> |
75 |
| - )} |
76 |
| - </form> |
77 |
| - ) |
| 18 | + return <ProfileForm /> |
78 | 19 | }
|
79 | 20 |
|
80 | 21 | export default BuildInfra
|
0 commit comments