Skip to content

Commit

Permalink
feat(releases): add cve
Browse files Browse the repository at this point in the history
  • Loading branch information
abhinandan13jan committed Mar 12, 2024
1 parent fb85c3d commit ca9d62b
Show file tree
Hide file tree
Showing 13 changed files with 429 additions and 199 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,39 @@ import { Formik } from 'formik';
import * as yup from 'yup';
import { ComponentProps } from '../../../../modal/createModalLauncher';
import BugFormContent from './BugFormContent';
import CVEFormContent from './CVEFormContent';
import { dateFormat } from './UploadDate';

type AddBugModalProps = ComponentProps & {
export enum IssueType {
BUG = 'bug',
CVE = 'cve',
}

type AddIssueModalProps = ComponentProps & {
bugArrayHelper: (values) => void;
issueType: IssueType;
};

const bugFormSchema = yup.object({
const BugFormSchema = yup.object({
issueKey: yup.string().required('Required'),
url: yup.string().required('Required'),
});

export const AddBugModal: React.FC<React.PropsWithChildren<AddBugModalProps>> = ({
const CVEFormSchema = yup.object({
issueKey: yup.string().required('Required'),
});

export const AddIssueModal: React.FC<React.PropsWithChildren<AddIssueModalProps>> = ({
onClose,
bugArrayHelper,
issueType,
}) => {
const [isModalOpen, setIsModalOpen] = React.useState(false);
const [isTimePickerOpen, setIsTimePickerOpen] = React.useState(false);
const dateRef = React.useRef(null);

const isBug = issueType === IssueType.BUG;

const handleModalToggle = () => {
setIsModalOpen(!isModalOpen);
};
Expand All @@ -47,22 +62,36 @@ export const AddBugModal: React.FC<React.PropsWithChildren<AddBugModalProps>> =
return (
<>
<Button variant="primary" onClick={handleModalToggle}>
Add a bug
{isBug ? 'Add a bug' : 'Add a CVE'}
</Button>
<Modal
id="date-time-picker-modal"
variant={ModalVariant.medium}
title="Add a bug fix"
title={isBug ? 'Add a bug fix' : 'Add a CVE'}
isOpen={isModalOpen}
onEscapePress={onEscapePress}
onClose={handleModalToggle}
>
<Formik
onSubmit={setValues}
initialValues={{ issueKey: '', url: '', summary: '', uploadDate: '' }}
validationSchema={bugFormSchema}
initialValues={
isBug
? { issueKey: '', url: '', summary: '', uploadDate: dateFormat(new Date()) }
: {
cveKey: '',
components: [''],
url: '',
summary: '',
uploadDate: dateFormat(new Date()),
}
}
validationSchema={isBug ? BugFormSchema : CVEFormSchema}
>
<BugFormContent modalToggle={handleModalToggle} />
{isBug ? (
<BugFormContent modalToggle={handleModalToggle} />
) : (
<CVEFormContent modalToggle={handleModalToggle} />
)}
</Formik>
</Modal>
</>
Expand Down
Loading

0 comments on commit ca9d62b

Please sign in to comment.