forked from konflux-ci/konflux-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathAddSecretForm.tsx
94 lines (93 loc) · 3.2 KB
/
AddSecretForm.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
import * as React from 'react';
import { useNavigate } from 'react-router-dom';
import { Form, PageSection, PageSectionVariants } from '@patternfly/react-core';
import { Formik } from 'formik';
import { isEmpty } from 'lodash-es';
import FormFooter from '../../../shared/components/form-components/FormFooter';
import ExternalLink from '../../../shared/components/links/ExternalLink';
import { AddSecretFormValues, SecretFor, SecretTypeDropdownLabel } from '../../../types';
import { addSecret } from '../../../utils/create-utils';
import PageLayout from '../../PageLayout/PageLayout';
import { useWorkspaceInfo } from '../../Workspace/useWorkspaceInfo';
import { getAddSecretBreadcrumbs } from '../utils/secret-utils';
import { secretFormValidationSchema } from '../utils/secret-validation';
import { SecretTypeSubForm } from './SecretTypeSubForm';
const AddSecretForm: React.FC = () => {
const { namespace, workspace } = useWorkspaceInfo();
const navigate = useNavigate();
const initialValues: AddSecretFormValues = {
type: SecretTypeDropdownLabel.opaque,
name: '',
secretFor: SecretFor.Build,
opaque: {
keyValues: [{ key: '', value: '' }],
},
image: {
authType: 'Image registry credentials',
registryCreds: [
{
registry: '',
username: '',
password: '',
email: '',
},
],
},
source: {
authType: 'Basic authentication',
},
};
return (
<Formik
initialValues={initialValues}
onReset={() => {
navigate(-1);
}}
onSubmit={(values, actions) => {
addSecret(values, workspace, namespace)
.then(() => {
navigate(`/workspaces/${workspace}/secrets`);
})
.catch((error) => {
// eslint-disable-next-line no-console
console.warn('Error while submitting secret form:', error);
actions.setSubmitting(false);
actions.setStatus({ submitError: error.message });
});
}}
validationSchema={secretFormValidationSchema}
>
{({ status, isSubmitting, handleReset, dirty, errors, handleSubmit }) => (
<PageLayout
breadcrumbs={getAddSecretBreadcrumbs(workspace)}
title="Add secret"
description={
<>
Add a secret that will be stored using AWS Secret Manager to keep your data private.{' '}
<ExternalLink href="https://konflux-ci.dev/docs/how-tos/configuring/creating-secrets/">
Learn more
</ExternalLink>
</>
}
footer={
<FormFooter
submitLabel="Add secret"
handleSubmit={handleSubmit}
errorMessage={status && status.submitError}
handleCancel={handleReset}
isSubmitting={isSubmitting}
disableSubmit={!dirty || !isEmpty(errors) || isSubmitting}
/>
}
>
<PageSection variant={PageSectionVariants.light} isFilled isWidthLimited>
<Form style={{ maxWidth: '70%' }}>
<SecretTypeSubForm />
</Form>
</PageSection>
</PageLayout>
)}
</Formik>
);
};
export default AddSecretForm;